buscar 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/spec/matchers.rb ADDED
@@ -0,0 +1,50 @@
1
+ module Buscar
2
+ module IndexMatchers
3
+ class IncludeTag
4
+ def initialize(name)
5
+ @name = name
6
+ end
7
+
8
+ def matches?(index)
9
+ @index = index
10
+ !index.records.detect { |tag| tag.name == @name }.nil?
11
+ end
12
+
13
+ def failure_message
14
+ "Expected records to include tag #{@name}. Got: [#{@index.records.collect(&:name).join(', ')}]"
15
+ end
16
+
17
+ def negative_failure_message
18
+ "Expected records to exclude tag #{@name}. Got: [#{@index.records.collect(&:name).join(', ')}]"
19
+ end
20
+ end
21
+
22
+ def include_tag(name)
23
+ IncludeTag.new(name)
24
+ end
25
+
26
+ class SortTags
27
+ def initialize(*names)
28
+ @names = names
29
+ end
30
+
31
+ def matches?(index)
32
+ @index = index
33
+ return false unless index.records.length == @names.length
34
+ index.records.collect(&:name) == @names
35
+ end
36
+
37
+ def failure_message
38
+ "Expected tags to be sorted in this order: [#{@names.join(', ')}], but got: [#{@index.records.collect(&:name).join(', ')}]"
39
+ end
40
+
41
+ def negative_failure_message
42
+ "Expected tags mot to be sorted in this order: [#{@names.join(', ')}]"
43
+ end
44
+ end
45
+
46
+ def sort_tags(*names)
47
+ SortTags.new(*names)
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,7 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'buscar'
4
+
5
+ #Spec::Runner.configure do |config|
6
+ #
7
+ #end
data/spec/test_db.rb ADDED
@@ -0,0 +1,60 @@
1
+ require 'active_record'
2
+ #ActiveRecord::Base.logger = Logger.new(STDOUT)
3
+
4
+ ActiveRecord::Base.establish_connection(
5
+ :adapter => "sqlite3",
6
+ :database => ":memory:"
7
+ )
8
+
9
+ ActiveRecord::Schema.define do
10
+ create_table :cities, :force => true do |t|
11
+ t.string :name, :null => false
12
+ end
13
+
14
+ create_table :businesses, :force => true do |t|
15
+ t.integer :city_id, :null => false
16
+ t.string :name, :null => false
17
+ t.boolean :active, :null => false, :default => true
18
+ end
19
+
20
+ create_table :tags, :force => true do |t|
21
+ t.string :name, :null => false
22
+ t.boolean :published, :null => false, :default => false
23
+ end
24
+
25
+ create_table :taggings, :force => true do |t|
26
+ t.integer :business_id, :null => false
27
+ t.integer :tag_id, :null => false
28
+ end
29
+ end
30
+
31
+ class City < ActiveRecord::Base
32
+ validates_presence_of :name
33
+ end
34
+
35
+ class Business < ActiveRecord::Base
36
+ belongs_to :city
37
+ has_many :taggings, :dependent => :destroy
38
+ has_many :tags, :through => :taggings
39
+ validates_presence_of :name, :city_id
40
+ end
41
+
42
+ class Tag < ActiveRecord::Base
43
+ has_many :taggings, :dependent => :destroy
44
+ has_many :businesses, :through => :taggings
45
+ validates_presence_of :name
46
+
47
+ def active_businesses_in_city(city)
48
+ unless city.is_a?(City)
49
+ raise(ArgumentError, "Expected City but got #{city.inspect}")
50
+ end
51
+ @active_businesss_by_city ||= {}
52
+ @active_businesss_by_city[city.id] ||= businesses.select { |b| b.active and b.city_id == city.id }
53
+ end
54
+ end
55
+
56
+ class Tagging < ActiveRecord::Base
57
+ belongs_to :tag
58
+ belongs_to :business
59
+ validates_presence_of :business_id, :tag_id
60
+ end
metadata ADDED
@@ -0,0 +1,360 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: buscar
3
+ version: !ruby/object:Gem::Version
4
+ hash: 23
5
+ prerelease: false
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - 0
10
+ version: 1.0.0
11
+ platform: ruby
12
+ authors:
13
+ - jarrett
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-12-07 00:00:00 -06:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ type: :development
23
+ prerelease: false
24
+ name: bundler
25
+ version_requirements: &id001 !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ~>
29
+ - !ruby/object:Gem::Version
30
+ hash: 23
31
+ segments:
32
+ - 1
33
+ - 0
34
+ - 0
35
+ version: 1.0.0
36
+ requirement: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ type: :development
39
+ prerelease: false
40
+ name: jeweler
41
+ version_requirements: &id002 !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ~>
45
+ - !ruby/object:Gem::Version
46
+ hash: 1
47
+ segments:
48
+ - 1
49
+ - 5
50
+ - 1
51
+ version: 1.5.1
52
+ requirement: *id002
53
+ - !ruby/object:Gem::Dependency
54
+ type: :development
55
+ prerelease: false
56
+ name: rspec
57
+ version_requirements: &id003 !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ hash: 7
63
+ segments:
64
+ - 2
65
+ - 2
66
+ - 0
67
+ version: 2.2.0
68
+ requirement: *id003
69
+ - !ruby/object:Gem::Dependency
70
+ type: :development
71
+ prerelease: false
72
+ name: rcov
73
+ version_requirements: &id004 !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ hash: 3
79
+ segments:
80
+ - 0
81
+ version: "0"
82
+ requirement: *id004
83
+ - !ruby/object:Gem::Dependency
84
+ type: :development
85
+ prerelease: false
86
+ name: machinist
87
+ version_requirements: &id005 !ruby/object:Gem::Requirement
88
+ none: false
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ hash: 27
93
+ segments:
94
+ - 1
95
+ - 0
96
+ - 6
97
+ version: 1.0.6
98
+ requirement: *id005
99
+ - !ruby/object:Gem::Dependency
100
+ type: :development
101
+ prerelease: false
102
+ name: faker
103
+ version_requirements: &id006 !ruby/object:Gem::Requirement
104
+ none: false
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ hash: 17
109
+ segments:
110
+ - 0
111
+ - 3
112
+ - 1
113
+ version: 0.3.1
114
+ requirement: *id006
115
+ - !ruby/object:Gem::Dependency
116
+ type: :development
117
+ prerelease: false
118
+ name: activesupport
119
+ version_requirements: &id007 !ruby/object:Gem::Requirement
120
+ none: false
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ hash: 1
125
+ segments:
126
+ - 3
127
+ - 0
128
+ - 3
129
+ version: 3.0.3
130
+ requirement: *id007
131
+ - !ruby/object:Gem::Dependency
132
+ type: :development
133
+ prerelease: false
134
+ name: actionpack
135
+ version_requirements: &id008 !ruby/object:Gem::Requirement
136
+ none: false
137
+ requirements:
138
+ - - ">="
139
+ - !ruby/object:Gem::Version
140
+ hash: 1
141
+ segments:
142
+ - 3
143
+ - 0
144
+ - 3
145
+ version: 3.0.3
146
+ requirement: *id008
147
+ - !ruby/object:Gem::Dependency
148
+ type: :development
149
+ prerelease: false
150
+ name: activerecord
151
+ version_requirements: &id009 !ruby/object:Gem::Requirement
152
+ none: false
153
+ requirements:
154
+ - - ">="
155
+ - !ruby/object:Gem::Version
156
+ hash: 1
157
+ segments:
158
+ - 3
159
+ - 0
160
+ - 3
161
+ version: 3.0.3
162
+ requirement: *id009
163
+ - !ruby/object:Gem::Dependency
164
+ type: :runtime
165
+ prerelease: false
166
+ name: activesupport
167
+ version_requirements: &id010 !ruby/object:Gem::Requirement
168
+ none: false
169
+ requirements:
170
+ - - ">="
171
+ - !ruby/object:Gem::Version
172
+ hash: 3
173
+ segments:
174
+ - 3
175
+ - 0
176
+ - 2
177
+ version: 3.0.2
178
+ requirement: *id010
179
+ - !ruby/object:Gem::Dependency
180
+ type: :runtime
181
+ prerelease: false
182
+ name: activerecord
183
+ version_requirements: &id011 !ruby/object:Gem::Requirement
184
+ none: false
185
+ requirements:
186
+ - - ">="
187
+ - !ruby/object:Gem::Version
188
+ hash: 3
189
+ segments:
190
+ - 3
191
+ - 0
192
+ - 2
193
+ version: 3.0.2
194
+ requirement: *id011
195
+ - !ruby/object:Gem::Dependency
196
+ type: :development
197
+ prerelease: false
198
+ name: actionpack
199
+ version_requirements: &id012 !ruby/object:Gem::Requirement
200
+ none: false
201
+ requirements:
202
+ - - ">="
203
+ - !ruby/object:Gem::Version
204
+ hash: 3
205
+ segments:
206
+ - 3
207
+ - 0
208
+ - 2
209
+ version: 3.0.2
210
+ requirement: *id012
211
+ - !ruby/object:Gem::Dependency
212
+ type: :development
213
+ prerelease: false
214
+ name: rspec
215
+ version_requirements: &id013 !ruby/object:Gem::Requirement
216
+ none: false
217
+ requirements:
218
+ - - ">="
219
+ - !ruby/object:Gem::Version
220
+ hash: 11
221
+ segments:
222
+ - 2
223
+ - 1
224
+ - 0
225
+ version: 2.1.0
226
+ requirement: *id013
227
+ - !ruby/object:Gem::Dependency
228
+ type: :development
229
+ prerelease: false
230
+ name: sqlite3-ruby
231
+ version_requirements: &id014 !ruby/object:Gem::Requirement
232
+ none: false
233
+ requirements:
234
+ - - ">="
235
+ - !ruby/object:Gem::Version
236
+ hash: 21
237
+ segments:
238
+ - 1
239
+ - 2
240
+ - 5
241
+ version: 1.2.5
242
+ requirement: *id014
243
+ - !ruby/object:Gem::Dependency
244
+ type: :development
245
+ prerelease: false
246
+ name: machinist
247
+ version_requirements: &id015 !ruby/object:Gem::Requirement
248
+ none: false
249
+ requirements:
250
+ - - ">="
251
+ - !ruby/object:Gem::Version
252
+ hash: 27
253
+ segments:
254
+ - 1
255
+ - 0
256
+ - 6
257
+ version: 1.0.6
258
+ requirement: *id015
259
+ - !ruby/object:Gem::Dependency
260
+ type: :development
261
+ prerelease: false
262
+ name: faker
263
+ version_requirements: &id016 !ruby/object:Gem::Requirement
264
+ none: false
265
+ requirements:
266
+ - - ">="
267
+ - !ruby/object:Gem::Version
268
+ hash: 17
269
+ segments:
270
+ - 0
271
+ - 3
272
+ - 1
273
+ version: 0.3.1
274
+ requirement: *id016
275
+ - !ruby/object:Gem::Dependency
276
+ type: :development
277
+ prerelease: false
278
+ name: webrat
279
+ version_requirements: &id017 !ruby/object:Gem::Requirement
280
+ none: false
281
+ requirements:
282
+ - - ">="
283
+ - !ruby/object:Gem::Version
284
+ hash: 7
285
+ segments:
286
+ - 0
287
+ - 7
288
+ - 2
289
+ version: 0.7.2
290
+ requirement: *id017
291
+ description: Simplifies searching, sorting, and pagination of ActiveRecord models. Includes a model class and a view helper.
292
+ email: jarrettcolby@gmail.com
293
+ executables: []
294
+
295
+ extensions: []
296
+
297
+ extra_rdoc_files:
298
+ - LICENSE
299
+ - README.markdown
300
+ files:
301
+ - .document
302
+ - .rvmrc
303
+ - Gemfile
304
+ - Gemfile.lock
305
+ - LICENSE
306
+ - README.markdown
307
+ - Rakefile
308
+ - VERSION
309
+ - buscar.gemspec
310
+ - lib/buscar.rb
311
+ - lib/buscar/helpers.rb
312
+ - lib/buscar/index.rb
313
+ - lib/buscar/railtie.rb
314
+ - spec/blueprint.rb
315
+ - spec/helpers_spec.rb
316
+ - spec/index_spec.rb
317
+ - spec/matchers.rb
318
+ - spec/spec_helper.rb
319
+ - spec/test_db.rb
320
+ has_rdoc: true
321
+ homepage: http://github.com/jarrett/buscar
322
+ licenses: []
323
+
324
+ post_install_message:
325
+ rdoc_options: []
326
+
327
+ require_paths:
328
+ - lib
329
+ required_ruby_version: !ruby/object:Gem::Requirement
330
+ none: false
331
+ requirements:
332
+ - - ">="
333
+ - !ruby/object:Gem::Version
334
+ hash: 3
335
+ segments:
336
+ - 0
337
+ version: "0"
338
+ required_rubygems_version: !ruby/object:Gem::Requirement
339
+ none: false
340
+ requirements:
341
+ - - ">="
342
+ - !ruby/object:Gem::Version
343
+ hash: 3
344
+ segments:
345
+ - 0
346
+ version: "0"
347
+ requirements: []
348
+
349
+ rubyforge_project:
350
+ rubygems_version: 1.3.7
351
+ signing_key:
352
+ specification_version: 3
353
+ summary: Searching, sorting, and pagination for Rails
354
+ test_files:
355
+ - spec/blueprint.rb
356
+ - spec/helpers_spec.rb
357
+ - spec/index_spec.rb
358
+ - spec/matchers.rb
359
+ - spec/spec_helper.rb
360
+ - spec/test_db.rb