searchlogic-donotuse 2.3.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +15 -0
- data/CHANGELOG.rdoc +418 -0
- data/LICENSE +20 -0
- data/README.rdoc +299 -0
- data/Rakefile +19 -0
- data/VERSION.yml +5 -0
- data/init.rb +1 -0
- data/lib/searchlogic.rb +40 -0
- data/lib/searchlogic/active_record/consistency.rb +32 -0
- data/lib/searchlogic/active_record/named_scopes.rb +60 -0
- data/lib/searchlogic/core_ext/object.rb +41 -0
- data/lib/searchlogic/core_ext/proc.rb +11 -0
- data/lib/searchlogic/named_scopes/alias_scope.rb +67 -0
- data/lib/searchlogic/named_scopes/association_conditions.rb +102 -0
- data/lib/searchlogic/named_scopes/association_ordering.rb +43 -0
- data/lib/searchlogic/named_scopes/conditions.rb +229 -0
- data/lib/searchlogic/named_scopes/or_conditions.rb +137 -0
- data/lib/searchlogic/named_scopes/ordering.rb +48 -0
- data/lib/searchlogic/rails_helpers.rb +76 -0
- data/lib/searchlogic/search.rb +179 -0
- data/rails/init.rb +1 -0
- data/searchlogic.gemspec +85 -0
- data/spec/core_ext/object_spec.rb +7 -0
- data/spec/core_ext/proc_spec.rb +9 -0
- data/spec/named_scopes/alias_scope_spec.rb +19 -0
- data/spec/named_scopes/association_conditions_spec.rb +141 -0
- data/spec/named_scopes/association_ordering_spec.rb +27 -0
- data/spec/named_scopes/conditions_spec.rb +319 -0
- data/spec/named_scopes/or_conditions_spec.rb +59 -0
- data/spec/named_scopes/ordering_spec.rb +34 -0
- data/spec/search_spec.rb +369 -0
- data/spec/spec_helper.rb +104 -0
- metadata +89 -0
@@ -0,0 +1,19 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
|
2
|
+
|
3
|
+
describe "AliasScope" do
|
4
|
+
before(:each) do
|
5
|
+
User.alias_scope :username_has, lambda { |value| User.username_like(value) }
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should allow alias scopes" do
|
9
|
+
User.create(:username => "bjohnson")
|
10
|
+
User.create(:username => "thunt")
|
11
|
+
User.username_has("bjohnson").all.should == User.find_all_by_username("bjohnson")
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should allow alias scopes from the search object" do
|
15
|
+
search = User.search
|
16
|
+
search.username_has = "bjohnson"
|
17
|
+
search.username_has.should == "bjohnson"
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,141 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
|
2
|
+
|
3
|
+
describe "Association Conditions" do
|
4
|
+
it "should create a named scope" do
|
5
|
+
Company.users_username_like("bjohnson").proxy_options.should == User.username_like("bjohnson").proxy_options.merge(:joins => :users)
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should create a deep named scope" do
|
9
|
+
Company.users_orders_total_greater_than(10).proxy_options.should == Order.total_greater_than(10).proxy_options.merge(:joins => {:users => :orders})
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should allow the use of foreign pre-existing named scopes" do
|
13
|
+
User.named_scope :uname, lambda { |value| {:conditions => ["users.username = ?", value]} }
|
14
|
+
Company.users_uname("bjohnson").proxy_options.should == User.uname("bjohnson").proxy_options.merge(:joins => :users)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should allow the use of deep foreign pre-existing named scopes" do
|
18
|
+
pending
|
19
|
+
Order.named_scope :big_id, :conditions => "orders.id > 100"
|
20
|
+
Company.users_orders_big_id.proxy_options.should == Order.big_id.proxy_options.merge(:joins => {:users => :orders})
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should allow the use of foreign pre-existing alias scopes" do
|
24
|
+
User.alias_scope :username_has, lambda { |value| User.username_like(value) }
|
25
|
+
Company.users_username_has("bjohnson").proxy_options.should == User.username_has("bjohnson").proxy_options.merge(:joins => :users)
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should not raise errors for scopes that don't return anything" do
|
29
|
+
User.alias_scope :blank_scope, lambda { |value| }
|
30
|
+
Company.users_blank_scope("bjohnson").proxy_options.should == {:joins => :users}
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should ignore polymorphic associations" do
|
34
|
+
lambda { Fee.owner_created_at_gt(Time.now) }.should raise_error(NoMethodError)
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should not allow named scopes on non existent association columns" do
|
38
|
+
lambda { User.users_whatever_like("bjohnson") }.should raise_error(NoMethodError)
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should not allow named scopes on non existent deep association columns" do
|
42
|
+
lambda { User.users_orders_whatever_like("bjohnson") }.should raise_error(NoMethodError)
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should allow named scopes to be called multiple times and reflect the value passed" do
|
46
|
+
Company.users_username_like("bjohnson").proxy_options.should == User.username_like("bjohnson").proxy_options.merge(:joins => :users)
|
47
|
+
Company.users_username_like("thunt").proxy_options.should == User.username_like("thunt").proxy_options.merge(:joins => :users)
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should allow deep named scopes to be called multiple times and reflect the value passed" do
|
51
|
+
Company.users_orders_total_greater_than(10).proxy_options.should == Order.total_greater_than(10).proxy_options.merge(:joins => {:users => :orders})
|
52
|
+
Company.users_orders_total_greater_than(20).proxy_options.should == Order.total_greater_than(20).proxy_options.merge(:joins => {:users => :orders})
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should have an arity of 1 if the underlying scope has an arity of 1" do
|
56
|
+
Company.users_orders_total_greater_than(10)
|
57
|
+
Company.named_scope_arity("users_orders_total_greater_than").should == Order.named_scope_arity("total_greater_than")
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should have an arity of nil if the underlying scope has an arity of nil" do
|
61
|
+
Company.users_orders_total_null
|
62
|
+
Company.named_scope_arity("users_orders_total_null").should == Order.named_scope_arity("total_null")
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should have an arity of -1 if the underlying scope has an arity of -1" do
|
66
|
+
Company.users_id_equals_any
|
67
|
+
Company.named_scope_arity("users_id_equals_any").should == User.named_scope_arity("id_equals_any")
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should allow aliases" do
|
71
|
+
Company.users_username_contains("bjohnson").proxy_options.should == User.username_contains("bjohnson").proxy_options.merge(:joins => :users)
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should allow deep aliases" do
|
75
|
+
Company.users_orders_total_gt(10).proxy_options.should == Order.total_gt(10).proxy_options.merge(:joins => {:users => :orders})
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should include optional associations" do
|
79
|
+
pending # this is a problem with using inner joins and left outer joins
|
80
|
+
Company.create
|
81
|
+
company = Company.create
|
82
|
+
user = company.users.create
|
83
|
+
order = user.orders.create(:total => 20, :taxes => 3)
|
84
|
+
Company.ascend_by_users_orders_total.all.should == Company.all
|
85
|
+
end
|
86
|
+
|
87
|
+
it "should not create the same join twice" do
|
88
|
+
company = Company.create
|
89
|
+
user = company.users.create
|
90
|
+
order = user.orders.create(:total => 20, :taxes => 3)
|
91
|
+
Company.users_orders_total_gt(10).users_orders_taxes_lt(5).ascend_by_users_orders_total.all.should == Company.all
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should not create the same join twice when traveling through the duplicate join" do
|
95
|
+
Company.users_username_like("bjohnson").users_orders_total_gt(100).all.should == Company.all
|
96
|
+
end
|
97
|
+
|
98
|
+
it "should not create the same join twice when traveling through the duplicate join 2" do
|
99
|
+
Company.users_orders_total_gt(100).users_orders_line_items_price_gt(20).all.should == Company.all
|
100
|
+
end
|
101
|
+
|
102
|
+
it "should allow the use of :include when a join was created" do
|
103
|
+
company = Company.create
|
104
|
+
user = company.users.create
|
105
|
+
order = user.orders.create(:total => 20, :taxes => 3)
|
106
|
+
Company.users_orders_total_gt(10).users_orders_taxes_lt(5).ascend_by_users_orders_total.all(:include => :users).should == Company.all
|
107
|
+
end
|
108
|
+
|
109
|
+
it "should allow the use of deep :include when a join was created" do
|
110
|
+
company = Company.create
|
111
|
+
user = company.users.create
|
112
|
+
order = user.orders.create(:total => 20, :taxes => 3)
|
113
|
+
Company.users_orders_total_gt(10).users_orders_taxes_lt(5).ascend_by_users_orders_total.all(:include => {:users => :orders}).should == Company.all
|
114
|
+
end
|
115
|
+
|
116
|
+
it "should allow the use of :include when traveling through the duplicate join" do
|
117
|
+
company = Company.create
|
118
|
+
user = company.users.create(:username => "bjohnson")
|
119
|
+
order = user.orders.create(:total => 20, :taxes => 3)
|
120
|
+
Company.users_username_like("bjohnson").users_orders_taxes_lt(5).ascend_by_users_orders_total.all(:include => :users).should == Company.all
|
121
|
+
end
|
122
|
+
|
123
|
+
it "should allow the use of deep :include when traveling through the duplicate join" do
|
124
|
+
company = Company.create
|
125
|
+
user = company.users.create(:username => "bjohnson")
|
126
|
+
order = user.orders.create(:total => 20, :taxes => 3)
|
127
|
+
Company.users_orders_taxes_lt(50).ascend_by_users_orders_total.all(:include => {:users => :orders}).should == Company.all
|
128
|
+
end
|
129
|
+
|
130
|
+
it "should automatically add string joins if the association condition is using strings" do
|
131
|
+
User.named_scope(:orders_big_id, :joins => User.inner_joins(:orders))
|
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
|
+
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
|
+
|
141
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
|
2
|
+
|
3
|
+
describe "Association Ordering" do
|
4
|
+
it "should allow ascending" do
|
5
|
+
Company.ascend_by_users_username.proxy_options.should == User.ascend_by_username.proxy_options.merge(:joins => :users)
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should allow descending" do
|
9
|
+
Company.descend_by_users_username.proxy_options.should == User.descend_by_username.proxy_options.merge(:joins => :users)
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should allow deep ascending" do
|
13
|
+
Company.ascend_by_users_orders_total.proxy_options.should == Order.ascend_by_total.proxy_options.merge(:joins => {:users => :orders})
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should allow deep descending" do
|
17
|
+
Company.descend_by_users_orders_total.proxy_options.should == Order.descend_by_total.proxy_options.merge(:joins => {:users => :orders})
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should ascend with a belongs to" do
|
21
|
+
User.ascend_by_company_name.proxy_options.should == Company.ascend_by_name.proxy_options.merge(:joins => :company)
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should work through #order" do
|
25
|
+
Company.order('ascend_by_users_username').proxy_options.should == Company.ascend_by_users_username.proxy_options
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,319 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
|
2
|
+
|
3
|
+
describe "Conditions" do
|
4
|
+
it "should be dynamically created and then cached" do
|
5
|
+
User.should_not respond_to(:age_less_than)
|
6
|
+
User.age_less_than(5)
|
7
|
+
User.should respond_to(:age_less_than)
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should not allow conditions on non columns" do
|
11
|
+
lambda { User.whatever_equals(2) }.should raise_error(NoMethodError)
|
12
|
+
end
|
13
|
+
|
14
|
+
context "comparison conditions" do
|
15
|
+
it "should have equals" do
|
16
|
+
(5..7).each { |age| User.create(:age => age) }
|
17
|
+
User.age_equals(6).all.should == User.find_all_by_age(6)
|
18
|
+
User.age_equals(5..6).all.should == User.find_all_by_age(5..6)
|
19
|
+
User.age_equals([5, 7]).all.should == User.find_all_by_age([5, 7])
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should have does not equal" do
|
23
|
+
(5..7).each { |age| User.create(:age => age) }
|
24
|
+
User.age_does_not_equal(6).all.should == User.find_all_by_age([5,7])
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should have less than" do
|
28
|
+
(5..7).each { |age| User.create(:age => age) }
|
29
|
+
User.age_less_than(6).all.should == User.find_all_by_age(5)
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should have less than or equal to" do
|
33
|
+
(5..7).each { |age| User.create(:age => age) }
|
34
|
+
User.age_less_than_or_equal_to(6).all.should == User.find_all_by_age([5, 6])
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should have greater than" do
|
38
|
+
(5..7).each { |age| User.create(:age => age) }
|
39
|
+
User.age_greater_than(6).all.should == User.find_all_by_age(7)
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should have greater than or equal to" do
|
43
|
+
(5..7).each { |age| User.create(:age => age) }
|
44
|
+
User.age_greater_than_or_equal_to(6).all.should == User.find_all_by_age([6, 7])
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
context "wildcard conditions" do
|
49
|
+
it "should have like" do
|
50
|
+
%w(bjohnson thunt).each { |username| User.create(:username => username) }
|
51
|
+
User.username_like("john").all.should == User.find_all_by_username("bjohnson")
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should have not like" do
|
55
|
+
%w(bjohnson thunt).each { |username| User.create(:username => username) }
|
56
|
+
User.username_not_like("john").all.should == User.find_all_by_username("thunt")
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should have begins with" do
|
60
|
+
%w(bjohnson thunt).each { |username| User.create(:username => username) }
|
61
|
+
User.username_begins_with("bj").all.should == User.find_all_by_username("bjohnson")
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should have not begin with" do
|
65
|
+
%w(bjohnson thunt).each { |username| User.create(:username => username) }
|
66
|
+
User.username_not_begin_with("bj").all.should == User.find_all_by_username("thunt")
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should have ends with" do
|
70
|
+
%w(bjohnson thunt).each { |username| User.create(:username => username) }
|
71
|
+
User.username_ends_with("son").all.should == User.find_all_by_username("bjohnson")
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should have not end with" do
|
75
|
+
%w(bjohnson thunt).each { |username| User.create(:username => username) }
|
76
|
+
User.username_not_end_with("son").all.should == User.find_all_by_username("thunt")
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
context "boolean conditions" do
|
81
|
+
it "should have scopes for boolean columns" do
|
82
|
+
female = User.create(:male => false)
|
83
|
+
male = User.create(:male => true)
|
84
|
+
User.male.all.should == [male]
|
85
|
+
User.not_male.all.should == [female]
|
86
|
+
end
|
87
|
+
|
88
|
+
it "should have null" do
|
89
|
+
["bjohnson", nil].each { |username| User.create(:username => username) }
|
90
|
+
User.username_null.all.should == User.find_all_by_username(nil)
|
91
|
+
end
|
92
|
+
|
93
|
+
it "should have not null" do
|
94
|
+
["bjohnson", nil].each { |username| User.create(:username => username) }
|
95
|
+
User.username_not_null.all.should == User.find_all_by_username("bjohnson")
|
96
|
+
end
|
97
|
+
|
98
|
+
it "should have empty" do
|
99
|
+
["bjohnson", ""].each { |username| User.create(:username => username) }
|
100
|
+
User.username_empty.all.should == User.find_all_by_username("")
|
101
|
+
end
|
102
|
+
|
103
|
+
it "should have blank" do
|
104
|
+
["bjohnson", "", nil].each { |username| User.create(:username => username) }
|
105
|
+
User.username_blank.all.should == [User.find_by_username(""), User.find_by_username(nil)]
|
106
|
+
end
|
107
|
+
|
108
|
+
it "should have not blank" do
|
109
|
+
["bjohnson", "", nil].each { |username| User.create(:username => username) }
|
110
|
+
User.username_not_blank.all.should == User.find_all_by_username("bjohnson")
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
context "any and all conditions" do
|
115
|
+
it "should do nothing if no arguments are passed" do
|
116
|
+
User.username_equals_any.proxy_options.should == {}
|
117
|
+
end
|
118
|
+
|
119
|
+
it "should treat an array and multiple arguments the same" do
|
120
|
+
%w(bjohnson thunt dgainor).each { |username| User.create(:username => username) }
|
121
|
+
User.username_like_any("bjohnson", "thunt").should == User.username_like_any(["bjohnson", "thunt"])
|
122
|
+
end
|
123
|
+
|
124
|
+
it "should have equals any" do
|
125
|
+
%w(bjohnson thunt dgainor).each { |username| User.create(:username => username) }
|
126
|
+
User.username_equals_any("bjohnson", "thunt").all == User.find_all_by_username(["bjohnson", "thunt"])
|
127
|
+
end
|
128
|
+
|
129
|
+
it "should have equals all" do
|
130
|
+
%w(bjohnson thunt dainor).each { |username| User.create(:username => username) }
|
131
|
+
User.username_equals_all("bjohnson", "thunt").all == []
|
132
|
+
end
|
133
|
+
|
134
|
+
it "should have does not equal any" do
|
135
|
+
%w(bjohnson thunt dgainor).each { |username| User.create(:username => username) }
|
136
|
+
User.username_does_not_equal_any("bjohnson", "thunt").all == User.find_all_by_username("dgainor")
|
137
|
+
end
|
138
|
+
|
139
|
+
it "should have does not equal all" do
|
140
|
+
%w(bjohnson thunt dgainor).each { |username| User.create(:username => username) }
|
141
|
+
User.username_does_not_equal_all("bjohnson", "thunt").all == User.find_all_by_username("dgainor")
|
142
|
+
end
|
143
|
+
|
144
|
+
it "should have less than any" do
|
145
|
+
(5..7).each { |age| User.create(:age => age) }
|
146
|
+
User.age_less_than_any(7,6).all == User.find_all_by_age([5, 6])
|
147
|
+
end
|
148
|
+
|
149
|
+
it "should have less than all" do
|
150
|
+
(5..7).each { |age| User.create(:age => age) }
|
151
|
+
User.age_less_than_all(7,6).all == User.find_all_by_age(5)
|
152
|
+
end
|
153
|
+
|
154
|
+
it "should have less than or equal to any" do
|
155
|
+
(5..7).each { |age| User.create(:age => age) }
|
156
|
+
User.age_less_than_or_equal_to_any(7,6).all == User.find_all_by_age([5, 6, 7])
|
157
|
+
end
|
158
|
+
|
159
|
+
it "should have less than or equal to all" do
|
160
|
+
(5..7).each { |age| User.create(:age => age) }
|
161
|
+
User.age_less_than_or_equal_to_all(7,6).all == User.find_all_by_age([5, 6])
|
162
|
+
end
|
163
|
+
|
164
|
+
it "should have less than any" do
|
165
|
+
(5..7).each { |age| User.create(:age => age) }
|
166
|
+
User.age_greater_than_any(5,6).all == User.find_all_by_age([6, 7])
|
167
|
+
end
|
168
|
+
|
169
|
+
it "should have greater than all" do
|
170
|
+
(5..7).each { |age| User.create(:age => age) }
|
171
|
+
User.age_greater_than_all(5,6).all == User.find_all_by_age(7)
|
172
|
+
end
|
173
|
+
|
174
|
+
it "should have greater than or equal to any" do
|
175
|
+
(5..7).each { |age| User.create(:age => age) }
|
176
|
+
User.age_greater_than_or_equal_to_any(5,6).all == User.find_all_by_age([5, 6, 7])
|
177
|
+
end
|
178
|
+
|
179
|
+
it "should have greater than or equal to all" do
|
180
|
+
(5..7).each { |age| User.create(:age => age) }
|
181
|
+
User.age_greater_than_or_equal_to_all(5,6).all == User.find_all_by_age([6, 7])
|
182
|
+
end
|
183
|
+
|
184
|
+
it "should have like all" do
|
185
|
+
%w(bjohnson thunt dgainor).each { |username| User.create(:username => username) }
|
186
|
+
User.username_like_all("bjohnson", "thunt").all == []
|
187
|
+
User.username_like_all("n", "o").all == User.find_all_by_username(["bjohnson", "thunt"])
|
188
|
+
end
|
189
|
+
|
190
|
+
it "should have like any" do
|
191
|
+
%w(bjohnson thunt dgainor).each { |username| User.create(:username => username) }
|
192
|
+
User.username_like_all("bjohnson", "thunt").all == User.find_all_by_username(["bjohnson", "thunt"])
|
193
|
+
end
|
194
|
+
|
195
|
+
it "should have begins with all" do
|
196
|
+
%w(bjohnson thunt dgainor).each { |username| User.create(:username => username) }
|
197
|
+
User.username_begins_with_all("bjohnson", "thunt").all == []
|
198
|
+
end
|
199
|
+
|
200
|
+
it "should have begins with any" do
|
201
|
+
%w(bjohnson thunt dgainor).each { |username| User.create(:username => username) }
|
202
|
+
User.username_begins_with_any("bj", "th").all == User.find_all_by_username(["bjohnson", "thunt"])
|
203
|
+
end
|
204
|
+
|
205
|
+
it "should have ends with all" do
|
206
|
+
%w(bjohnson thunt dgainor).each { |username| User.create(:username => username) }
|
207
|
+
User.username_ends_with_all("n", "r").all == []
|
208
|
+
end
|
209
|
+
|
210
|
+
it "should have ends with any" do
|
211
|
+
%w(bjohnson thunt dgainor).each { |username| User.create(:username => username) }
|
212
|
+
User.username_ends_with_any("n", "r").all == User.find_all_by_username(["bjohnson", "dgainor"])
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
216
|
+
context "alias conditions" do
|
217
|
+
it "should have is" do
|
218
|
+
User.age_is(5).proxy_options.should == User.age_equals(5).proxy_options
|
219
|
+
end
|
220
|
+
|
221
|
+
it "should have eq" do
|
222
|
+
User.age_eq(5).proxy_options.should == User.age_equals(5).proxy_options
|
223
|
+
end
|
224
|
+
|
225
|
+
it "should have not_equal_to" do
|
226
|
+
User.age_not_equal_to(5).proxy_options.should == User.age_does_not_equal(5).proxy_options
|
227
|
+
end
|
228
|
+
|
229
|
+
it "should have is_not" do
|
230
|
+
User.age_is_not(5).proxy_options.should == User.age_does_not_equal(5).proxy_options
|
231
|
+
end
|
232
|
+
|
233
|
+
it "should have not" do
|
234
|
+
User.age_not(5).proxy_options.should == User.age_does_not_equal(5).proxy_options
|
235
|
+
end
|
236
|
+
|
237
|
+
it "should have ne" do
|
238
|
+
User.age_ne(5).proxy_options.should == User.age_does_not_equal(5).proxy_options
|
239
|
+
end
|
240
|
+
|
241
|
+
it "should have lt" do
|
242
|
+
User.age_lt(5).proxy_options.should == User.age_less_than(5).proxy_options
|
243
|
+
end
|
244
|
+
|
245
|
+
it "should have lte" do
|
246
|
+
User.age_lte(5).proxy_options.should == User.age_less_than_or_equal_to(5).proxy_options
|
247
|
+
end
|
248
|
+
|
249
|
+
it "should have gt" do
|
250
|
+
User.age_gt(5).proxy_options.should == User.age_greater_than(5).proxy_options
|
251
|
+
end
|
252
|
+
|
253
|
+
it "should have gte" do
|
254
|
+
User.age_gte(5).proxy_options.should == User.age_greater_than_or_equal_to(5).proxy_options
|
255
|
+
end
|
256
|
+
|
257
|
+
it "should have contains" do
|
258
|
+
User.username_contains(5).proxy_options.should == User.username_like(5).proxy_options
|
259
|
+
end
|
260
|
+
|
261
|
+
it "should have contains" do
|
262
|
+
User.username_includes(5).proxy_options.should == User.username_like(5).proxy_options
|
263
|
+
end
|
264
|
+
|
265
|
+
it "should have bw" do
|
266
|
+
User.username_bw(5).proxy_options.should == User.username_begins_with(5).proxy_options
|
267
|
+
end
|
268
|
+
|
269
|
+
it "should have ew" do
|
270
|
+
User.username_ew(5).proxy_options.should == User.username_ends_with(5).proxy_options
|
271
|
+
end
|
272
|
+
|
273
|
+
it "should have nil" do
|
274
|
+
User.username_nil.proxy_options.should == User.username_nil.proxy_options
|
275
|
+
end
|
276
|
+
end
|
277
|
+
|
278
|
+
context "group conditions" do
|
279
|
+
it "should have in" do
|
280
|
+
(5..7).each { |age| User.create(:age => age) }
|
281
|
+
User.age_in([5,6]).all == User.find(:all, :conditions => ["users.age IN (?)", [5, 6]])
|
282
|
+
end
|
283
|
+
|
284
|
+
it "should have not_in" do
|
285
|
+
(5..7).each { |age| User.create(:age => age) }
|
286
|
+
User.age_not_in([5,6]).all == User.find(:all, :conditions => ["users.age NOT IN (?)", [5, 6]])
|
287
|
+
end
|
288
|
+
end
|
289
|
+
|
290
|
+
context "searchlogic lambda" do
|
291
|
+
it "should be a string" do
|
292
|
+
User.username_like("test")
|
293
|
+
User.named_scope_options(:username_like).searchlogic_arg_type.should == :string
|
294
|
+
end
|
295
|
+
|
296
|
+
it "should be an integer" do
|
297
|
+
User.id_gt(10)
|
298
|
+
User.named_scope_options(:id_gt).searchlogic_arg_type.should == :integer
|
299
|
+
end
|
300
|
+
|
301
|
+
it "should be a float" do
|
302
|
+
Order.total_gt(10)
|
303
|
+
Order.named_scope_options(:total_gt).searchlogic_arg_type.should == :float
|
304
|
+
end
|
305
|
+
end
|
306
|
+
|
307
|
+
it "should have priorty to columns over conflicting association conditions" do
|
308
|
+
Company.users_count_gt(10)
|
309
|
+
User.create
|
310
|
+
User.company_id_null.count.should == 1
|
311
|
+
User.company_id_not_null.count.should == 0
|
312
|
+
end
|
313
|
+
|
314
|
+
it "should fix bug for issue 26" do
|
315
|
+
count1 = User.id_ne(10).username_not_like("root").count
|
316
|
+
count2 = User.id_ne(10).username_not_like("root").count
|
317
|
+
count1.should == count2
|
318
|
+
end
|
319
|
+
end
|