active-fedora 8.2.1 → 8.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/active-fedora.gemspec +1 -2
- data/lib/active_fedora/datastream_collections.rb +4 -8
- data/lib/active_fedora/datastreams.rb +7 -9
- data/lib/active_fedora/version.rb +1 -1
- data/spec/config_helper.rb +3 -3
- data/spec/integration/associations_spec.rb +76 -76
- data/spec/integration/auditable_spec.rb +7 -7
- data/spec/integration/autosave_association_spec.rb +3 -3
- data/spec/integration/base_spec.rb +51 -51
- data/spec/integration/belongs_to_association_spec.rb +27 -27
- data/spec/integration/bug_spec.rb +1 -1
- data/spec/integration/collection_association_spec.rb +2 -2
- data/spec/integration/complex_rdf_datastream_spec.rb +32 -32
- data/spec/integration/datastream_collections_spec.rb +42 -42
- data/spec/integration/datastream_spec.rb +19 -19
- data/spec/integration/datastreams_spec.rb +25 -25
- data/spec/integration/delete_all_spec.rb +5 -5
- data/spec/integration/fedora_solr_sync_spec.rb +1 -1
- data/spec/integration/full_featured_model_spec.rb +9 -9
- data/spec/integration/has_and_belongs_to_many_associations_spec.rb +46 -47
- data/spec/integration/has_many_associations_spec.rb +17 -17
- data/spec/integration/json_serialization_spec.rb +2 -2
- data/spec/integration/load_from_solr_spec.rb +1 -1
- data/spec/integration/model_spec.rb +9 -9
- data/spec/integration/nested_attribute_spec.rb +17 -17
- data/spec/integration/ntriples_datastream_spec.rb +43 -43
- data/spec/integration/om_datastream_spec.rb +37 -37
- data/spec/integration/persistence_spec.rb +1 -1
- data/spec/integration/rdf_nested_attributes_spec.rb +9 -9
- data/spec/integration/relation_delegation_spec.rb +7 -7
- data/spec/integration/relation_spec.rb +2 -2
- data/spec/integration/rels_ext_datastream_spec.rb +3 -3
- data/spec/integration/scoped_query_spec.rb +14 -14
- data/spec/integration/solr_service_spec.rb +24 -24
- data/spec/support/mock_fedora.rb +9 -10
- data/spec/unit/active_fedora_spec.rb +20 -20
- data/spec/unit/attributes_spec.rb +24 -24
- data/spec/unit/base_active_model_spec.rb +6 -6
- data/spec/unit/base_cma_spec.rb +2 -2
- data/spec/unit/base_datastream_management_spec.rb +7 -7
- data/spec/unit/base_extra_spec.rb +20 -20
- data/spec/unit/base_spec.rb +141 -141
- data/spec/unit/builder/has_and_belongs_to_many_spec.rb +1 -1
- data/spec/unit/callback_spec.rb +12 -12
- data/spec/unit/code_configurator_spec.rb +7 -7
- data/spec/unit/config_spec.rb +2 -2
- data/spec/unit/content_model_spec.rb +19 -20
- data/spec/unit/core_spec.rb +1 -1
- data/spec/unit/datastream_collections_spec.rb +101 -101
- data/spec/unit/datastream_spec.rb +12 -12
- data/spec/unit/datastreams_spec.rb +39 -39
- data/spec/unit/file_configurator_spec.rb +117 -117
- data/spec/unit/has_and_belongs_to_many_collection_spec.rb +16 -16
- data/spec/unit/has_many_collection_spec.rb +5 -5
- data/spec/unit/inheritance_spec.rb +5 -5
- data/spec/unit/model_spec.rb +5 -5
- data/spec/unit/nom_datastream_spec.rb +5 -5
- data/spec/unit/ntriples_datastream_spec.rb +56 -56
- data/spec/unit/om_datastream_spec.rb +99 -99
- data/spec/unit/persistence_spec.rb +2 -2
- data/spec/unit/predicates_spec.rb +28 -28
- data/spec/unit/property_spec.rb +5 -5
- data/spec/unit/qualified_dublin_core_datastream_spec.rb +10 -10
- data/spec/unit/query_spec.rb +66 -66
- data/spec/unit/rdf_datastream_spec.rb +10 -10
- data/spec/unit/rdf_resource_datastream_spec.rb +2 -2
- data/spec/unit/rdf_xml_writer_spec.rb +3 -3
- data/spec/unit/rdfxml_rdf_datastream_spec.rb +9 -9
- data/spec/unit/relationship_graph_spec.rb +31 -31
- data/spec/unit/reload_on_save_spec.rb +3 -3
- data/spec/unit/rels_ext_datastream_spec.rb +28 -28
- data/spec/unit/rspec_matchers/belong_to_associated_active_fedora_object_matcher_spec.rb +11 -11
- data/spec/unit/rspec_matchers/have_many_associated_active_fedora_objects_matcher_spec.rb +11 -11
- data/spec/unit/rspec_matchers/have_predicate_matcher_spec.rb +11 -11
- data/spec/unit/rspec_matchers/match_fedora_datastream_matcher_spec.rb +7 -7
- data/spec/unit/rubydora_connection_spec.rb +3 -3
- data/spec/unit/semantic_node_spec.rb +17 -17
- data/spec/unit/serializers_spec.rb +1 -1
- data/spec/unit/service_definitions_spec.rb +11 -11
- data/spec/unit/simple_datastream_spec.rb +6 -6
- data/spec/unit/solr_config_options_spec.rb +10 -10
- data/spec/unit/solr_digital_object_spec.rb +4 -4
- data/spec/unit/solr_service_spec.rb +41 -41
- data/spec/unit/unsaved_digital_object_spec.rb +8 -8
- data/spec/unit/validations_spec.rb +6 -6
- metadata +4 -4
@@ -8,37 +8,37 @@ describe ActiveFedora::Datastream do
|
|
8
8
|
@test_datastream.content = "hi there"
|
9
9
|
end
|
10
10
|
|
11
|
-
its(:metadata?) { should
|
11
|
+
its(:metadata?) { should be_falsey}
|
12
12
|
|
13
13
|
it "should escape dots in to_param" do
|
14
|
-
@test_datastream.
|
15
|
-
@test_datastream.to_param.
|
14
|
+
allow(@test_datastream).to receive(:dsid).and_return('foo.bar')
|
15
|
+
expect(@test_datastream.to_param).to eq('foo%2ebar')
|
16
16
|
end
|
17
17
|
|
18
18
|
it "should be inspectable" do
|
19
|
-
@test_datastream.inspect.
|
19
|
+
expect(@test_datastream.inspect).to match /#<ActiveFedora::Datastream @pid=\"\" @dsid=\"abcd\" @controlGroup=\"M\" changed=\"true\" @mimeType=\"\" >/
|
20
20
|
end
|
21
21
|
|
22
22
|
it "should have mimeType accessors" do
|
23
23
|
ds1 = ActiveFedora::Datastream.new
|
24
24
|
ds1.mimeType = "text/foo"
|
25
|
-
ds1.mimeType.
|
25
|
+
expect(ds1.mimeType).to eq("text/foo")
|
26
26
|
ds2 = ActiveFedora::Datastream.new
|
27
27
|
ds2.mimeType = "text/bar"
|
28
|
-
ds2.mimeType.
|
28
|
+
expect(ds2.mimeType).to eq("text/bar")
|
29
29
|
end
|
30
30
|
|
31
31
|
describe "#generate_dsid" do
|
32
32
|
subject {ActiveFedora::Datastream.new(@test_object.inner_object) }
|
33
33
|
let(:digital_object) { double(datastreams: {})}
|
34
34
|
it "should create an autoincrementing dsid" do
|
35
|
-
subject.send(:generate_dsid, digital_object, 'FOO').
|
35
|
+
expect(subject.send(:generate_dsid, digital_object, 'FOO')).to eq('FOO1')
|
36
36
|
end
|
37
37
|
|
38
38
|
describe "when some datastreams exist" do
|
39
39
|
let(:digital_object) { double(datastreams: {'FOO56' => double})}
|
40
40
|
it "should start from the highest existing dsid" do
|
41
|
-
subject.send(:generate_dsid, digital_object, 'FOO').
|
41
|
+
expect(subject.send(:generate_dsid, digital_object, 'FOO')).to eq('FOO57')
|
42
42
|
end
|
43
43
|
end
|
44
44
|
end
|
@@ -71,13 +71,13 @@ describe ActiveFedora::Datastream do
|
|
71
71
|
EOS
|
72
72
|
|
73
73
|
mock_repo = Rubydora::Repository.new
|
74
|
-
@test_object.inner_object.
|
75
|
-
mock_repo.api.
|
76
|
-
@test_datastream.size.
|
74
|
+
allow(@test_object.inner_object).to receive(:repository).and_return(mock_repo)
|
75
|
+
expect(mock_repo.api).to receive(:datastream).with(:dsid => 'abcd', :pid => @test_object.pid).and_return(ds_profile)
|
76
|
+
expect(@test_datastream.size).to eq(9999)
|
77
77
|
end
|
78
78
|
|
79
79
|
it "should default to an empty string if ds has not been saved" do
|
80
|
-
@test_datastream.size.
|
80
|
+
expect(@test_datastream.size).to be_nil
|
81
81
|
end
|
82
82
|
end
|
83
83
|
end
|
@@ -12,15 +12,15 @@ describe ActiveFedora::Datastreams do
|
|
12
12
|
end
|
13
13
|
|
14
14
|
it "should have a ds_specs entry" do
|
15
|
-
FooHistory.ds_specs.
|
15
|
+
expect(FooHistory.ds_specs).to have_key('dsid')
|
16
16
|
end
|
17
17
|
|
18
18
|
it "should have reasonable defaults" do
|
19
|
-
FooHistory.ds_specs['dsid'].
|
19
|
+
expect(FooHistory.ds_specs['dsid']).to include(:autocreate => false)
|
20
20
|
end
|
21
21
|
|
22
22
|
it "should let you override defaults" do
|
23
|
-
FooHistory.ds_specs['complex_ds'].
|
23
|
+
expect(FooHistory.ds_specs['complex_ds']).to include(:versionable => true, :autocreate => true, :type => 'Z', :label => 'My Label', :control_group => 'Z')
|
24
24
|
end
|
25
25
|
|
26
26
|
it "should raise an error if you don't give a type" do
|
@@ -43,8 +43,8 @@ describe ActiveFedora::Datastreams do
|
|
43
43
|
end
|
44
44
|
|
45
45
|
it "should have reasonable defaults" do
|
46
|
-
FooHistory.ds_specs['dsid'].
|
47
|
-
FooHistory.ds_specs['another'].
|
46
|
+
expect(FooHistory.ds_specs['dsid']).to include(:type => ActiveFedora::Datastream, :label => 'File Datastream', :control_group => 'M')
|
47
|
+
expect(FooHistory.ds_specs['another']).to include(:type => ActiveFedora::Datastream, :label => 'File Datastream', :control_group => 'M')
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
@@ -53,9 +53,9 @@ describe ActiveFedora::Datastreams do
|
|
53
53
|
m1 = double()
|
54
54
|
m2 = double()
|
55
55
|
|
56
|
-
m1.
|
57
|
-
m2.
|
58
|
-
subject.
|
56
|
+
expect(m1).to receive(:serialize!)
|
57
|
+
expect(m2).to receive(:serialize!)
|
58
|
+
allow(subject).to receive_messages(:datastreams => { :m1 => m1, :m2 => m2})
|
59
59
|
subject.serialize_datastreams
|
60
60
|
end
|
61
61
|
end
|
@@ -65,62 +65,62 @@ describe ActiveFedora::Datastreams do
|
|
65
65
|
|
66
66
|
mock_specs = {'e' => { :disseminator => 'xyz' }}
|
67
67
|
mock_ds = double(:controlGroup => 'E')
|
68
|
-
ActiveFedora::Base.
|
69
|
-
ActiveFedora.
|
70
|
-
subject.
|
71
|
-
mock_ds.
|
68
|
+
allow(ActiveFedora::Base).to receive_messages(:ds_specs => mock_specs)
|
69
|
+
allow(ActiveFedora).to receive_messages(:config_for_environment => { :url => 'http://localhost'})
|
70
|
+
allow(subject).to receive_messages(:pid => 'test:1', :datastreams => {'e' => mock_ds})
|
71
|
+
expect(mock_ds).to receive(:dsLocation=).with("http://localhost/objects/test:1/methods/xyz")
|
72
72
|
subject.add_disseminator_location_to_datastreams
|
73
73
|
end
|
74
74
|
end
|
75
75
|
|
76
76
|
describe ".name_for_dsid" do
|
77
77
|
it "should use the name" do
|
78
|
-
ActiveFedora::Base.send(:name_for_dsid, 'abc').
|
78
|
+
expect(ActiveFedora::Base.send(:name_for_dsid, 'abc')).to eq('abc')
|
79
79
|
end
|
80
80
|
|
81
81
|
it "should use the name" do
|
82
|
-
ActiveFedora::Base.send(:name_for_dsid, 'ARCHIVAL_XML').
|
82
|
+
expect(ActiveFedora::Base.send(:name_for_dsid, 'ARCHIVAL_XML')).to eq('ARCHIVAL_XML')
|
83
83
|
end
|
84
84
|
|
85
85
|
it "should use the name" do
|
86
|
-
ActiveFedora::Base.send(:name_for_dsid, 'descMetadata').
|
86
|
+
expect(ActiveFedora::Base.send(:name_for_dsid, 'descMetadata')).to eq('descMetadata')
|
87
87
|
end
|
88
88
|
|
89
89
|
it "should hash-erize underscores" do
|
90
|
-
ActiveFedora::Base.send(:name_for_dsid, 'a-b').
|
90
|
+
expect(ActiveFedora::Base.send(:name_for_dsid, 'a-b')).to eq('a_b')
|
91
91
|
end
|
92
92
|
end
|
93
93
|
|
94
94
|
describe "#datastreams" do
|
95
95
|
it "should return the datastream hash proxy" do
|
96
|
-
subject.
|
97
|
-
subject.datastreams.
|
96
|
+
allow(subject).to receive(:load_datastreams)
|
97
|
+
expect(subject.datastreams).to be_a_kind_of(ActiveFedora::DatastreamHash)
|
98
98
|
end
|
99
99
|
|
100
100
|
it "should round-trip to/from YAML" do
|
101
|
-
YAML.load(subject.datastreams.to_yaml).inspect.
|
101
|
+
expect(YAML.load(subject.datastreams.to_yaml).inspect).to eq(subject.datastreams.inspect)
|
102
102
|
end
|
103
103
|
end
|
104
104
|
|
105
105
|
describe "#configure_datastream" do
|
106
106
|
it "should look up the ds_spec" do
|
107
107
|
mock_dsspec = { :type => nil }
|
108
|
-
subject.
|
108
|
+
allow(subject).to receive_messages(:ds_specs => {'abc' => mock_dsspec})
|
109
109
|
subject.configure_datastream(double(:dsid => 'abc'))
|
110
110
|
end
|
111
111
|
|
112
112
|
it "should be ok if there is no ds spec" do
|
113
113
|
mock_dsspec = double()
|
114
|
-
subject.
|
114
|
+
allow(subject).to receive_messages(:ds_specs => {})
|
115
115
|
subject.configure_datastream(double(:dsid => 'abc'))
|
116
116
|
end
|
117
117
|
|
118
118
|
it "should configure RelsExtDatastream" do
|
119
119
|
mock_dsspec = { :type => ActiveFedora::RelsExtDatastream }
|
120
|
-
subject.
|
120
|
+
allow(subject).to receive_messages(:ds_specs => {'abc' => mock_dsspec})
|
121
121
|
|
122
122
|
ds = double(:dsid => 'abc')
|
123
|
-
ds.
|
123
|
+
expect(ds).to receive(:model=).with(subject)
|
124
124
|
|
125
125
|
subject.configure_datastream(ds)
|
126
126
|
end
|
@@ -129,7 +129,7 @@ describe ActiveFedora::Datastreams do
|
|
129
129
|
ds = double(:dsid => 'abc')
|
130
130
|
@count = 0
|
131
131
|
mock_dsspec = { :block => lambda { |x| @count += 1 } }
|
132
|
-
subject.
|
132
|
+
allow(subject).to receive_messages(:ds_specs => {'abc' => mock_dsspec})
|
133
133
|
|
134
134
|
|
135
135
|
expect {
|
@@ -140,7 +140,7 @@ describe ActiveFedora::Datastreams do
|
|
140
140
|
|
141
141
|
describe "#datastream_from_spec" do
|
142
142
|
it "should fetch the rubydora datastream" do
|
143
|
-
subject.inner_object.
|
143
|
+
expect(subject.inner_object).to receive(:datastream_object_for).with('dsid', {}, {})
|
144
144
|
subject.datastream_from_spec({}, 'dsid')
|
145
145
|
end
|
146
146
|
end
|
@@ -149,12 +149,12 @@ describe ActiveFedora::Datastreams do
|
|
149
149
|
it "should add the datastream to the object" do
|
150
150
|
ds = double(:dsid => 'Abc')
|
151
151
|
subject.add_datastream(ds)
|
152
|
-
subject.datastreams['Abc'].
|
152
|
+
expect(subject.datastreams['Abc']).to eq(ds)
|
153
153
|
end
|
154
154
|
|
155
155
|
it "should mint a dsid" do
|
156
156
|
ds = ActiveFedora::Datastream.new(subject.inner_object)
|
157
|
-
subject.add_datastream(ds).
|
157
|
+
expect(subject.add_datastream(ds)).to eq('DS1')
|
158
158
|
end
|
159
159
|
end
|
160
160
|
|
@@ -165,24 +165,24 @@ describe ActiveFedora::Datastreams do
|
|
165
165
|
ds3 = double(:metadata? => true)
|
166
166
|
relsextds = ActiveFedora::RelsExtDatastream.new
|
167
167
|
file_ds = double(:metadata? => false)
|
168
|
-
subject.
|
169
|
-
subject.metadata_streams.
|
170
|
-
subject.metadata_streams.
|
171
|
-
subject.metadata_streams.
|
168
|
+
allow(subject).to receive_messages(:datastreams => {:a => ds1, :b => ds2, :c => ds3, :d => relsextds, :e => file_ds})
|
169
|
+
expect(subject.metadata_streams).to include(ds1, ds2, ds3)
|
170
|
+
expect(subject.metadata_streams).not_to include(relsextds)
|
171
|
+
expect(subject.metadata_streams).not_to include(file_ds)
|
172
172
|
end
|
173
173
|
end
|
174
174
|
|
175
175
|
describe "#relsext" do
|
176
176
|
it "should be the RELS-EXT datastream" do
|
177
177
|
m = double
|
178
|
-
subject.
|
179
|
-
subject.rels_ext.
|
178
|
+
allow(subject).to receive_messages(:datastreams => { 'RELS-EXT' => m})
|
179
|
+
expect(subject.rels_ext).to eq(m)
|
180
180
|
end
|
181
181
|
|
182
182
|
it "should make one up otherwise" do
|
183
|
-
subject.
|
183
|
+
allow(subject).to receive_messages(:datastreams => {})
|
184
184
|
|
185
|
-
subject.rels_ext.
|
185
|
+
expect(subject.rels_ext).to be_a_kind_of(ActiveFedora::RelsExtDatastream)
|
186
186
|
end
|
187
187
|
end
|
188
188
|
|
@@ -193,7 +193,7 @@ describe ActiveFedora::Datastreams do
|
|
193
193
|
describe "#create_datastream" do
|
194
194
|
it "should mint a DSID" do
|
195
195
|
ds = subject.create_datastream(ActiveFedora::Datastream, nil, {})
|
196
|
-
ds.dsid.
|
196
|
+
expect(ds.dsid).to eq('DS1')
|
197
197
|
end
|
198
198
|
|
199
199
|
it "should raise an argument error if the supplied dsid is nonsense" do
|
@@ -203,19 +203,19 @@ describe ActiveFedora::Datastreams do
|
|
203
203
|
it "should try to get a mime type from the blob" do
|
204
204
|
mock_file = double(:content_type => 'x-application/asdf')
|
205
205
|
ds = subject.create_datastream(ActiveFedora::Datastream, nil, {:blob => mock_file})
|
206
|
-
ds.mimeType.
|
206
|
+
expect(ds.mimeType).to eq('x-application/asdf')
|
207
207
|
end
|
208
208
|
|
209
209
|
it "should provide a default mime type" do
|
210
210
|
mock_file = double()
|
211
211
|
ds = subject.create_datastream(ActiveFedora::Datastream, nil, {:blob => mock_file})
|
212
|
-
ds.mimeType.
|
212
|
+
expect(ds.mimeType).to eq('application/octet-stream')
|
213
213
|
end
|
214
214
|
|
215
215
|
it "should use the filename as a default label" do
|
216
216
|
mock_file = double(:path => '/asdf/fdsa')
|
217
217
|
ds = subject.create_datastream(ActiveFedora::Datastream, nil, {:blob => mock_file})
|
218
|
-
ds.dsLabel.
|
218
|
+
expect(ds.dsLabel).to eq('fdsa')
|
219
219
|
end
|
220
220
|
|
221
221
|
it "should not set content for controlGroup 'E'" do
|
@@ -23,7 +23,7 @@ describe ActiveFedora::FileConfigurator do
|
|
23
23
|
subject.reset!
|
24
24
|
end
|
25
25
|
it "should be an empty hash" do
|
26
|
-
subject.config_options.
|
26
|
+
expect(subject.config_options).to eq({})
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
@@ -32,7 +32,7 @@ describe ActiveFedora::FileConfigurator do
|
|
32
32
|
subject.reset!
|
33
33
|
end
|
34
34
|
it "should trigger configuration to load" do
|
35
|
-
subject.
|
35
|
+
expect(subject).to receive(:load_fedora_config)
|
36
36
|
subject.fedora_config
|
37
37
|
end
|
38
38
|
end
|
@@ -41,7 +41,7 @@ describe ActiveFedora::FileConfigurator do
|
|
41
41
|
subject.reset!
|
42
42
|
end
|
43
43
|
it "should trigger configuration to load" do
|
44
|
-
subject.
|
44
|
+
expect(subject).to receive(:load_solr_config)
|
45
45
|
subject.solr_config
|
46
46
|
end
|
47
47
|
end
|
@@ -49,13 +49,13 @@ describe ActiveFedora::FileConfigurator do
|
|
49
49
|
describe "#reset!" do
|
50
50
|
before { subject.reset! }
|
51
51
|
it "should clear @fedora_config" do
|
52
|
-
subject.instance_variable_get(:@fedora_config).
|
52
|
+
expect(subject.instance_variable_get(:@fedora_config)).to eq({})
|
53
53
|
end
|
54
54
|
it "should clear @solr_config" do
|
55
|
-
subject.instance_variable_get(:@solr_config).
|
55
|
+
expect(subject.instance_variable_get(:@solr_config)).to eq({})
|
56
56
|
end
|
57
57
|
it "should clear @config_options" do
|
58
|
-
subject.instance_variable_get(:@config_options).
|
58
|
+
expect(subject.instance_variable_get(:@config_options)).to eq({})
|
59
59
|
end
|
60
60
|
end
|
61
61
|
|
@@ -63,87 +63,87 @@ describe ActiveFedora::FileConfigurator do
|
|
63
63
|
|
64
64
|
describe "get_config_path(:fedora)" do
|
65
65
|
it "should use the config_options[:config_path] if it exists" do
|
66
|
-
subject.
|
67
|
-
File.
|
68
|
-
subject.get_config_path(:fedora).
|
66
|
+
expect(subject).to receive(:config_options).and_return({:fedora_config_path => "/path/to/fedora.yml"})
|
67
|
+
expect(File).to receive(:file?).with("/path/to/fedora.yml").and_return(true)
|
68
|
+
expect(subject.get_config_path(:fedora)).to eql("/path/to/fedora.yml")
|
69
69
|
end
|
70
70
|
|
71
71
|
it "should look in Rails.root/config/fedora.yml if it exists and no fedora_config_path passed in" do
|
72
|
-
subject.
|
72
|
+
expect(subject).to receive(:config_options).and_return({})
|
73
73
|
stub_rails(:root => "/rails/root")
|
74
|
-
File.
|
75
|
-
subject.get_config_path(:fedora).
|
74
|
+
expect(File).to receive(:file?).with("/rails/root/config/fedora.yml").and_return(true)
|
75
|
+
expect(subject.get_config_path(:fedora)).to eql("/rails/root/config/fedora.yml")
|
76
76
|
unstub_rails
|
77
77
|
end
|
78
78
|
|
79
79
|
it "should look in ./config/fedora.yml if neither rails.root nor :fedora_config_path are set" do
|
80
|
-
subject.
|
81
|
-
Dir.
|
82
|
-
File.
|
83
|
-
subject.get_config_path(:fedora).
|
80
|
+
expect(subject).to receive(:config_options).and_return({})
|
81
|
+
allow(Dir).to receive_messages(:getwd => "/current/working/directory")
|
82
|
+
expect(File).to receive(:file?).with("/current/working/directory/config/fedora.yml").and_return(true)
|
83
|
+
expect(subject.get_config_path(:fedora)).to eql("/current/working/directory/config/fedora.yml")
|
84
84
|
end
|
85
85
|
|
86
86
|
it "should return default fedora.yml that ships with active-fedora if none of the above" do
|
87
|
-
subject.
|
88
|
-
Dir.
|
89
|
-
File.
|
90
|
-
File.
|
87
|
+
expect(subject).to receive(:config_options).and_return({})
|
88
|
+
expect(Dir).to receive(:getwd).and_return("/current/working/directory")
|
89
|
+
expect(File).to receive(:file?).with("/current/working/directory/config/fedora.yml").and_return(false)
|
90
|
+
expect(File).to receive(:file?).with(File.expand_path(File.join(File.dirname("__FILE__"),'config','fedora.yml'))).and_return(true)
|
91
91
|
expect(ActiveFedora::Base.logger).to receive(:warn).with("Using the default fedora.yml that comes with active-fedora. If you want to override this, pass the path to fedora.yml to ActiveFedora - ie. ActiveFedora.init(:fedora_config_path => '/path/to/fedora.yml') - or set Rails.root and put fedora.yml into \#{Rails.root}/config.")
|
92
|
-
subject.get_config_path(:fedora).
|
92
|
+
expect(subject.get_config_path(:fedora)).to eql(File.expand_path(File.join(File.dirname("__FILE__"),'config','fedora.yml')))
|
93
93
|
end
|
94
94
|
end
|
95
95
|
|
96
96
|
describe "get_config_path(:predicate_mappings)" do
|
97
97
|
it "should use the config_options[:config_path] if it exists" do
|
98
|
-
subject.
|
99
|
-
File.
|
100
|
-
subject.get_config_path(:predicate_mappings).
|
98
|
+
expect(subject).to receive(:config_options).and_return({:predicate_mappings_config_path => "/path/to/predicate_mappings.yml"})
|
99
|
+
expect(File).to receive(:file?).with("/path/to/predicate_mappings.yml").and_return(true)
|
100
|
+
expect(subject.get_config_path(:predicate_mappings)).to eql("/path/to/predicate_mappings.yml")
|
101
101
|
end
|
102
102
|
|
103
103
|
it "should look in Rails.root/config/predicate_mappings.yml if it exists and no predicate_mappings_config_path passed in" do
|
104
|
-
subject.
|
104
|
+
expect(subject).to receive(:config_options).and_return({})
|
105
105
|
stub_rails(:root => "/rails/root")
|
106
|
-
File.
|
107
|
-
subject.get_config_path(:predicate_mappings).
|
106
|
+
expect(File).to receive(:file?).with("/rails/root/config/predicate_mappings.yml").and_return(true)
|
107
|
+
expect(subject.get_config_path(:predicate_mappings)).to eql("/rails/root/config/predicate_mappings.yml")
|
108
108
|
unstub_rails
|
109
109
|
end
|
110
110
|
|
111
111
|
it "should look in ./config/predicate_mappings.yml if neither rails.root nor :predicate_mappings_config_path are set" do
|
112
|
-
subject.
|
113
|
-
Dir.
|
114
|
-
File.
|
115
|
-
subject.get_config_path(:predicate_mappings).
|
112
|
+
expect(subject).to receive(:config_options).and_return({})
|
113
|
+
allow(Dir).to receive_messages(:getwd => "/current/working/directory")
|
114
|
+
expect(File).to receive(:file?).with("/current/working/directory/config/predicate_mappings.yml").and_return(true)
|
115
|
+
expect(subject.get_config_path(:predicate_mappings)).to eql("/current/working/directory/config/predicate_mappings.yml")
|
116
116
|
end
|
117
117
|
|
118
118
|
it "should return default predicate_mappings.yml that ships with active-fedora if none of the above" do
|
119
|
-
subject.
|
120
|
-
Dir.
|
121
|
-
File.
|
122
|
-
File.
|
119
|
+
expect(subject).to receive(:config_options).and_return({})
|
120
|
+
expect(Dir).to receive(:getwd).and_return("/current/working/directory")
|
121
|
+
expect(File).to receive(:file?).with("/current/working/directory/config/predicate_mappings.yml").and_return(false)
|
122
|
+
expect(File).to receive(:file?).with(File.expand_path(File.join(File.dirname("__FILE__"),'config','predicate_mappings.yml'))).and_return(true)
|
123
123
|
expect(ActiveFedora::Base.logger).to receive(:warn).with("Using the default predicate_mappings.yml that comes with active-fedora. If you want to override this, pass the path to predicate_mappings.yml to ActiveFedora - ie. ActiveFedora.init(:predicate_mappings_config_path => '/path/to/predicate_mappings.yml') - or set Rails.root and put predicate_mappings.yml into \#{Rails.root}/config.")
|
124
|
-
subject.get_config_path(:predicate_mappings).
|
124
|
+
expect(subject.get_config_path(:predicate_mappings)).to eql(File.expand_path(File.join(File.dirname("__FILE__"),'config','predicate_mappings.yml')))
|
125
125
|
end
|
126
126
|
end
|
127
127
|
|
128
128
|
describe "get_config_path(:solr)" do
|
129
129
|
it "should return the solr_config_path if set in config_options hash" do
|
130
|
-
subject.
|
131
|
-
File.
|
132
|
-
subject.get_config_path(:solr).
|
130
|
+
allow(subject).to receive_messages(:config_options => {:solr_config_path => "/path/to/solr.yml"})
|
131
|
+
expect(File).to receive(:file?).with("/path/to/solr.yml").and_return(true)
|
132
|
+
expect(subject.get_config_path(:solr)).to eql("/path/to/solr.yml")
|
133
133
|
end
|
134
134
|
|
135
135
|
it "should return the solr.yml file in the same directory as the fedora.yml if it exists" do
|
136
|
-
subject.
|
137
|
-
File.
|
138
|
-
subject.get_config_path(:solr).
|
136
|
+
expect(subject).to receive(:path).and_return("/path/to/fedora/config/fedora.yml")
|
137
|
+
expect(File).to receive(:file?).with("/path/to/fedora/config/solr.yml").and_return(true)
|
138
|
+
expect(subject.get_config_path(:solr)).to eql("/path/to/fedora/config/solr.yml")
|
139
139
|
end
|
140
140
|
|
141
141
|
context "no solr.yml in same directory as fedora.yml and fedora.yml does not contain solr url" do
|
142
142
|
|
143
143
|
before :each do
|
144
|
-
subject.
|
145
|
-
subject.
|
146
|
-
File.
|
144
|
+
allow(subject).to receive_messages(:config_options => {})
|
145
|
+
expect(subject).to receive(:path).and_return("/path/to/fedora/config/fedora.yml")
|
146
|
+
expect(File).to receive(:file?).with("/path/to/fedora/config/solr.yml").and_return(false)
|
147
147
|
end
|
148
148
|
after :each do
|
149
149
|
unstub_rails
|
@@ -151,22 +151,22 @@ describe ActiveFedora::FileConfigurator do
|
|
151
151
|
|
152
152
|
it "should not raise an error if there is not a solr.yml in the same directory as the fedora.yml and the fedora.yml has a solr url defined and look in rails.root" do
|
153
153
|
stub_rails(:root=>"/rails/root")
|
154
|
-
File.
|
155
|
-
subject.get_config_path(:solr).
|
154
|
+
expect(File).to receive(:file?).with("/rails/root/config/solr.yml").and_return(true)
|
155
|
+
expect(subject.get_config_path(:solr)).to eql("/rails/root/config/solr.yml")
|
156
156
|
end
|
157
157
|
|
158
158
|
it "should look in ./config/solr.yml if no rails root" do
|
159
|
-
Dir.
|
160
|
-
File.
|
161
|
-
subject.get_config_path(:solr).
|
159
|
+
allow(Dir).to receive_messages(:getwd => "/current/working/directory")
|
160
|
+
expect(File).to receive(:file?).with("/current/working/directory/config/solr.yml").and_return(true)
|
161
|
+
expect(subject.get_config_path(:solr)).to eql("/current/working/directory/config/solr.yml")
|
162
162
|
end
|
163
163
|
|
164
164
|
it "should return the default solr.yml file that ships with active-fedora if no other option is set" do
|
165
|
-
Dir.
|
166
|
-
File.
|
167
|
-
File.
|
165
|
+
allow(Dir).to receive_messages(:getwd => "/current/working/directory")
|
166
|
+
expect(File).to receive(:file?).with("/current/working/directory/config/solr.yml").and_return(false)
|
167
|
+
expect(File).to receive(:file?).with(File.expand_path(File.join(File.dirname("__FILE__"),'config','solr.yml'))).and_return(true)
|
168
168
|
expect(ActiveFedora::Base.logger).to receive(:warn).with("Using the default solr.yml that comes with active-fedora. If you want to override this, pass the path to solr.yml to ActiveFedora - ie. ActiveFedora.init(:solr_config_path => '/path/to/solr.yml') - or set Rails.root and put solr.yml into \#{Rails.root}/config.")
|
169
|
-
subject.get_config_path(:solr).
|
169
|
+
expect(subject.get_config_path(:solr)).to eql(File.expand_path(File.join(File.dirname("__FILE__"),'config','solr.yml')))
|
170
170
|
end
|
171
171
|
end
|
172
172
|
|
@@ -177,30 +177,30 @@ describe ActiveFedora::FileConfigurator do
|
|
177
177
|
subject.reset!
|
178
178
|
end
|
179
179
|
it "should load the file specified in fedora_config_path" do
|
180
|
-
subject.
|
181
|
-
subject.
|
182
|
-
subject.
|
183
|
-
IO.
|
184
|
-
subject.load_fedora_config.
|
185
|
-
subject.fedora_config.
|
180
|
+
allow(subject).to receive(:load_solrizer_config)
|
181
|
+
expect(subject).to receive(:get_config_path).with(:fedora).and_return("/path/to/fedora.yml")
|
182
|
+
expect(subject).to receive(:load_solr_config)
|
183
|
+
expect(IO).to receive(:read).with("/path/to/fedora.yml").and_return("development:\n url: http://devfedora:8983\ntest:\n url: http://myfedora:8080")
|
184
|
+
expect(subject.load_fedora_config).to eq({:url=>"http://myfedora:8080"})
|
185
|
+
expect(subject.fedora_config).to eq({:url=>"http://myfedora:8080"})
|
186
186
|
end
|
187
187
|
|
188
188
|
it "should allow sharding" do
|
189
|
-
subject.
|
190
|
-
subject.
|
191
|
-
subject.
|
192
|
-
IO.
|
193
|
-
subject.load_fedora_config.
|
194
|
-
subject.fedora_config.
|
189
|
+
allow(subject).to receive(:load_solrizer_config)
|
190
|
+
expect(subject).to receive(:get_config_path).with(:fedora).and_return("/path/to/fedora.yml")
|
191
|
+
expect(subject).to receive(:load_solr_config)
|
192
|
+
expect(IO).to receive(:read).with("/path/to/fedora.yml").and_return("development:\n url: http://devfedora:8983\ntest:\n- url: http://myfedora:8080\n- url: http://myfedora:8081")
|
193
|
+
expect(subject.load_fedora_config).to eq([{:url=>"http://myfedora:8080"}, {:url=>"http://myfedora:8081"}])
|
194
|
+
expect(subject.fedora_config).to eq([{:url=>"http://myfedora:8080"}, {:url=>"http://myfedora:8081"}])
|
195
195
|
end
|
196
196
|
|
197
197
|
it "should parse the file using ERb" do
|
198
|
-
subject.
|
199
|
-
subject.
|
200
|
-
subject.
|
201
|
-
IO.
|
202
|
-
subject.load_fedora_config.
|
203
|
-
subject.fedora_config.
|
198
|
+
allow(subject).to receive(:load_solrizer_config)
|
199
|
+
expect(subject).to receive(:get_config_path).with(:fedora).and_return("/path/to/fedora.yml")
|
200
|
+
expect(subject).to receive(:load_solr_config)
|
201
|
+
expect(IO).to receive(:read).with("/path/to/fedora.yml").and_return("development:\n url: http://devfedora:<%= 8983 %>\ntest:\n url: http://myfedora:<%= 8081 %>")
|
202
|
+
expect(subject.load_fedora_config).to eq({:url=>"http://myfedora:8081"})
|
203
|
+
expect(subject.fedora_config).to eq({:url=>"http://myfedora:8081"})
|
204
204
|
end
|
205
205
|
end
|
206
206
|
|
@@ -209,21 +209,21 @@ describe ActiveFedora::FileConfigurator do
|
|
209
209
|
subject.reset!
|
210
210
|
end
|
211
211
|
it "should load the file specified in solr_config_path" do
|
212
|
-
subject.
|
213
|
-
subject.
|
214
|
-
subject.
|
215
|
-
IO.
|
216
|
-
subject.load_solr_config.
|
217
|
-
subject.solr_config.
|
212
|
+
allow(subject).to receive(:load_solrizer_config)
|
213
|
+
expect(subject).to receive(:get_config_path).with(:solr).and_return("/path/to/solr.yml")
|
214
|
+
expect(subject).to receive(:load_fedora_config)
|
215
|
+
expect(IO).to receive(:read).with("/path/to/solr.yml").and_return("development:\n default:\n url: http://devsolr:8983\ntest:\n default:\n url: http://mysolr:8080")
|
216
|
+
expect(subject.load_solr_config).to eq({:url=>"http://mysolr:8080"})
|
217
|
+
expect(subject.solr_config).to eq({:url=>"http://mysolr:8080"})
|
218
218
|
end
|
219
219
|
|
220
220
|
it "should parse the file using ERb" do
|
221
|
-
subject.
|
222
|
-
subject.
|
223
|
-
subject.
|
224
|
-
IO.
|
225
|
-
subject.load_solr_config.
|
226
|
-
subject.solr_config.
|
221
|
+
allow(subject).to receive(:load_solrizer_config)
|
222
|
+
expect(subject).to receive(:get_config_path).with(:solr).and_return("/path/to/solr.yml")
|
223
|
+
expect(subject).to receive(:load_fedora_config)
|
224
|
+
expect(IO).to receive(:read).with("/path/to/solr.yml").and_return("development:\n default:\n url: http://devsolr:<%= 8983 %>\ntest:\n default:\n url: http://mysolr:<%= 8081 %>")
|
225
|
+
expect(subject.load_solr_config).to eq({:url=>"http://mysolr:8081"})
|
226
|
+
expect(subject.solr_config).to eq({:url=>"http://mysolr:8081"})
|
227
227
|
end
|
228
228
|
end
|
229
229
|
|
@@ -233,9 +233,9 @@ describe ActiveFedora::FileConfigurator do
|
|
233
233
|
subject.instance_variable_set :@config_loaded, nil
|
234
234
|
end
|
235
235
|
it "should load the fedora and solr configs" do
|
236
|
-
subject.config_loaded
|
236
|
+
expect(subject.config_loaded?).to be_falsey
|
237
237
|
subject.load_configs
|
238
|
-
subject.config_loaded
|
238
|
+
expect(subject.config_loaded?).to be_truthy
|
239
239
|
end
|
240
240
|
end
|
241
241
|
describe "when config is loaded" do
|
@@ -243,24 +243,24 @@ describe ActiveFedora::FileConfigurator do
|
|
243
243
|
subject.instance_variable_set :@config_loaded, true
|
244
244
|
end
|
245
245
|
it "should load the fedora and solr configs" do
|
246
|
-
subject.
|
247
|
-
subject.config_loaded
|
246
|
+
expect(subject).to receive(:load_config).never
|
247
|
+
expect(subject.config_loaded?).to be_truthy
|
248
248
|
subject.load_configs
|
249
|
-
subject.config_loaded
|
249
|
+
expect(subject.config_loaded?).to be_truthy
|
250
250
|
end
|
251
251
|
end
|
252
252
|
end
|
253
253
|
|
254
254
|
describe "check_fedora_path_for_solr" do
|
255
255
|
it "should find the solr.yml file and return it if it exists" do
|
256
|
-
subject.
|
257
|
-
File.
|
258
|
-
subject.check_fedora_path_for_solr.
|
256
|
+
expect(subject).to receive(:path).and_return("/path/to/fedora/fedora.yml")
|
257
|
+
expect(File).to receive(:file?).with("/path/to/fedora/solr.yml").and_return(true)
|
258
|
+
expect(subject.check_fedora_path_for_solr).to eq("/path/to/fedora/solr.yml")
|
259
259
|
end
|
260
260
|
it "should return nil if the solr.yml file is not there" do
|
261
|
-
subject.
|
262
|
-
File.
|
263
|
-
subject.check_fedora_path_for_solr.
|
261
|
+
expect(subject).to receive(:path).and_return("/path/to/fedora/fedora.yml")
|
262
|
+
expect(File).to receive(:file?).with("/path/to/fedora/solr.yml").and_return(false)
|
263
|
+
expect(subject.check_fedora_path_for_solr).to be_nil
|
264
264
|
end
|
265
265
|
end
|
266
266
|
end
|
@@ -280,29 +280,29 @@ describe ActiveFedora::FileConfigurator do
|
|
280
280
|
|
281
281
|
it "can tell its config paths" do
|
282
282
|
subject.init
|
283
|
-
subject.
|
283
|
+
expect(subject).to respond_to(:solr_config_path)
|
284
284
|
end
|
285
285
|
it "loads a config from the current working directory as a second choice" do
|
286
|
-
subject.
|
287
|
-
Dir.
|
286
|
+
allow(subject).to receive(:load_solrizer_config)
|
287
|
+
allow(Dir).to receive(:getwd).and_return(@fake_rails_root)
|
288
288
|
subject.init
|
289
|
-
subject.get_config_path(:fedora).
|
290
|
-
subject.solr_config_path.
|
289
|
+
expect(subject.get_config_path(:fedora)).to eql("#{@fake_rails_root}/config/fedora.yml")
|
290
|
+
expect(subject.solr_config_path).to eql("#{@fake_rails_root}/config/solr.yml")
|
291
291
|
end
|
292
292
|
it "loads the config that ships with this gem as a last choice" do
|
293
|
-
Dir.
|
294
|
-
subject.
|
293
|
+
allow(Dir).to receive(:getwd).and_return("/fake/path")
|
294
|
+
allow(subject).to receive(:load_solrizer_config)
|
295
295
|
expect(ActiveFedora::Base.logger).to receive(:warn).with("Using the default fedora.yml that comes with active-fedora. If you want to override this, pass the path to fedora.yml to ActiveFedora - ie. ActiveFedora.init(:fedora_config_path => '/path/to/fedora.yml') - or set Rails.root and put fedora.yml into \#{Rails.root}/config.").exactly(3).times
|
296
296
|
subject.init
|
297
297
|
expected_config = File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "config"))
|
298
|
-
subject.get_config_path(:fedora).
|
299
|
-
subject.solr_config_path.
|
298
|
+
expect(subject.get_config_path(:fedora)).to eql(expected_config+'/fedora.yml')
|
299
|
+
expect(subject.solr_config_path).to eql(expected_config+'/solr.yml')
|
300
300
|
end
|
301
301
|
it "raises an error if you pass in a string" do
|
302
|
-
|
302
|
+
expect{ subject.init("#{@fake_rails_root}/config/fake_fedora.yml") }.to raise_exception(ArgumentError)
|
303
303
|
end
|
304
304
|
it "raises an error if you pass in a non-existant config file" do
|
305
|
-
|
305
|
+
expect{ subject.init(:fedora_config_path=>"really_fake_fedora.yml") }.to raise_exception(ActiveFedora::ConfigurationError)
|
306
306
|
end
|
307
307
|
|
308
308
|
describe "within Rails" do
|
@@ -315,16 +315,16 @@ describe ActiveFedora::FileConfigurator do
|
|
315
315
|
end
|
316
316
|
|
317
317
|
it "loads a config from Rails.root as a first choice" do
|
318
|
-
subject.
|
318
|
+
allow(subject).to receive(:load_solrizer_config)
|
319
319
|
subject.init
|
320
|
-
subject.get_config_path(:fedora).
|
321
|
-
subject.solr_config_path.
|
320
|
+
expect(subject.get_config_path(:fedora)).to eql("#{Rails.root}/config/fedora.yml")
|
321
|
+
expect(subject.solr_config_path).to eql("#{Rails.root}/config/solr.yml")
|
322
322
|
end
|
323
323
|
|
324
324
|
it "can tell what environment it is set to run in" do
|
325
325
|
stub_rails(:env=>"development")
|
326
326
|
subject.init
|
327
|
-
ActiveFedora.environment.
|
327
|
+
expect(ActiveFedora.environment).to eql("development")
|
328
328
|
end
|
329
329
|
|
330
330
|
end
|
@@ -334,7 +334,7 @@ describe ActiveFedora::FileConfigurator do
|
|
334
334
|
|
335
335
|
describe ".build_predicate_config_path" do
|
336
336
|
it "should return the path to the default config/predicate_mappings.yml if no valid path is given" do
|
337
|
-
subject.send(:build_predicate_config_path).
|
337
|
+
expect(subject.send(:build_predicate_config_path)).to eq(default_predicate_mapping_file)
|
338
338
|
end
|
339
339
|
end
|
340
340
|
|
@@ -343,29 +343,29 @@ describe ActiveFedora::FileConfigurator do
|
|
343
343
|
subject.instance_variable_set :@config_loaded, nil
|
344
344
|
end
|
345
345
|
it "should return the default mapping if it has not been initialized" do
|
346
|
-
subject.predicate_config().
|
346
|
+
expect(subject.predicate_config()).to eq(Psych.load(File.read(default_predicate_mapping_file)))
|
347
347
|
end
|
348
348
|
end
|
349
349
|
|
350
350
|
describe ".valid_predicate_mapping" do
|
351
351
|
it "should return true if the predicate mapping has the appropriate keys and value types" do
|
352
|
-
subject.send(:valid_predicate_mapping?,default_predicate_mapping_file).
|
352
|
+
expect(subject.send(:valid_predicate_mapping?,default_predicate_mapping_file)).to be_truthy
|
353
353
|
end
|
354
354
|
it "should return false if the mapping is missing the :default_namespace" do
|
355
355
|
mock_yaml({:default_namespace0=>"my_namespace",:predicate_mapping=>{:key0=>"value0", :key1=>"value1"}},"/path/to/predicate_mappings.yml")
|
356
|
-
subject.send(:valid_predicate_mapping?,"/path/to/predicate_mappings.yml").
|
356
|
+
expect(subject.send(:valid_predicate_mapping?,"/path/to/predicate_mappings.yml")).to be_falsey
|
357
357
|
end
|
358
358
|
it "should return false if the :default_namespace is not a string" do
|
359
359
|
mock_yaml({:default_namespace=>{:foo=>"bar"}, :predicate_mapping=>{:key0=>"value0", :key1=>"value1"}},"/path/to/predicate_mappings.yml")
|
360
|
-
subject.send(:valid_predicate_mapping?,"/path/to/predicate_mappings.yml").
|
360
|
+
expect(subject.send(:valid_predicate_mapping?,"/path/to/predicate_mappings.yml")).to be_falsey
|
361
361
|
end
|
362
362
|
it "should return false if the :predicate_mappings key is missing" do
|
363
363
|
mock_yaml({:default_namespace=>"a string"},"/path/to/predicate_mappings.yml")
|
364
|
-
subject.send(:valid_predicate_mapping?,"/path/to/predicate_mappings.yml").
|
364
|
+
expect(subject.send(:valid_predicate_mapping?,"/path/to/predicate_mappings.yml")).to be_falsey
|
365
365
|
end
|
366
366
|
it "should return false if the :predicate_mappings key is not a hash" do
|
367
367
|
mock_yaml({:default_namespace=>"a string",:predicate_mapping=>"another string"},"/path/to/predicate_mappings.yml")
|
368
|
-
subject.send(:valid_predicate_mapping?,"/path/to/predicate_mappings.yml").
|
368
|
+
expect(subject.send(:valid_predicate_mapping?,"/path/to/predicate_mappings.yml")).to be_falsey
|
369
369
|
end
|
370
370
|
|
371
371
|
end
|