sunspot_rails 2.0.0.pre.120925 → 2.0.0.pre.130115

Sign up to get free protection for your applications and to get access to all the features.
data/dev_tasks/spec.rake CHANGED
@@ -27,7 +27,7 @@ namespace :spec do
27
27
 
28
28
  unless File.exist?(ENV['BUNDLE_PATH'])
29
29
  puts "Installing gems for Rails #{version} (this will only be done once)..."
30
- system("bundle install #{ENV['BUNDLE_ARGS']}") || exit(1)
30
+ sh("bundle install #{ENV['BUNDLE_ARGS']}") || exit(1)
31
31
  end
32
32
  end
33
33
 
@@ -40,9 +40,9 @@ namespace :spec do
40
40
 
41
41
  puts "Generating Rails #{version} application..."
42
42
  if version.start_with?("2")
43
- system("#{rails_cmd} \"#{app_path}\" --force") || exit(1)
43
+ sh("#{rails_cmd} \"#{app_path}\" --force") || exit(1)
44
44
  elsif version.start_with?("3")
45
- system("#{rails_cmd} new \"#{app_path}\" --force --skip-git --skip-javascript --skip-gemfile --skip-sprockets") || exit(1)
45
+ sh("#{rails_cmd} new \"#{app_path}\" --force --skip-git --skip-javascript --skip-gemfile --skip-sprockets") || exit(1)
46
46
  end
47
47
  end
48
48
  end
@@ -66,7 +66,7 @@ namespace :spec do
66
66
  "rspec"
67
67
  end
68
68
 
69
- system "bundle exec #{spec_command} #{ENV['SPEC'] || 'spec/*_spec.rb'} --color"
69
+ sh "bundle exec #{spec_command} #{ENV['SPEC'] || 'spec/*_spec.rb'} --color"
70
70
  end
71
71
  end
72
72
 
@@ -9,4 +9,5 @@ gem 'sunspot_rails', :path => File.expand_path('../..', __FILE__)
9
9
 
10
10
  group :test do
11
11
  gem 'rspec-rails', '~> 1.3.4'
12
+ gem 'test-unit', '~> 1.2.3', :platform => :mri_19
12
13
  end
@@ -1,6 +1,6 @@
1
1
  source :rubygems
2
2
 
3
- gem 'rails', '3.0.15'
3
+ gem 'rails', '3.0.17'
4
4
  gem 'sqlite3-ruby', '~> 1.3.1'
5
5
 
6
6
  gem 'sunspot', :path => File.expand_path('../../../sunspot', __FILE__)
@@ -1,6 +1,6 @@
1
1
  source :rubygems
2
2
 
3
- gem 'rails', '3.1.6'
3
+ gem 'rails', '3.1.8'
4
4
  gem 'sqlite3-ruby', '~> 1.3.1'
5
5
 
6
6
  gem 'sunspot', :path => File.expand_path('../../../sunspot', __FILE__)
@@ -1,7 +1,7 @@
1
1
  source :rubygems
2
2
 
3
- gem 'rails', '3.2.6'
4
- gem 'sqlite3-ruby', '~> 1.3.1'
3
+ gem 'rails', '3.2.9'
4
+ gem 'sqlite3', '~> 1.3.3'
5
5
 
6
6
  gem 'sunspot', :path => File.expand_path('../../../sunspot', __FILE__)
7
7
  gem 'sunspot_solr', :path => File.expand_path('../../../sunspot_solr', __FILE__)
data/lib/sunspot/rails.rb CHANGED
@@ -11,7 +11,7 @@ module Sunspot #:nodoc:
11
11
  begin
12
12
  require 'sunspot_solr'
13
13
  autoload :Server, File.join(File.dirname(__FILE__), 'rails', 'server')
14
- rescue LoadError => e
14
+ rescue LoadError
15
15
  # We're fine
16
16
  end
17
17
 
@@ -20,7 +20,8 @@ module Sunspot #:nodoc:
20
20
 
21
21
  class ActiveRecordDataAccessor < Sunspot::Adapters::DataAccessor
22
22
  # options for the find
