active-fedora 6.0.0.pre6 → 6.0.0.pre7
Sign up to get free protection for your applications and to get access to all the features.
- data/active-fedora.gemspec +1 -1
- data/lib/active_fedora/associations.rb +11 -8
- data/lib/active_fedora/associations/association_collection.rb +3 -1
- data/lib/active_fedora/base.rb +5 -2
- data/lib/active_fedora/querying.rb +2 -2
- data/lib/active_fedora/relation.rb +1 -1
- data/lib/active_fedora/solr_service.rb +7 -2
- data/lib/active_fedora/version.rb +1 -1
- data/spec/integration/has_many_associations_spec.rb +33 -0
- data/spec/unit/base_spec.rb +2 -2
- data/spec/unit/has_many_collection_spec.rb +1 -2
- data/spec/unit/query_spec.rb +23 -1
- data/spec/unit/solr_config_options_spec.rb +1 -1
- metadata +6 -4
data/active-fedora.gemspec
CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |s|
|
|
18
18
|
s.add_dependency('rsolr')
|
19
19
|
s.add_dependency('om', '~> 1.8.0')
|
20
20
|
s.add_dependency('nom-xml', '>=0.5.1')
|
21
|
-
s.add_dependency('solrizer', '~>3.0.0.
|
21
|
+
s.add_dependency('solrizer', '~>3.0.0.pre6')
|
22
22
|
s.add_dependency("activeresource", '>= 3.0.0')
|
23
23
|
s.add_dependency("activesupport", '>= 3.0.0')
|
24
24
|
s.add_dependency("builder", '~> 3.0.0')
|
@@ -12,24 +12,27 @@ module ActiveFedora
|
|
12
12
|
|
13
13
|
autoload :AssociationCollection, 'active_fedora/associations/association_collection'
|
14
14
|
autoload :AssociationProxy, 'active_fedora/associations/association_proxy'
|
15
|
+
|
16
|
+
# Clears out the association cache.
|
17
|
+
def clear_association_cache #:nodoc:
|
18
|
+
@association_cache.clear if persisted?
|
19
|
+
end
|
20
|
+
|
21
|
+
# :nodoc:
|
22
|
+
attr_reader :association_cache
|
23
|
+
|
15
24
|
private
|
16
25
|
|
17
26
|
# Returns the specified association instance if it responds to :loaded?, nil otherwise.
|
18
27
|
def association_instance_get(name)
|
19
|
-
|
20
|
-
if instance_variable_defined?(ivar)
|
21
|
-
association = instance_variable_get(ivar)
|
22
|
-
association if association.respond_to?(:loaded?)
|
23
|
-
end
|
28
|
+
@association_cache[name.to_sym]
|
24
29
|
end
|
25
30
|
|
26
31
|
# Set the specified association instance.
|
27
32
|
def association_instance_set(name, association)
|
28
|
-
|
33
|
+
@association_cache[name] = association
|
29
34
|
end
|
30
35
|
|
31
|
-
|
32
|
-
|
33
36
|
module ClassMethods
|
34
37
|
|
35
38
|
def has_many(association_id, options={})
|
@@ -180,7 +180,9 @@ module ActiveFedora
|
|
180
180
|
end
|
181
181
|
|
182
182
|
def construct_query
|
183
|
-
|
183
|
+
clauses = {@reflection.options[:property] => @owner.internal_uri}
|
184
|
+
clauses[:has_model] = @reflection.class_name.constantize.to_class_uri if @reflection.class_name
|
185
|
+
@counter_query = @finder_query = ActiveFedora::SolrService.construct_query_for_rel(clauses)
|
184
186
|
end
|
185
187
|
|
186
188
|
|
data/lib/active_fedora/base.rb
CHANGED
@@ -68,6 +68,7 @@ module ActiveFedora
|
|
68
68
|
# the given namespace.
|
69
69
|
def initialize(attrs = nil)
|
70
70
|
attrs = {} if attrs.nil?
|
71
|
+
@association_cache = {}
|
71
72
|
attributes = attrs.dup
|
72
73
|
@inner_object = UnsavedDigitalObject.new(self.class, attributes.delete(:namespace), attributes.delete(:pid))
|
73
74
|
self.relationships_loaded = true
|
@@ -80,6 +81,7 @@ module ActiveFedora
|
|
80
81
|
|
81
82
|
# Reloads the object from Fedora.
|
82
83
|
def reload
|
84
|
+
clear_association_cache
|
83
85
|
init_with(self.class.find(self.pid).inner_object)
|
84
86
|
end
|
85
87
|
|
@@ -94,6 +96,7 @@ module ActiveFedora
|
|
94
96
|
# post.init_with(DigitalObject.find(pid))
|
95
97
|
# post.properties.title # => 'hello world'
|
96
98
|
def init_with(inner_obj)
|
99
|
+
@association_cache = {}
|
97
100
|
@inner_object = inner_obj
|
98
101
|
unless @inner_object.is_a? SolrDigitalObject
|
99
102
|
@inner_object.original_class = self.class
|
@@ -304,8 +307,8 @@ module ActiveFedora
|
|
304
307
|
c_time = Time.parse(c_time) unless c_time.is_a?(Time)
|
305
308
|
m_time = modified_date
|
306
309
|
m_time = Time.parse(m_time) unless m_time.is_a?(Time)
|
307
|
-
Solrizer.set_field(solr_doc, 'system_create', c_time)
|
308
|
-
Solrizer.set_field(solr_doc, 'system_modified', m_time)
|
310
|
+
Solrizer.set_field(solr_doc, 'system_create', c_time, :stored_sortable)
|
311
|
+
Solrizer.set_field(solr_doc, 'system_modified', m_time, :stored_sortable)
|
309
312
|
Solrizer.set_field(solr_doc, 'active_fedora_model', self.class.inspect, :symbol)
|
310
313
|
solr_doc.merge!(SOLR_DOCUMENT_ID.to_sym => pid)
|
311
314
|
solrize_profile(solr_doc)
|
@@ -40,7 +40,7 @@ module ActiveFedora
|
|
40
40
|
end
|
41
41
|
|
42
42
|
def default_sort_params
|
43
|
-
[ActiveFedora::SolrService.solr_name(:system_create, type: :date)+' asc']
|
43
|
+
[ActiveFedora::SolrService.solr_name(:system_create, :stored_sortable, type: :date)+' asc']
|
44
44
|
end
|
45
45
|
|
46
46
|
# Yields the found ActiveFedora::Base object to the passed block
|
@@ -149,7 +149,7 @@ module ActiveFedora
|
|
149
149
|
# Return the solr clause that queries for this type of class
|
150
150
|
def search_model_clause
|
151
151
|
unless self == ActiveFedora::Base
|
152
|
-
return ActiveFedora::SolrService.construct_query_for_rel(:has_model
|
152
|
+
return ActiveFedora::SolrService.construct_query_for_rel(:has_model => self.to_class_uri)
|
153
153
|
end
|
154
154
|
end
|
155
155
|
end
|
@@ -75,8 +75,13 @@ module ActiveFedora
|
|
75
75
|
return uri.gsub(/(:)/, '\\:').gsub(/(\/)/, '\\/')
|
76
76
|
end
|
77
77
|
|
78
|
-
|
79
|
-
|
78
|
+
# Create a query with a clause for each key, value
|
79
|
+
# @param [Hash] args key is the predicate, value is the target_uri
|
80
|
+
def self.construct_query_for_rel(args)
|
81
|
+
clauses = args.map do |predicate, target_uri|
|
82
|
+
"#{solr_name(predicate, :symbol)}:#{escape_uri_for_query(target_uri)}"
|
83
|
+
end
|
84
|
+
clauses.join(" AND ")
|
80
85
|
end
|
81
86
|
|
82
87
|
def self.query(query, args={})
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "When two or more relationships share the same property" do
|
4
|
+
before do
|
5
|
+
class Book < ActiveFedora::Base
|
6
|
+
has_many :collections, :property=>:is_part_of, :class_name=>'Collection'
|
7
|
+
has_many :people, :property=>:is_part_of#, :class_name=>'Person'
|
8
|
+
end
|
9
|
+
|
10
|
+
class Person < ActiveFedora::Base
|
11
|
+
belongs_to :book, :property=>:is_part_of
|
12
|
+
end
|
13
|
+
|
14
|
+
class Collection < ActiveFedora::Base
|
15
|
+
belongs_to :book, :property=>:is_part_of
|
16
|
+
end
|
17
|
+
|
18
|
+
@book = Book.create!#(:collections=>[@collection1, @collection2], :people=>[@person1, @person2])
|
19
|
+
@person1 = Person.create!(:book=>@book)
|
20
|
+
@person2 = Person.create!(:book=>@book)
|
21
|
+
end
|
22
|
+
after do
|
23
|
+
Object.send(:remove_const, :Collection)
|
24
|
+
Object.send(:remove_const, :Person)
|
25
|
+
Object.send(:remove_const, :Book)
|
26
|
+
end
|
27
|
+
|
28
|
+
it "Should only return relationships of the correct class" do
|
29
|
+
@book.reload
|
30
|
+
@book.people.should == [@person1, @person2]
|
31
|
+
@book.collections.should == []
|
32
|
+
end
|
33
|
+
end
|
data/spec/unit/base_spec.rb
CHANGED
@@ -392,8 +392,8 @@ describe ActiveFedora::Base do
|
|
392
392
|
@test_object.should_receive(:create_date).and_return("2012-03-04T03:12:02Z")
|
393
393
|
@test_object.should_receive(:modified_date).and_return("2012-03-07T03:12:02Z")
|
394
394
|
solr_doc = @test_object.to_solr
|
395
|
-
solr_doc[ActiveFedora::SolrService.solr_name("system_create", type: :date)].should eql(["2012-03-04T03:12:02Z"])
|
396
|
-
solr_doc[ActiveFedora::SolrService.solr_name("system_modified", type: :date)].should eql(["2012-03-07T03:12:02Z"])
|
395
|
+
solr_doc[ActiveFedora::SolrService.solr_name("system_create", :stored_sortable, type: :date)].should eql(["2012-03-04T03:12:02Z"])
|
396
|
+
solr_doc[ActiveFedora::SolrService.solr_name("system_modified", :stored_sortable, type: :date)].should eql(["2012-03-07T03:12:02Z"])
|
397
397
|
solr_doc[:id].should eql("#{@test_object.pid}")
|
398
398
|
end
|
399
399
|
|
@@ -3,8 +3,7 @@ require 'spec_helper'
|
|
3
3
|
describe ActiveFedora::Associations::HasManyAssociation do
|
4
4
|
it "should be able to replace the collection" do
|
5
5
|
@owner = stub(:new_record? => false, :to_ary => nil, :internal_uri => 'info:fedora/changeme:99')
|
6
|
-
@reflection = stub(:klass => mock.class, :options=>{:property=>'predicate'})
|
7
|
-
#ac = ActiveFedora::Associations::AssociationCollection.new(@owner, @reflection)
|
6
|
+
@reflection = stub(:klass => mock.class, :options=>{:property=>'predicate'}, :class_name=> nil)
|
8
7
|
ac = ActiveFedora::Associations::HasManyAssociation.new(@owner, @reflection)
|
9
8
|
@target = [stub(:to_ary => nil, :new_record? => false, :remove_relationship=>true), stub(:to_ary => nil, :new_record? => false, :remove_relationship=>true), stub(:to_ary => nil, :new_record? => false, :remove_relationship=>true)]
|
10
9
|
ac.target = @target
|
data/spec/unit/query_spec.rb
CHANGED
@@ -8,7 +8,7 @@ describe ActiveFedora::Base do
|
|
8
8
|
end
|
9
9
|
end
|
10
10
|
@model_query = ActiveFedora::SolrService.solr_name("has_model", :symbol) + ":#{solr_uri("info:fedora/afmodel:SpecModel_Basic")}"
|
11
|
-
@sort_query = ActiveFedora::SolrService.solr_name("system_create", type: :date) + ' asc'
|
11
|
+
@sort_query = ActiveFedora::SolrService.solr_name("system_create", :stored_sortable, type: :date) + ' asc'
|
12
12
|
end
|
13
13
|
|
14
14
|
after(:all) do
|
@@ -81,6 +81,28 @@ describe ActiveFedora::Base do
|
|
81
81
|
}.and_return('response'=>{'docs'=>mock_docs})
|
82
82
|
SpecModel::Basic.find({:foo=>'bar', :baz=>['quix','quack']}).should == ["Fake Object1", "Fake Object2"]
|
83
83
|
end
|
84
|
+
|
85
|
+
it "should add options" do
|
86
|
+
SpecModel::Basic.should_receive(:find_one).with("changeme:30", nil).and_return("Fake Object1")
|
87
|
+
SpecModel::Basic.should_receive(:find_one).with("changeme:22", nil).and_return("Fake Object2")
|
88
|
+
|
89
|
+
mock_docs = [{"id" => "changeme:30"},{"id" => "changeme:22"}]
|
90
|
+
mock_docs.should_receive(:has_next?).and_return(false)
|
91
|
+
ActiveFedora::SolrService.instance.conn.should_receive(:paginate).with() { |page, rows, method, hash|
|
92
|
+
page == 1 &&
|
93
|
+
rows == 1000 &&
|
94
|
+
method == 'select' &&
|
95
|
+
hash[:params] &&
|
96
|
+
hash[:params][:fl] == 'id' &&
|
97
|
+
hash[:params][:sort] == [@sort_query] &&
|
98
|
+
hash[:params][:q].split(" AND ").include?(@model_query) &&
|
99
|
+
hash[:params][:q].split(" AND ").include?("foo:\"bar\"") &&
|
100
|
+
hash[:params][:q].split(" AND ").include?("baz:\"quix\"") &&
|
101
|
+
hash[:params][:q].split(" AND ").include?("baz:\"quack\"")
|
102
|
+
}.and_return('response'=>{'docs'=>mock_docs})
|
103
|
+
SpecModel::Basic.find({:foo=>'bar', :baz=>['quix','quack']}, :sort=>'title_t desc').should == ["Fake Object1", "Fake Object2"]
|
104
|
+
end
|
105
|
+
|
84
106
|
end
|
85
107
|
end
|
86
108
|
|
@@ -34,7 +34,7 @@ describe ActiveFedora do
|
|
34
34
|
|
35
35
|
it "should be used by ActiveFedora::Base#find_with_conditions" do
|
36
36
|
mock_response = mock("SolrResponse")
|
37
|
-
ActiveFedora::SolrService.should_receive(:query).with("#{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", type: :date)} asc"]}).and_return(mock_response)
|
37
|
+
ActiveFedora::SolrService.should_receive(:query).with("#{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)
|
38
38
|
|
39
39
|
SolrSpecModel::Basic.find_with_conditions(:id=>"changeme:30").should equal(mock_response)
|
40
40
|
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: 6.0.0.
|
4
|
+
version: 6.0.0.pre7
|
5
5
|
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2013-01-
|
14
|
+
date: 2013-01-30 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: rsolr
|
@@ -68,7 +68,7 @@ dependencies:
|
|
68
68
|
requirements:
|
69
69
|
- - ~>
|
70
70
|
- !ruby/object:Gem::Version
|
71
|
-
version: 3.0.0.
|
71
|
+
version: 3.0.0.pre6
|
72
72
|
type: :runtime
|
73
73
|
prerelease: false
|
74
74
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -76,7 +76,7 @@ dependencies:
|
|
76
76
|
requirements:
|
77
77
|
- - ~>
|
78
78
|
- !ruby/object:Gem::Version
|
79
|
-
version: 3.0.0.
|
79
|
+
version: 3.0.0.pre6
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: activeresource
|
82
82
|
requirement: !ruby/object:Gem::Requirement
|
@@ -438,6 +438,7 @@ files:
|
|
438
438
|
- spec/integration/datastreams_spec.rb
|
439
439
|
- spec/integration/delete_all_spec.rb
|
440
440
|
- spec/integration/full_featured_model_spec.rb
|
441
|
+
- spec/integration/has_many_associations_spec.rb
|
441
442
|
- spec/integration/model_spec.rb
|
442
443
|
- spec/integration/mods_article_integration_spec.rb
|
443
444
|
- spec/integration/nested_attribute_spec.rb
|
@@ -594,6 +595,7 @@ test_files:
|
|
594
595
|
- spec/integration/datastreams_spec.rb
|
595
596
|
- spec/integration/delete_all_spec.rb
|
596
597
|
- spec/integration/full_featured_model_spec.rb
|
598
|
+
- spec/integration/has_many_associations_spec.rb
|
597
599
|
- spec/integration/model_spec.rb
|
598
600
|
- spec/integration/mods_article_integration_spec.rb
|
599
601
|
- spec/integration/nested_attribute_spec.rb
|