wvanbergen-scoped_search 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/test/test_helper.rb CHANGED
@@ -1,3 +1,5 @@
1
+ $:.reject! { |e| e.include? 'TextMate' }
2
+
1
3
  require 'test/unit'
2
4
  require 'rubygems'
3
5
  require 'active_record'
@@ -5,243 +7,38 @@ require 'ruby-debug'
5
7
 
6
8
  require "#{File.dirname(__FILE__)}/../lib/scoped_search"
7
9
 
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
10
+ module ScopedSearch::Test
135
11
 
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')
12
+ def self.establish_connection
13
+ if ENV['DATABASE']
14
+ ScopedSearch::Test.establish_named_connection(ENV['DATABASE'])
15
+ else
16
+ ScopedSearch::Test.establish_default_connection
17
+ end
159
18
  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')
19
+
20
+ def self.establish_named_connection(name)
21
+ @database_connections ||= YAML.load(File.read("#{File.dirname(__FILE__)}/database.yml"))
22
+ raise "#{name} database not configured" if @database_connections[name.to_s].nil?
23
+ ActiveRecord::Base.establish_connection(@database_connections[name.to_s])
193
24
  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')
25
+
26
+ def self.establish_default_connection
27
+ ActiveRecord::Base.establish_connection(:adapter => 'sqlite3', :database => ':memory:')
203
28
  end
204
- end
205
-
206
- class Note < ActiveRecord::Base
207
- belongs_to :user
29
+
208
30
  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
31
+ ScopedSearch::Test::Models::Foo.create_corpus!
32
+ ScopedSearch::Test::Models::Location.create_corpus!
33
+ ScopedSearch::Test::Models::User.create_corpus!
34
+ ScopedSearch::Test::Models::Note.create_corpus!
35
+ ScopedSearch::Test::Models::Group.create_corpus!
36
+ ScopedSearch::Test::Models::Office.create_corpus!
37
+ ScopedSearch::Test::Models::Client.create_corpus!
38
+ ScopedSearch::Test::Models::Address.create_corpus!
39
+ end
236
40
  end
237
41
 
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
42
+ # Load helpers
43
+ require "#{File.dirname(__FILE__)}/lib/test_schema"
44
+ require "#{File.dirname(__FILE__)}/lib/test_models"
@@ -1,6 +1,6 @@
1
- require File.dirname(__FILE__) + '/test_helper'
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
2
 
3
- class QueryConditionsBuilderTest < Test::Unit::TestCase
3
+ class ScopedSearch::Test::QueryConditionsBuilder < Test::Unit::TestCase
4
4
 
5
5
  # change this function if you switch to another query language parser
6
6
  def build_query(search_conditions, query_fields)
@@ -1,6 +1,6 @@
1
- require File.dirname(__FILE__) + '/test_helper'
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
2
 
3
- class QueryLanguageTest < Test::Unit::TestCase
3
+ class ScopedSearch::Test::QueryLanguage < Test::Unit::TestCase
4
4
 
5
5
  # change this function if you switch to another query language parser
6
6
  def parse_query(query)
