scoped_search 2.2.1 → 2.3.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.
@@ -1,4 +1,4 @@
1
- require 'spec_helper'
1
+ require "#{File.dirname(__FILE__)}/../spec_helper"
2
2
 
3
3
  # These specs will run on all databases that are defined in the spec/database.yml file.
4
4
  # Comment out any databases that you do not have available for testing purposes if needed.
@@ -20,7 +20,7 @@ ScopedSearch::RSpec::Database.test_databases.each do |db|
20
20
  ScopedSearch::RSpec::Database.close_connection
21
21
  end
22
22
 
23
- context 'quering numerical fields' do
23
+ context 'querying numerical fields' do
24
24
 
25
25
  before(:all) do
26
26
  @record = @class.create!(:int => 9)
@@ -102,17 +102,19 @@ ScopedSearch::RSpec::Database.test_databases.each do |db|
102
102
  @class.search_for('date = 09-01-02').should have(1).item
103
103
  end
104
104
 
105
- it "should accept MM/DD/YY as date format" do
106
- @class.search_for('date = 01/02/09').should have(1).item
107
- end
105
+ if RUBY_VERSION.to_f == 1.8
106
+ it "should accept MM/DD/YY as date format" do
107
+ @class.search_for('date = 01/02/09').should have(1).item
108
+ end
108
109
 
110
+ it "should accept MM/DD/YYYY as date format" do
111
+ @class.search_for('date = 01/02/2009').should have(1).item
112
+ end
113
+ end
114
+
109
115
  it "should accept YYYY/MM/DD as date format" do
110
116
  @class.search_for('date = 2009/01/02').should have(1).item
111
- end
112
-
113
- it "should accept MM/DD/YYYY as date format" do
114
- @class.search_for('date = 01/02/2009').should have(1).item
115
- end
117
+ end
116
118
 
117
119
  it "should ignore an invalid date and thus return all records" do
118
120
  @class.search_for('>= 2009-14-57').should have(2).items
@@ -153,6 +155,99 @@ ScopedSearch::RSpec::Database.test_databases.each do |db|
153
155
  it "should find no record with a timestamp later than today" do
154
156
  @class.search_for('> 2009-01-02').should have(0).item
155
157
  end
