active-fedora 6.8.0 → 7.0.0.pre1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +15 -5
- data/CONTRIBUTING.md +2 -0
- data/Gemfile +0 -2
- data/History.txt +2 -32
- data/README.md +143 -0
- data/Rakefile +5 -7
- data/active-fedora.gemspec +9 -9
- data/gemfiles/rails3.gemfile +11 -0
- data/gemfiles/rails4.gemfile +10 -0
- data/lib/active_fedora.rb +31 -4
- data/lib/active_fedora/association_relation.rb +18 -0
- data/lib/active_fedora/associations.rb +38 -171
- data/lib/active_fedora/associations/association.rb +163 -0
- data/lib/active_fedora/associations/association_scope.rb +39 -0
- data/lib/active_fedora/associations/belongs_to_association.rb +47 -25
- data/lib/active_fedora/associations/builder/association.rb +55 -0
- data/lib/active_fedora/associations/builder/belongs_to.rb +100 -0
- data/lib/active_fedora/associations/builder/collection_association.rb +56 -0
- data/lib/active_fedora/associations/builder/has_and_belongs_to_many.rb +30 -0
- data/lib/active_fedora/associations/builder/has_many.rb +63 -0
- data/lib/active_fedora/associations/builder/singular_association.rb +32 -0
- data/lib/active_fedora/associations/{association_collection.rb → collection_association.rb} +203 -53
- data/lib/active_fedora/associations/collection_proxy.rb +862 -0
- data/lib/active_fedora/associations/has_and_belongs_to_many_association.rb +35 -25
- data/lib/active_fedora/associations/has_many_association.rb +36 -11
- data/lib/active_fedora/associations/singular_association.rb +62 -0
- data/lib/active_fedora/attributes.rb +43 -139
- data/lib/active_fedora/autosave_association.rb +317 -0
- data/lib/active_fedora/base.rb +10 -327
- data/lib/active_fedora/callbacks.rb +1 -3
- data/lib/active_fedora/content_model.rb +16 -0
- data/lib/active_fedora/core.rb +151 -0
- data/lib/active_fedora/datastream_attribute.rb +76 -0
- data/lib/active_fedora/datastream_hash.rb +8 -13
- data/lib/active_fedora/datastreams.rb +39 -26
- data/lib/active_fedora/digital_object.rb +2 -2
- data/lib/active_fedora/fedora_attributes.rb +45 -0
- data/lib/active_fedora/fixture_loader.rb +1 -1
- data/lib/active_fedora/indexing.rb +6 -1
- data/lib/active_fedora/model.rb +0 -17
- data/lib/active_fedora/nested_attributes.rb +2 -2
- data/lib/active_fedora/null_relation.rb +7 -0
- data/lib/active_fedora/om_datastream.rb +3 -4
- data/lib/active_fedora/persistence.rb +41 -29
- data/lib/active_fedora/querying.rb +2 -163
- data/lib/active_fedora/rdf.rb +1 -0
- data/lib/active_fedora/rdf/indexing.rb +67 -0
- data/lib/active_fedora/rdf_datastream.rb +2 -50
- data/lib/active_fedora/rdf_node.rb +12 -7
- data/lib/active_fedora/rdf_node/term_proxy.rb +30 -21
- data/lib/active_fedora/rdfxml_rdf_datastream.rb +1 -1
- data/lib/active_fedora/reflection.rb +163 -20
- data/lib/active_fedora/relation.rb +33 -130
- data/lib/active_fedora/relation/calculations.rb +19 -0
- data/lib/active_fedora/relation/delegation.rb +22 -0
- data/lib/active_fedora/relation/finder_methods.rb +247 -0
- data/lib/active_fedora/relation/merger.rb +22 -0
- data/lib/active_fedora/relation/query_methods.rb +58 -0
- data/lib/active_fedora/relation/spawn_methods.rb +46 -0
- data/lib/active_fedora/relationship_graph.rb +0 -2
- data/lib/active_fedora/rels_ext_datastream.rb +1 -4
- data/lib/active_fedora/rubydora_connection.rb +1 -1
- data/lib/active_fedora/scoping.rb +20 -0
- data/lib/active_fedora/scoping/default.rb +38 -0
- data/lib/active_fedora/scoping/named.rb +32 -0
- data/lib/active_fedora/semantic_node.rb +54 -106
- data/lib/active_fedora/serialization.rb +19 -0
- data/lib/active_fedora/sharding.rb +58 -0
- data/lib/active_fedora/solr_digital_object.rb +15 -5
- data/lib/active_fedora/solr_instance_loader.rb +1 -1
- data/lib/active_fedora/solr_service.rb +1 -1
- data/lib/active_fedora/unsaved_digital_object.rb +6 -4
- data/lib/active_fedora/version.rb +1 -1
- data/lib/tasks/active_fedora.rake +3 -0
- data/lib/tasks/active_fedora_dev.rake +6 -5
- data/spec/config_helper.rb +14 -14
- data/spec/integration/associations_spec.rb +168 -455
- data/spec/integration/attributes_spec.rb +12 -11
- data/spec/integration/auditable_spec.rb +11 -11
- data/spec/integration/autosave_association_spec.rb +25 -0
- data/spec/integration/base_spec.rb +163 -163
- data/spec/integration/belongs_to_association_spec.rb +166 -0
- data/spec/integration/bug_spec.rb +7 -7
- data/spec/integration/collection_association_spec.rb +58 -0
- data/spec/integration/complex_rdf_datastream_spec.rb +88 -88
- data/spec/integration/datastream_collections_spec.rb +69 -69
- data/spec/integration/datastream_spec.rb +43 -43
- data/spec/integration/datastreams_spec.rb +63 -63
- data/spec/integration/delete_all_spec.rb +46 -39
- data/spec/integration/fedora_solr_sync_spec.rb +5 -5
- data/spec/integration/field_to_solr_name_spec.rb +34 -0
- data/spec/integration/full_featured_model_spec.rb +100 -101
- data/spec/integration/has_and_belongs_to_many_associations_spec.rb +341 -0
- data/spec/integration/has_many_associations_spec.rb +172 -24
- data/spec/integration/json_serialization_spec.rb +31 -0
- data/spec/integration/load_from_solr_spec.rb +48 -0
- data/spec/integration/model_spec.rb +35 -40
- data/spec/integration/nested_attribute_spec.rb +42 -43
- data/spec/integration/ntriples_datastream_spec.rb +131 -113
- data/spec/integration/om_datastream_spec.rb +67 -67
- data/spec/integration/persistence_spec.rb +7 -7
- data/spec/integration/rdf_nested_attributes_spec.rb +56 -56
- data/spec/integration/relation_delegation_spec.rb +26 -25
- data/spec/integration/relation_spec.rb +42 -0
- data/spec/integration/rels_ext_datastream_spec.rb +20 -20
- data/spec/integration/scoped_query_spec.rb +61 -51
- data/spec/integration/solr_instance_loader_spec.rb +5 -5
- data/spec/integration/solr_service_spec.rb +46 -46
- data/spec/samples/hydra-mods_article_datastream.rb +334 -334
- data/spec/samples/hydra-rights_metadata_datastream.rb +57 -57
- data/spec/samples/marpa-dc_datastream.rb +17 -17
- data/spec/samples/models/audio_record.rb +16 -16
- data/spec/samples/models/image.rb +2 -2
- data/spec/samples/models/mods_article.rb +5 -5
- data/spec/samples/models/oral_history.rb +18 -18
- data/spec/samples/models/seminar.rb +24 -24
- data/spec/samples/models/seminar_audio_file.rb +17 -17
- data/spec/samples/oral_history_sample_model.rb +21 -21
- data/spec/samples/special_thing.rb +14 -14
- data/spec/spec_helper.rb +11 -7
- data/spec/support/an_active_model.rb +2 -8
- data/spec/support/freeze_mocks.rb +12 -0
- data/spec/support/mock_fedora.rb +17 -16
- data/spec/unit/active_fedora_spec.rb +58 -60
- data/spec/unit/attributes_spec.rb +314 -0
- data/spec/unit/base_active_model_spec.rb +28 -27
- data/spec/unit/base_cma_spec.rb +5 -5
- data/spec/unit/base_datastream_management_spec.rb +27 -27
- data/spec/unit/base_extra_spec.rb +76 -48
- data/spec/unit/base_spec.rb +277 -348
- data/spec/unit/callback_spec.rb +18 -19
- data/spec/unit/code_configurator_spec.rb +17 -17
- data/spec/unit/config_spec.rb +8 -16
- data/spec/unit/content_model_spec.rb +79 -60
- data/spec/unit/datastream_collections_spec.rb +229 -229
- data/spec/unit/datastream_spec.rb +51 -63
- data/spec/unit/datastreams_spec.rb +87 -87
- data/spec/unit/file_configurator_spec.rb +217 -217
- data/spec/unit/has_and_belongs_to_many_collection_spec.rb +44 -25
- data/spec/unit/has_many_collection_spec.rb +26 -8
- data/spec/unit/inheritance_spec.rb +13 -12
- data/spec/unit/model_spec.rb +39 -45
- data/spec/unit/nom_datastream_spec.rb +15 -15
- data/spec/unit/ntriples_datastream_spec.rb +123 -118
- data/spec/unit/om_datastream_spec.rb +227 -233
- data/spec/unit/persistence_spec.rb +34 -15
- data/spec/unit/predicates_spec.rb +73 -73
- data/spec/unit/property_spec.rb +17 -9
- data/spec/unit/qualified_dublin_core_datastream_spec.rb +33 -33
- data/spec/unit/query_spec.rb +222 -198
- data/spec/unit/rdf_datastream_spec.rb +21 -28
- data/spec/unit/rdf_list_nested_attributes_spec.rb +34 -34
- data/spec/unit/rdf_list_spec.rb +65 -64
- data/spec/unit/rdf_node_spec.rb +7 -7
- data/spec/unit/rdf_xml_writer_spec.rb +10 -10
- data/spec/unit/rdfxml_rdf_datastream_spec.rb +27 -27
- data/spec/unit/relationship_graph_spec.rb +51 -51
- data/spec/unit/rels_ext_datastream_spec.rb +68 -74
- data/spec/unit/rspec_matchers/belong_to_associated_active_fedora_object_matcher_spec.rb +15 -15
- data/spec/unit/rspec_matchers/have_many_associated_active_fedora_objects_matcher_spec.rb +15 -15
- data/spec/unit/rspec_matchers/have_predicate_matcher_spec.rb +15 -15
- data/spec/unit/rspec_matchers/match_fedora_datastream_matcher_spec.rb +12 -12
- data/spec/unit/rubydora_connection_spec.rb +5 -5
- data/spec/unit/semantic_node_spec.rb +48 -107
- data/spec/unit/serializers_spec.rb +4 -4
- data/spec/unit/service_definitions_spec.rb +26 -26
- data/spec/unit/simple_datastream_spec.rb +17 -17
- data/spec/unit/solr_config_options_spec.rb +29 -28
- data/spec/unit/solr_digital_object_spec.rb +17 -25
- data/spec/unit/solr_service_spec.rb +95 -82
- data/spec/unit/unsaved_digital_object_spec.rb +24 -23
- data/spec/unit/validations_spec.rb +21 -21
- metadata +110 -159
- data/.rspec +0 -1
- data/.rubocop.yml +0 -1
- data/.rubocop_todo.yml +0 -938
- data/CONSOLE_GETTING_STARTED.textile +0 -1
- data/NOKOGIRI_DATASTREAMS.textile +0 -1
- data/README.textile +0 -116
- data/lib/active_fedora/associations/association_proxy.rb +0 -178
- data/lib/active_fedora/delegating.rb +0 -72
- data/lib/active_fedora/nokogiri_datastream.rb +0 -11
- data/spec/integration/delegating_spec.rb +0 -59
- data/spec/rails3_test_app/.gitignore +0 -4
- data/spec/rails3_test_app/.rspec +0 -1
- data/spec/rails3_test_app/Gemfile +0 -40
- data/spec/rails3_test_app/Rakefile +0 -7
- data/spec/rails3_test_app/app/controllers/application_controller.rb +0 -3
- data/spec/rails3_test_app/app/helpers/application_helper.rb +0 -2
- data/spec/rails3_test_app/app/views/layouts/application.html.erb +0 -14
- data/spec/rails3_test_app/config.ru +0 -4
- data/spec/rails3_test_app/config/application.rb +0 -42
- data/spec/rails3_test_app/config/boot.rb +0 -6
- data/spec/rails3_test_app/config/database.yml +0 -22
- data/spec/rails3_test_app/config/environment.rb +0 -5
- data/spec/rails3_test_app/config/environments/development.rb +0 -25
- data/spec/rails3_test_app/config/environments/production.rb +0 -49
- data/spec/rails3_test_app/config/environments/test.rb +0 -35
- data/spec/rails3_test_app/config/initializers/backtrace_silencers.rb +0 -7
- data/spec/rails3_test_app/config/initializers/inflections.rb +0 -10
- data/spec/rails3_test_app/config/initializers/mime_types.rb +0 -5
- data/spec/rails3_test_app/config/initializers/secret_token.rb +0 -7
- data/spec/rails3_test_app/config/initializers/session_store.rb +0 -8
- data/spec/rails3_test_app/config/locales/en.yml +0 -5
- data/spec/rails3_test_app/config/routes.rb +0 -58
- data/spec/rails3_test_app/db/seeds.rb +0 -7
- data/spec/rails3_test_app/run_tests +0 -3
- data/spec/rails3_test_app/script/rails +0 -6
- data/spec/rails3_test_app/spec/spec_helper.rb +0 -27
- data/spec/rails3_test_app/spec/unit/rails_3_init.rb +0 -15
- data/spec/unit/association_proxy_spec.rb +0 -12
- data/spec/unit/base_delegate_spec.rb +0 -197
- data/spec/unit/base_delegate_to_spec.rb +0 -73
@@ -0,0 +1,314 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ActiveFedora::Base do
|
4
|
+
before :all do
|
5
|
+
class BarStream2 < ActiveFedora::OmDatastream
|
6
|
+
set_terminology do |t|
|
7
|
+
t.root(:path=>"animals", :xmlns=>"urn:zoobar")
|
8
|
+
t.waterfowl do
|
9
|
+
t.ducks do
|
10
|
+
t.duck
|
11
|
+
end
|
12
|
+
end
|
13
|
+
t.donkey()
|
14
|
+
t.cow()
|
15
|
+
t.pig()
|
16
|
+
t.horse()
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.xml_template
|
20
|
+
Nokogiri::XML::Document.parse '<animals xmlns="urn:zoobar">
|
21
|
+
<waterfowl>
|
22
|
+
<ducks>
|
23
|
+
<duck/>
|
24
|
+
</ducks>
|
25
|
+
</waterfowl>
|
26
|
+
<cow></cow>
|
27
|
+
</animals>'
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
after :all do
|
32
|
+
Object.send(:remove_const, :BarStream2)
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "first level delegation" do
|
36
|
+
before :all do
|
37
|
+
class BarHistory2 < ActiveFedora::Base
|
38
|
+
has_metadata :type=>ActiveFedora::SimpleDatastream, :name=>"someData" do |m|
|
39
|
+
m.field "fubar", :string
|
40
|
+
m.field "bandana", :string
|
41
|
+
m.field "swank", :text
|
42
|
+
end
|
43
|
+
has_metadata :type=>ActiveFedora::SimpleDatastream, :name=>"withText" do |m|
|
44
|
+
m.field "fubar", :text
|
45
|
+
end
|
46
|
+
has_metadata :type=>ActiveFedora::SimpleDatastream, :name=>"withText2", :label=>"withLabel" do |m|
|
47
|
+
m.field "fubar", :text
|
48
|
+
end
|
49
|
+
|
50
|
+
has_metadata :type=>BarStream2, :name=>"xmlish"
|
51
|
+
has_attributes :cow, datastream: 'xmlish' # for testing the default value of multiple
|
52
|
+
has_attributes :fubar, datastream: 'withText', multiple: true # test alternate datastream
|
53
|
+
has_attributes :pig, datastream: 'xmlish', multiple: false
|
54
|
+
has_attributes :horse, datastream: 'xmlish', multiple: true
|
55
|
+
has_attributes :duck, datastream: 'xmlish', :at=>[:waterfowl, :ducks, :duck], multiple: true
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
after :all do
|
60
|
+
Object.send(:remove_const, :BarHistory2)
|
61
|
+
end
|
62
|
+
|
63
|
+
subject { BarHistory2.new }
|
64
|
+
|
65
|
+
describe "inspect" do
|
66
|
+
it "should show the attributes" do
|
67
|
+
expect(subject.inspect).to eq "#<BarHistory2 pid: nil, cow: \"\", fubar: [], pig: nil, horse: [], duck: [\"\"]>"
|
68
|
+
end
|
69
|
+
describe "with a pid" do
|
70
|
+
before { subject.stub(pid: 'test:123') }
|
71
|
+
it "should show a pid" do
|
72
|
+
expect(subject.inspect).to eq "#<BarHistory2 pid: \"test:123\", cow: \"\", fubar: [], pig: nil, horse: [], duck: [\"\"]>"
|
73
|
+
end
|
74
|
+
end
|
75
|
+
describe "with no attributes" do
|
76
|
+
subject { ActiveFedora::Base.new }
|
77
|
+
it "should show a pid" do
|
78
|
+
expect(subject.inspect).to eq "#<ActiveFedora::Base pid: nil>"
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
describe "with relationships" do
|
83
|
+
before do
|
84
|
+
class BarHistory3 < BarHistory2
|
85
|
+
belongs_to :library, property: :has_constituent, class_name: 'BarHistory2'
|
86
|
+
end
|
87
|
+
subject.library = library
|
88
|
+
end
|
89
|
+
let (:library) { BarHistory2.create }
|
90
|
+
subject {BarHistory3.new}
|
91
|
+
after do
|
92
|
+
Object.send(:remove_const, :BarHistory3)
|
93
|
+
end
|
94
|
+
it "should show the library_id" do
|
95
|
+
expect(subject.inspect).to eq "#<BarHistory3 pid: nil, cow: \"\", fubar: [], pig: nil, horse: [], duck: [\"\"], library_id: \"#{library.pid}\">"
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
|
101
|
+
|
102
|
+
it "should reveal the unique properties" do
|
103
|
+
BarHistory2.unique?(:horse).should be_false
|
104
|
+
BarHistory2.unique?(:pig).should be_true
|
105
|
+
BarHistory2.unique?(:cow).should be_true
|
106
|
+
end
|
107
|
+
|
108
|
+
it "should save a delegated property uniquely" do
|
109
|
+
subject.fubar="Quack"
|
110
|
+
subject.fubar.should == ["Quack"]
|
111
|
+
subject.withText.get_values(:fubar).first.should == 'Quack'
|
112
|
+
subject.cow="Low"
|
113
|
+
subject.cow.should == "Low"
|
114
|
+
subject.xmlish.term_values(:cow).first.should == 'Low'
|
115
|
+
|
116
|
+
subject.pig="Oink"
|
117
|
+
subject.pig.should == "Oink"
|
118
|
+
end
|
119
|
+
|
120
|
+
it "should allow passing parameters to the delegate accessor" do
|
121
|
+
subject.cow=["one", "two"]
|
122
|
+
subject.cow(1).should == 'two'
|
123
|
+
end
|
124
|
+
|
125
|
+
it "should return a single value if not marked as multiple" do
|
126
|
+
subject.cow=["one", "two"]
|
127
|
+
subject.cow.should == "one"
|
128
|
+
end
|
129
|
+
|
130
|
+
it "should return an array if marked as multiple" do
|
131
|
+
subject.horse=["neigh", "whinny"]
|
132
|
+
subject.horse.should == ["neigh", "whinny"]
|
133
|
+
end
|
134
|
+
|
135
|
+
it "should be able to delegate deeply into the terminology" do
|
136
|
+
subject.duck=["Quack", "Peep"]
|
137
|
+
subject.duck.should == ["Quack", "Peep"]
|
138
|
+
end
|
139
|
+
|
140
|
+
it "should be able to track change status" do
|
141
|
+
subject.fubar_changed?.should be_false
|
142
|
+
subject.fubar = "Meow"
|
143
|
+
subject.fubar_changed?.should be_true
|
144
|
+
end
|
145
|
+
|
146
|
+
describe "array getters and setters" do
|
147
|
+
it "should accept symbol keys" do
|
148
|
+
subject[:duck]= ["Cluck", "Gobble"]
|
149
|
+
subject[:duck].should == ["Cluck", "Gobble"]
|
150
|
+
end
|
151
|
+
|
152
|
+
it "should accept string keys" do
|
153
|
+
subject['duck']= ["Cluck", "Gobble"]
|
154
|
+
subject['duck'].should == ["Cluck", "Gobble"]
|
155
|
+
end
|
156
|
+
|
157
|
+
it "should raise an error on the reader when the field isn't delegated" do
|
158
|
+
expect {subject['goose'] }.to raise_error ActiveFedora::UnknownAttributeError, "BarHistory2 does not have an attribute `goose'"
|
159
|
+
end
|
160
|
+
|
161
|
+
it "should raise an error on the setter when the field isn't delegated" do
|
162
|
+
expect {subject['goose']="honk" }.to raise_error ActiveFedora::UnknownAttributeError, "BarHistory2 does not have an attribute `goose'"
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
describe "attributes=" do
|
167
|
+
it "should raise an error on an invalid attribute" do
|
168
|
+
expect {subject.attributes = {'goose'=>"honk" }}.to raise_error ActiveFedora::UnknownAttributeError, "BarHistory2 does not have an attribute `goose'"
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
describe "attributes" do
|
173
|
+
let(:vals) { {'cow'=>["moo"], 'pig' => ['oink'], 'horse' =>['neigh'], "fubar"=>[], 'duck'=>['quack'] } }
|
174
|
+
before { subject.attributes = vals }
|
175
|
+
it "should return a hash" do
|
176
|
+
expect(subject.attributes).to eq(vals.merge('id' => nil))
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
end
|
181
|
+
|
182
|
+
describe "with a superclass" do
|
183
|
+
before :all do
|
184
|
+
class BarHistory2 < ActiveFedora::Base
|
185
|
+
has_metadata 'xmlish', :type=>BarStream2
|
186
|
+
has_attributes :donkey, :cow, datastream: 'xmlish', multiple: true
|
187
|
+
end
|
188
|
+
class BarHistory3 < BarHistory2
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
after :all do
|
193
|
+
Object.send(:remove_const, :BarHistory3)
|
194
|
+
Object.send(:remove_const, :BarHistory2)
|
195
|
+
end
|
196
|
+
|
197
|
+
subject { BarHistory3.new }
|
198
|
+
|
199
|
+
it "should be able to delegate deeply into the terminology" do
|
200
|
+
subject.donkey=["Bray", "Hee-haw"]
|
201
|
+
subject.donkey.should == ["Bray", "Hee-haw"]
|
202
|
+
end
|
203
|
+
|
204
|
+
it "should be able to track change status" do
|
205
|
+
subject.cow_changed?.should be_false
|
206
|
+
subject.cow = ["Moo"]
|
207
|
+
subject.cow_changed?.should be_true
|
208
|
+
end
|
209
|
+
end
|
210
|
+
|
211
|
+
describe "with a RDF datastream" do
|
212
|
+
before :all do
|
213
|
+
class BarRdfDatastream < ActiveFedora::NtriplesRDFDatastream
|
214
|
+
map_predicates do |map|
|
215
|
+
map.title(in: RDF::DC)
|
216
|
+
map.description(in: RDF::DC, multivalue: false)
|
217
|
+
end
|
218
|
+
end
|
219
|
+
class BarHistory4 < ActiveFedora::Base
|
220
|
+
has_metadata 'rdfish', :type=>BarRdfDatastream
|
221
|
+
has_attributes :title, :description, datastream: 'rdfish', multiple: true
|
222
|
+
end
|
223
|
+
end
|
224
|
+
|
225
|
+
after :all do
|
226
|
+
Object.send(:remove_const, :BarHistory4)
|
227
|
+
Object.send(:remove_const, :BarRdfDatastream)
|
228
|
+
end
|
229
|
+
|
230
|
+
subject { BarHistory4.new }
|
231
|
+
|
232
|
+
describe "with a multivalued field" do
|
233
|
+
it "should be able to track change status" do
|
234
|
+
subject.title_changed?.should be_false
|
235
|
+
subject.title = ["Title1", "Title2"]
|
236
|
+
subject.title_changed?.should be_true
|
237
|
+
end
|
238
|
+
end
|
239
|
+
describe "with a single-valued field" do
|
240
|
+
it "should be able to track change status" do
|
241
|
+
subject.description_changed?.should be_false
|
242
|
+
subject.description = "A brief description"
|
243
|
+
subject.description_changed?.should be_true
|
244
|
+
end
|
245
|
+
end
|
246
|
+
end
|
247
|
+
|
248
|
+
describe "without a datastream" do
|
249
|
+
before :all do
|
250
|
+
class BarHistory4 < ActiveFedora::Base
|
251
|
+
end
|
252
|
+
end
|
253
|
+
|
254
|
+
after :all do
|
255
|
+
Object.send(:remove_const, :BarHistory4)
|
256
|
+
end
|
257
|
+
|
258
|
+
subject { BarHistory4}
|
259
|
+
|
260
|
+
it "should raise an error" do
|
261
|
+
expect {subject.has_attributes :title, :description, multiple: true}.to raise_error
|
262
|
+
end
|
263
|
+
end
|
264
|
+
|
265
|
+
describe "when an unknown datastream is specified" do
|
266
|
+
before :all do
|
267
|
+
class BarHistory4 < ActiveFedora::Base
|
268
|
+
has_attributes :description, datastream: 'rdfish', multiple: true
|
269
|
+
end
|
270
|
+
end
|
271
|
+
|
272
|
+
after :all do
|
273
|
+
Object.send(:remove_const, :BarHistory4)
|
274
|
+
end
|
275
|
+
|
276
|
+
subject { BarHistory4.new }
|
277
|
+
|
278
|
+
it "should raise an error on get" do
|
279
|
+
expect {subject.description}.to raise_error(ArgumentError, "Undefined datastream id: `rdfish' in has_attributes")
|
280
|
+
end
|
281
|
+
|
282
|
+
it "should raise an error on set" do
|
283
|
+
expect {subject.description = 'Neat'}.to raise_error(ArgumentError, "Undefined datastream id: `rdfish' in has_attributes")
|
284
|
+
end
|
285
|
+
end
|
286
|
+
|
287
|
+
describe "when a datastream is specified as a symbol" do
|
288
|
+
before :all do
|
289
|
+
class BarRdfDatastream < ActiveFedora::NtriplesRDFDatastream
|
290
|
+
map_predicates do |map|
|
291
|
+
map.title(in: RDF::DC)
|
292
|
+
map.description(in: RDF::DC)
|
293
|
+
end
|
294
|
+
end
|
295
|
+
class BarHistory4 < ActiveFedora::Base
|
296
|
+
has_metadata 'rdfish', :type=>BarRdfDatastream
|
297
|
+
has_attributes :description, datastream: :rdfish
|
298
|
+
end
|
299
|
+
end
|
300
|
+
|
301
|
+
after :all do
|
302
|
+
Object.send(:remove_const, :BarHistory4)
|
303
|
+
Object.send(:remove_const, :BarRdfDatastream)
|
304
|
+
end
|
305
|
+
|
306
|
+
subject { BarHistory4.new(description: 'test1') }
|
307
|
+
|
308
|
+
it "should be able to access the attributes" do
|
309
|
+
expect(subject.description).to eq 'test1'
|
310
|
+
end
|
311
|
+
end
|
312
|
+
end
|
313
|
+
|
314
|
+
|
@@ -1,54 +1,54 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe ActiveFedora::Base do
|
4
|
-
describe
|
5
|
-
class BarStream < ActiveFedora::OmDatastream
|
4
|
+
describe "active model methods" do
|
5
|
+
class BarStream < ActiveFedora::OmDatastream
|
6
6
|
set_terminology do |t|
|
7
|
-
t.root(:path
|
7
|
+
t.root(:path=>"first", :xmlns=>"urn:foobar")
|
8
8
|
t.duck()
|
9
9
|
end
|
10
10
|
|
11
11
|
def self.xml_template
|
12
|
-
Nokogiri::XML::Document.parse '<first xmlns="urn:foobar">
|
12
|
+
Nokogiri::XML::Document.parse '<first xmlns="urn:foobar">
|
13
13
|
<duck></duck>
|
14
14
|
</first>'
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
18
|
class BarHistory < ActiveFedora::Base
|
19
|
-
has_metadata :type
|
20
|
-
m.field
|
21
|
-
m.field
|
19
|
+
has_metadata :type=>ActiveFedora::SimpleDatastream, :name=>"someData" do |m|
|
20
|
+
m.field "fubar", :string
|
21
|
+
m.field "swank", :text
|
22
22
|
end
|
23
|
-
has_metadata :type
|
24
|
-
m.field
|
25
|
-
end
|
26
|
-
has_metadata :type => ActiveFedora::SimpleDatastream, :name => 'withText2', :label => 'withLabel' do |m|
|
27
|
-
m.field 'fubar', :text
|
23
|
+
has_metadata :type=>ActiveFedora::SimpleDatastream, :name=>"withText" do |m|
|
24
|
+
m.field "fubar", :text
|
28
25
|
end
|
26
|
+
has_metadata :type=>ActiveFedora::SimpleDatastream, :name=>"withText2", :label=>"withLabel" do |m|
|
27
|
+
m.field "fubar", :text
|
28
|
+
end
|
29
29
|
|
30
|
-
has_metadata :type
|
31
|
-
|
32
|
-
|
30
|
+
has_metadata :type=>BarStream, :name=>"xmlish"
|
31
|
+
has_attributes :fubar, datastream: 'withText', multiple: false
|
32
|
+
has_attributes :duck, datastream: 'xmlish', multiple: false
|
33
33
|
end
|
34
34
|
before :each do
|
35
35
|
@n = BarHistory.new()
|
36
36
|
end
|
37
|
-
describe
|
38
|
-
it
|
39
|
-
@n.attributes = {:fubar
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
37
|
+
describe "attributes=" do
|
38
|
+
it "should set attributes" do
|
39
|
+
@n.attributes = {:fubar=>"baz", :duck=>"Quack"}
|
40
|
+
@n.fubar.should == "baz"
|
41
|
+
@n.withText.get_values(:fubar).first.should == 'baz'
|
42
|
+
@n.duck.should == "Quack"
|
43
|
+
@n.xmlish.term_values(:duck).first.should == 'Quack'
|
44
44
|
end
|
45
45
|
end
|
46
|
-
describe
|
47
|
-
it
|
48
|
-
@n.update_attributes(:fubar
|
46
|
+
describe "update_attributes" do
|
47
|
+
it "should set attributes and save " do
|
48
|
+
@n.update_attributes(:fubar=>"baz", :duck=>"Quack")
|
49
49
|
@q = BarHistory.find(@n.pid)
|
50
|
-
|
51
|
-
|
50
|
+
@q.fubar.should == "baz"
|
51
|
+
@q.duck.should == "Quack"
|
52
52
|
end
|
53
53
|
after do
|
54
54
|
@n.delete
|
@@ -57,3 +57,4 @@ describe ActiveFedora::Base do
|
|
57
57
|
|
58
58
|
end
|
59
59
|
end
|
60
|
+
|
data/spec/unit/base_cma_spec.rb
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe ActiveFedora::Base do
|
4
|
-
|
4
|
+
|
5
5
|
before(:each) do
|
6
6
|
@test_object = ActiveFedora::Base.new
|
7
7
|
end
|
8
|
-
|
8
|
+
|
9
9
|
describe '.save' do
|
10
10
|
|
11
|
-
it
|
12
|
-
|
13
|
-
|
11
|
+
it "should add hasModel relationship that points to the CModel if @new_object" do
|
12
|
+
@test_object.stub(:update_index)
|
13
|
+
@test_object.should_receive(:refresh)
|
14
14
|
@test_object.save
|
15
15
|
end
|
16
16
|
end
|
@@ -1,57 +1,57 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe ActiveFedora::Base do
|
4
|
-
|
4
|
+
|
5
5
|
before(:each) do
|
6
6
|
@test_object = ActiveFedora::Base.new
|
7
7
|
end
|
8
|
-
|
8
|
+
|
9
9
|
describe '.generate_dsid' do
|
10
|
-
it
|
11
|
-
dsids = Hash[
|
12
|
-
|
10
|
+
it "should return a dsid that is not currently in use" do
|
11
|
+
dsids = Hash["DS1"=>1, "DS2"=>1]
|
12
|
+
@test_object.should_receive(:datastreams).and_return(dsids)
|
13
13
|
generated_id = @test_object.generate_dsid
|
14
|
-
|
15
|
-
|
14
|
+
generated_id.should_not be_nil
|
15
|
+
generated_id.should == "DS3"
|
16
16
|
end
|
17
|
-
it
|
18
|
-
|
17
|
+
it "should accept a prefix argument, default to using DS as prefix" do
|
18
|
+
@test_object.generate_dsid("FOO").should == "FOO1"
|
19
19
|
end
|
20
20
|
|
21
|
-
it
|
22
|
-
dsids = Hash[
|
23
|
-
|
21
|
+
it "if delete a datastream it should still use next index for a prefix" do
|
22
|
+
dsids = Hash["DS2"=>1]
|
23
|
+
@test_object.should_receive(:datastreams).and_return(dsids)
|
24
24
|
generated_id = @test_object.generate_dsid
|
25
|
-
|
26
|
-
|
25
|
+
generated_id.should_not be_nil
|
26
|
+
generated_id.should == "DS3"
|
27
27
|
end
|
28
28
|
end
|
29
29
|
describe '.add_datastream' do
|
30
|
-
it
|
30
|
+
it "should not call Datastream.save" do
|
31
31
|
ds = ActiveFedora::Datastream.new(@test_object.inner_object, 'ds_to_add')
|
32
|
-
|
32
|
+
ds.should_receive(:save).never
|
33
33
|
@test_object.add_datastream(ds)
|
34
34
|
end
|
35
|
-
it
|
35
|
+
it "should add the datastream to the datastreams_in_memory array" do
|
36
36
|
ds = ActiveFedora::Datastream.new(@test_object.inner_object, 'ds_to_add')
|
37
|
-
|
37
|
+
@test_object.datastreams.should_not have_key(ds.dsid)
|
38
38
|
@test_object.add_datastream(ds)
|
39
|
-
|
39
|
+
@test_object.datastreams.should have_key(ds.dsid)
|
40
40
|
end
|
41
|
-
it
|
41
|
+
it "should auto-assign dsids using auto-incremented integers if dsid is nil or an empty string" do
|
42
42
|
ds = ActiveFedora::Datastream.new(@test_object.inner_object, nil)
|
43
|
-
|
43
|
+
ds.dsid.should == nil
|
44
44
|
ds_emptystringid = ActiveFedora::Datastream.new(@test_object.inner_object, '')
|
45
45
|
@test_object.stub(:generate_dsid => 'foo')
|
46
46
|
# ds.should_receive(:dsid=).with("foo")
|
47
|
-
|
48
|
-
|
47
|
+
@test_object.add_datastream(ds).should == 'foo'
|
48
|
+
@test_object.add_datastream(ds_emptystringid).should == 'foo'
|
49
49
|
end
|
50
|
-
it
|
50
|
+
it "should accept a prefix option and apply it to automatically assigned dsids" do
|
51
51
|
ds = ActiveFedora::Datastream.new(@test_object.inner_object, nil)
|
52
|
-
|
53
|
-
@test_object.stub(:generate_dsid =>
|
54
|
-
|
52
|
+
ds.dsid.should == nil
|
53
|
+
@test_object.stub(:generate_dsid => "FOO")
|
54
|
+
@test_object.add_datastream(ds, :prefix => "FOO").should == 'FOO'
|
55
55
|
end
|
56
56
|
end
|
57
57
|
end
|