active-fedora 7.0.0.pre2 → 7.0.0.pre3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +0 -7
  3. data/active-fedora.gemspec +2 -2
  4. data/lib/active_fedora/associations/builder/belongs_to.rb +1 -0
  5. data/lib/active_fedora/associations/has_many_association.rb +3 -2
  6. data/lib/active_fedora/core.rb +9 -0
  7. data/lib/active_fedora/datastream.rb +13 -0
  8. data/lib/active_fedora/datastream_attribute.rb +10 -9
  9. data/lib/active_fedora/datastream_hash.rb +7 -0
  10. data/lib/active_fedora/datastreams.rb +1 -1
  11. data/lib/active_fedora/indexing.rb +1 -2
  12. data/lib/active_fedora/om_datastream.rb +9 -1
  13. data/lib/active_fedora/persistence.rb +2 -5
  14. data/lib/active_fedora/querying.rb +5 -1
  15. data/lib/active_fedora/rdf/indexing.rb +18 -10
  16. data/lib/active_fedora/relation/finder_methods.rb +5 -5
  17. data/lib/active_fedora/rels_ext_datastream.rb +4 -24
  18. data/lib/active_fedora/semantic_node.rb +24 -9
  19. data/lib/active_fedora/solr_instance_loader.rb +1 -7
  20. data/lib/active_fedora/solr_service.rb +106 -98
  21. data/lib/active_fedora/version.rb +1 -1
  22. data/lib/generators/active_fedora/config/solr/templates/solr_conf/conf/schema.xml +5 -0
  23. data/lib/generators/active_fedora/config/solr/templates/solr_conf/conf/solrconfig.xml +51 -0
  24. data/spec/integration/has_many_associations_spec.rb +7 -0
  25. data/spec/integration/scoped_query_spec.rb +1 -1
  26. data/spec/integration/solr_service_spec.rb +6 -6
  27. data/spec/unit/base_extra_spec.rb +4 -4
  28. data/spec/unit/base_spec.rb +2 -2
  29. data/spec/unit/core_spec.rb +77 -0
  30. data/spec/unit/ntriples_datastream_spec.rb +4 -4
  31. data/spec/unit/om_datastream_spec.rb +40 -4
  32. data/spec/unit/query_spec.rb +19 -19
  33. data/spec/unit/rels_ext_datastream_spec.rb +3 -2
  34. data/spec/unit/solr_config_options_spec.rb +1 -4
  35. data/spec/unit/solr_service_spec.rb +7 -1
  36. metadata +10 -8
@@ -0,0 +1,77 @@
1
+ require 'spec_helper'
2
+
3
+ describe ActiveFedora::Base do
4
+ before do
5
+ class MyDatastream < ActiveFedora::NtriplesRDFDatastream
6
+ map_predicates do |map|
7
+ map.publisher(:in => RDF::DC)
8
+ end
9
+ end
10
+ class Library < ActiveFedora::Base
11
+ end
12
+ class Book < ActiveFedora::Base
13
+ belongs_to :library, property: :has_constituent
14
+ has_metadata "foo", type: ActiveFedora::SimpleDatastream do |m|
15
+ m.field "title", :string
16
+ end
17
+ has_metadata "bar", type: MyDatastream
18
+ has_attributes :title, datastream: 'foo' # Om backed property
19
+ has_attributes :publisher, datastream: 'bar' # RDF backed property
20
+ end
21
+ subject.library = library
22
+ end
23
+ let (:library) { Library.create }
24
+ subject {Book.new(library: library, title: "War and Peace", publisher: "Random House")}
25
+ after do
26
+ Object.send(:remove_const, :Book)
27
+ Object.send(:remove_const, :Library)
28
+ end
29
+
30
+ describe "#freeze" do
31
+ before { subject.freeze }
32
+
33
+ it "should be frozen" do
34
+ expect(subject).to be_frozen
35
+ end
36
+
37
+ it "should make the associations immutable" do
38
+ expect {
39
+ subject.library_id = Library.create!.pid
40
+ }.to raise_error RuntimeError, "can't modify frozen Book"
41
+ expect(subject.library_id).to eq library.pid
42
+ end
43
+
44
+ describe "when the association is set via an id" do
45
+ subject {Book.new(library_id: library.id)}
46
+ it "should be able to load the association" do
47
+ expect(subject.library).to eq library
48
+ end
49
+ end
50
+
51
+ it "should make the om properties immutable" do
52
+ expect {
53
+ subject.title = "HEY"
54
+ }.to raise_error RuntimeError, "can't modify frozen ActiveFedora::SimpleDatastream"
55
+ expect(subject.title).to eq "War and Peace"
56
+ end
57
+
58
+ it "should make the RDF properties immutable" do
59
+ expect {
60
+ subject.publisher = "HEY"
61
+ }.to raise_error RuntimeError, "can't modify frozen MyDatastream"
62
+ expect(subject.publisher).to eq "Random House"
63
+ end
64
+
65
+ end
66
+
67
+ describe "an object that hasn't loaded the associations" do
68
+ before {subject.save! }
69
+
70
+ it "should access associations" do
71
+ f = Book.find(subject.id)
72
+ f.freeze
73
+ f.library_id.should_not be_nil
74
+
75
+ end
76
+ end
77
+ end
@@ -82,8 +82,8 @@ describe ActiveFedora::NtriplesRDFDatastream do
82
82
  @two = ActiveFedora::RDFDatastream.new('fakepid', 'myQuix')