158
+
159
+ end
160
+ context 'humenized date and time query' do
161
+
162
+ before(:all) do
163
+ @curent_record = @class.create!(:timestamp => Time.current, :date => Date.current)
164
+ @hour_ago_record = @class.create!(:timestamp => Time.current - 1.hour, :date => Date.current)
165
+ @day_ago_record = @class.create!(:timestamp => Time.current - 1.day, :date => Date.current - 1.day)
166
+ @month_ago_record = @class.create!(:timestamp => Time.current - 1.month, :date => Date.current - 1.month)
167
+ @year_ago_record = @class.create!(:timestamp => Time.current - 1.year, :date => Date.current - 1.year)
168
+ end
169
+
170
+ after(:all) do
171
+ @curent_record.destroy
172
+ @hour_ago_record.destroy
173
+ @day_ago_record.destroy
174
+ @month_ago_record.destroy
175
+ @year_ago_record.destroy
176
+ end
177
+
178
+ it "should accept Today as date format" do
179
+ @class.search_for('date = Today').should have(2).item
180
+ end
181
+
182
+ it "should accept Yesterday as date format" do
183
+ @class.search_for('date = yesterday').should have(1).item
184
+ end
185
+
186
+ it "should find all timestamps and date from today using the = operator" do
187
+ @class.search_for('= Today').should have(2).item
188
+ end
189
+
190
+ it "should find all timestamps and date from today no operator" do
191
+ @class.search_for('Today').should have(2).item
192
+ end
193
+
194
+ it "should accept 2 days ago as date format" do
195
+ @class.search_for('date < "2 days ago"').should have(2).item
196
+ end
197
+
198
+ it "should accept 3 hours ago as date format" do
199
+ @class.search_for('timestamp > "3 hours ago"').should have(2).item
200
+ end
201
+
202
+ it "should accept 1 month ago as date format" do
203
+ @class.search_for('date > "1 month ago"').should have(3).item
204
+ end
205
+
206
+ it "should accept 1 year ago as date format" do
207
+ @class.search_for('date > "1 year ago"').should have(4).item
208
+ end
209
+
210
+ end
211
+
212
+ context 'querying bitwize fields' do
213
+
214
+ before(:all) do
215
+ @foo = ScopedSearch::RSpec::Database.create_model(:int => :integer) do |klass|
216
+ klass.scoped_search :on => :int, :offset => 0, :word_size => 8, :rename => :first
217
+ klass.scoped_search :on => :int, :offset => 1, :word_size => 8, :rename => :sec
218
+ end
219
+ # 1026 => is first = 2 and sec = 4
220
+ @record = @foo.create!(:int => 1026)
221
+ end
222
+
223
+ after(:all) do
224
+ ScopedSearch::RSpec::Database.drop_model(@foo)
225
+ @record.destroy
226
+ end
227
+
228
+ it "should not find any record because first equal = 2" do
229
+ @foo.search_for('first = 4').should have(0).item
230
+ end
231
+
232
+ it "should find the record" do
233
+ @foo.search_for('first = 2').should have(1).item
234
+ end
235
+
236
+ it "should not find any record with a grater than operator" do
237
+ @foo.search_for('first > 9').should have(0).item
238
+ end
239
+
240
+ it "should find the record with an >= operator" do
241
+ @foo.search_for('sec >= 4').should have(1).item
242
+ end
243
+
244
+ it "should find the record with AND operator is used" do
245
+ @foo.search_for('sec <= 8 and first = 2').should have(1).item
246
+ end
247
+
248
+ it "should return the record in if one predicate is true and OR is used as operator" do
249
+ @foo.search_for('sec <= 8 || first > 8').should have(1).item
250
+ end
156
251
  end
157
252
  end
158
253
  end
@@ -1,4 +1,4 @@
1
- require 'spec_helper'
1
+ require "#{File.dirname(__FILE__)}/../spec_helper"
2
2
 
3
3
  # These specs will run on all databases that are defined in the spec/database.yml file.
4
4
  # Comment out any databases that you do not have available for testing purposes if needed.
@@ -1,265 +1,257 @@
1
- require 'spec_helper'
1
+ require "#{File.dirname(__FILE__)}/../spec_helper"
2
2
 
3
- if ActiveRecord::VERSION::MAJOR == 2
4
- # These specs will run on all databases that are defined in the spec/database.yml file.
5
- # Comment out any databases that you do not have available for testing purposes if needed.
6
- ScopedSearch::RSpec::Database.test_databases.each do |db|
3
+ # These specs will run on all databases that are defined in the spec/database.yml file.
4
+ # Comment out any databases that you do not have available for testing purposes if needed.
5
+ ScopedSearch::RSpec::Database.test_databases.each do |db|
7
6
 
8
- describe ScopedSearch, "using a #{db} database" do
7
+ describe ScopedSearch, "using a #{db} database" do
9
8
 
10
- before(:all) do
11
- ScopedSearch::RSpec::Database.establish_named_connection(db)
12
- end
13
-
14
- after(:all) do
15
- ScopedSearch::RSpec::Database.close_connection
16
- end
17
-
18
- context 'querying a :belongs_to relation' do
19
-
20
- before(:all) do
9
+ before(:all) do
10
+ ScopedSearch::RSpec::Database.establish_named_connection(db)
11
+ end
21
12
 
22
- # The related class
23
- ActiveRecord::Migration.create_table(:bars) { |t| t.string :related }
24
- class ::Bar < ActiveRecord::Base; has_many :foos; end
13
+ after(:all) do
14
+ ScopedSearch::RSpec::Database.close_connection
15
+ end
25
16
 
