scoped_search 2.2.1 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,76 @@
1
+ require "#{File.dirname(__FILE__)}/../spec_helper"
2
+
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|
6
+
7
+ describe ScopedSearch, "using a #{db} database" do
8
+
9
+ before(:all) do
10
+ ScopedSearch::RSpec::Database.establish_named_connection(db)
11
+
12
+ @class = ScopedSearch::RSpec::Database.create_model(:bool => :boolean, :status => :integer) do |klass|
13
+ klass.scoped_search :on => :bool, :complete_value => {:yes => true, :no => false}
14
+ klass.scoped_search :on => :status, :complete_value => {:unknown => 0, :up => 1, :down => 2}
15
+ end
16
+ end
17
+
18
+ after(:all) do
19
+ ScopedSearch::RSpec::Database.drop_model(@class)
20
+ ScopedSearch::RSpec::Database.close_connection
21
+ end
22
+
23
+ context 'querying boolean fields' do
24
+
25
+ before(:all) do
26
+ @record1 = @class.create!(:status => 0)
27
+ @record2 = @class.create!(:status => 1)
28
+ @record3 = @class.create!(:status => 2)
29
+ end
30
+
31
+ after(:all) do
32
+ @record1.destroy
33
+ @record2.destroy
34
+ @record3.destroy
35
+ end
36
+
37
+ it "should find the record status = 1" do
38
+ @class.search_for('status = up').should have(1).item
39
+ end
40
+
41
+ it "should find the record with status = 0" do
42
+ @class.search_for('status = unknown').should have(1).item
43
+ end
44
+
45
+ it "should find two record with status != 1" do
46
+ @class.search_for('status != up').should have(2).item
47
+ end
48
+ end
49
+ context 'querying boolean fields' do
50
+
51
+ before(:all) do
52
+ @record1 = @class.create!(:bool => true)
53
+ @record2 = @class.create!(:bool => false)
54
+ @record3 = @class.create!(:bool => false)
55
+ end
56
+
57
+ after(:all) do
58
+ @record1.destroy
59
+ @record2.destroy
60
+ @record3.destroy
61
+ end
62
+
63
+ it "should find the record bool = true" do
64
+ @class.search_for('bool = yes').should have(1).item
65
+ end
66
+
67
+ it "should find two record with bool = false" do
68
+ @class.search_for('bool = no').should have(2).item
69
+ end
70
+
71
+ it "should find two record with bool = false" do
72
+ @class.search_for('bool != yes').should have(2).item
73
+ end
74
+ end
75
+ end
76
+ 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.
@@ -11,7 +11,7 @@ ScopedSearch::RSpec::Database.test_databases.each do |db|
11
11
 
12
12
  @class = ScopedSearch::RSpec::Database.create_model(:string => :string, :another => :string, :explicit => :string) do |klass|
13
13
  klass.scoped_search :on => :string
14
- klass.scoped_search :on => :another, :default_operator => :eq, :alias => :alias
14
+ klass.scoped_search :on => :another, :default_operator => :eq, :alias => :alias, :default_order => :desc
15
15
  klass.scoped_search :on => :explicit, :only_explicit => true
16
16
  end
17
17
 
@@ -192,5 +192,22 @@ ScopedSearch::RSpec::Database.test_databases.each do |db|
192
192
  @class.search_for('null? explicit').should have(1).items
193
193
  end
194
194
  end
195
+ context 'using order' do
196
+ it "sort by string ASC" do
197
+ @class.search_for('',:order => 'string ASC').first.string.should eql('bar')
198
+ end
199
+
200
+ it "sort by string DESC" do
201
+ @class.search_for('',:order => 'string DESC').first.string.should eql('foo')
202
+ end
203
+
204
+ it "default order by another DESC" do
205
+ @class.search_for('').first.string.should eql('bar')
206
+ end
207
+
208
+ it "group by explicit" do
209
+ @class.search_for('',:group => 'explicit').should have(2).items
210
+ end
211
+ end
195
212
  end
196
213
  end
data/spec/lib/matchers.rb CHANGED
@@ -21,3 +21,13 @@ end
21
21
  RSpec::Matchers.define :parse_to do |tree|
22
22
  match { |str| tree == ScopedSearch::QueryLanguage::Compiler.parse(str).to_a }
23
23
  end
24
+
25
+ RSpec::Matchers.define :contain do |*expected|
26
+ match_for_should do |actual|
27
+ expected.all? { |e| actual.include?(e) }
28
+ end
29
+
30
+ match_for_should_not do |actual|
31
+ expected.none? { |e| actual.include?(e) }
32
+ end
33
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,9 +1,7 @@
1
- $:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
-
3
1
  require 'rubygems'
4
- require 'rspec'
5
- require 'active_record'
2
+ require 'bundler/setup'
6
3
 
4
+ require 'rspec'
7
5
  require 'scoped_search'
8
6
 