83
83
  end
84
84
  it "should generate predictable prexies" do
85
- @one .prefix("baz").should == :my_foobar__baz
86
- @two.prefix("baz").should == :my_quix__baz
85
+ @one.apply_prefix("baz").should == 'my_foobar__baz'
86
+ @two.apply_prefix("baz").should == 'my_quix__baz'
87
87
  end
88
88
  end
89
89
 
@@ -180,8 +180,8 @@ describe ActiveFedora::NtriplesRDFDatastream do
180
180
  end
181
181
 
182
182
  it "should have a solr_name method" do
183
- expect(MyDatastream.primary_solr_name('descMetadata', :based_near)).to eq 'desc_metadata__based_near_sim'
184
- expect(MyDatastream.primary_solr_name('props', :title)).to eq 'props__title_tesim'
183
+ expect(MyDatastream.new(nil, 'descMetadata').primary_solr_name(:based_near)).to eq 'desc_metadata__based_near_sim'
184
+ expect(MyDatastream.new(nil, 'props').primary_solr_name(:title)).to eq 'props__title_tesim'
185
185
  end
186
186
 
187
187
  it "should optionally allow you to provide the Solr::Document to add fields to and return that document when done" do
@@ -55,6 +55,13 @@ describe ActiveFedora::OmDatastream do
55
55
  n.ng_xml.should be_equivalent_to("<fake template/>")
56
56
  end
57
57
  end
58
+
59
+ describe "#prefix" do
60
+ subject { ActiveFedora::OmDatastream.new(nil, 'descMetadata') }
61
+ it "should be an empty string (until active-fedora 8. Then it should be \"\#{dsid.underscore}__\"" do
62
+ subject.send(:prefix).should == ""
63
+ end
64
+ end
58
65
 
59
66
  describe '#xml_template' do
60
67
  it "should return an empty xml document" do
@@ -62,10 +69,39 @@ describe ActiveFedora::OmDatastream do
62
69
  end
63
70
  end
64
71
 
65
- describe "an instance" do
66
- subject { ActiveFedora::OmDatastream.new }
67
- it{ should.respond_to? :to_solr }
68
- its(:to_solr) {should == { }}
72
+ describe "to_solr" do
73
+ describe "with a dsid" do
74
+ subject { ActiveFedora::OmDatastream.new(@mock_inner, "descMetadata") }
75
+ its(:to_solr) {should == { }}
76
+ end
77
+ describe "without a dsid" do
78
+ subject { ActiveFedora::OmDatastream.new }
79
+ it "should raise an error" do
80
+ expect{subject.to_solr}.to raise_error RuntimeError, "to_solr requires the dsid to be set"
81
+ end
82
+ end
83
+
84
+ describe "when prefix is set" do
85
+ before do
86
+ class MyDatastream < ActiveFedora::OmDatastream
87
+ set_terminology do |t|
88
+ t.root(:path=>"mods")
89
+ t.title(:index_as=>[:stored_searchable])
90
+ end
91
+ def prefix
92
+ "foo__"
93
+ end
94
+ end
95
+ end
96
+ after do
97
+ Object.send(:remove_const, :MyDatastream)
98
+ end
99
+ subject { MyDatastream.new }
100
+ it "should use the prefix" do
101
+ subject.title = 'Science'
102
+ expect(subject.to_solr).to have_key('foo__title_tesim')
103
+ end
104
+ end
69
105
  end
