Skip to content

Commit

Permalink
fix issue #12 -- empty (single-value) profile attributes should be ni…
Browse files Browse the repository at this point in the history
…l rather than an empty string..
  • Loading branch information
Chris Beer committed Mar 21, 2012
1 parent e0d0296 commit 963aac9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
6 changes: 3 additions & 3 deletions lib/rubydora/datastream.rb
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,9 @@ def profile_xml_to_hash profile_xml
sum[node.name] ||= []
sum[node.name] << node.text
sum
end
h.select { |key, value| value.length == 1 }.each do |key, value|
h[key] = value.first
end.reject { |key, values| values.empty? }
h.select { |key, values| values.length == 1 }.each do |key, values|
h[key] = values.reject { |x| x.empty? }.first
end

h['dsSize'] &&= h['dsSize'].to_i rescue h['dsSize']
Expand Down
7 changes: 4 additions & 3 deletions lib/rubydora/digital_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,11 @@ def profile
end

sum
end
h.select { |key, value| value.length == 1 }.each do |key, value|
end.reject { |key, values| values.empty? }

h.select { |key, values| values.length == 1 }.each do |key, values|
next if key == "objModels"
h[key] = value.first
h[key] = values.reject { |x| x.empty? }.first
end
@new = false

Expand Down
4 changes: 4 additions & 0 deletions spec/lib/digital_object_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@
h = @object.profile

expect { h['asdf'] = 'asdf' }.to raise_error
end

it "should return nil for empty profile fields" do
@mock_repository.should_receive(:object).with(:pid => 'pid').and_return("<objectProfile><a></a></objectProfile>")
@object.profile['a'].should be_nil
end
end

Expand Down

0 comments on commit 963aac9

Please sign in to comment.