26
- # The class on which to call search_for
27
- ::Foo = ScopedSearch::Spec::Database.create_model(:foo => :string, :bar_id => :integer) do |klass|
28
- klass.belongs_to :bar
29
- klass.scoped_search :in => :bar, :on => :related
30
- end
17
+ context 'querying a :belongs_to relation' do
31
18
 
32
- @bar_record = Bar.create!(:related => 'bar')
19
+ before do
20
+
21
+ # The related class
22
+ ActiveRecord::Migration.create_table(:hars) { |t| t.string :related }
23
+ class Har < ActiveRecord::Base; has_many :loos; end
33
24
 
34
- Foo.create!(:foo => 'foo', :bar => @bar_record)
35
- Foo.create!(:foo => 'foo too', :bar => @bar_record)
36
- Foo.create!(:foo => 'foo three', :bar => Bar.create!(:related => 'another bar'))
37
- Foo.create!(:foo => 'foo four')
25
+ # The class on which to call search_for
26
+ ActiveRecord::Migration.create_table(:loos) { |t| t.string :foo; t.integer :har_id }
27
+ class Loo < ActiveRecord::Base
28
+ belongs_to :har
29
+ scoped_search :in => :har, :on => :related
38
30
  end
39
31
 
40
- after(:all) do
41
- ScopedSearch::RSpec::Database.drop_model(Bar)
42
- ScopedSearch::RSpec::Database.drop_model(Foo)
43
- Object.send :remove_const, :Foo
44
- Object.send :remove_const, :Bar
45
- end
32
+ @har_record = Har.create!(:related => 'bar')
46
33
 
47
- it "should find all records with a related bar record containing bar" do
48
- Foo.search_for('bar').should have(3).items
49
- end
34
+ Loo.create!(:foo => 'foo', :har => @har_record)
35
+ Loo.create!(:foo => 'foo too', :har => @har_record)
36
+ Loo.create!(:foo => 'foo three', :har => Har.create!(:related => 'another bar'))
37
+ Loo.create!(:foo => 'foo four')
38
+ end
50
39
 
51
- it "should find all records with a related bar record having an exact value of bar with an explicit field" do
52
- Foo.search_for('related = bar').should have(2).items
53
- end
40
+ after do
41
+ ScopedSearch::RSpec::Database.drop_model(Har)
42
+ ScopedSearch::RSpec::Database.drop_model(Loo)
43
+ end
54
44
 
55
- it "should find records for which the bar relation is not set using null?" do
56
- Foo.search_for('null? related').should have(1).items
57
- end
45
+ it "should find all records with a related bar record containing bar" do
46
+ Loo.search_for('bar').should have(3).items
58
47
  end
59
48
 
60
- context 'querying a :has_many relation' do
49
+ it "should find all records with a related bar record having an exact value of bar with an explicit field" do
50
+ Loo.search_for('related = bar').should have(2).items
51
+ end
61
52
 
62
- before(:all) do
53
+ it "should find records for which the bar relation is not set using null?" do
54
+ Loo.search_for('null? related').should have(1).items
55
+ end
63
56
 
64
- # The related class
65
- ActiveRecord::Migration.create_table(:bars) { |t| t.string :related; t.integer :foo_id }
66
- class ::Bar < ActiveRecord::Base; belongs_to :foo; end
57
+ it "should find records for which the bar relation is not set using null?" do
58
+ Loo.search_for('',:order => 'related asc').first.foo.should eql('foo four')
59
+ end
67
60
 
68
- # The class on which to call search_for
69
- ::Foo = ScopedSearch::Spec::Database.create_model(:foo => :string, :bar_id => :integer) do |klass|
70
- klass.has_many :bars
71
- klass.scoped_search :in => :bars, :on => :related
72
- end
61
+ end
73
62
 
74
- @foo_1 = Foo.create!(:foo => 'foo')
75
- @foo_2 = Foo.create!(:foo => 'foo too')
76
- @foo_3 = Foo.create!(:foo => 'foo three')
63
+ context 'querying a :has_many relation' do
77
64
 