@@ -0,0 +1,122 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+
3
+ class ScopedSearch::Test::SearchFor < Test::Unit::TestCase
4
+
5
+ def self.const_missing(const)
6
+ ScopedSearch::Test::Models.const_get(const)
7
+ end
8
+
9
+ def setup
10
+ ScopedSearch::Test.establish_connection
11
+ ScopedSearch::Test::DatabaseSchema.up
12
+ ScopedSearch::Test.create_corpus!
13
+ end
14
+
15
+ def teardown
16
+ ScopedSearch::Test::DatabaseSchema.down
17
+ end
18
+
19
+ def test_search
20
+ Foo.searchable_on :string_field, :text_field, :date_field
21
+
22
+ assert_equal Foo.count, Foo.search_for('').count
23
+ assert_equal 0, Foo.search_for('456').count
24
+ assert_equal 2, Foo.search_for('hays').count
25
+ assert_equal 1, Foo.search_for('hay ob').count
26
+ assert_equal 15, Foo.search_for('o').count
27
+ assert_equal 2, Foo.search_for('-o').count
28
+ assert_equal 15, Foo.search_for('-Jim').count
29
+ assert_equal 1, Foo.search_for('Jim -Bush').count
30
+ assert_equal 1, Foo.search_for('"Hello World" -"Goodnight Moon"').count
31
+ assert_equal 2, Foo.search_for('Wes OR Bob').count
32
+ assert_equal 3, Foo.search_for('"Happy cow" OR "Sad Frog"').count
33
+ assert_equal 3, Foo.search_for('"Man made" OR Dogs').count
34
+ assert_equal 2, Foo.search_for('Cows OR "Frog Toys"').count
35
+
36
+ # ** DATES **
37
+ #
38
+ # The next two dates are invalid therefore it will be ignored.
39
+ # Since it is just a date being searched for it will also
40
+ # be searched for in text fields regardless of whether or
41
+ # not it is a valid date.
42
+ assert_equal 0, Foo.search_for('2/30/1980').count
43
+ assert_equal 0, Foo.search_for('99/99/9999').count
44
+
45
+ assert_equal 1, Foo.search_for('9/27/1980').count
46
+ assert_equal 1, Foo.search_for('hays 9/27/1980').count
47
+ assert_equal 0, Foo.search_for('hays 2/30/1980').count
48
+
49
+ assert_equal 1, Foo.search_for('< 12/01/1980').count
50
+ assert_equal 6, Foo.search_for('> 2006/1/1').count
51
+
52
+ assert_equal 5, Foo.search_for('< 12/26/2002').count
53
+ assert_equal 6, Foo.search_for('<= 12/26/2002').count
54
+
55
+ assert_equal 6, Foo.search_for('> 2/5/2005').count
56
+ assert_equal 7, Foo.search_for('>= 2/5/2005').count
57
+
58
+ assert_equal 3, Foo.search_for('1/1/2005 TO 1/1/2007').count
59
+
60
+ assert_equal 2, Foo.search_for('Happy 1/1/2005 TO 1/1/2007').count
61
+
62
+ # This should return one with a date of 7/15/2006 found in the text.
63
+ assert_equal 2, Foo.search_for('7/15/2006').count
64
+ end
65
+
66
+ def test_search_belongs_to_association
67
+ User.searchable_on :first_name, :last_name, :group_name
68
+
69
+ assert_equal User.count, User.search_for('').count
70
+ assert_equal 1, User.search_for('Wes').count
71
+ assert_equal 2, User.search_for('System Administrator').count
72
+ assert_equal 2, User.search_for('Managers').count
73
+ end
74
+
75
+ def test_search_has_many_association
76
+ User.searchable_on :first_name, :last_name, :notes_title, :notes_content
77
+
78
+ assert_equal User.count, User.search_for('').count
79
+ assert_equal 2, User.search_for('Router').count
80
+ assert_equal 1, User.search_for('milk').count
81
+ assert_equal 1, User.search_for('"Spec Tests"').count
82
+ assert_equal 0, User.search_for('Wes "Spec Tests"').count
83
+ end
84
+
85
+ def test_search_has_many_through_association
86
+ User.searchable_on :first_name, :last_name, :clients_first_name, :clients_last_name
87
+
88
+ assert_equal User.count, User.search_for('').count
89
+ assert_equal 2, User.search_for('Smith').count
90
+ assert_equal 1, User.search_for('Sam').count
91
+ assert_equal 1, User.search_for('Johnson').count
92
+ end
93
+
94
+ def test_search_has_one_association
95
+ User.searchable_on :first_name, :last_name, :address_street, :address_city, :address_state, :address_postal_code
96
+
97
+ assert_equal User.count, User.search_for('').count
98
+ assert_equal 1, User.search_for('Fernley').count
99
+ assert_equal 4, User.search_for('NV').count
100
+ assert_equal 1, User.search_for('Haskell').count
101
+ assert_equal 2, User.search_for('89434').count
102
+ end
103
+
104
+ def test_search_has_and_belongs_to_many_association
105
+ User.searchable_on :first_name, :last_name, :locations_name
106
+
107
+ assert_equal User.count, User.search_for('').count
108
+ assert_equal 2, User.search_for('Office').count
109
+ assert_equal 1, User.search_for('Store').count
110
+ assert_equal 1, User.search_for('John Office').count
111
+ end
112
+
113
+ def test_search_with_very_long_query
114
+ User.searchable_on :first_name, :last_name, :address_street, :address_city, :address_state, :address_postal_code
115
+ really_long_string = ''
116
+ 10000.times {really_long_string << 'really long string'}
117
+ assert_equal 0, User.search_for(really_long_string).count
118
+ end
119
+
120
+ end
121
+
122
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wvanbergen-scoped_search
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Willem van Bergen
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2009-01-15 00:00:00 -08:00
13
+ date: 2009-01-29 00:00:00 -08:00
14
14
  default_executable:
