active-fedora 3.2.0.pre6 → 3.2.0.pre7

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- active-fedora (3.2.0.pre6)
4
+ active-fedora (3.2.0.pre7)
5
5
  activeresource (>= 3.0.0)
6
6
  activesupport (>= 3.0.0)
7
7
  equivalent-xml
@@ -1,16 +1,21 @@
1
1
  3.2.0
2
2
 
3
+ Added a count method
4
+ HYDRA-731 running count on a has_many relationship returns zero unless the relationship has been loaded
3
5
  Added ActiveModel validations.
4
6
  Added callbacks on initialize, save, update, create, delete and find
5
7
  Added Base.create
6
8
  HYDRA-730 ActiveFedora isn't being initialized unless it is specified in the project Gemfile
7
- Don't create pids until save
8
- inspect and equality methods
9
- Deprecate datastream_collections
9
+ Don't create pids until save so that we don't cycle through pids we don't intend to save
10
+ inspect method gives less information (more readable)
11
+ Added an equality method
12
+ Deprecate the automatic inclusion of datastream_collections (you should include this optional module in your models if you intend to use it)
13
+ Deprecate the automatic inclusion of relationships (you should include this optional module in your models if you intend to use it)
14
+ Deprecate the automatic inclusion of file_management (you should include this optional module in your models if you intend to use it)
10
15
  Disseminators have been added
11
16
  HYDRA-729 don't update xml datastreams unless they've changed
12
- Adapt To
13
- ActiveFedora::Relationship is deprecated
17
+ Added adapt_to method to reduce number of round trips to fedora.
18
+ ActiveFedora::Relationship is deprecated (was not being used)
14
19
  Rails 3.1 compatibility
15
20
  Ruby 1.9 compatibility
16
21
 
@@ -3,6 +3,7 @@ module ActiveFedora
3
3
  class AssociationCollection < AssociationProxy #:nodoc:
4
4
  def initialize(owner, reflection)
5
5
  super
6
+ construct_query
6
7
  end
7
8
 
8
9
  # Returns the size of the collection
@@ -129,23 +130,12 @@ module ActiveFedora
129
130
  end
130
131
 
131
132
  def find_target
132
- load_inbound_relationship(@owner.pid, @reflection.options[:property])
133
- end
134
-
135
- def load_inbound_relationship(pid, predicate, opts={})
136
- opts = {:rows=>25}.merge(opts)
137
- query = inbound_relationship_query(pid, predicate)
138
- return [] if query.empty?
139
- solr_result = SolrService.instance.conn.query(query, :rows=>opts[:rows])
133
+ return [] if @finder_query.empty?
134
+ solr_result = SolrService.instance.conn.query(@finder_query, :rows=>1000)
140
135
  #TODO, don't reify, just store the solr results and lazily reify.
141
136
  return ActiveFedora::SolrService.reify_solr_results(solr_result)
142
137
  end
143
138
 
144
- def inbound_relationship_query(pid,predicate)
145
- internal_uri = "info:fedora/#{pid}"
146
- escaped_uri = internal_uri.gsub(/(:)/, '\\:')
147
- "#{predicate}_s:#{escaped_uri}"
148
- end
149
139
 
150
140
  def add_record_to_target_with_callbacks(record)
151
141
  # callback(:before_add, record)
@@ -68,18 +68,11 @@ module ActiveFedora
68
68
  end
69
69
  end
70
70
 
71
- # def construct_sql
72
- # if @reflection.options[:finder_sql]
73
- # @finder_sql = interpolate_and_sanitize_sql(@reflection.options[:finder_sql])
74
- # else
75
- # @finder_sql = "#{@owner.connection.quote_table_name @reflection.options[:join_table]}.#{@reflection.primary_key_name} = #{owner_quoted_id} "
76
- # @finder_sql << " AND (#{conditions})" if conditions
77
- # end
78
-
79
- # @join_sql = "INNER JOIN #{@owner.connection.quote_table_name @reflection.options[:join_table]} ON #{@reflection.quoted_table_name}.#{@reflection.klass.primary_key} = #{@owner.connection.quote_table_name @reflection.options[:join_table]}.#{@reflection.association_foreign_key}"
80
-
81
- # construct_counter_sql
82
- # end
71
+ def construct_query
72
+ internal_uri = @owner.internal_uri
73
+ escaped_uri = internal_uri.gsub(/(:)/, '\\:')
74
+ @counter_query = @finder_query = "#{@reflection.options[:property]}_s:#{escaped_uri}"
75
+ end
83
76
 
84
77
  def construct_scope