78
- Bar.create!(:related => 'bar', :foo => @foo_1)
79
- Bar.create!(:related => 'another bar', :foo => @foo_1)
80
- Bar.create!(:related => 'other bar', :foo => @foo_2)
81
- end
65
+ before do
82
66
 
83
- after(:all) do
84
- ScopedSearch::Spec::Database.drop_model(Bar)
85
- ScopedSearch::Spec::Database.drop_model(Foo)
86
- Object.send :remove_const, :Foo
87
- Object.send :remove_const, :Bar
88
- end
67
+ # The related class
68
+ ActiveRecord::Migration.create_table(:jars) { |t| t.string :related; t.integer :goo_id }
69
+ class Jar < ActiveRecord::Base; belongs_to :goo; end
89
70
 
90
- it "should find all records with at least one bar record containing 'bar'" do
91
- Foo.search_for('bar').should have(2).items
71
+ # The class on which to call search_for
72
+ ActiveRecord::Migration.create_table(:goos) { |t| t.string :foo }
73
+ class Goo < ActiveRecord::Base
74
+ has_many :jars
75
+ scoped_search :in => :jars, :on => :related
92
76
  end
93
77
 
94
- it "should find the only record with at least one bar record having the exact value 'bar'" do
95
- Foo.search_for('= bar').should have(1).item
96
- end
78
+ @foo_1 = Goo.create!(:foo => 'foo')
79
+ @foo_2 = Goo.create!(:foo => 'foo too')
80
+ @foo_3 = Goo.create!(:foo => 'foo three')
97
81
 
98
- it "should find all records for which at least one related bar record exists" do
99
- Foo.search_for('set? related').should have(2).items
100
- end
82
+ Jar.create!(:related => 'bar', :goo => @foo_1)
83
+ Jar.create!(:related => 'another bar', :goo => @foo_1)
84
+ Jar.create!(:related => 'other bar', :goo => @foo_2)
85
+ end
101
86
 
102
- it "should find all records for which none related bar records exist" do
103
- Foo.search_for('null? related').should have(1).items
104
- end
87
+ after do
88
+ ScopedSearch::RSpec::Database.drop_model(Jar)
89
+ ScopedSearch::RSpec::Database.drop_model(Goo)
90
+ end
105
91
 
92
+ it "should find all records with at least one bar record containing 'bar'" do
93
+ ::Goo.search_for('bar').should have(2).items
106
94
  end
107
95
 
108
- context 'querying a :has_one relation' do
96
+ it "should find the only record with at least one bar record having the exact value 'bar'" do
97
+ ::Goo.search_for('= bar').should have(1).item
98
+ end
109
99
 
110
- before(:all) do
100
+ it "should find all records for which at least one related bar record exists" do
101
+ ::Goo.search_for('set? related').should have(2).items
102
+ end
111
103
 
112
- # The related class
113
- ActiveRecord::Migration.create_table(:bars) { |t| t.string :related; t.integer :foo_id }
114
- class ::Bar < ActiveRecord::Base; belongs_to :foo; end
104
+ it "should find all records for which none related bar records exist" do
105
+ ::Goo.search_for('null? related').should have(1).items
106
+ end
115
107
 
116
- # The class on which to call search_for
117
- ::Foo = ScopedSearch::Spec::Database.create_model(:foo => :string) do |klass|
118
- klass.has_one :bar
119
- klass.scoped_search :in => :bar, :on => :related
120
- end
108
+ end
121
109
 
122
- @foo_1 = ::Foo.create!(:foo => 'foo')
123
- @foo_2 = ::Foo.create!(:foo => 'foo too')
124
- @foo_3 = ::Foo.create!(:foo => 'foo three')
110
+ context 'querying a :has_one relation' do
125
111
 
126
- ::Bar.create!(:related => 'bar', :foo => @foo_1)
127
- ::Bar.create!(:related => 'other bar', :foo => @foo_2)
128
- end
112
+ before do
129
113
 