23
- attr_accessor :include, :select
23
+ attr_accessor :include
24
+ attr_reader :select
24
25
 
25
26
  def initialize(clazz)
26
27
  super(clazz)
@@ -78,8 +79,8 @@ module Sunspot #:nodoc:
78
79
 
79
80
  def options_for_find
80
81
  options = {}
81
- options[:include] = @include unless @include.blank?
82
- options[:select] = @select unless @select.blank?
82
+ options[:include] = @include unless !defined?(@include) || @include.blank?
83
+ options[:select] = @select unless !defined?(@select) || @select.blank?
83
84
  options
84
85
  end
85
86
  end
@@ -19,7 +19,7 @@ module Sunspot
19
19
  end
20
20
 
21
21
  def self.logger
22
- @logger
22
+ @logger if defined?(@logger)
23
23
  end
24
24
 
25
25
  def logger
@@ -46,6 +46,11 @@ module Sunspot #:nodoc:
46
46
  # :ignore_attribute_changes_of<Array>::
47
47
  # Define attributes, that should not trigger a reindex of that
48
48
  # object. Usual suspects are updated_at or counters.
49
+ # :only_reindex_attribute_changes_of<Array>::
50
+ # Define attributes, that are the only attributes that should
51
+ # trigger a reindex of that object. Useful if there are a small
52
+ # number of searchable attributes and a large number of attributes
53
+ # to ignore.
49
54
  # :include<Mixed>::
50
55
  # Define default ActiveRecord includes, set this to allow ActiveRecord
51
56
  # to load required associations when indexing. See ActiveRecord's
@@ -294,7 +299,7 @@ module Sunspot #:nodoc:
294
299
  solr_ids.concat ids
295
300
  end
296
301
 
297
- return solr_ids - self.connection.select_values(select(:id).arel).collect(&:to_i)
302
+ return solr_ids - self.connection.select_values("SELECT id FROM #{quoted_table_name}").collect(&:to_i)
298
303
  end
299
304
 
300
305
  #
@@ -465,6 +470,8 @@ module Sunspot #:nodoc:
465
470
  @marked_for_auto_indexing =
466
471
  if !new_record? && ignore_attributes = self.class.sunspot_options[:ignore_attribute_changes_of]
467
472
  !(changed.map { |attr| attr.to_sym } - ignore_attributes).blank?
473
+ elsif !new_record? && only_attributes = self.class.sunspot_options[:only_reindex_attribute_changes_of]
474
+ !(changed.map { |attr| attr.to_sym } & only_attributes).blank?
468
475
  else
469
476
  true
470
477
  end
data/lib/sunspot_rails.rb CHANGED
@@ -1,11 +1,11 @@
1
1
  # This needs to be loaded before sunspot/search/paginated_collection
2
2
  # or #to_json gets defined in Object breaking delegation to Array via
3
3
  # method_missing
4
- require 'active_support/core_ext/object/to_json' if Rails::VERSION::MAJOR == 3
4
+ require 'active_support/core_ext/object/to_json' if ::Rails.version >= '3'
5
5
 
6
6
  require 'sunspot/rails'
7
7
 
8
- if Rails::VERSION::MAJOR == 3
8
+ if ::Rails.version >= '3'
9
9
  require 'sunspot/rails/railtie'
10
10
  else
11
11
  require 'sunspot/rails/init'
@@ -37,7 +37,7 @@ describe 'searchable with lifecycle' do
37
37
  @post.save!
38
38
  end
39
39
  end
40
-
40
+
41
41
  describe 'on destroy' do
42
42
  before :each do
43
43
  @post = PostWithAuto.create
@@ -49,15 +49,33 @@ describe 'searchable with lifecycle' do
49
49
  PostWithAuto.search_ids.should be_empty
50
50
  end
51
51
  end
52
- end
53
52
 
54
- describe 'searchable with lifecycle - ignoring specific attributes' do
55
- before(:each) do
56
- @post = PostWithAuto.create
53
+ describe 'ignoring specific attributes' do
54
+ before(:each) do
55
+ @post = PostWithAuto.create
56
+ end
57
+
58
+ it "should not reindex the object on an update_at change, because it is marked as to-ignore" do
59
+ Sunspot.should_not_receive(:index).with(@post)
60
+ @post.update_attribute :updated_at, 123.seconds.from_now
61
+ end
57
62
  end