70
106
 
71
107
  describe ".update_indexed_attributes" do
@@ -84,9 +84,9 @@ describe ActiveFedora::Base do
84
84
  hash[:params][:sort] == [@sort_query] &&
85
85
  hash[:params][:fl] == 'id' &&
86
86
  hash[:params][:q].split(" AND ").include?(@model_query) &&
87
- hash[:params][:q].split(" AND ").include?("foo:\"bar\"") &&
88
- hash[:params][:q].split(" AND ").include?("baz:\"quix\"") &&
89
- hash[:params][:q].split(" AND ").include?("baz:\"quack\"")
87
+ hash[:params][:q].split(" AND ").include?("foo:bar") &&
88
+ hash[:params][:q].split(" AND ").include?("baz:quix") &&
89
+ hash[:params][:q].split(" AND ").include?("baz:quack")
90
90
  }.and_return('response'=>{'docs'=>mock_docs})
91
91
  SpecModel::Basic.find({:foo=>'bar', :baz=>['quix','quack']}).should == ["Fake Object1", "Fake Object2"]
92
92
  end
@@ -113,9 +113,9 @@ describe ActiveFedora::Base do
113
113
  hash[:params][:fl] == 'id' &&
114
114
  hash[:params][:sort] == [@sort_query] &&
115
115
  hash[:params][:q].split(" AND ").include?(@model_query) &&
116
- hash[:params][:q].split(" AND ").include?("foo:\"bar\"") &&
117
- hash[:params][:q].split(" AND ").include?("baz:\"quix\"") &&
118
- hash[:params][:q].split(" AND ").include?("baz:\"quack\"")
116
+ hash[:params][:q].split(" AND ").include?("foo:bar") &&
117
+ hash[:params][:q].split(" AND ").include?("baz:quix") &&
118
+ hash[:params][:q].split(" AND ").include?("baz:quack")
119
119
  }.and_return('response'=>{'docs'=>mock_docs})
120
120
  SpecModel::Basic.find({:foo=>'bar', :baz=>['quix','quack']}, :sort=>'title_t desc').should == ["Fake Object1", "Fake Object2"]
121
121
  end
@@ -153,9 +153,9 @@ describe ActiveFedora::Base do
153
153
  hash[:params][:sort] == [@sort_query] &&
154
154
  hash[:params][:fl] == 'id' &&
155
155
  hash[:params][:q].split(" AND ").include?(@model_query) &&
156
- hash[:params][:q].split(" AND ").include?("foo:\"bar\"") &&
157
- hash[:params][:q].split(" AND ").include?("baz:\"quix\"") &&
158
- hash[:params][:q].split(" AND ").include?("baz:\"quack\"")
156
+ hash[:params][:q].split(" AND ").include?("foo:bar") &&
157
+ hash[:params][:q].split(" AND ").include?("baz:quix") &&
158
+ hash[:params][:q].split(" AND ").include?("baz:quack")
159
159
  }.and_return('response'=>{'docs'=>mock_docs})
160
160
  yielded = double("yielded method")
161
161
  yielded.should_receive(:run).with { |obj| obj.class == SpecModel::Basic}.twice
@@ -177,9 +177,9 @@ describe ActiveFedora::Base do
177
177
  hash[:params][:sort] == [@sort_query] &&
178
178
  hash[:params][:fl] == 'id' &&
179
179
  hash[:params][:q].split(" AND ").include?(@model_query) &&
180
- hash[:params][:q].split(" AND ").include?("foo:\"bar\"") &&
181
- hash[:params][:q].split(" AND ").include?("baz:\"quix\"") &&
182
- hash[:params][:q].split(" AND ").include?("baz:\"quack\"")
180
+ hash[:params][:q].split(" AND ").include?("foo:bar") &&
181
+ hash[:params][:q].split(" AND ").include?("baz:quix") &&
182
+ hash[:params][:q].split(" AND ").include?("baz:quack")
183
183
  }.and_return('response'=>{'docs'=>mock_docs})
184
184
  yielded = double("yielded method")
185
185
  yielded.should_receive(:run).with(mock_docs)
@@ -257,9 +257,9 @@ describe ActiveFedora::Base do
257
257
  q = args.first if args.is_a? Array
258
258
  q ||= args
