jnewland-scoped_search 0.7.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +12 -0
- data/LICENSE +20 -0
- data/README.textile +76 -0
- data/Rakefile +70 -0
- data/TODO +15 -0
- data/init.rb +1 -0
- data/lib/scoped_search.rb +78 -0
- data/lib/scoped_search/query_conditions_builder.rb +189 -0
- data/lib/scoped_search/query_language_parser.rb +100 -0
- data/lib/scoped_search/reg_tokens.rb +51 -0
- data/test/query_conditions_builder_test.rb +114 -0
- data/test/query_language_test.rb +172 -0
- data/test/search_for_test.rb +159 -0
- data/test/tasks.rake +13 -0
- data/test/test_helper.rb +247 -0
- metadata +75 -0
data/test/tasks.rake
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'rake/testtask'
|
2
|
+
|
3
|
+
desc 'Test the scoped_search plugin.'
|
4
|
+
Rake::TestTask.new(:test) do |t|
|
5
|
+
t.pattern = 'test/**/*_test.rb'
|
6
|
+
t.verbose = true
|
7
|
+
t.libs << 'test'
|
8
|
+
|
9
|
+
# options are sqlite3, mysql or postgresql. The default
|
10
|
+
# is sqlite3 if not specified or if the parameter is invalid.
|
11
|
+
# If DATABASE is mysql then the MYSQLSOCKET can also be set if needed.
|
12
|
+
ENV['DATABASE'] = ENV['DATABASE'].nil? ? 'sqlite3' : ENV['DATABASE'].downcase
|
13
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,247 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'rubygems'
|
3
|
+
require 'active_record'
|
4
|
+
require 'ruby-debug'
|
5
|
+
|
6
|
+
require "#{File.dirname(__FILE__)}/../lib/scoped_search"
|
7
|
+
|
8
|
+
class InitialSchema < ActiveRecord::Migration
|
9
|
+
|
10
|
+
def self.up
|
11
|
+
create_table :search_test_models do |t|
|
12
|
+
t.string :string_field
|
13
|
+
t.text :text_field
|
14
|
+
t.string :ignored_field
|
15
|
+
t.date :date_field
|
16
|
+
t.timestamps
|
17
|
+
end
|
18
|
+
|
19
|
+
create_table :users do |t|
|
20
|
+
t.string :first_name, :last_name, :login
|
21
|
+
t.integer :group_id
|
22
|
+
t.integer :address_id
|
23
|
+
end
|
24
|
+
|
25
|
+
create_table :clients do |t|
|
26
|
+
t.string :first_name, :last_name
|
27
|
+
end
|
28
|
+
|
29
|
+
create_table :offices do |t|
|
30
|
+
t.string :name
|
31
|
+
t.integer :user_id, :client_id
|
32
|
+
end
|
33
|
+
|
34
|
+
create_table :groups do |t|
|
35
|
+
t.string :name
|
36
|
+
end
|
37
|
+
|
38
|
+
create_table :locations do |t|
|
39
|
+
t.string :name
|
40
|
+
end
|
41
|
+
|
42
|
+
create_table :locations_users, :id => false, :force => true do |t|
|
43
|
+
t.integer :user_id
|
44
|
+
t.integer :location_id
|
45
|
+
end
|
46
|
+
|
47
|
+
create_table :notes do |t|
|
48
|
+
t.string :title
|
49
|
+
t.text :content
|
50
|
+
t.integer :user_id
|
51
|
+
end
|
52
|
+
|
53
|
+
create_table :addresses do |t|
|
54
|
+
t.string :street, :city, :state, :postal_code
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def self.down
|
59
|
+
drop_table :search_test_models
|
60
|
+
drop_table :users
|
61
|
+
drop_table :clients
|
62
|
+
drop_table :offices
|
63
|
+
drop_table :groups
|
64
|
+
drop_table :locations
|
65
|
+
drop_table :locations_users
|
66
|
+
drop_table :notes
|
67
|
+
drop_table :addresses
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
|
72
|
+
|
73
|
+
def create_sqlite3_connection
|
74
|
+
ActiveRecord::Base.establish_connection(
|
75
|
+
:adapter => "sqlite3",
|
76
|
+
:dbfile => ":memory:"
|
77
|
+
)
|
78
|
+
end
|
79
|
+
|
80
|
+
def create_postgresql_connection
|
81
|
+
ActiveRecord::Base.establish_connection(
|
82
|
+
:adapter => "postgresql",
|
83
|
+
:host => "localhost",
|
84
|
+
:username => "sstest",
|
85
|
+
:password => "sstest",
|
86
|
+
:database => "scoped_search_test"
|
87
|
+
)
|
88
|
+
end
|
89
|
+
|
90
|
+
def create_mysql_connection
|
91
|
+
# '/tmp/mysql.sock' is the default location and file rails looks for.
|
92
|
+
mysql_socket = ENV['MYSQLSOCKET'].nil? ? '/tmp/mysql.sock' : ENV['MYSQLSOCKET']
|
93
|
+
ActiveRecord::Base.establish_connection(
|
94
|
+
:adapter => "mysql",
|
95
|
+
:host => "localhost",
|
96
|
+
:username => "sstest",
|
97
|
+
:password => "sstest",
|
98
|
+
:database => "scoped_search_test",
|
99
|
+
:socket => mysql_socket
|
100
|
+
)
|
101
|
+
end
|
102
|
+
|
103
|
+
|
104
|
+
class SearchTestModel < ActiveRecord::Base
|
105
|
+
def self.create_corpus!
|
106
|
+
create!(:string_field => "Programmer 123", :text_field => nil, :ignored_field => "123456", :date_field => '2000-01-01')
|
107
|
+
create!(:string_field => "Jim", :text_field => "Henson", :ignored_field => "123456a", :date_field => '2001-04-15')
|
108
|
+
create!(:string_field => "Jim", :text_field => "Bush", :ignored_field => "123456b", :date_field => '2001-04-17')
|
109
|
+
create!(:string_field => "Wes", :text_field => "Hays", :ignored_field => "123456c", :date_field => '1980-09-27')
|
110
|
+
create!(:string_field => "Bob", :text_field => "Hays", :ignored_field => "123456d", :date_field => '2002-11-09')
|
111
|
+
create!(:string_field => "Dogs", :text_field => "Pit Bull", :ignored_field => "123456e", :date_field => '2002-12-26')
|
112
|
+
create!(:string_field => "Dogs", :text_field => "Eskimo", :ignored_field => "123456f", :date_field => '2003-03-19')
|
113
|
+
create!(:string_field => "Cows", :text_field => "Farms", :ignored_field => "123456g", :date_field => '2004-05-01')
|
114
|
+
create!(:string_field => "Hello World", :text_field => "Hello Moon", :ignored_field => "123456h", :date_field => '2004-07-11')
|
115
|
+
create!(:string_field => "Hello World", :text_field => "Goodnight Moon", :ignored_field => "123456i", :date_field => '2004-09-12')
|
116
|
+
create!(:string_field => "Happy Cow", :text_field => "Sad Cow", :ignored_field => "123456j", :date_field => '2005-02-05')
|
117
|
+
create!(:string_field => "Happy Frog", :text_field => "Sad Frog", :ignored_field => "123456k", :date_field => '2006-03-09')
|
118
|
+
create!(:string_field => "Excited Frog", :text_field => "Sad Frog", :ignored_field => "123456l", :date_field => '2006-07-15')
|
119
|
+
create!(:string_field => "Man made", :text_field => "Woman made", :ignored_field => "123456m", :date_field => '2007-06-13')
|
120
|
+
create!(:string_field => "Cat Toys", :text_field => "Frog Toys", :ignored_field => "123456n", :date_field => '2008-03-04')
|
121
|
+
create!(:string_field => "Happy Toys", :text_field => "Sad Toys", :ignored_field => "123456n", :date_field => '2008-05-12')
|
122
|
+
|
123
|
+
create!(:string_field => "My son was born on 7/15/2006 and weighed 5.5 lbs",
|
124
|
+
:text_field => "Sad Toys",
|
125
|
+
:ignored_field => "123456n",
|
126
|
+
:date_field => '2008-09-22')
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
class User < ActiveRecord::Base
|
131
|
+
belongs_to :group
|
132
|
+
belongs_to :address
|
133
|
+
has_many :notes
|
134
|
+
has_and_belongs_to_many :locations
|
135
|
+
|
136
|
+
has_many :offices, :dependent => :destroy
|
137
|
+
has_many :clients, :through => :offices
|
138
|
+
def self.create_corpus!
|
139
|
+
create!(:first_name => 'Willem', :last_name => 'Van Bergen', :login => 'wvanbergen', :group_id => 1, :address_id => 1)
|
140
|
+
create!(:first_name => 'Wes', :last_name => 'Hays', :login => 'weshays', :group_id => 1, :address_id => 2)
|
141
|
+
create!(:first_name => 'John', :last_name => 'Dell', :login => 'jdell', :group_id => 2, :address_id => 3)
|
142
|
+
create!(:first_name => 'Ray', :last_name => 'York', :login => 'ryork', :group_id => 3, :address_id => 4)
|
143
|
+
create!(:first_name => 'Anna', :last_name => 'Landis', :login => 'alandis', :group_id => 4, :address_id => 5)
|
144
|
+
|
145
|
+
user = self.find_by_first_name('Willem')
|
146
|
+
user.locations << Location.find_by_name('Office')
|
147
|
+
|
148
|
+
user = self.find_by_first_name('Wes')
|
149
|
+
user.locations << Location.find_by_name('Store')
|
150
|
+
|
151
|
+
user = self.find_by_first_name('John')
|
152
|
+
user.locations << Location.find_by_name('Office')
|
153
|
+
|
154
|
+
user = self.find_by_first_name('Ray')
|
155
|
+
user.locations << Location.find_by_name('Home')
|
156
|
+
|
157
|
+
user = self.find_by_first_name('Anna')
|
158
|
+
user.locations << Location.find_by_name('Beach')
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
class Client < ActiveRecord::Base
|
163
|
+
has_many :offices, :dependent => :destroy
|
164
|
+
has_many :users, :through => :offices
|
165
|
+
def self.create_corpus!
|
166
|
+
create!(:first_name => 'Bob', :last_name => 'Smith')
|
167
|
+
create!(:first_name => 'Sam', :last_name => 'Lovett')
|
168
|
+
create!(:first_name => 'Sally', :last_name => 'May')
|
169
|
+
create!(:first_name => 'Mary', :last_name => 'Smith')
|
170
|
+
create!(:first_name => 'Darren', :last_name => 'Johnson')
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
class Office < ActiveRecord::Base
|
175
|
+
belongs_to :client
|
176
|
+
belongs_to :user
|
177
|
+
def self.create_corpus!
|
178
|
+
create!(:name => 'California Office', :user_id => 1, :client_id => 1)
|
179
|
+
create!(:name => 'California Office', :user_id => 2, :client_id => 2)
|
180
|
+
create!(:name => 'California Office', :user_id => 3, :client_id => 3)
|
181
|
+
create!(:name => 'Reno Office', :user_id => 4, :client_id => 4)
|
182
|
+
create!(:name => 'Reno Office', :user_id => 5, :client_id => 5)
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
class Group < ActiveRecord::Base
|
187
|
+
has_many :users
|
188
|
+
def self.create_corpus!
|
189
|
+
create!(:name => 'System Administrator')
|
190
|
+
create!(:name => 'Software Managers')
|
191
|
+
create!(:name => 'Office Managers')
|
192
|
+
create!(:name => 'Accounting')
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
class Location < ActiveRecord::Base
|
197
|
+
has_and_belongs_to_many :users
|
198
|
+
def self.create_corpus!
|
199
|
+
create!(:name => 'Home')
|
200
|
+
create!(:name => 'Office')
|
201
|
+
create!(:name => 'Store')
|
202
|
+
create!(:name => 'Beach')
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
class Note < ActiveRecord::Base
|
207
|
+
belongs_to :user
|
208
|
+
def self.create_corpus!
|
209
|
+
wes = User.find_by_first_name('Wes')
|
210
|
+
john = User.find_by_first_name('John')
|
211
|
+
|
212
|
+
create!(:user_id => wes.id,
|
213
|
+
:title => 'Purchases',
|
214
|
+
:content => "1) Linksys Router. 2) Network Cable")
|
215
|
+
|
216
|
+
create!(:user_id => wes.id,
|
217
|
+
:title => 'Tasks',
|
218
|
+
:content => 'Clean my car, walk the dog and mow the yard buy milk')
|
219
|
+
|
220
|
+
create!(:user_id => wes.id,
|
221
|
+
:title => 'Grocery List',
|
222
|
+
:content => 'milk, gum, apples')
|
223
|
+
|
224
|
+
create!(:user_id => wes.id,
|
225
|
+
:title => 'Stocks to watch',
|
226
|
+
:content => 'MA, AAPL, V and SSO. Straddle MA at 200 with JAN 09 options')
|
227
|
+
|
228
|
+
create!(:user_id => john.id,
|
229
|
+
:title => 'Spec Tests',
|
230
|
+
:content => 'Spec Tests... Spec Tests... Spec Tests!!')
|
231
|
+
|
232
|
+
create!(:user_id => john.id,
|
233
|
+
:title => 'Things To Do',
|
234
|
+
:content => '1) Did I mention Spec Tests!!!, 2) Buy Linksys Router WRT160N')
|
235
|
+
end
|
236
|
+
end
|
237
|
+
|
238
|
+
class Address < ActiveRecord::Base
|
239
|
+
has_one :user
|
240
|
+
def self.create_corpus!
|
241
|
+
create!(:street => '800 Haskell St', :city => 'Reno', :state => 'NV', :postal_code => '89509')
|
242
|
+
create!(:street => '2499 Dorchester Rd', :city => 'Charleston', :state => 'SC', :postal_code => '29414')
|
243
|
+
create!(:street => '474 Mallard Way', :city => 'Fernley', :state => 'NV', :postal_code => '89408')
|
244
|
+
create!(:street => '1600 Montero Ct', :city => 'Sparks', :state => 'NV', :postal_code => '89434')
|
245
|
+
create!(:street => '200 4th St', :city => 'Sparks', :state => 'NV', :postal_code => '89434')
|
246
|
+
end
|
247
|
+
end
|
metadata
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jnewland-scoped_search
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.7.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Willem van Bergen
|
8
|
+
- Wes Hays
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2008-10-11 00:00:00 -07:00
|
14
|
+
default_executable:
|
15
|
+
dependencies: []
|
16
|
+
|
17
|
+
description: Scoped search makes it easy to search your ActiveRecord-based models. It will create a named scope according to a provided query string. The named_scope can be used like any other named_scope, so it can be cchained or combined with will_paginate.
|
18
|
+
email:
|
19
|
+
- willem@vanbergen.org
|
20
|
+
- weshays@gbdev.com
|
21
|
+
executables: []
|
22
|
+
|
23
|
+
extensions: []
|
24
|
+
|
25
|
+
extra_rdoc_files: []
|
26
|
+
|
27
|
+
files:
|
28
|
+
- CHANGELOG
|
29
|
+
- LICENSE
|
30
|
+
- README.textile
|
31
|
+
- Rakefile
|
32
|
+
- TODO
|
33
|
+
- init.rb
|
34
|
+
- lib
|
35
|
+
- lib/scoped_search
|
36
|
+
- lib/scoped_search.rb
|
37
|
+
- lib/scoped_search/query_conditions_builder.rb
|
38
|
+
- lib/scoped_search/query_language_parser.rb
|
39
|
+
- lib/scoped_search/reg_tokens.rb
|
40
|
+
- test
|
41
|
+
- test/query_conditions_builder_test.rb
|
42
|
+
- test/query_language_test.rb
|
43
|
+
- test/search_for_test.rb
|
44
|
+
- test/tasks.rake
|
45
|
+
- test/test_helper.rb
|
46
|
+
has_rdoc: false
|
47
|
+
homepage: http://github.com/wvanbergen/scoped_search/wikis
|
48
|
+
post_install_message:
|
49
|
+
rdoc_options: []
|
50
|
+
|
51
|
+
require_paths:
|
52
|
+
- lib
|
53
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: "0"
|
58
|
+
version:
|
59
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: "0"
|
64
|
+
version:
|
65
|
+
requirements: []
|
66
|
+
|
67
|
+
rubyforge_project:
|
68
|
+
rubygems_version: 1.2.0
|
69
|
+
signing_key:
|
70
|
+
specification_version: 2
|
71
|
+
summary: A Rails plugin to search your models using a named_scope
|
72
|
+
test_files:
|
73
|
+
- test/query_conditions_builder_test.rb
|
74
|
+
- test/query_language_test.rb
|
75
|
+
- test/search_for_test.rb
|