58
-
59
- it "should not reindex the object on an update_at change, because it is marked as to-ignore" do
60
- Sunspot.should_not_receive(:index).with(@post)
61
- @post.update_attribute :updated_at, 123.seconds.from_now
63
+
64
+ describe 'only paying attention to specific attributes' do
65
+ before(:each) do
66
+ @post = PostWithOnlySomeAttributesTriggeringReindex.create
67
+ end
68
+
69
+ it "should not reindex the object on an update_at change, because it is not in the whitelist" do
70
+ Sunspot.should_not_receive(:index).with(@post)
71
+ @post.update_attribute :updated_at, 123.seconds.from_now
72
+ end
73
+
74
+ it "should reindex the object on a title change, because it is in the whitelist" do
75
+ Sunspot.should_receive(:index).with(@post)
76
+ @post.update_attribute :title, "brand new title"
77
+ end
78
+
62
79
  end
63
80
  end
81
+
data/spec/model_spec.rb CHANGED
@@ -211,12 +211,6 @@ describe 'ActiveRecord mixin' do
211
211
  it 'should return IDs of objects that are in the index but not the database' do
212
212
  Post.index_orphans.should == [@posts.first.id]
213
213
  end
214
-
215
- it 'should find the orphans in batches to improve performance' do
216
- Post.should_receive(:find_each).with(hash_including(:batch_size => 10)).and_return([])
217
- Post.index_orphans(:batch_size => 10)
218
- end
219
-
220
214
  end
221
215
 
222
216
  describe 'clean_index_orphans()' do
@@ -0,0 +1,12 @@
1
+ class PostWithOnlySomeAttributesTriggeringReindex < ActiveRecord::Base
2
+ def self.table_name
3
+ 'posts'
4
+ end
5
+
6
+ attr_accessible :title, :type, :location_id, :body, :blog
7
+
8
+ searchable :only_reindex_attribute_changes_of => [ :title, :body ] do
9
+ string :title
10
+ text :body, :more_like_this => true
11
+ end
12
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sunspot_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0.pre.120925
4
+ version: 2.0.0.pre.130115
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors:
@@ -27,52 +27,72 @@ authors:
27
27
  autorequire:
28
28
  bindir: bin
29
29
  cert_chain: []
30
- date: 2012-09-25 00:00:00.000000000 Z
30
+ date: 2013-01-15 00:00:00.000000000 Z
31
31
  dependencies:
32
32
  - !ruby/object:Gem::Dependency
33
33
  name: sunspot
34
- requirement: &70271798724000 !ruby/object:Gem::Requirement
35
- none: false
34
+ prerelease: false
35
+ requirement: !ruby/object:Gem::Requirement
36
36
  requirements:
37
- - - =
37
+ - - '='
38
38
  - !ruby/object:Gem::Version
39
- version: 2.0.0.pre.120925
39
+ version: 2.0.0.pre.130115
40
+ none: false
40
41
  type: :runtime
41
- prerelease: false
42
- version_requirements: *70271798724000
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - '='
45
+ - !ruby/object:Gem::Version
46
+ version: 2.0.0.pre.130115
47
+ none: false
43
48
  - !ruby/object:Gem::Dependency
44
49
  name: nokogiri
45
- requirement: &70271798723340 !ruby/object:Gem::Requirement
46
- none: false
50
+ prerelease: false
51
+ requirement: !ruby/object:Gem::Requirement
47
52
  requirements:
48
53
  - - ! '>='
49
54
  - !ruby/object:Gem::Version
50
55
  version: '0'
56
+ none: false
51
57
  type: :runtime
52
- prerelease: false
53
- version_requirements: *70271798723340
58
+ version_requirements: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ none: false
54
64
  - !ruby/object:Gem::Dependency
55
65
  name: rspec