259
259
  q.split(" AND ").include?(@model_query) &&
260
- q.split(" AND ").include?("foo:\"bar\"") &&
261
- q.split(" AND ").include?("baz:\"quix\"") &&
262
- q.split(" AND ").include?("baz:\"quack\"")
260
+ q.split(" AND ").include?("foo:bar") &&
261
+ q.split(" AND ").include?("baz:quix") &&
262
+ q.split(" AND ").include?("baz:quack")
263
263
  }.and_return(mock_result)
264
264
  SpecModel::Basic.find_with_conditions(:foo=>'bar', :baz=>['quix','quack']).should == mock_result
265
265
  end
@@ -271,16 +271,16 @@ describe ActiveFedora::Base do
271
271
  q ||= args
272
272
  q.split(" AND ").include?(@model_query) &&
273
273
  q.split(" AND ").include?(@model_query) &&
274
- q.split(" AND ").include?('foo:"9\\" Nails"') &&
275
- q.split(" AND ").include?('baz:"7\\" version"') &&
276
- q.split(" AND ").include?('baz:"quack"')
274
+ q.split(" AND ").include?('foo:9\\"\\ Nails') &&
275
+ q.split(" AND ").include?('baz:7\\"\\ version') &&
276
+ q.split(" AND ").include?('baz:quack')
277
277
  }.and_return(mock_result)
278
278
  SpecModel::Basic.find_with_conditions(:foo=>'9" Nails', :baz=>['7" version','quack']).should == mock_result
279
279
  end
280
280
 
281
281
  it "shouldn't use the class if it's called on AF:Base " do
282
282
  mock_result = double('Result')
283
- ActiveFedora::SolrService.should_receive(:query).with('baz:"quack"', {:sort => [@sort_query]}).and_return(mock_result)
283
+ ActiveFedora::SolrService.should_receive(:query).with('baz:quack', {:sort => [@sort_query]}).and_return(mock_result)
284
284
  ActiveFedora::Base.find_with_conditions(:baz=>'quack').should == mock_result
285
285
  end
286
286
  it "should use the query string if it's provided" do
@@ -28,10 +28,11 @@ describe ActiveFedora::RelsExtDatastream do
28
28
 
29
29
  describe "#changed?" do
30
30
  it "should be false when no changes have been made" do
31
+ subject.model = double(:relationships_are_dirty? => false)
31
32
  subject.changed?.should == false
32
33
  end
33
34
  it "should be true when the model has changes" do
34
- subject.model = double(:relationships_are_dirty=>true)
35
+ subject.model = double(:relationships_are_dirty? => true)
35
36
  subject.changed?.should == true
36
37
  end
37
38
  end
@@ -44,7 +45,7 @@ describe ActiveFedora::RelsExtDatastream do
44
45
  subject = RDF::URI.new "info:fedora/test:sample_pid"
45
46
  graph.insert RDF::Statement.new(subject, ActiveFedora::Predicates.find_graph_predicate(:is_member_of), RDF::URI.new('demo:10'))
46
47
 
47
- @test_ds.stub(:new? => true, :relationships_are_dirty? =>true, :relationships => graph, :model => double(:relationships_are_dirty= => true))
48
+ @test_ds.stub(:new? => true, :relationships => graph, :model => double(:relationships_are_dirty? =>true, :relationships_are_not_dirty! => true))
48
49
  @test_ds.serialize!
49
50
  EquivalentXml.equivalent?(@test_ds.content, "<rdf:RDF xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'>\n <rdf:Description rdf:about='info:fedora/test:sample_pid'>\n <isMemberOf rdf:resource='demo:10' xmlns='info:fedora/fedora-system:def/relations-external#'/></rdf:Description>\n </rdf:RDF>").should be_true
50
51
  end
@@ -1,8 +1,5 @@
1
1
  require 'spec_helper'
2
2
 
3
-
4
- #include ActiveFedora
5
-
6
3
  describe ActiveFedora do
7
4
 
8
5
  before(:all) do
@@ -35,7 +32,7 @@ describe ActiveFedora do
35
32
 
36
33
  it "should be used by ActiveFedora::Base#find_with_conditions" do
37
34
  mock_response = double("SolrResponse")
