Skip to content

Commit

Permalink
Merge pull request #2 from samvera-labs/add-test-case
Browse files Browse the repository at this point in the history
🐛 Fix "undefined method `size' for nil" error
  • Loading branch information
jeremyf authored Nov 15, 2023
2 parents 4ac2197 + 12d541c commit 614209d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/order_already.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ module InputOrderSerializer
# @param arr [Array]
# @return [Array]
def self.deserialize(arr)
return [] if arr&.empty?
arr = arr&.compact || []
arr = arr.reject(&:empty?)
return [] if arr.empty?

sort(arr).map do |val|
get_value(val)
Expand All @@ -95,7 +97,9 @@ def self.deserialize(arr)
# @param arr [Array]
# @return [Array]
def self.serialize(arr)
return [] if arr&.empty?
arr = arr&.compact || []
arr = arr.reject(&:empty?)
return [] if arr.empty?

arr = sanitize(arr)

Expand All @@ -108,6 +112,8 @@ def self.serialize(arr)
end

def self.sanitize(values)
return if values.nil?

full_sanitizer = Rails::Html::FullSanitizer.new
sanitized_values = Array.new(values.size, '')
empty = TOKEN_DELIMITER * 3
Expand Down
25 changes: 25 additions & 0 deletions spec/order_already_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,31 @@ def creators=(values)
expect(record.instance_variable_get(:@creators)).to eq(creators)
end

context "with setting the value to nil" do
let(:creators) { nil }

it "returns nil" do
expect(record.creators).to eq([])
end
end

context "with setting the value to an array with an empty string" do
let(:creators) { [''] }

it "returns nil" do
expect(record.creators).to eq([])
end
end

context "with setting the value to an array with a nil value" do
let(:creators) { [nil] }

it "returns nil" do
expect(record.creators).to eq([])
end
end


context "with what looks like encoding" do
let(:creators) { ["2~Clotho", "1~Lachesis", "0~Atropos"] }

Expand Down

0 comments on commit 614209d

Please sign in to comment.