56
- requirement: &70271798722140 !ruby/object:Gem::Requirement
57
- none: false
66
+ prerelease: false
67
+ requirement: !ruby/object:Gem::Requirement
58
68
  requirements:
59
69
  - - ~>
60
70
  - !ruby/object:Gem::Version
61
71
  version: '1.2'
72
+ none: false
62
73
  type: :development
63
- prerelease: false
64
- version_requirements: *70271798722140
74
+ version_requirements: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ~>
77
+ - !ruby/object:Gem::Version
78
+ version: '1.2'
79
+ none: false
65
80
  - !ruby/object:Gem::Dependency
66
81
  name: rspec-rails
67
- requirement: &70271798721500 !ruby/object:Gem::Requirement
68
- none: false
82
+ prerelease: false
83
+ requirement: !ruby/object:Gem::Requirement
69
84
  requirements:
70
85
  - - ~>
71
86
  - !ruby/object:Gem::Version
72
87
  version: '1.2'
88
+ none: false
73
89
  type: :development
74
- prerelease: false
75
- version_requirements: *70271798721500
90
+ version_requirements: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ~>
93
+ - !ruby/object:Gem::Version
94
+ version: '1.2'
95
+ none: false
76
96
  description: ! " Sunspot::Rails is an extension to the Sunspot library for Solr
77
97
  search.\n Sunspot::Rails adds integration between Sunspot and ActiveRecord, including\n
78
98
  \ defining search and indexing related methods on ActiveRecord models themselves,\n
@@ -97,9 +117,9 @@ files:
97
117
  - dev_tasks/spec.rake
98
118
  - dev_tasks/todo.rake
99
119
  - gemfiles/rails-2.3.14
100
- - gemfiles/rails-3.0.15
101
- - gemfiles/rails-3.1.6
102
- - gemfiles/rails-3.2.6
120
+ - gemfiles/rails-3.0.17
121
+ - gemfiles/rails-3.1.8
122
+ - gemfiles/rails-3.2.9
103
123
  - generators/sunspot/sunspot_generator.rb
104
124
  - generators/sunspot/templates/sunspot.yml
105
125
  - install.rb
@@ -134,6 +154,7 @@ files:
134
154
  - spec/rails_template/app/models/post.rb
135
155
  - spec/rails_template/app/models/post_with_auto.rb
136
156
  - spec/rails_template/app/models/post_with_default_scope.rb
157
+ - spec/rails_template/app/models/post_with_only_some_attributes_triggering_reindex.rb
137
158
  - spec/rails_template/config/boot.rb
138
159
  - spec/rails_template/config/preinitializer.rb
139
160
  - spec/rails_template/config/routes.rb
@@ -162,20 +183,20 @@ rdoc_options:
162
183
  require_paths:
163
184
  - lib
164
185
  required_ruby_version: !ruby/object:Gem::Requirement
165
- none: false
166
186
  requirements:
167
187
  - - ! '>='
168
188
  - !ruby/object:Gem::Version
169
189
  version: '0'
170
- required_rubygems_version: !ruby/object:Gem::Requirement
171
190
  none: false
191
+ required_rubygems_version: !ruby/object:Gem::Requirement
172
192
  requirements:
173
193
  - - ! '>'
174
194
  - !ruby/object:Gem::Version
175
195
  version: 1.3.1
196
+ none: false
176
197
  requirements: []
177
198
  rubyforge_project: sunspot
178
- rubygems_version: 1.8.15
199
+ rubygems_version: 1.8.24
179
200
  signing_key:
180
201
  specification_version: 3
181
202
  summary: Rails integration for the Sunspot Solr search library
@@ -192,6 +213,7 @@ test_files:
192
213
  - spec/rails_template/app/models/post.rb
193
214
  - spec/rails_template/app/models/post_with_auto.rb
194
215
  - spec/rails_template/app/models/post_with_default_scope.rb
216
+ - spec/rails_template/app/models/post_with_only_some_attributes_triggering_reindex.rb
195
217
  - spec/rails_template/config/boot.rb
196
218
  - spec/rails_template/config/preinitializer.rb
197
219
  - spec/rails_template/config/routes.rb