meta_search 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +21 -0
- data/LICENSE +20 -0
- data/README.rdoc +101 -0
- data/Rakefile +53 -0
- data/VERSION +1 -0
- data/lib/meta_search/builder.rb +247 -0
- data/lib/meta_search/exceptions.rb +3 -0
- data/lib/meta_search/helpers/action_view.rb +168 -0
- data/lib/meta_search/model_compatibility.rb +8 -0
- data/lib/meta_search/railtie.rb +21 -0
- data/lib/meta_search/searches/active_record.rb +19 -0
- data/lib/meta_search/searches/base.rb +46 -0
- data/lib/meta_search/utility.rb +85 -0
- data/lib/meta_search/where.rb +174 -0
- data/lib/meta_search.rb +31 -0
- data/meta_search.gemspec +83 -0
- data/test/fixtures/companies.yml +17 -0
- data/test/fixtures/company.rb +9 -0
- data/test/fixtures/data_type.rb +4 -0
- data/test/fixtures/data_types.yml +15 -0
- data/test/fixtures/developer.rb +5 -0
- data/test/fixtures/developers.yml +55 -0
- data/test/fixtures/developers_projects.yml +25 -0
- data/test/fixtures/note.rb +3 -0
- data/test/fixtures/notes.yml +79 -0
- data/test/fixtures/project.rb +4 -0
- data/test/fixtures/projects.yml +24 -0
- data/test/fixtures/schema.rb +47 -0
- data/test/helper.rb +37 -0
- data/test/test_search.rb +351 -0
- data/test/test_view_helpers.rb +149 -0
- metadata +116 -0
@@ -0,0 +1,47 @@
|
|
1
|
+
ActiveRecord::Schema.define do
|
2
|
+
|
3
|
+
create_table "companies", :force => true do |t|
|
4
|
+
t.string "name"
|
5
|
+
t.datetime "created_at"
|
6
|
+
t.datetime "updated_at"
|
7
|
+
end
|
8
|
+
|
9
|
+
create_table "developers", :force => true do |t|
|
10
|
+
t.integer "company_id"
|
11
|
+
t.string "name"
|
12
|
+
t.integer "salary"
|
13
|
+
t.boolean "slacker"
|
14
|
+
end
|
15
|
+
|
16
|
+
create_table "projects", :force => true do |t|
|
17
|
+
t.string "name"
|
18
|
+
t.float "estimated_hours"
|
19
|
+
end
|
20
|
+
|
21
|
+
create_table "developers_projects", :id => false, :force => true do |t|
|
22
|
+
t.integer "developer_id"
|
23
|
+
t.integer "project_id"
|
24
|
+
end
|
25
|
+
|
26
|
+
create_table "notes", :force => true do |t|
|
27
|
+
t.string "notable_type"
|
28
|
+
t.integer "notable_id"
|
29
|
+
t.string "note"
|
30
|
+
end
|
31
|
+
|
32
|
+
create_table "data_types", :force => true do |t|
|
33
|
+
t.integer "company_id"
|
34
|
+
t.string "str"
|
35
|
+
t.text "txt"
|
36
|
+
t.integer "int"
|
37
|
+
t.float "flt"
|
38
|
+
t.decimal "dec"
|
39
|
+
t.datetime "dtm"
|
40
|
+
t.timestamp "tms"
|
41
|
+
t.time "tim"
|
42
|
+
t.date "dat"
|
43
|
+
t.binary "bin"
|
44
|
+
t.boolean "bln"
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'test/unit'
|
3
|
+
require 'shoulda'
|
4
|
+
require 'active_record'
|
5
|
+
require 'active_record/fixtures'
|
6
|
+
require 'action_view'
|
7
|
+
|
8
|
+
FIXTURES_PATH = File.join(File.dirname(__FILE__), 'fixtures')
|
9
|
+
|
10
|
+
Time.zone = 'Eastern Time (US & Canada)'
|
11
|
+
|
12
|
+
ActiveRecord::Base.establish_connection(
|
13
|
+
:adapter => 'sqlite3',
|
14
|
+
:database => ':memory:'
|
15
|
+
)
|
16
|
+
|
17
|
+
dep = defined?(ActiveSupport::Dependencies) ? ActiveSupport::Dependencies : ::Dependencies
|
18
|
+
dep.load_paths.unshift FIXTURES_PATH
|
19
|
+
|
20
|
+
ActiveRecord::Base.silence do
|
21
|
+
ActiveRecord::Migration.verbose = false
|
22
|
+
load File.join(FIXTURES_PATH, 'schema.rb')
|
23
|
+
end
|
24
|
+
|
25
|
+
Fixtures.create_fixtures(FIXTURES_PATH, ActiveRecord::Base.connection.tables)
|
26
|
+
|
27
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
28
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
29
|
+
require 'meta_search'
|
30
|
+
require 'meta_search/searches/active_record'
|
31
|
+
require 'meta_search/helpers/action_view'
|
32
|
+
|
33
|
+
MetaSearch::Searches::ActiveRecord.enable!
|
34
|
+
MetaSearch::Helpers::FormBuilder.enable!
|
35
|
+
|
36
|
+
class Test::Unit::TestCase
|
37
|
+
end
|
data/test/test_search.rb
ADDED
@@ -0,0 +1,351 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestSearch < Test::Unit::TestCase
|
4
|
+
|
5
|
+
context "A company search" do
|
6
|
+
setup do
|
7
|
+
@s = Company.search
|
8
|
+
end
|
9
|
+
|
10
|
+
should "have an association named developers" do
|
11
|
+
assert @s.association(:developers)
|
12
|
+
end
|
13
|
+
|
14
|
+
should "have a column named name" do
|
15
|
+
assert @s.column(:name)
|
16
|
+
end
|
17
|
+
|
18
|
+
should "exclude the column named updated_at" do
|
19
|
+
assert_nil @s.column(:updated_at)
|
20
|
+
end
|
21
|
+
|
22
|
+
should "raise an error if we try to search on updated_at" do
|
23
|
+
assert_raise NoMethodError do
|
24
|
+
@s.updated_at_eq = [2009, 1, 1]
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
should "exclude the association named notes" do
|
29
|
+
assert_nil @s.association(:notes)
|
30
|
+
end
|
31
|
+
|
32
|
+
should "raise an error if we try to search on notes" do
|
33
|
+
assert_raise NoMethodError do
|
34
|
+
@s.notes_note_eq = 'Blah'
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
should "honor its associations' excluded attributes" do
|
39
|
+
assert_nil @s.association_column(:data_types, :str)
|
40
|
+
end
|
41
|
+
|
42
|
+
should "raise an error if we try to search data_types.str" do
|
43
|
+
assert_raise NoMethodError do
|
44
|
+
@s.data_types_str_eq = 'Blah'
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
context "where name contains optical" do
|
49
|
+
setup do
|
50
|
+
@s.name_contains = 'optical'
|
51
|
+
end
|
52
|
+
|
53
|
+
should "return one result" do
|
54
|
+
assert_equal 1, @s.all.size
|
55
|
+
end
|
56
|
+
|
57
|
+
should "return a company named Advanced Optical Solutions" do
|
58
|
+
assert_contains @s.all, Company.where(:name => 'Advanced Optical Solutions').first
|
59
|
+
end
|
60
|
+
|
61
|
+
should "not return a company named Initech" do
|
62
|
+
assert_does_not_contain @s.all, Company.where(:name => "Initech").first
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
context "where developer name starts with Ernie" do
|
67
|
+
setup do
|
68
|
+
@s.developers_name_starts_with = 'Ernie'
|
69
|
+
end
|
70
|
+
|
71
|
+
should "return one result" do
|
72
|
+
assert_equal 1, @s.all.size
|
73
|
+
end
|
74
|
+
|
75
|
+
should "return a company named Mission Data" do
|
76
|
+
assert_contains @s.all, Company.where(:name => 'Mission Data').first
|
77
|
+
end
|
78
|
+
|
79
|
+
should "not return a company named Initech" do
|
80
|
+
assert_does_not_contain @s.all, Company.where(:name => "Initech").first
|
81
|
+
end
|
82
|
+
|
83
|
+
context "and slackers salary is greater than $70k" do
|
84
|
+
setup do
|
85
|
+
@s.slackers_salary_gt = 70000
|
86
|
+
end
|
87
|
+
|
88
|
+
should "return no results" do
|
89
|
+
assert_equal 0, @s.all.size
|
90
|
+
end
|
91
|
+
|
92
|
+
should "join developers twice" do
|
93
|
+
assert @s.to_sql.match(/join "developers".*join "developers"/i)
|
94
|
+
end
|
95
|
+
|
96
|
+
should "alias the second join of developers" do
|
97
|
+
assert @s.to_sql.match(/join "developers" "slackers_companies"/i)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
context "where developer note indicates he will crack yo skull" do
|
103
|
+
setup do
|
104
|
+
@s.developer_notes_note_equals = "Will show you what he's doing."
|
105
|
+
end
|
106
|
+
|
107
|
+
should "return one result" do
|
108
|
+
assert_equal 1, @s.all.size
|
109
|
+
end
|
110
|
+
|
111
|
+
should "return a company named Advanced Optical Solutions" do
|
112
|
+
assert_contains @s.all, Company.where(:name => 'Advanced Optical Solutions').first
|
113
|
+
end
|
114
|
+
|
115
|
+
should "not return a company named Mission Data" do
|
116
|
+
assert_does_not_contain @s.all, Company.where(:name => "Mission Data").first
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
context "A developer search" do
|
122
|
+
setup do
|
123
|
+
@s = Developer.search
|
124
|
+
end
|
125
|
+
|
126
|
+
should "have an association named projects" do
|
127
|
+
assert @s.association(:projects)
|
128
|
+
end
|
129
|
+
|
130
|
+
context "where developer is Bob-approved" do
|
131
|
+
setup do
|
132
|
+
@s.notes_note_equals = "A straight shooter with upper management written all over him."
|
133
|
+
end
|
134
|
+
|
135
|
+
should "return Peter Gibbons" do
|
136
|
+
assert_contains @s.all, Developer.where(:name => 'Peter Gibbons').first
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
context "where name ends with Miller" do
|
141
|
+
setup do
|
142
|
+
@s.name_ends_with = 'Miller'
|
143
|
+
end
|
144
|
+
|
145
|
+
should "return one result" do
|
146
|
+
assert_equal 1, @s.all.size
|
147
|
+
end
|
148
|
+
|
149
|
+
should "return a developer named Ernie Miller" do
|
150
|
+
assert_contains @s.all, Developer.where(:name => 'Ernie Miller').first
|
151
|
+
end
|
152
|
+
|
153
|
+
should "not return a developer named Herb Myers" do
|
154
|
+
assert_does_not_contain @s.all, Developer.where(:name => "Herb Myers").first
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
context "where project estimated hours are greater than or equal to 1000" do
|
159
|
+
setup do
|
160
|
+
@s.projects_estimated_hours_gte = 1000
|
161
|
+
end
|
162
|
+
|
163
|
+
should "return three results" do
|
164
|
+
assert_equal 3, @s.all.size
|
165
|
+
end
|
166
|
+
|
167
|
+
should "return these developers" do
|
168
|
+
assert_same_elements @s.all.collect {|d| d.name},
|
169
|
+
['Peter Gibbons', 'Michael Bolton', 'Samir Nagheenanajar']
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
context "where project estimated hours are greater than 1000" do
|
174
|
+
setup do
|
175
|
+
@s.projects_estimated_hours_gt = 1000
|
176
|
+
end
|
177
|
+
|
178
|
+
should "return no results" do
|
179
|
+
assert_equal 0, @s.all.size
|
180
|
+
end
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
context "A data type search" do
|
185
|
+
setup do
|
186
|
+
@s = DataType.search
|
187
|
+
end
|
188
|
+
|
189
|
+
should "raise an error on a contains search against a boolean column" do
|
190
|
+
assert_raise NoMethodError do
|
191
|
+
@s.bln_contains = "true"
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
context "where boolean column equals true" do
|
196
|
+
setup do
|
197
|
+
@s.bln_equals = true
|
198
|
+
end
|
199
|
+
|
200
|
+
should "return five results" do
|
201
|
+
assert_equal 5, @s.all.size
|
202
|
+
end
|
203
|
+
|
204
|
+
should "contain no results with a false boolean column" do
|
205
|
+
assert_does_not_contain @s.all.collect {|r| r.bln}, false
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
209
|
+
context "where date column is Christmas 2009 by array" do
|
210
|
+
setup do
|
211
|
+
@s.dat_equals = [2009, 12, 25]
|
212
|
+
end
|
213
|
+
|
214
|
+
should "return one result" do
|
215
|
+
assert_equal 1, @s.all.size
|
216
|
+
end
|
217
|
+
|
218
|
+
should "contain a result with Christmas 2009 as its date" do
|
219
|
+
assert_equal Date.parse('2009/12/25'), @s.first.dat
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
223
|
+
context "where date column is Christmas 2009 by Date object" do
|
224
|
+
setup do
|
225
|
+
@s.dat_equals = Date.new(2009, 12, 25)
|
226
|
+
end
|
227
|
+
|
228
|
+
should "return one result" do
|
229
|
+
assert_equal 1, @s.all.size
|
230
|
+
end
|
231
|
+
|
232
|
+
should "contain a result with Christmas 2009 as its date" do
|
233
|
+
assert_equal Date.parse('2009/12/25'), @s.first.dat
|
234
|
+
end
|
235
|
+
end
|
236
|
+
|
237
|
+
context "where time column is > 1:00 PM and < 3:30 PM" do
|
238
|
+
setup do
|
239
|
+
@s.tim_gt = Time.parse('2000-01-01 13:00') # Rails "dummy time" format
|
240
|
+
@s.tim_lt = Time.parse('2000-01-01 15:30') # Rails "dummy time" format
|
241
|
+
end
|
242
|
+
|
243
|
+
should "return three results" do
|
244
|
+
assert_equal 3, @s.all.size
|
245
|
+
end
|
246
|
+
|
247
|
+
should "not contain results with time column before or after constraints" do
|
248
|
+
assert_empty @s.all.select {|r|
|
249
|
+
r.tim < Time.parse('2000-01-01 13:00') || r.tim > Time.parse('2000-01-01 15:30')
|
250
|
+
}
|
251
|
+
end
|
252
|
+
end
|
253
|
+
|
254
|
+
context "where timestamp column is in the year 2010" do
|
255
|
+
setup do
|
256
|
+
@s.tms_gte = Time.utc(2010, 1, 1)
|
257
|
+
end
|
258
|
+
|
259
|
+
should "return two results" do
|
260
|
+
assert_equal 2, @s.all.size
|
261
|
+
end
|
262
|
+
|
263
|
+
should "not contain results with timestamp column before 2010" do
|
264
|
+
assert_empty @s.all.select {|r|
|
265
|
+
r.tms < Time.utc(2010, 1, 1)
|
266
|
+
}
|
267
|
+
end
|
268
|
+
end
|
269
|
+
|
270
|
+
context "where datetime column is before the year 2010" do
|
271
|
+
setup do
|
272
|
+
@s.tms_lt = Time.utc(2010, 1, 1)
|
273
|
+
end
|
274
|
+
|
275
|
+
should "return seven results" do
|
276
|
+
assert_equal 7, @s.all.size
|
277
|
+
end
|
278
|
+
|
279
|
+
should "not contain results with timestamp in 2010" do
|
280
|
+
assert_empty @s.all.select {|r|
|
281
|
+
r.tms >= Time.utc(2010, 1, 1)
|
282
|
+
}
|
283
|
+
end
|
284
|
+
end
|
285
|
+
|
286
|
+
context "where decimal column is > 5000" do
|
287
|
+
setup do
|
288
|
+
@s.dec_gt = 5000
|
289
|
+
end
|
290
|
+
|
291
|
+
should "return four results" do
|
292
|
+
assert_equal 4, @s.all.size
|
293
|
+
end
|
294
|
+
|
295
|
+
should "not contain results with decimal column <= 5000" do
|
296
|
+
assert_empty @s.all.select {|r|
|
297
|
+
r.dec <= 5000
|
298
|
+
}
|
299
|
+
end
|
300
|
+
end
|
301
|
+
|
302
|
+
context "where float column is between 2.5 and 3.5" do
|
303
|
+
setup do
|
304
|
+
@s.flt_gte = 2.5
|
305
|
+
@s.flt_lte = 3.5
|
306
|
+
end
|
307
|
+
|
308
|
+
should "return three results" do
|
309
|
+
assert_equal 3, @s.all.size
|
310
|
+
end
|
311
|
+
|
312
|
+
should "not contain results with float column outside constraints" do
|
313
|
+
assert_empty @s.all.select {|r|
|
314
|
+
r.flt < 2.5 || r.flt > 3.5
|
315
|
+
}
|
316
|
+
end
|
317
|
+
end
|
318
|
+
|
319
|
+
context "where integer column is in the set (1, 8, 729)" do
|
320
|
+
setup do
|
321
|
+
@s.int_in = [1, 8, 729]
|
322
|
+
end
|
323
|
+
|
324
|
+
should "return three results" do
|
325
|
+
assert_equal 3, @s.all.size
|
326
|
+
end
|
327
|
+
|
328
|
+
should "not contain results outside the specified set" do
|
329
|
+
assert_empty @s.all.select {|r|
|
330
|
+
![1, 8, 729].include?(r.int)
|
331
|
+
}
|
332
|
+
end
|
333
|
+
end
|
334
|
+
|
335
|
+
context "where integer column is not in the set (1, 8, 729)" do
|
336
|
+
setup do
|
337
|
+
@s.int_not_in = [1, 8, 729]
|
338
|
+
end
|
339
|
+
|
340
|
+
should "return six results" do
|
341
|
+
assert_equal 6, @s.all.size
|
342
|
+
end
|
343
|
+
|
344
|
+
should "not contain results outside the specified set" do
|
345
|
+
assert_empty @s.all.reject {|r|
|
346
|
+
![1, 8, 729].include?(r.int)
|
347
|
+
}
|
348
|
+
end
|
349
|
+
end
|
350
|
+
end
|
351
|
+
end
|
@@ -0,0 +1,149 @@
|
|
1
|
+
require 'helper'
|
2
|
+
require 'action_controller'
|
3
|
+
require 'action_view/test_case'
|
4
|
+
|
5
|
+
class TestViewHelpers < ActionView::TestCase
|
6
|
+
tests ActionView::Helpers::FormHelper
|
7
|
+
|
8
|
+
context "A previously-filled search form" do
|
9
|
+
setup do
|
10
|
+
@s = Company.search
|
11
|
+
@s.created_at_gte = [2001, 2, 3, 4, 5]
|
12
|
+
@s.name_contains = "bacon"
|
13
|
+
fields_for :search, @s do |f|
|
14
|
+
@f = f
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
should "retain previous search terms" do
|
19
|
+
html = @f.datetime_select(:created_at_gte)
|
20
|
+
['2001', '3', '04', '05'].each do |v|
|
21
|
+
assert_match /<option selected="selected" value="#{v}">#{v}<\/option>/,
|
22
|
+
html
|
23
|
+
end
|
24
|
+
assert_match /<option selected="selected" value="2">February<\/option>/, html
|
25
|
+
assert_dom_equal '<input id="search_name_contains" name="search[name_contains]" ' +
|
26
|
+
'size="30" type="text" value="bacon" />',
|
27
|
+
@f.text_field(:name_contains)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context "A form using mutiparameter_field with default size option" do
|
32
|
+
setup do
|
33
|
+
@s = Developer.search
|
34
|
+
fields_for :search, @s do |f|
|
35
|
+
@f = f
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
should "apply proper cast and default size attribute to text fields" do
|
40
|
+
html = @f.multiparameter_field :salary_in,
|
41
|
+
{:field_type => :text_field, :type_cast => 'i'},
|
42
|
+
{:field_type => :text_field, :type_cast => 'i'}, :size => 10
|
43
|
+
assert_dom_equal '<input id="search_salary_in(1i)" name="search[salary_in(1i)]" ' +
|
44
|
+
'size="10" type="text" />' +
|
45
|
+
'<input id="search_salary_in(2i)" name="search[salary_in(2i)]" ' +
|
46
|
+
'size="10" type="text" />',
|
47
|
+
html
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
context "A form using check_boxes with three choices" do
|
52
|
+
setup do
|
53
|
+
@s = Company.search
|
54
|
+
fields_for :search, @s do |f|
|
55
|
+
@f = f
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
should "generate the expected HTML without a block" do
|
60
|
+
assert_dom_equal '<input id="search_id_in_1" name="search[id_in][]" ' +
|
61
|
+
'type="checkbox" value="1" /><label for="search_id_in_1">One</label>' +
|
62
|
+
'<input id="search_id_in_2" name="search[id_in][]" ' +
|
63
|
+
'type="checkbox" value="2" /><label for="search_id_in_2">Two</label>' +
|
64
|
+
'<input id="search_id_in_3" name="search[id_in][]" ' +
|
65
|
+
'type="checkbox" value="3" /><label for="search_id_in_3">Three</label>',
|
66
|
+
@f.check_boxes(:id_in, [['One', 1], ['Two', 2], ['Three', 3]])
|
67
|
+
end
|
68
|
+
|
69
|
+
should "generate the expected HTML with a block" do
|
70
|
+
@f.check_boxes(:id_in, [['One', 1], ['Two', 2], ['Three', 3]]) do |c|
|
71
|
+
concat render :to => :string, :inline => "<p><%= c[:label] %> <%= c[:check_box] %></p>", :locals => {:c => c}
|
72
|
+
end
|
73
|
+
assert_dom_equal output_buffer,
|
74
|
+
'<p><label for="search_id_in_1">One</label> ' +
|
75
|
+
'<input id="search_id_in_1" name="search[id_in][]" ' +
|
76
|
+
'type="checkbox" value="1" /></p>' +
|
77
|
+
'<p><label for="search_id_in_2">Two</label> ' +
|
78
|
+
'<input id="search_id_in_2" name="search[id_in][]" ' +
|
79
|
+
'type="checkbox" value="2" /></p>' +
|
80
|
+
'<p><label for="search_id_in_3">Three</label> ' +
|
81
|
+
'<input id="search_id_in_3" name="search[id_in][]" ' +
|
82
|
+
'type="checkbox" value="3" /></p>'
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
context "A form using check_boxes with three choices and a previous selection" do
|
87
|
+
setup do
|
88
|
+
@s = Company.search
|
89
|
+
@s.id_in = [1, 3]
|
90
|
+
fields_for :search, @s do |f|
|
91
|
+
@f = f
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
should "generate the expected HTML without a block" do
|
96
|
+
assert_dom_equal '<input checked="checked" id="search_id_in_1" name="search[id_in][]" ' +
|
97
|
+
'type="checkbox" value="1" /><label for="search_id_in_1">One</label>' +
|
98
|
+
'<input id="search_id_in_2" name="search[id_in][]" ' +
|
99
|
+
'type="checkbox" value="2" /><label for="search_id_in_2">Two</label>' +
|
100
|
+
'<input checked="checked" id="search_id_in_3" name="search[id_in][]" ' +
|
101
|
+
'type="checkbox" value="3" /><label for="search_id_in_3">Three</label>',
|
102
|
+
@f.check_boxes(:id_in, [['One', 1], ['Two', 2], ['Three', 3]])
|
103
|
+
end
|
104
|
+
|
105
|
+
should "generate the expected HTML with a block" do
|
106
|
+
@f.check_boxes(:id_in, [['One', 1], ['Two', 2], ['Three', 3]]) do |c|
|
107
|
+
concat render :to => :string, :inline => "<p><%= c[:label] %> <%= c[:check_box] %></p>", :locals => {:c => c}
|
108
|
+
end
|
109
|
+
assert_dom_equal output_buffer,
|
110
|
+
'<p><label for="search_id_in_1">One</label> <input checked="checked" id="search_id_in_1" ' +
|
111
|
+
'name="search[id_in][]" type="checkbox" value="1" /></p><p><label for="search_id_in_2">' +
|
112
|
+
'Two</label> <input id="search_id_in_2" name="search[id_in][]" type="checkbox" value="2" />' +
|
113
|
+
'</p><p><label for="search_id_in_3">Three</label> <input checked="checked" id="search_id_in_3" ' +
|
114
|
+
'name="search[id_in][]" type="checkbox" value="3" /></p>'
|
115
|
+
end
|
116
|
+
|
117
|
+
context "A form using collection_check_boxes with companies" do
|
118
|
+
setup do
|
119
|
+
@s = Company.search
|
120
|
+
fields_for :search, @s do |f|
|
121
|
+
@f = f
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
should "generate the expected HTML without a block" do
|
126
|
+
assert_dom_equal '<input id="search_id_in_1" name="search[id_in][]" type="checkbox" ' +
|
127
|
+
'value="1" /><label for="search_id_in_1">Initech</label>' +
|
128
|
+
'<input id="search_id_in_2" name="search[id_in][]" type="checkbox" ' +
|
129
|
+
'value="2" /><label for="search_id_in_2">Advanced Optical Solutions</label>' +
|
130
|
+
'<input id="search_id_in_3" name="search[id_in][]" type="checkbox" ' +
|
131
|
+
'value="3" /><label for="search_id_in_3">Mission Data</label>',
|
132
|
+
@f.collection_check_boxes(:id_in, Company.all, :id, :name)
|
133
|
+
end
|
134
|
+
|
135
|
+
should "generate the expected HTML with a block" do
|
136
|
+
@f.collection_check_boxes(:id_in, Company.all, :id, :name) do |c|
|
137
|
+
concat render :to => :string, :inline => "<p><%= c[:label] %> <%= c[:check_box] %></p>", :locals => {:c => c}
|
138
|
+
end
|
139
|
+
assert_dom_equal output_buffer,
|
140
|
+
'<p><label for="search_id_in_1">Initech</label> ' +
|
141
|
+
'<input id="search_id_in_1" name="search[id_in][]" type="checkbox" value="1" /></p>' +
|
142
|
+
'<p><label for="search_id_in_2">Advanced Optical Solutions</label> ' +
|
143
|
+
'<input id="search_id_in_2" name="search[id_in][]" type="checkbox" value="2" /></p>' +
|
144
|
+
'<p><label for="search_id_in_3">Mission Data</label> ' +
|
145
|
+
'<input id="search_id_in_3" name="search[id_in][]" type="checkbox" value="3" /></p>'
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
metadata
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: meta_search
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 3
|
8
|
+
- 0
|
9
|
+
version: 0.3.0
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Ernie Miller
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-03-16 00:00:00 -04:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: activerecord
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 3
|
29
|
+
- 0
|
30
|
+
- 0
|
31
|
+
- beta
|
32
|
+
version: 3.0.0.beta
|
33
|
+
type: :development
|
34
|
+
version_requirements: *id001
|
35
|
+
description: Adds a search method to your ActiveRecord models which returns an object to be used in form_for while constructing a search. Works with Rails 3 only.
|
36
|
+
email: ernie@metautonomo.us
|
37
|
+
executables: []
|
38
|
+
|
39
|
+
extensions: []
|
40
|
+
|
41
|
+
extra_rdoc_files:
|
42
|
+
- LICENSE
|
43
|
+
- README.rdoc
|
44
|
+
files:
|
45
|
+
- .document
|
46
|
+
- .gitignore
|
47
|
+
- LICENSE
|
48
|
+
- README.rdoc
|
49
|
+
- Rakefile
|
50
|
+
- VERSION
|
51
|
+
- lib/meta_search.rb
|
52
|
+
- lib/meta_search/builder.rb
|
53
|
+
- lib/meta_search/exceptions.rb
|
54
|
+
- lib/meta_search/helpers/action_view.rb
|
55
|
+
- lib/meta_search/model_compatibility.rb
|
56
|
+
- lib/meta_search/railtie.rb
|
57
|
+
- lib/meta_search/searches/active_record.rb
|
58
|
+
- lib/meta_search/searches/base.rb
|
59
|
+
- lib/meta_search/utility.rb
|
60
|
+
- lib/meta_search/where.rb
|
61
|
+
- meta_search.gemspec
|
62
|
+
- test/fixtures/companies.yml
|
63
|
+
- test/fixtures/company.rb
|
64
|
+
- test/fixtures/data_type.rb
|
65
|
+
- test/fixtures/data_types.yml
|
66
|
+
- test/fixtures/developer.rb
|
67
|
+
- test/fixtures/developers.yml
|
68
|
+
- test/fixtures/developers_projects.yml
|
69
|
+
- test/fixtures/note.rb
|
70
|
+
- test/fixtures/notes.yml
|
71
|
+
- test/fixtures/project.rb
|
72
|
+
- test/fixtures/projects.yml
|
73
|
+
- test/fixtures/schema.rb
|
74
|
+
- test/helper.rb
|
75
|
+
- test/test_search.rb
|
76
|
+
- test/test_view_helpers.rb
|
77
|
+
has_rdoc: true
|
78
|
+
homepage: http://metautonomo.us
|
79
|
+
licenses: []
|
80
|
+
|
81
|
+
post_install_message:
|
82
|
+
rdoc_options:
|
83
|
+
- --charset=UTF-8
|
84
|
+
require_paths:
|
85
|
+
- lib
|
86
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
segments:
|
91
|
+
- 0
|
92
|
+
version: "0"
|
93
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
segments:
|
98
|
+
- 0
|
99
|
+
version: "0"
|
100
|
+
requirements: []
|
101
|
+
|
102
|
+
rubyforge_project:
|
103
|
+
rubygems_version: 1.3.6
|
104
|
+
signing_key:
|
105
|
+
specification_version: 3
|
106
|
+
summary: ActiveRecord 3 object-based searching.
|
107
|
+
test_files:
|
108
|
+
- test/fixtures/company.rb
|
109
|
+
- test/fixtures/data_type.rb
|
110
|
+
- test/fixtures/developer.rb
|
111
|
+
- test/fixtures/note.rb
|
112
|
+
- test/fixtures/project.rb
|
113
|
+
- test/fixtures/schema.rb
|
114
|
+
- test/helper.rb
|
115
|
+
- test/test_search.rb
|
116
|
+
- test/test_view_helpers.rb
|