kazjote-searchlogic 2.3.4 → 2.3.5
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -1
- data/VERSION.yml +1 -1
- data/lib/searchlogic/active_record/consistency.rb +11 -1
- data/lib/searchlogic/named_scopes/or_conditions.rb +1 -1
- data/lib/searchlogic/search.rb +1 -1
- data/spec/named_scopes/association_conditions_spec.rb +7 -0
- data/spec/named_scopes/conditions_spec.rb +6 -0
- data/spec/named_scopes/or_conditions_spec.rb +12 -7
- data/spec/search_spec.rb +1 -4
- data/spec/spec_helper.rb +1 -2
- metadata +6 -5
- data/searchlogic.gemspec +0 -85
data/Rakefile
CHANGED
@@ -4,7 +4,7 @@ require 'rake'
|
|
4
4
|
begin
|
5
5
|
require 'jeweler'
|
6
6
|
Jeweler::Tasks.new do |gem|
|
7
|
-
gem.name = "searchlogic"
|
7
|
+
gem.name = "kazjote-searchlogic"
|
8
8
|
gem.summary = "Searchlogic makes using ActiveRecord named scopes easier and less repetitive."
|
9
9
|
gem.description = "Searchlogic makes using ActiveRecord named scopes easier and less repetitive."
|
10
10
|
gem.email = "bjohnson@binarylogic.com"
|
data/VERSION.yml
CHANGED
@@ -15,7 +15,17 @@ module Searchlogic
|
|
15
15
|
# the merge_joins method to delete duplicates.
|
16
16
|
def merge_joins_with_searchlogic(*args)
|
17
17
|
joins = merge_joins_without_searchlogic(*args)
|
18
|
-
joins.collect { |j| j.is_a?(String) ? j.split(" ") : j }.flatten.uniq
|
18
|
+
joins = joins.collect { |j| j.is_a?(String) ? j.split(" ") : j }.flatten.uniq
|
19
|
+
joins = joins.collect do |j|
|
20
|
+
if j.is_a?(String) && !j =~ / (AND|OR) /i
|
21
|
+
j.gsub(/(.*) ON (.*) = (.*)/) do |m|
|
22
|
+
sorted = [$2,$3].sort
|
23
|
+
"#{$1} ON #{sorted[0]} = #{sorted[1]}"
|
24
|
+
end
|
25
|
+
else
|
26
|
+
j
|
27
|
+
end
|
28
|
+
end
|
19
29
|
end
|
20
30
|
end
|
21
31
|
end
|
data/lib/searchlogic/search.rb
CHANGED
@@ -100,7 +100,7 @@ module Searchlogic
|
|
100
100
|
conditions[condition_name]
|
101
101
|
end
|
102
102
|
else
|
103
|
-
scope = conditions.inject(klass.scoped(current_scope)) do |scope, condition|
|
103
|
+
scope = conditions.inject(klass.scoped(current_scope) || {}) do |scope, condition|
|
104
104
|
scope_name, value = condition
|
105
105
|
scope_name = normalize_scope_name(scope_name)
|
106
106
|
klass.send(scope_name, value) if !klass.respond_to?(scope_name)
|
@@ -131,4 +131,11 @@ describe "Association Conditions" do
|
|
131
131
|
User.named_scope(:orders_big_id, :joins => User.inner_joins(:orders))
|
132
132
|
Company.users_orders_big_id.proxy_options.should == {:joins=>[" INNER JOIN \"users\" ON users.company_id = companies.id ", " INNER JOIN \"orders\" ON orders.user_id = users.id "]}
|
133
133
|
end
|
134
|
+
|
135
|
+
it "should order the join statements ascending by the fieldnames so that we don't get double joins where the only difference is that the order of the fields is different" do
|
136
|
+
company = Company.create
|
137
|
+
user = company.users.create(:company_id => company.id)
|
138
|
+
company.users.company_id_eq(company.id).should == [user]
|
139
|
+
end
|
140
|
+
|
134
141
|
end
|
@@ -292,4 +292,10 @@ describe "Conditions" do
|
|
292
292
|
User.company_id_null.count.should == 1
|
293
293
|
User.company_id_not_null.count.should == 0
|
294
294
|
end
|
295
|
+
|
296
|
+
it "should fix bug for issue 26" do
|
297
|
+
count1 = User.id_ne(10).username_not_like("root").count
|
298
|
+
count2 = User.id_ne(10).username_not_like("root").count
|
299
|
+
count1.should == count2
|
300
|
+
end
|
295
301
|
end
|
@@ -1,16 +1,21 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
|
2
2
|
|
3
3
|
describe "Or conditions" do
|
4
|
+
it "should define a scope by the exact same name as requested by the code" do
|
5
|
+
User.name_or_username_like('Test')
|
6
|
+
User.respond_to?(:name_or_username_like).should be_true
|
7
|
+
end
|
8
|
+
|
4
9
|
it "should match username or name" do
|
5
|
-
User.username_or_name_like("ben").proxy_options.should == {:conditions => "(users.
|
10
|
+
User.username_or_name_like("ben").proxy_options.should == {:conditions => "(users.username LIKE '%ben%') OR (users.name LIKE '%ben%')"}
|
6
11
|
end
|
7
12
|
|
8
13
|
it "should use the specified condition" do
|
9
|
-
User.username_begins_with_or_name_like("ben").proxy_options.should == {:conditions => "(users.
|
14
|
+
User.username_begins_with_or_name_like("ben").proxy_options.should == {:conditions => "(users.username LIKE 'ben%') OR (users.name LIKE '%ben%')"}
|
10
15
|
end
|
11
16
|
|
12
17
|
it "should use the last specified condition" do
|
13
|
-
User.username_or_name_like_or_id_or_age_lt(10).proxy_options.should == {:conditions => "(users.
|
18
|
+
User.username_or_name_like_or_id_or_age_lt(10).proxy_options.should == {:conditions => "(users.username LIKE '%10%') OR (users.name LIKE '%10%') OR (users.id < 10) OR (users.age < 10)"}
|
14
19
|
end
|
15
20
|
|
16
21
|
it "should raise an error on unknown conditions" do
|
@@ -18,19 +23,19 @@ describe "Or conditions" do
|
|
18
23
|
end
|
19
24
|
|
20
25
|
it "should work well with _or_equal_to" do
|
21
|
-
User.id_less_than_or_equal_to_or_age_gt(10).proxy_options.should == {:conditions => "(users.
|
26
|
+
User.id_less_than_or_equal_to_or_age_gt(10).proxy_options.should == {:conditions => "(users.id <= 10) OR (users.age > 10)"}
|
22
27
|
end
|
23
28
|
|
24
29
|
it "should work well with _or_equal_to_any" do
|
25
|
-
User.id_less_than_or_equal_to_all_or_age_gt(10).proxy_options.should == {:conditions => "(users.
|
30
|
+
User.id_less_than_or_equal_to_all_or_age_gt(10).proxy_options.should == {:conditions => "(users.id <= 10) OR (users.age > 10)"}
|
26
31
|
end
|
27
32
|
|
28
33
|
it "should work well with _or_equal_to_all" do
|
29
|
-
User.id_less_than_or_equal_to_any_or_age_gt(10).proxy_options.should == {:conditions => "(users.
|
34
|
+
User.id_less_than_or_equal_to_any_or_age_gt(10).proxy_options.should == {:conditions => "(users.id <= 10) OR (users.age > 10)"}
|
30
35
|
end
|
31
36
|
|
32
37
|
it "should play nice with other scopes" do
|
33
38
|
User.username_begins_with("ben").id_gt(10).age_not_nil.username_or_name_ends_with("ben").scope(:find).should ==
|
34
|
-
{:conditions => "((users.
|
39
|
+
{:conditions => "((users.username LIKE '%ben') OR (users.name LIKE '%ben')) AND ((users.age IS NOT NULL) AND ((users.id > 10) AND (users.username LIKE 'ben%')))"}
|
35
40
|
end
|
36
41
|
end
|
data/spec/search_spec.rb
CHANGED
@@ -322,12 +322,9 @@ describe "Search" do
|
|
322
322
|
it "should recognize the order condition" do
|
323
323
|
User.search(:order => "ascend_by_username").proxy_options.should == User.ascend_by_username.proxy_options
|
324
324
|
end
|
325
|
-
|
325
|
+
|
326
326
|
it "should not use default scope ordering when one explicitly provided" do
|
327
327
|
# default_scope is :order => "created_at asc"
|
328
|
-
fee1 = Fee.create(:cost => 2.0)
|
329
|
-
fee2 = Fee.create(:cost => 1.0)
|
330
|
-
|
331
328
|
Fee.search(:order => "ascend_by_cost").proxy_options.should == {:order => "fees.cost ASC"}
|
332
329
|
end
|
333
330
|
|
data/spec/spec_helper.rb
CHANGED
@@ -6,7 +6,7 @@ require 'activerecord'
|
|
6
6
|
ENV['TZ'] = 'UTC'
|
7
7
|
Time.zone = 'Eastern Time (US & Canada)'
|
8
8
|
|
9
|
-
ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :
|
9
|
+
ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
|
10
10
|
ActiveRecord::Base.configurations = true
|
11
11
|
|
12
12
|
ActiveRecord::Schema.verbose = false
|
@@ -81,7 +81,6 @@ Spec::Runner.configure do |config|
|
|
81
81
|
|
82
82
|
class Fee < ActiveRecord::Base
|
83
83
|
belongs_to :owner, :polymorphic => true
|
84
|
-
|
85
84
|
default_scope :order => "created_at ASC"
|
86
85
|
end
|
87
86
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kazjote-searchlogic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.3.
|
4
|
+
version: 2.3.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Johnson of Binary Logic
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-10-08 00:00:00 +02:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -53,7 +53,6 @@ files:
|
|
53
53
|
- lib/searchlogic/rails_helpers.rb
|
54
54
|
- lib/searchlogic/search.rb
|
55
55
|
- rails/init.rb
|
56
|
-
- searchlogic.gemspec
|
57
56
|
- spec/core_ext/object_spec.rb
|
58
57
|
- spec/core_ext/proc_spec.rb
|
59
58
|
- spec/named_scopes/alias_scope_spec.rb
|
@@ -64,8 +63,10 @@ files:
|
|
64
63
|
- spec/named_scopes/ordering_spec.rb
|
65
64
|
- spec/search_spec.rb
|
66
65
|
- spec/spec_helper.rb
|
67
|
-
has_rdoc:
|
66
|
+
has_rdoc: true
|
68
67
|
homepage: http://github.com/binarylogic/searchlogic
|
68
|
+
licenses: []
|
69
|
+
|
69
70
|
post_install_message:
|
70
71
|
rdoc_options:
|
71
72
|
- --charset=UTF-8
|
@@ -86,7 +87,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
86
87
|
requirements: []
|
87
88
|
|
88
89
|
rubyforge_project: searchlogic
|
89
|
-
rubygems_version: 1.
|
90
|
+
rubygems_version: 1.3.5
|
90
91
|
signing_key:
|
91
92
|
specification_version: 3
|
92
93
|
summary: Searchlogic makes using ActiveRecord named scopes easier and less repetitive.
|
data/searchlogic.gemspec
DELETED
@@ -1,85 +0,0 @@
|
|
1
|
-
# Generated by jeweler
|
2
|
-
# DO NOT EDIT THIS FILE
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
|
4
|
-
# -*- encoding: utf-8 -*-
|
5
|
-
|
6
|
-
Gem::Specification.new do |s|
|
7
|
-
s.name = %q{searchlogic}
|
8
|
-
s.version = "2.3.4"
|
9
|
-
|
10
|
-
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
-
s.authors = ["Ben Johnson of Binary Logic"]
|
12
|
-
s.date = %q{2009-09-02}
|
13
|
-
s.description = %q{Searchlogic makes using ActiveRecord named scopes easier and less repetitive.}
|
14
|
-
s.email = %q{bjohnson@binarylogic.com}
|
15
|
-
s.extra_rdoc_files = [
|
16
|
-
"LICENSE",
|
17
|
-
"README.rdoc"
|
18
|
-
]
|
19
|
-
s.files = [
|
20
|
-
".gitignore",
|
21
|
-
"CHANGELOG.rdoc",
|
22
|
-
"LICENSE",
|
23
|
-
"README.rdoc",
|
24
|
-
"Rakefile",
|
25
|
-
"VERSION.yml",
|
26
|
-
"init.rb",
|
27
|
-
"lib/searchlogic.rb",
|
28
|
-
"lib/searchlogic/active_record/consistency.rb",
|
29
|
-
"lib/searchlogic/active_record/named_scopes.rb",
|
30
|
-
"lib/searchlogic/core_ext/object.rb",
|
31
|
-
"lib/searchlogic/core_ext/proc.rb",
|
32
|
-
"lib/searchlogic/named_scopes/alias_scope.rb",
|
33
|
-
"lib/searchlogic/named_scopes/association_conditions.rb",
|
34
|
-
"lib/searchlogic/named_scopes/association_ordering.rb",
|
35
|
-
"lib/searchlogic/named_scopes/conditions.rb",
|
36
|
-
"lib/searchlogic/named_scopes/or_conditions.rb",
|
37
|
-
"lib/searchlogic/named_scopes/ordering.rb",
|
38
|
-
"lib/searchlogic/rails_helpers.rb",
|
39
|
-
"lib/searchlogic/search.rb",
|
40
|
-
"rails/init.rb",
|
41
|
-
"searchlogic.gemspec",
|
42
|
-
"spec/core_ext/object_spec.rb",
|
43
|
-
"spec/core_ext/proc_spec.rb",
|
44
|
-
"spec/named_scopes/alias_scope_spec.rb",
|
45
|
-
"spec/named_scopes/association_conditions_spec.rb",
|
46
|
-
"spec/named_scopes/association_ordering_spec.rb",
|
47
|
-
"spec/named_scopes/conditions_spec.rb",
|
48
|
-
"spec/named_scopes/or_conditions_spec.rb",
|
49
|
-
"spec/named_scopes/ordering_spec.rb",
|
50
|
-
"spec/search_spec.rb",
|
51
|
-
"spec/spec_helper.rb"
|
52
|
-
]
|
53
|
-
s.homepage = %q{http://github.com/binarylogic/searchlogic}
|
54
|
-
s.rdoc_options = ["--charset=UTF-8"]
|
55
|
-
s.require_paths = ["lib"]
|
56
|
-
s.rubyforge_project = %q{searchlogic}
|
57
|
-
s.rubygems_version = %q{1.3.5}
|
58
|
-
s.summary = %q{Searchlogic makes using ActiveRecord named scopes easier and less repetitive.}
|
59
|
-
s.test_files = [
|
60
|
-
"spec/core_ext/object_spec.rb",
|
61
|
-
"spec/core_ext/proc_spec.rb",
|
62
|
-
"spec/named_scopes/alias_scope_spec.rb",
|
63
|
-
"spec/named_scopes/association_conditions_spec.rb",
|
64
|
-
"spec/named_scopes/association_ordering_spec.rb",
|
65
|
-
"spec/named_scopes/conditions_spec.rb",
|
66
|
-
"spec/named_scopes/or_conditions_spec.rb",
|
67
|
-
"spec/named_scopes/ordering_spec.rb",
|
68
|
-
"spec/search_spec.rb",
|
69
|
-
"spec/spec_helper.rb"
|
70
|
-
]
|
71
|
-
|
72
|
-
if s.respond_to? :specification_version then
|
73
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
74
|
-
s.specification_version = 3
|
75
|
-
|
76
|
-
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
77
|
-
s.add_runtime_dependency(%q<activerecord>, [">= 2.0.0"])
|
78
|
-
else
|
79
|
-
s.add_dependency(%q<activerecord>, [">= 2.0.0"])
|
80
|
-
end
|
81
|
-
else
|
82
|
-
s.add_dependency(%q<activerecord>, [">= 2.0.0"])
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|