38
- ActiveFedora::SolrService.should_receive(:query).with("_query_:\"{!raw f=#{ActiveFedora::SolrService.solr_name("has_model", :symbol)}}info:fedora/afmodel:SolrSpecModel_Basic\" AND " + SOLR_DOCUMENT_ID + ':"changeme\\:30"', {:sort => ["#{ActiveFedora::SolrService.solr_name("system_create", :stored_sortable, type: :date)} asc"]}).and_return(mock_response)
35
+ ActiveFedora::SolrService.should_receive(:query).with("_query_:\"{!raw f=#{ActiveFedora::SolrService.solr_name("has_model", :symbol)}}info:fedora/afmodel:SolrSpecModel_Basic\" AND " + SOLR_DOCUMENT_ID + ':changeme\\:30', {:sort => ["#{ActiveFedora::SolrService.solr_name("system_create", :stored_sortable, type: :date)} asc"]}).and_return(mock_response)
39
36
 
40
37
  SolrSpecModel::Basic.find_with_conditions(:id=>"changeme:30").should equal(mock_response)
41
38
  end
@@ -91,6 +91,12 @@ describe ActiveFedora::SolrService do
91
91
  end
92
92
  end
93
93
  end
94
+
95
+ describe "raw_query" do
96
+ it "should generate a raw query clause" do
97
+ expect(ActiveFedora::SolrService.raw_query('id', "my:_PID1_")).to eq '_query_:"{!raw f=id}my:_PID1_"'
98
+ end
99
+ end
94
100
 
95
101
  describe '#construct_query_for_pids' do
96
102
  it "should generate a useable solr query from an array of Fedora pids" do
@@ -138,7 +144,7 @@ describe ActiveFedora::SolrService do
138
144
  it "should call solr" do
139
145
  mock_conn = double("Connection")
140
146
  doc = {'id' => '1234'}
141
- mock_conn.should_receive(:add).with(doc)
147
+ mock_conn.should_receive(:add).with(doc, {:params=>{}})
142
148
  ActiveFedora::SolrService.stub(:instance =>double("instance", :conn=>mock_conn))
143
149
  ActiveFedora::SolrService.add(doc)
144
150
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active-fedora
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.0.0.pre2
4
+ version: 7.0.0.pre3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Zumwalt
@@ -10,22 +10,22 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2014-01-14 00:00:00.000000000 Z
13
+ date: 2014-01-17 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rsolr
17
17
  requirement: !ruby/object:Gem::Requirement
18
18
  requirements:
19
- - - '>='
19
+ - - ~>
20
20
  - !ruby/object:Gem::Version
21
- version: '0'
21
+ version: 1.0.10.pre1
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  requirements:
26
- - - '>='
26
+ - - ~>
27
27
  - !ruby/object:Gem::Version
28
- version: '0'
28
+ version: 1.0.10.pre1
29
29
  - !ruby/object:Gem::Dependency
30
30
  name: om
31
31
  requirement: !ruby/object:Gem::Requirement
@@ -88,14 +88,14 @@ dependencies:
88
88
  requirements:
89
89
  - - ~>
90
90
  - !ruby/object:Gem::Version
91
- version: 1.7.0.pre1
91
+ version: 1.7.0
92
92
  type: :runtime
93
93
  prerelease: false
94
94
  version_requirements: !ruby/object:Gem::Requirement
95
95
  requirements:
96
96
  - - ~>
97
97
  - !ruby/object:Gem::Version
98
- version: 1.7.0.pre1
98
+ version: 1.7.0
99
99
  - !ruby/object:Gem::Dependency
100
100
  name: rdf
101
101
  requirement: !ruby/object:Gem::Requirement
@@ -478,6 +478,7 @@ files:
478
478
  - spec/unit/code_configurator_spec.rb
479
479
  - spec/unit/config_spec.rb
480
480
  - spec/unit/content_model_spec.rb
481
+ - spec/unit/core_spec.rb
481
482
  - spec/unit/datastream_collections_spec.rb
482
483
  - spec/unit/datastream_spec.rb
483
484
  - spec/unit/datastreams_spec.rb
@@ -621,6 +622,7 @@ test_files:
621
622
  - spec/unit/code_configurator_spec.rb
622
623
  - spec/unit/config_spec.rb
623
624
  - spec/unit/content_model_spec.rb
625
+ - spec/unit/core_spec.rb
624
626
  - spec/unit/datastream_collections_spec.rb
625
627
  - spec/unit/datastream_spec.rb
626
628
  - spec/unit/datastreams_spec.rb