Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RDF lists should be able to accept nested attributes as a hash #173

Merged
merged 1 commit into from
Aug 1, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/active_fedora/rdf_list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ def assign_nested_attributes_for_collection_association(association_name, attrib
# TODO
#check_record_limit!(options[:limit], attributes_collection)

if attributes_collection.is_a?(Hash) || attributes_collection.is_a?(String)
attributes_collection = [attributes_collection]
if attributes_collection.is_a?(Hash)# || attributes_collection.is_a?(String)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like some cruft may be hanging around here.

attributes_collection = attributes_collection.values
end

association = self.send(association_name)
Expand Down
35 changes: 29 additions & 6 deletions spec/integration/rdf_nested_attributes_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,24 @@ class PersonalName
accepts_nested_attributes_for :elementList, :extraProperty
end
class ElementList
include ActiveFedora::RdfObject
include ActiveFedora::RdfList
rdf_type DummyMADS.elementList
map_predicates do |map|
map.topicElement(in: DummyMADS, to: "TopicElement")
map.topicElement(in: DummyMADS, to: "TopicElement", :class_name => "MadsTopicElement")
map.temporalElement(in: DummyMADS, to: "TemporalElement")
map.fullNameElement(in: DummyMADS, to: "FullNameElement")
map.dateNameElement(in: DummyMADS, to: "DateNameElement")
map.nameElement(in: DummyMADS, to: "NameElement")
map.elementValue(in: DummyMADS)
end
accepts_nested_attributes_for :topicElement
end
class MadsTopicElement
include ActiveFedora::RdfObject
rdf_type DummyMADS.TopicElement
map_predicates do |map|
map.elementValue(in: DummyMADS)
end
end
end
end
Expand All @@ -74,13 +82,13 @@ class ElementList
'0' =>
{
elementList_attributes: [{
topicElement:"Cosmology"
topicElement_attributes: [{elementValue:"Cosmology"}]
}]
},
'1' =>
{
elementList_attributes: [{
topicElement:"Quantum Behavior"
topicElement_attributes: {'0' => {elementValue:"Quantum Behavior"}}
}]
}
},
Expand All @@ -97,6 +105,21 @@ class ElementList
}
end

describe "on lists" do
subject { ComplexRDFDatastream::PersonalName.new(RDF::Graph.new) }
it "should accept a hash" do
subject.elementList_attributes = [{ topicElement_attributes: {'0' => { elementValue:"Quantum Behavior" }, '1' => { elementValue:"Wave Function" }}}]
subject.elementList.first[0].elementValue.should == ["Quantum Behavior"]
subject.elementList.first[1].elementValue.should == ["Wave Function"]

end
it "should accept an array" do
subject.elementList_attributes = [{ topicElement_attributes: [{ elementValue:"Quantum Behavior" }, { elementValue:"Wave Function" }]}]
subject.elementList.first[0].elementValue.should == ["Quantum Behavior"]
subject.elementList.first[1].elementValue.should == ["Wave Function"]
end
end

it "should create nested objects" do
# Replace the graph's contents with the Hash
subject.attributes = params[:myResource]
Expand All @@ -110,8 +133,8 @@ class ElementList
# elem_list = topic.elementList.build
# elem_list.fullNameElement = 'Cosmology'

subject.topic.first.elementList.first.topicElement.should == ["Cosmology"]
subject.topic[1].elementList.first.topicElement.should == ["Quantum Behavior"]
subject.topic[0].elementList.first[0].elementValue.should == ["Cosmology"]
subject.topic[1].elementList.first[0].elementValue.should == ["Quantum Behavior"]
subject.personalName.first.elementList.first.fullNameElement.should == ["Jefferson, Thomas"]
subject.personalName.first.elementList.first.dateNameElement.should == ["1743-1826"]
end
Expand Down