9
7
  module ScopedSearch::RSpec; end
@@ -1,4 +1,4 @@
1
- require 'spec_helper'
1
+ require "#{File.dirname(__FILE__)}/../spec_helper"
2
2
 
3
3
  describe ScopedSearch::QueryLanguage::AST do
4
4
 
@@ -0,0 +1,20 @@
1
+ require "#{File.dirname(__FILE__)}/../spec_helper"
2
+
3
+ describe ScopedSearch::AutoCompleteBuilder do
4
+
5
+ before(:each) do
6
+ @definition = mock('ScopedSearch::Definition')
7
+ @definition.stub!(:klass).and_return(Class.new(ActiveRecord::Base))
8
+ @definition.stub!(:profile).and_return(:default)
9
+ @definition.stub!(:profile=).and_return(true)
10
+ end
11
+
12
+ it "should return empty suggestions if the search query is nil" do
13
+ ScopedSearch::AutoCompleteBuilder.auto_complete(@definition, nil).should == []
14
+ end
15
+
16
+ it "should return empty suggestions if the query is blank" do
17
+ ScopedSearch::AutoCompleteBuilder.auto_complete(@definition, "").should == []
18
+ end
19
+
20
+ end
@@ -1,4 +1,4 @@
1
- require 'spec_helper'
1
+ require "#{File.dirname(__FILE__)}/../spec_helper"
2
2
 
3
3
  describe ScopedSearch::Definition do
4
4
 
@@ -1,4 +1,4 @@
1
- require 'spec_helper'
1
+ require "#{File.dirname(__FILE__)}/../spec_helper"
2
2
 
3
3
  describe ScopedSearch::QueryLanguage::Parser do
4
4
 
@@ -1,4 +1,4 @@
1
- require 'spec_helper'
1
+ require "#{File.dirname(__FILE__)}/../spec_helper"
2
2
 
3
3
  describe ScopedSearch::QueryBuilder do
4
4
 
@@ -6,6 +6,7 @@ describe ScopedSearch::QueryBuilder do
6
6
  @definition = mock('ScopedSearch::Definition')
7
7
  @definition.stub!(:klass).and_return(Class.new(ActiveRecord::Base))
8
8
  @definition.stub!(:profile).and_return(:default)
9
+ @definition.stub!(:default_order).and_return(nil)
9
10
  @definition.stub!(:profile=).and_return(true)
10
11
  end
11
12
 
@@ -1,4 +1,4 @@
1
- require 'spec_helper'
1
+ require "#{File.dirname(__FILE__)}/../spec_helper"
2
2
 
3
3
  describe ScopedSearch::QueryLanguage::Tokenizer do
4
4
 
@@ -220,7 +220,7 @@ module GithubGem
220
220
 
221
221
  def check_version_task
222
222
  raise "#{ENV['VERSION']} is not a valid version number!" if ENV['VERSION'] && !Gem::Version.correct?(ENV['VERSION'])
223
- proposed_version = Gem::Version.new(ENV['VERSION'].dup || gemspec.version)
223
+ proposed_version = Gem::Version.new((ENV['VERSION'] || gemspec.version).dup)
224
224
  raise "This version (#{proposed_version}) is not higher than the highest tagged version (#{newest_version})" if newest_version >= proposed_version
225
225
  end
226
226
 
@@ -339,22 +339,26 @@ module GithubGem
339
339
 
340
340
  # Updates the tasks file using the latest file found on Github
341
341
  def update_tasks_task
342
- require 'net/http'
343
-
344
- server = 'github.com'
345
- path = '/wvanbergen/github-gem/raw/master/tasks/github-gem.rake'
342
+ require 'net/https'
343
+ require 'uri'
344
+
345
+ uri = URI.parse('https://github.com/wvanbergen/github-gem/raw/master/tasks/github-gem.rake')
346
+ http = Net::HTTP.new(uri.host, uri.port)
347
+ http.use_ssl = true
348
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
349
+ response = http.request(Net::HTTP::Get.new(uri.path))
346
350
 
347
- Net::HTTP.start(server) do |http|
348
- response = http.get(path)
351
+ if Net::HTTPSuccess === response
349
352
  open(__FILE__, "w") { |file| file.write(response.body) }
