active-fedora 4.1.0 → 4.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.rvmrc +1 -1
- data/Gemfile +10 -2
- data/Gemfile.lock +53 -27
- data/History.txt +22 -1
- data/README.textile +2 -2
- data/active-fedora.gemspec +3 -3
- data/config/predicate_mappings.yml +2 -0
- data/lib/active_fedora/associations/belongs_to_association.rb +2 -6
- data/lib/active_fedora/base.rb +44 -7
- data/lib/active_fedora/datastreams.rb +15 -13
- data/lib/active_fedora/model.rb +76 -51
- data/lib/active_fedora/rdf_datastream.rb +56 -26
- data/lib/active_fedora/semantic_node.rb +9 -0
- data/lib/active_fedora/unsaved_digital_object.rb +6 -0
- data/lib/active_fedora/version.rb +1 -1
- data/lib/tasks/active_fedora_dev.rake +11 -2
- data/spec/integration/associations_spec.rb +17 -0
- data/spec/integration/base_spec.rb +87 -36
- data/spec/integration/datastream_spec.rb +29 -0
- data/spec/integration/ntriples_datastream_spec.rb +7 -0
- data/spec/spec_helper.rb +9 -0
- data/spec/support/mock_fedora.rb +6 -2
- data/spec/unit/base_spec.rb +55 -40
- data/spec/unit/datastreams_spec.rb +6 -2
- data/spec/unit/model_spec.rb +106 -60
- data/spec/unit/ntriples_datastream_spec.rb +85 -7
- data/spec/unit/semantic_node_spec.rb +17 -3
- data/spec/unit/unsaved_digital_object_spec.rb +9 -0
- metadata +272 -173
data/spec/support/mock_fedora.rb
CHANGED
@@ -9,14 +9,18 @@ end
|
|
9
9
|
|
10
10
|
def stub_get(pid, datastreams=nil, record_exists=false)
|
11
11
|
pid.gsub!(/:/, '%3A')
|
12
|
-
|
13
|
-
|
12
|
+
if record_exists
|
13
|
+
mock_client.stubs(:[]).with("objects/#{pid}?format=xml").returns(stub('get getter', :get=>'foobar'))
|
14
|
+
else
|
15
|
+
mock_client.stubs(:[]).with("objects/#{pid}?format=xml").raises(RestClient::ResourceNotFound)
|
16
|
+
end
|
14
17
|
mock_client.stubs(:[]).with("objects/#{pid}/datastreams?format=xml").returns(@getter)
|
15
18
|
datastreams ||= ['someData', 'withText', 'withText2', 'RELS-EXT']
|
16
19
|
datastreams.each do |dsid|
|
17
20
|
mock_client.stubs(:[]).with("objects/#{pid}/datastreams/#{dsid}?format=xml").returns(@getter)
|
18
21
|
end
|
19
22
|
end
|
23
|
+
|
20
24
|
def stub_ingest(pid=nil)
|
21
25
|
n = pid ? pid.gsub(/:/, '%3A') : nil
|
22
26
|
mock_client.expects(:[]).with("objects/#{n || 'new'}").returns(stub("ingester", :post=>pid))
|
data/spec/unit/base_spec.rb
CHANGED
@@ -7,60 +7,75 @@ describe ActiveFedora::Base do
|
|
7
7
|
ActiveFedora::Base.shard_index(@this_pid).should == 0
|
8
8
|
end
|
9
9
|
|
10
|
-
|
11
|
-
|
10
|
+
context "When the repository is NOT sharded" do
|
11
|
+
subject {ActiveFedora::Base.connection_for_pid('foo:bar')}
|
12
|
+
before(:each) do
|
13
|
+
ActiveFedora.config.stubs(:sharded?).returns(false)
|
12
14
|
ActiveFedora::Base.fedora_connection = {}
|
15
|
+
ActiveFedora.config.stubs(:credentials).returns(:url=>'myfedora')
|
16
|
+
end
|
17
|
+
it { should be_kind_of Rubydora::Repository}
|
18
|
+
it "should be the standard connection" do
|
19
|
+
subject.client.url.should == 'myfedora'
|
13
20
|
end
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
ActiveFedora.config.expects(:sharded?).returns(false)
|
18
|
-
ActiveFedora.config.expects(:credentials).returns(:url=>'myfedora')
|
21
|
+
describe "assign_pid" do
|
22
|
+
after do
|
23
|
+
ActiveFedora::RubydoraConnection.unstub(:new)
|
19
24
|
end
|
20
|
-
it
|
21
|
-
|
22
|
-
|
25
|
+
it "should use fedora to generate pids" do
|
26
|
+
# TODO: This juggling of Fedora credentials & establishing connections should be handled by an establish_fedora_connection method,
|
27
|
+
# possibly wrap it all into a fedora_connection method - MZ 06-05-2012
|
28
|
+
stubfedora = mock("Fedora")
|
29
|
+
stubfedora.expects(:connection).returns(mock("Connection", :next_pid =>"<pid>sample:newpid</pid>"))
|
30
|
+
# Should use ActiveFedora.config.credentials as a single hash rather than an array of shards
|
31
|
+
ActiveFedora::RubydoraConnection.expects(:new).with(ActiveFedora.config.credentials).returns(stubfedora)
|
32
|
+
ActiveFedora::Base.assign_pid(ActiveFedora::Base.new.inner_object)
|
23
33
|
end
|
24
34
|
end
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
def self.shard_index(pid)
|
29
|
-
pid == 'foo:bar' ? 0 : 1
|
30
|
-
end
|
31
|
-
end
|
35
|
+
describe "shard_index" do
|
36
|
+
it "should always return zero (the first and only connection)" do
|
37
|
+
ActiveFedora::Base.shard_index('foo:bar').should == 0
|
32
38
|
end
|
33
|
-
|
34
|
-
|
39
|
+
end
|
40
|
+
end
|
41
|
+
context "When the repository is sharded" do
|
42
|
+
before :each do
|
43
|
+
ActiveFedora.config.stubs(:sharded?).returns(true)
|
44
|
+
ActiveFedora::Base.fedora_connection = {}
|
45
|
+
ActiveFedora.config.stubs(:credentials).returns([{:url=>'shard1'}, {:url=>'shard2'} ])
|
46
|
+
end
|
47
|
+
describe "assign_pid" do
|
48
|
+
it "should always use the first shard to generate pids" do
|
49
|
+
stubshard1 = mock("Shard")
|
50
|
+
stubshard2 = mock("Shard")
|
51
|
+
stubshard1.expects(:connection).returns(mock("Connection", :next_pid =>"<pid>sample:newpid</pid>"))
|
52
|
+
stubshard2.expects(:connection).never
|
53
|
+
ActiveFedora::Base.fedora_connection = {0 => stubshard1, 1 => stubshard2}
|
54
|
+
ActiveFedora::Base.assign_pid(ActiveFedora::Base.new.inner_object)
|
35
55
|
end
|
36
|
-
|
37
|
-
|
56
|
+
end
|
57
|
+
describe "shard_index" do
|
58
|
+
it "should use modulo of md5 of the pid to distribute objects across shards" do
|
59
|
+
ActiveFedora::Base.shard_index('foo:bar').should == 0
|
60
|
+
ActiveFedora::Base.shard_index('foo:nanana').should == 1
|
38
61
|
end
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
62
|
+
end
|
63
|
+
describe "the repository" do
|
64
|
+
describe "for foo:bar" do
|
65
|
+
subject {ActiveFedora::Base.connection_for_pid('foo:bar')}
|
66
|
+
it "should be shard1" do
|
67
|
+
subject.client.url.should == 'shard1'
|
43
68
|
end
|
44
69
|
end
|
45
|
-
describe "
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
describe "for foo:bar" do
|
50
|
-
subject {FooHistory.connection_for_pid('foo:bar')}
|
51
|
-
it "should be shard1" do
|
52
|
-
subject.client.url.should == 'shard1'
|
53
|
-
end
|
54
|
-
end
|
55
|
-
describe "for foo:baz" do
|
56
|
-
subject {FooHistory.connection_for_pid('foo:baz')}
|
57
|
-
it "should be shard1" do
|
58
|
-
subject.client.url.should == 'shard2'
|
59
|
-
end
|
70
|
+
describe "for foo:baz" do
|
71
|
+
subject {ActiveFedora::Base.connection_for_pid('foo:nanana')}
|
72
|
+
it "should be shard1" do
|
73
|
+
subject.client.url.should == 'shard2'
|
60
74
|
end
|
61
75
|
end
|
62
76
|
end
|
63
77
|
end
|
78
|
+
|
64
79
|
end
|
65
80
|
|
66
81
|
describe "With a test class" do
|
@@ -272,7 +272,8 @@ describe ActiveFedora::Datastreams do
|
|
272
272
|
before do
|
273
273
|
class FileDS < ActiveFedora::Datastream; end
|
274
274
|
class FooHistory < ActiveFedora::Base
|
275
|
-
has_file_datastream
|
275
|
+
has_file_datastream
|
276
|
+
has_file_datastream :name=>"second", :label=>"Second file", :type=>FileDS, :control_group=>'X'
|
276
277
|
end
|
277
278
|
end
|
278
279
|
after do
|
@@ -280,9 +281,12 @@ describe ActiveFedora::Datastreams do
|
|
280
281
|
Object.send(:remove_const, :FileDS)
|
281
282
|
end
|
282
283
|
it "Should add a line in ds_spec" do
|
283
|
-
FooHistory.ds_specs['content'][:type].should ==
|
284
|
+
FooHistory.ds_specs['content'][:type].should == ActiveFedora::Datastream
|
284
285
|
FooHistory.ds_specs['content'][:label].should == "File Datastream"
|
285
286
|
FooHistory.ds_specs['content'][:control_group].should == "M"
|
287
|
+
FooHistory.ds_specs['second'][:type].should == FileDS
|
288
|
+
FooHistory.ds_specs['second'][:label].should == "Second file"
|
289
|
+
FooHistory.ds_specs['second'][:control_group].should == "X"
|
286
290
|
end
|
287
291
|
end
|
288
292
|
|
data/spec/unit/model_spec.rb
CHANGED
@@ -6,75 +6,27 @@ describe ActiveFedora::Model do
|
|
6
6
|
module SpecModel
|
7
7
|
class Basic
|
8
8
|
include ActiveFedora::Model
|
9
|
+
def initialize (args = {})
|
10
|
+
end
|
9
11
|
end
|
10
12
|
end
|
11
|
-
@test_property = ActiveFedora::Property.new("foo_model","test_property", :text)
|
12
|
-
end
|
13
|
-
|
14
|
-
before(:each) do
|
15
|
-
ActiveFedora::Base.stubs(:assign_pid).returns('_nextid_')
|
16
|
-
@test_instance = SpecModel::Basic.new
|
17
|
-
@property = stub("myproperty", :name => "mock_prop", :instance_variable_name => "@mock_prop")
|
18
|
-
SpecModel::Basic.extend(ActiveFedora::Model)
|
19
|
-
SpecModel::Basic.create_property_getter(@property)
|
20
|
-
@obj = SpecModel::Basic.new
|
21
13
|
end
|
22
14
|
|
23
15
|
after(:all) do
|
24
16
|
Object.send(:remove_const, :SpecModel)
|
25
17
|
end
|
26
18
|
|
27
|
-
it 'should provide #attribute_set and #attribute_get' do
|
28
|
-
SpecModel::Basic.should respond_to(:attribute_set)
|
29
|
-
SpecModel::Basic.should respond_to(:attribute_get)
|
30
|
-
end
|
31
|
-
|
32
|
-
it 'should provide #create_property_getter' do
|
33
|
-
SpecModel::Basic.should respond_to(:create_property_getter)
|
34
|
-
end
|
35
|
-
|
36
|
-
describe '#create_property_getter' do
|
37
|
-
it 'should add getter to the model' do
|
38
|
-
@obj.should respond_to(@property.name)
|
39
|
-
end
|
40
|
-
|
41
|
-
it 'should use attribute_get in custom getter method' do
|
42
|
-
@obj.expects(:attribute_get).with(@property.name)
|
43
|
-
@obj.send @property.name
|
44
|
-
end
|
45
|
-
|
46
|
-
end
|
47
|
-
|
48
|
-
it 'should provide #create_property_setter' do
|
49
|
-
SpecModel::Basic.should respond_to(:create_property_setter)
|
50
|
-
end
|
51
|
-
|
52
|
-
describe '#create_property_setter' do
|
53
|
-
|
54
|
-
before(:each) do
|
55
|
-
@property = stub("myproperty", :name => "mock_prop", :instance_variable_name => "@mock_prop")
|
56
|
-
SpecModel::Basic.create_property_setter(@property)
|
57
|
-
@obj = SpecModel::Basic.new
|
58
|
-
end
|
59
|
-
|
60
|
-
it 'should add setter to the model' do
|
61
|
-
@obj.should respond_to("#{@property.name}=")
|
62
|
-
end
|
63
|
-
|
64
|
-
it 'should use attribute_set in custom setter method' do
|
65
|
-
@obj.expects(:attribute_set).with(@property.name, "sample value")
|
66
|
-
@obj.send "#{@property.name}=", "sample value"
|
67
|
-
end
|
68
|
-
|
69
|
-
end
|
70
19
|
|
71
20
|
describe '#find' do
|
72
21
|
describe "without :cast" do
|
73
22
|
it "(:all) should query solr for all objects with :active_fedora_model_s of self.class" do
|
74
|
-
ActiveFedora::SolrService.expects(:query).with('has_model_s:info\\:fedora/afmodel\\:SpecModel_Basic', :rows=>1001).returns([{"id" => "changeme:30"}, {"id" => "changeme:22"}])
|
75
23
|
SpecModel::Basic.expects(:find_one).with("changeme:30", nil).returns("Fake Object1")
|
76
24
|
SpecModel::Basic.expects(:find_one).with("changeme:22", nil).returns("Fake Object2")
|
77
|
-
|
25
|
+
mock_docs = mock('docs')
|
26
|
+
mock_docs.expects(:each).multiple_yields([{"id" => "changeme:30"}],[{"id" => "changeme:22"}])
|
27
|
+
mock_docs.expects(:has_next?).returns(false)
|
28
|
+
ActiveFedora::SolrService.instance.conn.expects(:paginate).with(1, 1000, 'select', :params=>{:q=>'has_model_s:info\\:fedora/afmodel\\:SpecModel_Basic', :qt => 'standard', :sort => ['system_create_dt asc'], :fl=> 'id', }).returns('response'=>{'docs'=>mock_docs})
|
29
|
+
SpecModel::Basic.find(:all).should == ["Fake Object1", "Fake Object2"]
|
78
30
|
end
|
79
31
|
it "should use SpecModel::Basic.allocate.init_with to instantiate an object" do
|
80
32
|
SpecModel::Basic.any_instance.expects(:init_with).returns(SpecModel::Basic.new)
|
@@ -82,6 +34,7 @@ describe ActiveFedora::Model do
|
|
82
34
|
SpecModel::Basic.find("_PID_").should be_a SpecModel::Basic
|
83
35
|
end
|
84
36
|
it "should raise an exception if it is not found" do
|
37
|
+
Rubydora::Repository.any_instance.expects(:object).raises(RestClient::ResourceNotFound)
|
85
38
|
SpecModel::Basic.expects(:connection_for_pid).with("_PID_")
|
86
39
|
lambda {SpecModel::Basic.find("_PID_")}.should raise_error ActiveFedora::ObjectNotFoundError
|
87
40
|
end
|
@@ -94,13 +47,91 @@ describe ActiveFedora::Model do
|
|
94
47
|
end
|
95
48
|
end
|
96
49
|
|
97
|
-
describe "with conditions
|
50
|
+
describe "with conditions" do
|
98
51
|
it "should filter by the provided fields" do
|
99
52
|
SpecModel::Basic.expects(:find_one).with("changeme:30", nil).returns("Fake Object1")
|
100
53
|
SpecModel::Basic.expects(:find_one).with("changeme:22", nil).returns("Fake Object2")
|
101
54
|
|
102
|
-
|
103
|
-
|
55
|
+
mock_docs = mock('docs')
|
56
|
+
mock_docs.expects(:each).multiple_yields([{"id" => "changeme:30"}],[{"id" => "changeme:22"}])
|
57
|
+
mock_docs.expects(:has_next?).returns(false)
|
58
|
+
ActiveFedora::SolrService.instance.conn.expects(:paginate).with() { |page, rows, method, hash|
|
59
|
+
page == 1 &&
|
60
|
+
rows == 1000 &&
|
61
|
+
method == 'select' &&
|
62
|
+
hash[:params] &&
|
63
|
+
hash[:params][:sort] == ['system_create_dt asc'] &&
|
64
|
+
hash[:params][:fl] == 'id' &&
|
65
|
+
hash[:params][:q].split(" AND ").include?("has_model_s:info\\:fedora/afmodel\\:SpecModel_Basic") &&
|
66
|
+
hash[:params][:q].split(" AND ").include?("foo:\"bar\"") &&
|
67
|
+
hash[:params][:q].split(" AND ").include?("baz:\"quix\"") &&
|
68
|
+
hash[:params][:q].split(" AND ").include?("baz:\"quack\"")
|
69
|
+
}.returns('response'=>{'docs'=>mock_docs})
|
70
|
+
SpecModel::Basic.find({:foo=>'bar', :baz=>['quix','quack']}).should == ["Fake Object1", "Fake Object2"]
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
describe '#find_each' do
|
76
|
+
it "should query solr for all objects with :active_fedora_model_s of self.class" do
|
77
|
+
mock_docs = mock('docs')
|
78
|
+
mock_docs.expects(:each).multiple_yields([{"id" => "changeme:30"}],[{"id" => "changeme:22"}])
|
79
|
+
mock_docs.expects(:has_next?).returns(false)
|
80
|
+
ActiveFedora::SolrService.instance.conn.expects(:paginate).with(1, 1000, 'select', :params=>{:q=>'has_model_s:info\\:fedora/afmodel\\:SpecModel_Basic', :qt => 'standard', :sort => ['system_create_dt asc'], :fl=> 'id', }).returns('response'=>{'docs'=>mock_docs})
|
81
|
+
|
82
|
+
SpecModel::Basic.expects(:find_one).with("changeme:30", nil).returns(SpecModel::Basic.new(:pid=>'changeme:30'))
|
83
|
+
SpecModel::Basic.expects(:find_one).with("changeme:22", nil).returns(SpecModel::Basic.new(:pid=>'changeme:22'))
|
84
|
+
yielded = mock("yielded method")
|
85
|
+
yielded.expects(:run).with { |obj| obj.class == SpecModel::Basic}.twice
|
86
|
+
SpecModel::Basic.find_each(){|obj| yielded.run(obj) }
|
87
|
+
end
|
88
|
+
describe "with conditions" do
|
89
|
+
it "should filter by the provided fields" do
|
90
|
+
SpecModel::Basic.expects(:find_one).with("changeme:30", nil).returns(SpecModel::Basic.new(:pid=>'changeme:30'))
|
91
|
+
SpecModel::Basic.expects(:find_one).with("changeme:22", nil).returns(SpecModel::Basic.new(:pid=>'changeme:22'))
|
92
|
+
|
93
|
+
mock_docs = mock('docs')
|
94
|
+
mock_docs.expects(:each).multiple_yields([{"id" => "changeme:30"}],[{"id" => "changeme:22"}])
|
95
|
+
mock_docs.expects(:has_next?).returns(false)
|
96
|
+
ActiveFedora::SolrService.instance.conn.expects(:paginate).with() { |page, rows, method, hash|
|
97
|
+
page == 1 &&
|
98
|
+
rows == 1000 &&
|
99
|
+
method == 'select' &&
|
100
|
+
hash[:params] &&
|
101
|
+
hash[:params][:sort] == ['system_create_dt asc'] &&
|
102
|
+
hash[:params][:fl] == 'id' &&
|
103
|
+
hash[:params][:q].split(" AND ").include?("has_model_s:info\\:fedora/afmodel\\:SpecModel_Basic") &&
|
104
|
+
hash[:params][:q].split(" AND ").include?("foo:\"bar\"") &&
|
105
|
+
hash[:params][:q].split(" AND ").include?("baz:\"quix\"") &&
|
106
|
+
hash[:params][:q].split(" AND ").include?("baz:\"quack\"")
|
107
|
+
}.returns('response'=>{'docs'=>mock_docs})
|
108
|
+
yielded = mock("yielded method")
|
109
|
+
yielded.expects(:run).with { |obj| obj.class == SpecModel::Basic}.twice
|
110
|
+
SpecModel::Basic.find_each({:foo=>'bar', :baz=>['quix','quack']}){|obj| yielded.run(obj) }
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
describe '#find_in_batches' do
|
116
|
+
describe "with conditions hash" do
|
117
|
+
it "should filter by the provided fields" do
|
118
|
+
mock_docs = mock('docs')
|
119
|
+
mock_docs.expects(:has_next?).returns(false)
|
120
|
+
ActiveFedora::SolrService.instance.conn.expects(:paginate).with() { |page, rows, method, hash|
|
121
|
+
page == 1 &&
|
122
|
+
rows == 1002 &&
|
123
|
+
method == 'select' &&
|
124
|
+
hash[:params] &&
|
125
|
+
hash[:params][:sort] == ['system_create_dt asc'] &&
|
126
|
+
hash[:params][:fl] == 'id' &&
|
127
|
+
hash[:params][:q].split(" AND ").include?("has_model_s:info\\:fedora/afmodel\\:SpecModel_Basic") &&
|
128
|
+
hash[:params][:q].split(" AND ").include?("foo:\"bar\"") &&
|
129
|
+
hash[:params][:q].split(" AND ").include?("baz:\"quix\"") &&
|
130
|
+
hash[:params][:q].split(" AND ").include?("baz:\"quack\"")
|
131
|
+
}.returns('response'=>{'docs'=>mock_docs})
|
132
|
+
yielded = mock("yielded method")
|
133
|
+
yielded.expects(:run).with(mock_docs)
|
134
|
+
SpecModel::Basic.find_in_batches({:foo=>'bar', :baz=>['quix','quack']}, {:batch_size=>1002, :fl=>'id'}){|group| yielded.run group }.should
|
104
135
|
end
|
105
136
|
end
|
106
137
|
end
|
@@ -137,13 +168,28 @@ describe ActiveFedora::Model do
|
|
137
168
|
describe '#find_with_conditions' do
|
138
169
|
it "should make a query to solr and return the results" do
|
139
170
|
mock_result = stub('Result')
|
140
|
-
|
171
|
+
ActiveFedora::SolrService.expects(:query).with() { |args|
|
172
|
+
q = args.first if args.is_a? Array
|
173
|
+
q ||= args
|
174
|
+
q.split(" AND ").include?("has_model_s:info\\:fedora/afmodel\\:SpecModel_Basic") &&
|
175
|
+
q.split(" AND ").include?("foo:\"bar\"") &&
|
176
|
+
q.split(" AND ").include?("baz:\"quix\"") &&
|
177
|
+
q.split(" AND ").include?("baz:\"quack\"")
|
178
|
+
}.returns(mock_result)
|
141
179
|
SpecModel::Basic.find_with_conditions(:foo=>'bar', :baz=>['quix','quack']).should == mock_result
|
142
180
|
|
143
181
|
end
|
144
182
|
it "should escape quotes" do
|
145
183
|
mock_result = stub('Result')
|
146
|
-
|
184
|
+
ActiveFedora::SolrService.expects(:query).with() { |args|
|
185
|
+
q = args.first if args.is_a? Array
|
186
|
+
q ||= args
|
187
|
+
q.split(" AND ").include?("has_model_s:info\\:fedora/afmodel\\:SpecModel_Basic") &&
|
188
|
+
q.split(" AND ").include?("has_model_s:info\\:fedora/afmodel\\:SpecModel_Basic") &&
|
189
|
+
q.split(" AND ").include?('foo:"9\\" Nails"') &&
|
190
|
+
q.split(" AND ").include?('baz:"7\\" version"') &&
|
191
|
+
q.split(" AND ").include?('baz:"quack"')
|
192
|
+
}.returns(mock_result)
|
147
193
|
SpecModel::Basic.find_with_conditions(:foo=>'9" Nails', :baz=>['7" version','quack']).should == mock_result
|
148
194
|
|
149
195
|
end
|
@@ -13,12 +13,22 @@ describe ActiveFedora::NtriplesRDFDatastream do
|
|
13
13
|
map.related_url(:to => "seeAlso", :in => RDF::RDFS)
|
14
14
|
end
|
15
15
|
end
|
16
|
-
|
16
|
+
class Foo < ActiveFedora::Base
|
17
|
+
has_metadata :name => "descMetadata", :type => MyDatastream
|
18
|
+
delegate :created, :to => :descMetadata
|
19
|
+
delegate :title, :to => :descMetadata
|
20
|
+
delegate :publisher, :to => :descMetadata
|
21
|
+
delegate :based_near, :to => :descMetadata
|
22
|
+
delegate :related_url, :to => :descMetadata
|
23
|
+
end
|
24
|
+
@object = Foo.new(:pid => 'test:1')
|
25
|
+
@subject = @object.descMetadata
|
17
26
|
@subject.content = File.new('spec/fixtures/mixed_rdf_descMetadata.nt').read
|
18
|
-
@
|
19
|
-
|
27
|
+
@object.save
|
28
|
+
end
|
29
|
+
after do
|
30
|
+
@object.delete
|
20
31
|
end
|
21
|
-
|
22
32
|
it "should have a subject" do
|
23
33
|
@subject.rdf_subject.should == "info:fedora/test:1"
|
24
34
|
end
|
@@ -29,7 +39,7 @@ describe ActiveFedora::NtriplesRDFDatastream do
|
|
29
39
|
@subject.mimeType.should == 'text/plain'
|
30
40
|
end
|
31
41
|
it "should have dsid" do
|
32
|
-
@subject.dsid.should == '
|
42
|
+
@subject.dsid.should == 'descMetadata'
|
33
43
|
end
|
34
44
|
it "should have fields" do
|
35
45
|
@subject.created.should == ["2010-12-31"]
|
@@ -59,6 +69,21 @@ describe ActiveFedora::NtriplesRDFDatastream do
|
|
59
69
|
end
|
60
70
|
end
|
61
71
|
|
72
|
+
describe "some dummy instances" do
|
73
|
+
before do
|
74
|
+
class MyFoobarRDFDatastream < ActiveFedora::NtriplesRDFDatastream
|
75
|
+
end
|
76
|
+
class MyFoobarRdfDatastream < ActiveFedora::NtriplesRDFDatastream
|
77
|
+
end
|
78
|
+
end
|
79
|
+
it "should generate predictable prexies" do
|
80
|
+
MyFoobarRDFDatastream.prefix("baz").should == :my_foobar__baz
|
81
|
+
end
|
82
|
+
it "should generate prefixes case-insensitively" do
|
83
|
+
MyFoobarRDFDatastream.prefix("quux").should == MyFoobarRdfDatastream.prefix("quux")
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
62
87
|
describe "an instance with a custom subject" do
|
63
88
|
before do
|
64
89
|
class MyDatastream < ActiveFedora::NtriplesRDFDatastream
|
@@ -73,9 +98,9 @@ describe ActiveFedora::NtriplesRDFDatastream do
|
|
73
98
|
end
|
74
99
|
end
|
75
100
|
@subject = MyDatastream.new(@inner_object, 'mixed_rdf')
|
76
|
-
@subject.content = File.new('spec/fixtures/mixed_rdf_descMetadata.nt').read
|
77
101
|
@subject.stubs(:pid => 'test:1')
|
78
102
|
@subject.stubs(:new? => false)
|
103
|
+
@subject.content = File.new('spec/fixtures/mixed_rdf_descMetadata.nt').read
|
79
104
|
end
|
80
105
|
|
81
106
|
it "should have fields" do
|
@@ -220,7 +245,16 @@ describe ActiveFedora::NtriplesRDFDatastream do
|
|
220
245
|
ActiveFedora::SolrService.load_mappings
|
221
246
|
end
|
222
247
|
describe "with an actual object" do
|
223
|
-
before(:
|
248
|
+
before(:each) do
|
249
|
+
class Foo < ActiveFedora::Base
|
250
|
+
has_metadata :name => "descMetadata", :type => MyDatastream
|
251
|
+
delegate :created, :to => :descMetadata
|
252
|
+
delegate :title, :to => :descMetadata
|
253
|
+
delegate :publisher, :to => :descMetadata
|
254
|
+
delegate :based_near, :to => :descMetadata
|
255
|
+
delegate :related_url, :to => :descMetadata
|
256
|
+
delegate :rights, :to => :descMetadata
|
257
|
+
end
|
224
258
|
@obj = MyDatastream.new(@inner_object, 'solr_rdf')
|
225
259
|
@obj.created = "2012-03-04"
|
226
260
|
@obj.title = "Of Mice and Men, The Sequel"
|
@@ -230,6 +264,39 @@ describe ActiveFedora::NtriplesRDFDatastream do
|
|
230
264
|
@obj.rights = "Totally open, y'all"
|
231
265
|
@obj.save
|
232
266
|
end
|
267
|
+
describe '#save' do
|
268
|
+
it "should set dirty? to false" do
|
269
|
+
@obj.dirty?.should be_false
|
270
|
+
@obj.title = "something"
|
271
|
+
@obj.dirty?.should be_true
|
272
|
+
@obj.save
|
273
|
+
@obj.dirty?.should be_false
|
274
|
+
end
|
275
|
+
end
|
276
|
+
describe '.content=' do
|
277
|
+
it "should update the content and graph, marking the datastream as changed" do
|
278
|
+
mock_repo = mock('repository')
|
279
|
+
mock_repo.expects(:datastream_dissemination).with(:pid => 'test:123',
|
280
|
+
:dsid => 'solr_rdf')
|
281
|
+
sample_rdf = File.new('spec/fixtures/mixed_rdf_descMetadata.nt').read
|
282
|
+
@obj.stubs(:pid).returns('test:123')
|
283
|
+
@obj.stubs(:repository).returns(mock_repo)
|
284
|
+
@obj.should_not be_changed
|
285
|
+
@obj.content.should_not be_equivalent_to(sample_rdf)
|
286
|
+
@obj.content = sample_rdf
|
287
|
+
@obj.should be_changed
|
288
|
+
@obj.content.should be_equivalent_to(sample_rdf)
|
289
|
+
end
|
290
|
+
end
|
291
|
+
it "should save content properly upon save" do
|
292
|
+
foo = Foo.new(:pid => 'test:1')
|
293
|
+
foo.title = 'Hamlet'
|
294
|
+
foo.save
|
295
|
+
foo.title.should == ['Hamlet']
|
296
|
+
foo.descMetadata.content = File.new('spec/fixtures/mixed_rdf_descMetadata.nt').read
|
297
|
+
foo.save
|
298
|
+
foo.title.should == ['Title of work']
|
299
|
+
end
|
233
300
|
describe ".fields()" do
|
234
301
|
it "should return the right # of fields" do
|
235
302
|
@obj.fields.keys.count.should == 5
|
@@ -252,6 +319,17 @@ describe ActiveFedora::NtriplesRDFDatastream do
|
|
252
319
|
@obj.fields[:my_datastream__based_near][:values].should include("Tacoma, WA")
|
253
320
|
@obj.fields[:my_datastream__based_near][:values].should include("Renton, WA")
|
254
321
|
end
|
322
|
+
it "should solrize even when the object is not new" do
|
323
|
+
foo = Foo.new
|
324
|
+
foo.expects(:update_index).once
|
325
|
+
foo.title = "title1"
|
326
|
+
foo.save
|
327
|
+
foo = Foo.find(foo.pid)
|
328
|
+
foo.expects(:update_index).once
|
329
|
+
foo.publisher = "Allah2"
|
330
|
+
foo.title = "The Work2"
|
331
|
+
foo.save
|
332
|
+
end
|
255
333
|
end
|
256
334
|
describe ".to_solr()" do
|
257
335
|
it "should return the right # of fields" do
|