85
78
  { :find => { :conditions => @finder_sql,
@@ -14,10 +14,12 @@ module ActiveFedora
14
14
  # If the collection is empty the target is set to an empty array and
15
15
  # the loaded flag is set to true as well.
16
16
  def count_records
17
- count = if @target
17
+ count = if loaded?
18
18
  @target.size
19
19
  else
20
- 0
20
+ @reflection.klass.count(:conditions => @counter_query)
21
+ # load_target
22
+ # @target.size
21
23
  end
22
24
 
23
25
  # If there's nothing in the database and @target has no new records
@@ -44,9 +46,11 @@ module ActiveFedora
44
46
  end
45
47
 
46
48
 
47
-
49
+ def construct_query
50
+ internal_uri = @owner.internal_uri
51
+ escaped_uri = internal_uri.gsub(/(:)/, '\\:')
52
+ @counter_query = @finder_query = "#{@reflection.options[:property]}_s:#{escaped_uri}"
53
+ end
48
54
  end
49
-
50
55
  end
51
-
52
56
  end
@@ -157,7 +157,7 @@ module ActiveFedora
157
157
  ds_specs[args[:name]]= {:type => args[:type], :label => args.fetch(:label,""), :control_group => args.fetch(:control_group,"X"), :disseminator => args.fetch(:disseminator,""), :url => args.fetch(:url,""),:block => block}
158
158
  end
159
159
 
160
- def self.create(args)
160
+ def self.create(args = {})
161
161
  obj = self.new(args)
162
162
  obj.save
163
163
  obj
@@ -119,6 +119,15 @@ module ActiveFedora
119
119
  end
120
120
  end
121
121
 
122
+ # Get a count of the number of objects from solr
123
+ # Takes :conditions as an argument
124
+ def count(args = {})
125
+ escaped_class_uri = SolrService.escape_uri_for_query(self.to_class_uri)
126
+ q = "#{ActiveFedora::SolrService.solr_name(:has_model, :symbol)}:#{escaped_class_uri}"
127
+ q << " AND #{args[:conditions]}" if args[:conditions]
128
+ SolrService.instance.conn.query(q, :rows=>0).total_hits
129
+ end
130
+
122
131
  #Sends a query directly to SolrService
123
132
  def solr_search(query, args={})
124
133
  SolrService.instance.conn.query(query, args)
@@ -1,3 +1,3 @@
1
1
  module ActiveFedora
2
- VERSION = "3.2.0.pre6"
2
+ VERSION = "3.2.0.pre7"
3
3
  end
@@ -34,28 +34,29 @@ describe ActiveFedora::Base do
34
34
  @library.books.to_ary.should == []
35
35
  @library.book_ids.should ==[]
36
36
  @library.books << @book
37
- @library.books.map(&:pid).should == [@book.pid]
37
+ @library.books.to_a.should == [@book]
38
38
  @library.book_ids.should ==[@book.pid]
39
+
39
40
  end
40
41
 
41
42
  it "should let you set an array of objects" do
42
43
  @library.books = [@book, @book2]
43
- @library.books.map(&:pid).should == [@book.pid, @book2.pid]
44
+ @library.books.to_a.should == [@book, @book2]
44
45
  @library.save
45
46
 
46
47
  @library.books = [@book]
47
- @library.books.map(&:pid).should == [@book.pid]
48
+ @library.books.to_a.should == [@book]
48
49
 
49
50
  end
50
51
  it "should let you set an array of object ids" do
51
52
  @library.book_ids = [@book.pid, @book2.pid]
52
- @library.books.map(&:pid).should == [@book.pid, @book2.pid]
53
+ @library.books.to_a.should == [@book, @book2]
53
54
  end
54
55
 
55
56
  it "setter should wipe out previously saved relations" do
56
57
  @library.book_ids = [@book.pid, @book2.pid]
57
58
  @library.book_ids = [@book2.pid]
58
- @library.books.map(&:pid).should == [@book2.pid]
59
+ @library.books.to_a.should == [@book2]
59
60
 
60
61
  end
61
62
 
@@ -97,7 +98,7 @@ describe ActiveFedora::Base do
97
98
  @book = Book.new
98
99
  @book.topics << @topic1
99
100
  @book.topics.map(&:pid).should == [@topic1.pid]
100
- Topic.find(@topic1.pid).books.map(&:pid).should == [] #Can't have saved it because @book isn't saved yet.
101
+ Topic.find(@topic1.pid).books.to_a.should == [] #Can't have saved it because @book isn't saved yet.
101
102
  end
102
103
  after do
103
104
  @topic1.delete
@@ -124,11 +125,22 @@ describe ActiveFedora::Base do
124
125
 
125
126
  @book.library.pid.should == @library.pid
126
127
  @library.books.reload
127
- @library.books.map(&:pid).should == [@book.pid]
128
+ @library.books.to_a.should == [@book]
128
129
 
130
+ @library2 = Library.find(@library.pid)
131
+ @library2.books.to_a.should == [@book]
132
+ end
133
+
134
+ it "should have a count once it has been saved" do
135
+ @library.books << @book << Book.create
136
+ @library.save
137
+
138
+ # @book.library.pid.should == @library.pid
139
+ # @library.books.reload
140
+ # @library.books.to_a.should == [@book]
129
141
 
130
142
  @library2 = Library.find(@library.pid)
131
- @library2.books.map(&:pid).should == [@book.pid]
143
+ @library2.books.size.should == 2
132
144
  end
133
145
 
134
146
  it "should respect the :class_name parameter" do
@@ -154,8 +166,8 @@ describe ActiveFedora::Base do
154
166
  end
155
167
  it "habtm should set relationships bidirectionally" do
156
168
  @book.topics << @topic1
157
- @book.topics.map(&:pid).should == [@topic1.pid]
158
- Topic.find(@topic1.pid).books.map(&:pid).should == [@book.pid] #Can't have saved it because @book isn't saved yet.
169
+ @book.topics.to_a.should == [@topic1]
170
+ Topic.find(@topic1.pid).books.to_a.should == [@book] #Can't have saved it because @book isn't saved yet.
159
171
  end
160
172
  it "should save new child objects" do
161
173
  @book.topics << Topic.new
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  describe ActiveFedora::Associations::HasManyAssociation do
4
4
  it "should be able to replace the collection" do
5
- @owner = stub(:new_record? => false, :to_ary => nil)
5
+ @owner = stub(:new_record? => false, :to_ary => nil, :internal_uri => 'info:fedora/changeme:99')
6
6
  @reflection = stub(:klass => Mocha::Mock, :options=>{:property=>'predicate'})
7
7
  #ac = ActiveFedora::Associations::AssociationCollection.new(@owner, @reflection)
8
8
  ac = ActiveFedora::Associations::HasManyAssociation.new(@owner, @reflection)
@@ -17,11 +17,10 @@ describe ActiveFedora::Associations::HasManyAssociation do
17
17
  end
18
18
 
19
19
  it "should build" do
20
- class Foo; end
21
- @owner = stub(:new_record? => false)
20
+ @owner = stub(:new_record? => false, :internal_uri => 'info:fedora/changeme:99')
21
+ @reflection = stub(:klass => Mocha::Mock, :options=>{:property=>'predicate'})
22
22
  @assoc = ActiveFedora::Associations::HasManyAssociation.new(@owner, @reflection)
23
23
  @assoc.should respond_to :build
24
- Object.send(:remove_const, :Foo)
25
24
 
26
25
  end
27
26
 
@@ -102,7 +102,6 @@ describe ActiveFedora::Model do
102
102
  mock_solr = mock("SolrConnection")
103
103
  mock_result = mock("MockResult")
104
104
  mock_result.expects(:hits).returns([{"id" => "changeme:30"}, {"id" => "changeme:22"}])
105
- #mock_solr.expects(:query).with('has_model_s:info\\:fedora/afmodel\\:SpecModel\:\:Basic', :rows=>1001).returns(mock_result)
106
105
  mock_solr.expects(:query).with('has_model_s:info\\:fedora/afmodel\\:SpecModel_Basic', :rows=>1001).returns(mock_result)
107
106
  ActiveFedora::SolrService.expects(:instance).returns(mock("SolrService", :conn => mock_solr))
108
107
  ActiveFedora::RubydoraConnection.instance.expects(:find_model).with("changeme:30", SpecModel::Basic).returns("Fake Object1")
@@ -150,6 +149,26 @@ describe ActiveFedora::Model do
150
149
  end
151
150
 
152
151
  end
152
+
153
+ describe '#count' do
154
+
155
+ it "should return a count" do
156
+ mock_solr = mock("SolrConnection")
157
+ mock_result = mock("MockResult")
158
+ mock_result.expects(:total_hits).returns(7)
159
+ mock_solr.expects(:query).with('has_model_s:info\\:fedora/afmodel\\:SpecModel_Basic', :rows=>0).returns(mock_result)
160
+ ActiveFedora::SolrService.expects(:instance).returns(mock("SolrService", :conn => mock_solr))
161
+ SpecModel::Basic.count.should == 7
162
+ end
163
+ it "should allow conditions" do
164
+ mock_solr = mock("SolrConnection")
165
+ mock_result = mock("MockResult")
166
+ mock_result.expects(:total_hits).returns(7)
167
+ mock_solr.expects(:query).with('has_model_s:info\\:fedora/afmodel\\:SpecModel_Basic AND foo:bar', :rows=>0).returns(mock_result)
168
+ ActiveFedora::SolrService.expects(:instance).returns(mock("SolrService", :conn => mock_solr))
169
+ SpecModel::Basic.count(:conditions=>'foo:bar').should == 7
170
+ end
171
+ end
153
172
 
154
173
 
155
174
  it 'should provide #find_by_solr' do
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active-fedora
3
3
  version: !ruby/object:Gem::Version
4
- hash: 1923832037
4
+ hash: 1923832039
5
5
  prerelease: 6
6
6
  segments:
7
7
  - 3
8
8
  - 2
9
9
  - 0
10
10
  - pre
11
- - 6
12
- version: 3.2.0.pre6
11
+ - 7
12
+ version: 3.2.0.pre7
13
13
  platform: ruby
14
14
  authors:
15
15
  - Matt Zumwalt
@@ -19,7 +19,7 @@ autorequire:
19
19
  bindir: bin
20
20
  cert_chain: []
21
21
 
22
- date: 2012-01-02 00:00:00 -06:00
22
+ date: 2012-01-04 00:00:00 -06:00
23
23
  default_executable:
24
24
  dependencies:
25
25
  - !ruby/object:Gem::Dependency