130
- after(:all) do
131
- ScopedSearch::Spec::Database.drop_model(::Bar)
132
- ScopedSearch::Spec::Database.drop_model(::Foo)
133
- Object.send :remove_const, :Foo
134
- Object.send :remove_const, :Bar
135
- end
114
+ # The related class
115
+ ActiveRecord::Migration.drop_table(:cars) rescue nil
116
+ ActiveRecord::Migration.create_table(:cars) { |t| t.string :related; t.integer :hoo_id }
117
+ class Car < ActiveRecord::Base; belongs_to :hoo; end
136
118
 
137
- it "should find all records with a bar record containing 'bar" do
138
- ::Foo.search_for('bar').should have(2).items
119
+ # The class on which to call search_for
120
+ ActiveRecord::Migration.create_table(:hoos) { |t| t.string :foo }
121
+ class Hoo < ActiveRecord::Base
122
+ has_one :car
123
+ scoped_search :on => :foo
124
+ scoped_search :in => :car, :on => :related
139
125
  end
140
126
 
141
- it "should find the only record with the bar record has the exact value 'bar" do
142
- ::Foo.search_for('= bar').should have(1).item
143
- end
127
+ @hoo_1 = Hoo.create!(:foo => 'foo')
128
+ @hoo_2 = Hoo.create!(:foo => 'foo too')
129
+ @hoo_3 = Hoo.create!(:foo => 'foo three')
144
130
 
145
- it "should find all records for which the related bar record exists" do
146
- ::Foo.search_for('set? related').should have(2).items
147
- end
131
+ Car.create!(:related => 'bar', :hoo => @hoo_1)
132
+ Car.create!(:related => 'other bar', :hoo => @hoo_2)
133
+ end
148
134
 
149
- it "should find all records for which the related bar record does not exist" do
150
- ::Foo.search_for('null? related').should have(1).items
151
- end
135
+ after do
136
+ ScopedSearch::RSpec::Database.drop_model(Car)
137
+ ScopedSearch::RSpec::Database.drop_model(Hoo)
152
138
  end
153
139
 
154
- context 'querying a :has_and_belongs_to_many relation' do
140
+ it "should find all records with a car record containing 'bar" do
141
+ Hoo.search_for('bar').should have(2).items
142
+ end
155
143
 
156
- before(:all) do
144
+ it "should find the only record with the bar record has the exact value 'bar" do
145
+ Hoo.search_for('= bar').should have(1).item
146
+ end
157
147
 
158
- # Create some tables
159
- ActiveRecord::Migration.create_table(:bars) { |t| t.string :related }
160
- ActiveRecord::Migration.create_table(:bars_foos, :id => false) { |t| t.integer :foo_id; t.integer :bar_id }
161
- ActiveRecord::Migration.create_table(:foos) { |t| t.string :foo }
148
+ it "should find all records for which the related bar record exists" do
149
+ Hoo.search_for('set? related').should have(2).items
150
+ end
162
151
 
163
- # The related class
164
- class ::Bar < ActiveRecord::Base; end
152
+ it "should find all records for which the related bar record does not exist" do
153
+ Hoo.search_for('null? related').should have(1).items
154
+ end
155
+ end
165
156
 
166
- # The class on which to call search_for
167
- class ::Foo < ActiveRecord::Base
168
- has_and_belongs_to_many :bars
169
- scoped_search :in => :bars, :on => :related
170
- end
157
+ context 'querying a :has_and_belongs_to_many relation' do
171
158
 
172
- @foo_1 = ::Foo.create!(:foo => 'foo')
173
- @foo_2 = ::Foo.create!(:foo => 'foo too')
174
- @foo_3 = ::Foo.create!(:foo => 'foo three')
159
+ before do
175
160
 