350
- end
351
-
352
- relative_file = File.expand_path(__FILE__).sub(%r[^#{@root_dir}/], '')
353
- if `#{git} ls-files -m #{relative_file}`.split("\n").any?
354
- sh git, 'add', relative_file
355
- sh git, 'commit', '-m', "Updated to latest gem release management tasks."
353
+ relative_file = File.expand_path(__FILE__).sub(%r[^#{@root_dir}/], '')
354
+ if `#{git} ls-files -m #{relative_file}`.split("\n").any?
355
+ sh git, 'add', relative_file
356
+ sh git, 'commit', '-m', "Updated to latest gem release management tasks."
357
+ else
358
+ puts "Release managament tasks already are at the latest version."
359
+ end
356
360
  else
357
- puts "Release managament tasks already are at the latest version."
361
+ raise "Download failed with HTTP status #{response.code}!"
358
362
  end
359
363
  end
360
364
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scoped_search
3
3
  version: !ruby/object:Gem::Version
4
- hash: 5
5
- prerelease: false
4
+ hash: 3
5
+ prerelease:
6
6
  segments:
7
7
  - 2
8
- - 2
9
- - 1
10
- version: 2.2.1
8
+ - 3
9
+ - 0
10
+ version: 2.3.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Willem van Bergen
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2010-11-09 00:00:00 +01:00
19
+ date: 2011-05-16 00:00:00 -04:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
@@ -50,6 +50,20 @@ dependencies:
50
50
  version: "2.0"
51
51
  type: :development
52
52
  version_requirements: *id002
53
+ - !ruby/object:Gem::Dependency
54
+ name: sqlite3-ruby
55
+ prerelease: false
56
+ requirement: &id003 !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ hash: 3
62
+ segments:
63
+ - 0
64
+ version: "0"
65
+ type: :development
66
+ version_requirements: *id003
53
67
  description: " Scoped search makes it easy to search your ActiveRecord-based models.\n \n It will create a named scope :search_for that can be called with a query string. It will build an SQL query using\n the provided query string and a definition that specifies on what fields to search. Because the functionality is\n built on named_scope, the result of the search_for call can be used like any other named_scope, so it can be\n chained with another scope or combined with will_paginate.\n \n Because it uses standard SQL, it does not require any setup, indexers or daemons. This makes scoped_search\n suitable to quickly add basic search functionality to your application with little hassle. On the other hand,\n it may not be the best choice if it is going to be used on very large datasets or by a large user base.\n"
54
68
  email:
55
69
  - willem@railsdoctors.com
@@ -62,29 +76,37 @@ extra_rdoc_files:
62
76
  - README.rdoc
63
77
  files:
64
78
  - .gitignore
79
+ - .infinity_test
80
+ - Gemfile
65
81
  - LICENSE
66
82
  - README.rdoc
67
83
  - Rakefile
68
84
  - init.rb
69
85
  - lib/scoped_search.rb
86
+ - lib/scoped_search/auto_complete_builder.rb
70
87
  - lib/scoped_search/definition.rb
71
88
  - lib/scoped_search/query_builder.rb
72
89
  - lib/scoped_search/query_language.rb
73
90
  - lib/scoped_search/query_language/ast.rb
74
91
  - lib/scoped_search/query_language/parser.rb
75
92
  - lib/scoped_search/query_language/tokenizer.rb
93
+ - lib/scoped_search/rails_helper.rb
76
94
  - scoped_search.gemspec
77
95
  - spec/database.yml
78
96
  - spec/integration/api_spec.rb
97
+ - spec/integration/auto_complete_spec.rb
98
+ - spec/integration/key_value_querying_spec.rb
79
99
  - spec/integration/ordinal_querying_spec.rb
80
100
  - spec/integration/profile_querying_spec.rb
81
101
  - spec/integration/relation_querying_spec.rb
102
+ - spec/integration/set_query_spec.rb
82
103
  - spec/integration/string_querying_spec.rb
83
104
  - spec/lib/database.rb
84
105
  - spec/lib/matchers.rb
85
106
  - spec/lib/mocks.rb
86
107
  - spec/spec_helper.rb
87
108
  - spec/unit/ast_spec.rb
109
+ - spec/unit/auto_complete_builder_spec.rb
88
110
  - spec/unit/definition_spec.rb
89
111
  - spec/unit/parser_spec.rb
90
112
  - spec/unit/query_builder_spec.rb
@@ -125,17 +147,21 @@ required_rubygems_version: !ruby/object:Gem::Requirement
125
147
  requirements: []
126
148
 
127
149
  rubyforge_project:
128
- rubygems_version: 1.3.7
150
+ rubygems_version: 1.6.2
129
151
  signing_key:
130
152
  specification_version: 3
131
153
  summary: Easily search you ActiveRecord models with a simple query language using a named scope.
132
154
  test_files:
133
155
  - spec/integration/api_spec.rb
156
+ - spec/integration/auto_complete_spec.rb
157
+ - spec/integration/key_value_querying_spec.rb
134
158
  - spec/integration/ordinal_querying_spec.rb
135
159
  - spec/integration/profile_querying_spec.rb
136
160
  - spec/integration/relation_querying_spec.rb
161
+ - spec/integration/set_query_spec.rb
137
162
  - spec/integration/string_querying_spec.rb
138
163
  - spec/unit/ast_spec.rb
164
+ - spec/unit/auto_complete_builder_spec.rb
139
165
  - spec/unit/definition_spec.rb
140
166
  - spec/unit/parser_spec.rb
141
167
  - spec/unit/query_builder_spec.rb