15
15
  dependencies: []
16
16
 
@@ -22,16 +22,16 @@ executables: []
22
22
 
23
23
  extensions: []
24
24
 
25
- extra_rdoc_files: []
26
-
25
+ extra_rdoc_files:
26
+ - README.rdoc
27
+ - CHANGELOG.rdoc
28
+ - TODO.rdoc
27
29
  files:
28
- - CHANGELOG
30
+ - CHANGELOG.rdoc
29
31
  - LICENSE
30
- - README
31
- - README.textile
32
+ - README.rdoc
32
33
  - Rakefile
33
- - TODO
34
- - coverage
34
+ - TODO.rdoc
35
35
  - init.rb
36
36
  - lib
37
37
  - lib/scoped_search
@@ -41,17 +41,28 @@ files:
41
41
  - lib/scoped_search/reg_tokens.rb
42
42
  - tasks
43
43
  - tasks/github-gem.rake
44
- - tasks/test.rake
45
44
  - test
46
- - test/query_conditions_builder_test.rb
47
- - test/query_language_test.rb
48
- - test/search_for_test.rb
45
+ - test/database.yml
46
+ - test/integration
47
+ - test/integration/api_test.rb
48
+ - test/lib
49
+ - test/lib/test_models.rb
50
+ - test/lib/test_schema.rb
49
51
  - test/test_helper.rb
50
- has_rdoc: false
51
- homepage: http://github.com/wvanbergen/scoped_search/wikis
52
+ - test/unit
53
+ - test/unit/query_conditions_builder_test.rb
54
+ - test/unit/query_language_test.rb
55
+ - test/unit/search_for_test.rb
56
+ has_rdoc: true
57
+ homepage: http://wiki.github.com/wvanbergen/scoped_search
52
58
  post_install_message:
53
- rdoc_options: []
54
-
59
+ rdoc_options:
60
+ - --title
61
+ - scoped_search
62
+ - --main
63
+ - README.rdoc
64
+ - --line-numbers
65
+ - --inline-source
55
66
  require_paths:
56
67
  - lib
57
68
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -74,6 +85,7 @@ signing_key:
74
85
  specification_version: 2
75
86
  summary: A Rails plugin to search your models using a named_scope
76
87
  test_files:
77
- - test/query_conditions_builder_test.rb
78
- - test/query_language_test.rb
79
- - test/search_for_test.rb
88
+ - test/integration/api_test.rb
89
+ - test/unit/query_conditions_builder_test.rb
90
+ - test/unit/query_language_test.rb
91
+ - test/unit/search_for_test.rb
data/CHANGELOG DELETED
@@ -1,12 +0,0 @@
1
- scoped_search 0.3.0
2
- ===================
3
- - Detection of column types so they can be handled properly
4
- - Date based queries supported on date and time fields
5
-
6
- scoped_search 0.2.0
7
- ===================
8
- - OR keyword supported in query language
9
-
10
- scoped_search 0.1.0
11
- ===================
12
- - Initial version
data/README.textile DELETED
@@ -1,76 +0,0 @@
1
- h1. "scoped_search":http://github.com/wvanbergen/scoped_search/tree/master
2
-
3
- This simple plugin will make it easy to search your ActiveRecord models. Searching is performed using a query string, which should be passed to the named_scope <tt>search_for</tt> that uses SQL %LIKE% conditions for searching (ILIKE for Postgres). You can specify what fields should be used for searching.
4
-
5
- * "scoped_search installation":#INSTALLATION
6
- * "scoped_search usage":#USAGE
7
- * "scoped_search license":#LICENSE
8
-
9
- <a id="INSTALLATION"/> </a>
10
- h2. Installing scoped_search
11
-
12
- <pre><code>
13
- gem install wvanbergen-scoped_search
14
-
15
- </code></pre>
16
-
17
- <a id="USAGE"/> </a>
18
- h2. Usage
19
-
20
- First, you have to specify in what columns should be searched:
21
-
22
- <pre><code>
23
- class User < ActiveRecord::Base
24
- searchable_on :first_name, :last_name
25
- end
26
-
27
- </code></pre>
28
-
29
- Now, the *search_for* scope is available for queries. You should pass a query string to the scope.
30
- This can be empty or nil, in which case all no search conditions are set (and all records will be returned).
31
-
32
- <pre><code>
33
- User.search_for(params[:q]).each { |project| ... }
34
-
35
- </code></pre>
36
-
37
- You can also search on associate models. This works with *belongs_to*, *has_one*, *has_many*,
38
- *has_many :through*, and *HABTM*. For example if a User *has_many* Notes (title, content, created_at, updated_at)
39
-
40
- <pre><code>
41
- class User < ActiveRecord::Base
42
- has_many: notes
43
- searchable_on :first_name, :last_name, :notes_title, :notes_content
44
- end
45
-
46
- </code></pre>
47
-
48
- The search query language is simple. It supports these constructs:
49
- * words: some search keywords
50
- * phrases: "a single search phrase"
51
- * negation: "look for this" -"but do not look for this phrase and this" -word
52
- * OR words/phrases: word/phrase OR word/phrase. Example: "Hello World" OR "Hello Moon"
53
- * dates: mm/dd/yyyy, dd/mm/yyyy, yyyy/mm/dd, yyyy-mm-dd
54
- * date ranges: > date, >= date, < date, <= date, date TO date. Examples: > mm/dd/yyyy, < yyyy-mm-dd
55
-
56
- This functionality is build on named_scope. The searchable_on statement creates
57
- a named_scope *search_for*. Because of this, you can actually chain the call with
58
- other scopes. For example, this can be very useful if you only want to search in
59
- projects that are accessible by a given user.
60
-
61
- <pre><code>
62
- class Project < ActiveRecord::Base
63
- searchable_on :name, :description
64
- named_scope :accessible_by, lambda { |user| ... }
65
- end
66
-
67
- # using chained named_scopes and will_paginate
68
- Project.accessible_by(current_user).search_for(params[:q]).paginate(:page => params[:page], :include => :tasks)
69
-
70
- </code></pre>
71
-
72
- <a id="LICENSE"/> </a>
73
- h2. License
74
-
75
- This plugin is released under the MIT license. Please contact (willem AT vanbergen DOT org) if you have any suggestions or remarks.
76
-
data/TODO DELETED
@@ -1,15 +0,0 @@
1
- TODO items for named_scope
2
- ==========================
3
- Contact willem AT vanbergen DOT org if you want to help out
4
-
5
- 0.8.0
6
-
7
-
8
- 0.9.0
9
-
10
-
11
- 1.0.0
12
- - Extensive testing
13
-
14
- Documentation & testing:
15
- - Add rdoc en comments to code
data/tasks/test.rake DELETED
@@ -1,32 +0,0 @@
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
14
-
15
- begin
16
- require 'rcov/rcovtask'
17
- Rcov::RcovTask.new do |t|
18
- t.test_files = Dir[ "test/*_test.rb" ]
19
- end
20
- rescue LoadError
21
- nil
22
- end
23
-
24
- begin
25
- require 'rcov/rcovtask'
26
- desc 'Runs spec:rcov and then displays the coverage/index.html file in the browswer.'
27
- task :rcov_display => [:clobber_rcov, :rcov] do
28
- system("open coverage/index.html")
29
- end
30
- rescue LoadError
31
- nil
32
- end