176
- @bar_1 = ::Bar.create!(:related => 'bar')
177
- @bar_2 = ::Bar.create!(:related => 'other bar')
178
- @bar_3 = ::Bar.create!(:related => 'last bar')
161
+ # Create some tables
162
+ ActiveRecord::Migration.create_table(:dars) { |t| t.string :related }
163
+ ActiveRecord::Migration.create_table(:dars_joos, :id => false) { |t| t.integer :joo_id; t.integer :dar_id }
164
+ ActiveRecord::Migration.create_table(:joos) { |t| t.string :foo }
179
165
 
180
- @foo_1.bars << @bar_1 << @bar_2
181
- @foo_2.bars << @bar_2 << @bar_3
182
- end
166
+ # The related class
167
+ class Dar < ActiveRecord::Base; end
183
168
 
184
- after(:all) do
185
- ActiveRecord::Migration.drop_table(:bars_foos)
186
- ActiveRecord::Migration.drop_table(:bars)
187
- ActiveRecord::Migration.drop_table(:foos)
188
- Object.send :remove_const, :Foo
189
- Object.send :remove_const, :Bar
169
+ # The class on which to call search_for
170
+ class Joo < ActiveRecord::Base
171
+ has_and_belongs_to_many :dars
172
+ scoped_search :in => :dars, :on => :related
190
173
  end
191
174
 
192
- it "should find all records with at least one associated bar record containing 'bar'" do
193
- ::Foo.search_for('bar').should have(2).items
194
- end
175
+ @joo_1 = Joo.create!(:foo => 'foo')
176
+ @joo_2 = Joo.create!(:foo => 'foo too')
177
+ @joo_3 = Joo.create!(:foo => 'foo three')
195
178
 
196
- it "should find record which is related to @bar_1" do
197
- ::Foo.search_for('= bar').should have(1).items
198
- end
179
+ @dar_1 = Dar.create!(:related => 'bar')
180
+ @dar_2 = Dar.create!(:related => 'other bar')
181
+ @dar_3 = Dar.create!(:related => 'last bar')
199
182
 
200
- it "should find the only record related to @bar_3" do
201
- ::Foo.search_for('last').should have(1).items
202
- end
183
+ @joo_1.dars << @dar_1 << @dar_2
184
+ @joo_2.dars << @dar_2 << @dar_3
185
+ end
203
186
 
204
- it "should find all records that are related to @bar_2" do
205
- ::Foo.search_for('other').should have(2).items
206
- end
187
+ after do
188
+ ActiveRecord::Migration.drop_table(:dars_joos)
189
+ ActiveRecord::Migration.drop_table(:dars)
190
+ ActiveRecord::Migration.drop_table(:joos)
207
191
  end
208
192
 
209
- context 'querying a :has_many => :through relation' do
193
+ it "should find all records with at least one associated bar record containing 'bar'" do
194
+ Joo.search_for('bar').should have(2).items
195
+ end
210
196
 
211
- before(:all) do
197
+ it "should find record which is related to @bar_1" do
198
+ Joo.search_for('= bar').should have(1).items
199
+ end
212
200
 
213
- # Create some tables
214
- ActiveRecord::Migration.create_table(:bars) { |t| t.integer :foo_id; t.integer :baz_id }
215
- ActiveRecord::Migration.create_table(:bazs) { |t| t.string :related }
216
- ActiveRecord::Migration.create_table(:foos) { |t| t.string :foo }
201
+ it "should find the only record related to @bar_3" do
202
+ Joo.search_for('last').should have(1).items
203
+ end
217
204
 
218
- # The related classes
219
- class ::Bar < ActiveRecord::Base; belongs_to :baz; belongs_to :foo; end
220
- class ::Baz < ActiveRecord::Base; has_many :bars; end
205
+ it "should find all records that are related to @bar_2" do
206
+ Joo.search_for('other').should have(2).items
207
+ end
208
+ end
221
209
 
222
- # The class on which to call search_for
223
- class ::Foo < ActiveRecord::Base
224
- has_many :bars
225
- has_many :bazs, :through => :bars
210
+ context 'querying a :has_many => :through relation' do
226
211
 
227
- scoped_search :in => :bazs, :on => :related
228
- end
212
+ before do
229
213
 
230
- @foo_1 = ::Foo.create!(:foo => 'foo')
231
- @foo_2 = ::Foo.create!(:foo => 'foo too')
232
- @foo_3 = ::Foo.create!(:foo => 'foo three')
214
+ # Create some tables
215
+ ActiveRecord::Migration.create_table(:mars) { |t| t.integer :koo_id; t.integer :baz_id }
216
+ ActiveRecord::Migration.create_table(:bazs) { |t| t.string :related }
217
+ ActiveRecord::Migration.create_table(:koos) { |t| t.string :foo }
233
218
 
234
- @baz_1 = ::Baz.create(:related => 'baz')
235
- @baz_2 = ::Baz.create(:related => 'baz too!')
219
+ # The related classes
220
+ class Mar < ActiveRecord::Base; belongs_to :baz; belongs_to :koo; end
221
+ class Baz < ActiveRecord::Base; has_many :mars; end
236
222
 
237
- @bar_1 = ::Bar.create!(:foo => @foo_1, :baz => @baz_1)
238
- @bar_2 = ::Bar.create!(:foo => @foo_1)
239
- @bar_3 = ::Bar.create!(:foo => @foo_2, :baz => @baz_1)
240
- @bar_3 = ::Bar.create!(:foo => @foo_2, :baz => @baz_2)
241
- @bar_3 = ::Bar.create!(:foo => @foo_2, :baz => @baz_2)
242
- @bar_4 = ::Bar.create!(:foo => @foo_3)
243
- end
223
+ # The class on which to call search_for
224
+ class Koo < ActiveRecord::Base
225
+ has_many :mars
226
+ has_many :bazs, :through => :mars
244
227
 
245
- after(:all) do
246
- ActiveRecord::Migration.drop_table(:bazs)
247
- ActiveRecord::Migration.drop_table(:bars)
248
- ActiveRecord::Migration.drop_table(:foos)
249
- Object.send :remove_const, :Foo
250
- Object.send :remove_const, :Bar
251
- Object.send :remove_const, :Baz
228
+ scoped_search :in => :bazs, :on => :related
252
229
  end
253
230
 
254
- it "should find the two records that are related to a baz record" do
255
- ::Foo.search_for('baz').should have(2).items
256
- end
231
+ @koo_1 = Koo.create!(:foo => 'foo')
232
+ @koo_2 = Koo.create!(:foo => 'foo too')
233
+ @koo_3 = Koo.create!(:foo => 'foo three')
234
+
235
+ @baz_1 = Baz.create(:related => 'baz')
236
+ @baz_2 = Baz.create(:related => 'baz too!')
237
+
238
+ @bar_1 = Mar.create!(:koo => @koo_1, :baz => @baz_1)
239
+ @bar_2 = Mar.create!(:koo => @koo_1)
240
+ @bar_3 = Mar.create!(:koo => @koo_2, :baz => @baz_1)
241
+ @bar_3 = Mar.create!(:koo => @koo_2, :baz => @baz_2)
242
+ @bar_3 = Mar.create!(:koo => @koo_2, :baz => @baz_2)
243
+ @bar_4 = Mar.create!(:koo => @koo_3)
244
+ end
245
+
246
+ after do
247
+ ActiveRecord::Migration.drop_table(:bazs)
248
+ ActiveRecord::Migration.drop_table(:mars)
249
+ ActiveRecord::Migration.drop_table(:koos)
250
+ end
251
+
252
+ it "should find the two records that are related to a baz record" do
253
+ Koo.search_for('baz').should have(2).items
257
254
  end
258
255
  end
259
256
  end
260
- else
261
- puts
262
- puts "WARNING:"
263
- puts "Currently, relationships querying is only 100% supported on Rails 2.x. Use at your own risk when using Rails 3."
264
- puts
265
257
  end