searchlogic 1.6.6 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (178) hide show
  1. data/.gitignore +6 -0
  2. data/CHANGELOG.rdoc +17 -0
  3. data/{MIT-LICENSE → LICENSE} +2 -2
  4. data/README.rdoc +128 -379
  5. data/Rakefile +56 -20
  6. data/VERSION.yml +4 -0
  7. data/init.rb +1 -1
  8. data/lib/searchlogic.rb +18 -98
  9. data/lib/searchlogic/core_ext/object.rb +33 -13
  10. data/lib/searchlogic/core_ext/proc.rb +11 -0
  11. data/lib/searchlogic/named_scopes/alias_scope.rb +63 -0
  12. data/lib/searchlogic/named_scopes/associations.rb +126 -0
  13. data/lib/searchlogic/named_scopes/conditions.rb +215 -0
  14. data/lib/searchlogic/named_scopes/ordering.rb +53 -0
  15. data/lib/searchlogic/rails_helpers.rb +69 -0
  16. data/lib/searchlogic/search.rb +146 -0
  17. data/rails/init.rb +1 -0
  18. data/searchlogic.gemspec +69 -0
  19. data/spec/core_ext/object_spec.rb +7 -0
  20. data/spec/core_ext/proc_spec.rb +9 -0
  21. data/spec/named_scopes/alias_scope_spec.rb +15 -0
  22. data/spec/named_scopes/associations_spec.rb +120 -0
  23. data/spec/named_scopes/conditions_spec.rb +253 -0
  24. data/spec/named_scopes/ordering_spec.rb +23 -0
  25. data/spec/search_spec.rb +283 -0
  26. data/spec/spec_helper.rb +78 -0
  27. metadata +40 -231
  28. data/Manifest.txt +0 -158
  29. data/TODO.rdoc +0 -4
  30. data/lib/searchlogic/active_record/associations.rb +0 -52
  31. data/lib/searchlogic/active_record/base.rb +0 -224
  32. data/lib/searchlogic/active_record/connection_adapters/mysql_adapter.rb +0 -176
  33. data/lib/searchlogic/active_record/connection_adapters/postgresql_adapter.rb +0 -172
  34. data/lib/searchlogic/active_record/connection_adapters/sqlite_adapter.rb +0 -80
  35. data/lib/searchlogic/condition/base.rb +0 -165
  36. data/lib/searchlogic/condition/begins_with.rb +0 -17
  37. data/lib/searchlogic/condition/blank.rb +0 -24
  38. data/lib/searchlogic/condition/child_of.rb +0 -11
  39. data/lib/searchlogic/condition/descendant_of.rb +0 -11
  40. data/lib/searchlogic/condition/ends_with.rb +0 -17
  41. data/lib/searchlogic/condition/equals.rb +0 -33
  42. data/lib/searchlogic/condition/greater_than.rb +0 -15
  43. data/lib/searchlogic/condition/greater_than_or_equal_to.rb +0 -15
  44. data/lib/searchlogic/condition/inclusive_descendant_of.rb +0 -10
  45. data/lib/searchlogic/condition/keywords.rb +0 -52
  46. data/lib/searchlogic/condition/less_than.rb +0 -15
  47. data/lib/searchlogic/condition/less_than_or_equal_to.rb +0 -15
  48. data/lib/searchlogic/condition/like.rb +0 -15
  49. data/lib/searchlogic/condition/nested_set.rb +0 -17
  50. data/lib/searchlogic/condition/nil.rb +0 -21
  51. data/lib/searchlogic/condition/not_begin_with.rb +0 -20
  52. data/lib/searchlogic/condition/not_blank.rb +0 -19
  53. data/lib/searchlogic/condition/not_end_with.rb +0 -20
  54. data/lib/searchlogic/condition/not_equal.rb +0 -27
  55. data/lib/searchlogic/condition/not_have_keywords.rb +0 -20
  56. data/lib/searchlogic/condition/not_like.rb +0 -20
  57. data/lib/searchlogic/condition/not_nil.rb +0 -19
  58. data/lib/searchlogic/condition/sibling_of.rb +0 -14
  59. data/lib/searchlogic/conditions/any_or_all.rb +0 -42
  60. data/lib/searchlogic/conditions/base.rb +0 -244
  61. data/lib/searchlogic/conditions/groups.rb +0 -74
  62. data/lib/searchlogic/conditions/magic_methods.rb +0 -286
  63. data/lib/searchlogic/conditions/multiparameter_attributes.rb +0 -105
  64. data/lib/searchlogic/conditions/protection.rb +0 -36
  65. data/lib/searchlogic/config.rb +0 -31
  66. data/lib/searchlogic/config/helpers.rb +0 -338
  67. data/lib/searchlogic/config/search.rb +0 -53
  68. data/lib/searchlogic/core_ext/hash.rb +0 -75
  69. data/lib/searchlogic/helpers/control_types/link.rb +0 -310
  70. data/lib/searchlogic/helpers/control_types/links.rb +0 -242
  71. data/lib/searchlogic/helpers/control_types/remote_link.rb +0 -87
  72. data/lib/searchlogic/helpers/control_types/remote_links.rb +0 -72
  73. data/lib/searchlogic/helpers/control_types/remote_select.rb +0 -36
  74. data/lib/searchlogic/helpers/control_types/select.rb +0 -82
  75. data/lib/searchlogic/helpers/form.rb +0 -208
  76. data/lib/searchlogic/helpers/utilities.rb +0 -197
  77. data/lib/searchlogic/modifiers/absolute.rb +0 -15
  78. data/lib/searchlogic/modifiers/acos.rb +0 -11
  79. data/lib/searchlogic/modifiers/asin.rb +0 -11
  80. data/lib/searchlogic/modifiers/atan.rb +0 -11
  81. data/lib/searchlogic/modifiers/avg.rb +0 -15
  82. data/lib/searchlogic/modifiers/base.rb +0 -27
  83. data/lib/searchlogic/modifiers/ceil.rb +0 -15
  84. data/lib/searchlogic/modifiers/char_length.rb +0 -15
  85. data/lib/searchlogic/modifiers/cos.rb +0 -15
  86. data/lib/searchlogic/modifiers/cot.rb +0 -15
  87. data/lib/searchlogic/modifiers/count.rb +0 -11
  88. data/lib/searchlogic/modifiers/day_of_month.rb +0 -15
  89. data/lib/searchlogic/modifiers/day_of_week.rb +0 -15
  90. data/lib/searchlogic/modifiers/day_of_year.rb +0 -15
  91. data/lib/searchlogic/modifiers/degrees.rb +0 -11
  92. data/lib/searchlogic/modifiers/exp.rb +0 -15
  93. data/lib/searchlogic/modifiers/floor.rb +0 -15
  94. data/lib/searchlogic/modifiers/hex.rb +0 -11
  95. data/lib/searchlogic/modifiers/hour.rb +0 -11
  96. data/lib/searchlogic/modifiers/log.rb +0 -15
  97. data/lib/searchlogic/modifiers/log10.rb +0 -11
  98. data/lib/searchlogic/modifiers/log2.rb +0 -11
  99. data/lib/searchlogic/modifiers/lower.rb +0 -15
  100. data/lib/searchlogic/modifiers/ltrim.rb +0 -15
  101. data/lib/searchlogic/modifiers/md5.rb +0 -11
  102. data/lib/searchlogic/modifiers/microseconds.rb +0 -11
  103. data/lib/searchlogic/modifiers/milliseconds.rb +0 -11
  104. data/lib/searchlogic/modifiers/minute.rb +0 -15
  105. data/lib/searchlogic/modifiers/month.rb +0 -15
  106. data/lib/searchlogic/modifiers/octal.rb +0 -15
  107. data/lib/searchlogic/modifiers/radians.rb +0 -11
  108. data/lib/searchlogic/modifiers/round.rb +0 -11
  109. data/lib/searchlogic/modifiers/rtrim.rb +0 -15
  110. data/lib/searchlogic/modifiers/second.rb +0 -15
  111. data/lib/searchlogic/modifiers/sign.rb +0 -11
  112. data/lib/searchlogic/modifiers/sin.rb +0 -11
  113. data/lib/searchlogic/modifiers/square_root.rb +0 -15
  114. data/lib/searchlogic/modifiers/sum.rb +0 -11
  115. data/lib/searchlogic/modifiers/tan.rb +0 -15
  116. data/lib/searchlogic/modifiers/trim.rb +0 -15
  117. data/lib/searchlogic/modifiers/upper.rb +0 -15
  118. data/lib/searchlogic/modifiers/week.rb +0 -11
  119. data/lib/searchlogic/modifiers/year.rb +0 -11
  120. data/lib/searchlogic/search/base.rb +0 -148
  121. data/lib/searchlogic/search/conditions.rb +0 -53
  122. data/lib/searchlogic/search/ordering.rb +0 -244
  123. data/lib/searchlogic/search/pagination.rb +0 -121
  124. data/lib/searchlogic/search/protection.rb +0 -89
  125. data/lib/searchlogic/search/searching.rb +0 -32
  126. data/lib/searchlogic/shared/utilities.rb +0 -57
  127. data/lib/searchlogic/shared/virtual_classes.rb +0 -39
  128. data/lib/searchlogic/version.rb +0 -79
  129. data/test/active_record_tests/associations_test.rb +0 -94
  130. data/test/active_record_tests/base_test.rb +0 -115
  131. data/test/condition_tests/base_test.rb +0 -62
  132. data/test/condition_tests/begins_with_test.rb +0 -11
  133. data/test/condition_tests/blank_test.rb +0 -31
  134. data/test/condition_tests/child_of_test.rb +0 -17
  135. data/test/condition_tests/descendant_of_test.rb +0 -12
  136. data/test/condition_tests/ends_with_test.rb +0 -11
  137. data/test/condition_tests/equals_test.rb +0 -28
  138. data/test/condition_tests/greater_than_or_equal_to_test.rb +0 -11
  139. data/test/condition_tests/greater_than_test.rb +0 -11
  140. data/test/condition_tests/inclusive_descendant_of_test.rb +0 -12
  141. data/test/condition_tests/keywords_test.rb +0 -23
  142. data/test/condition_tests/less_than_or_equal_to_test.rb +0 -11
  143. data/test/condition_tests/less_than_test.rb +0 -11
  144. data/test/condition_tests/like_test.rb +0 -11
  145. data/test/condition_tests/nil_test.rb +0 -31
  146. data/test/condition_tests/not_begin_with_test.rb +0 -8
  147. data/test/condition_tests/not_blank_test.rb +0 -8
  148. data/test/condition_tests/not_end_with_test.rb +0 -8
  149. data/test/condition_tests/not_equal_test.rb +0 -19
  150. data/test/condition_tests/not_have_keywords_test.rb +0 -8
  151. data/test/condition_tests/not_like_test.rb +0 -8
  152. data/test/condition_tests/not_nil_test.rb +0 -13
  153. data/test/condition_tests/sibling_of_test.rb +0 -15
  154. data/test/conditions_tests/any_or_all_test.rb +0 -23
  155. data/test/conditions_tests/base_test.rb +0 -185
  156. data/test/conditions_tests/groups_test.rb +0 -68
  157. data/test/conditions_tests/magic_methods_test.rb +0 -36
  158. data/test/conditions_tests/multiparameter_attributes_test.rb +0 -15
  159. data/test/conditions_tests/protection_test.rb +0 -18
  160. data/test/config_test.rb +0 -23
  161. data/test/fixtures/accounts.yml +0 -12
  162. data/test/fixtures/animals.yml +0 -7
  163. data/test/fixtures/orders.yml +0 -12
  164. data/test/fixtures/user_groups.yml +0 -5
  165. data/test/fixtures/users.yml +0 -45
  166. data/test/libs/awesome_nested_set.rb +0 -545
  167. data/test/libs/awesome_nested_set/.autotest +0 -13
  168. data/test/libs/awesome_nested_set/compatability.rb +0 -29
  169. data/test/libs/awesome_nested_set/helper.rb +0 -40
  170. data/test/libs/awesome_nested_set/named_scope.rb +0 -140
  171. data/test/libs/rexml_fix.rb +0 -14
  172. data/test/modifier_tests/day_of_month_test.rb +0 -16
  173. data/test/search_tests/base_test.rb +0 -241
  174. data/test/search_tests/conditions_test.rb +0 -21
  175. data/test/search_tests/ordering_test.rb +0 -167
  176. data/test/search_tests/pagination_test.rb +0 -74
  177. data/test/search_tests/protection_test.rb +0 -26
  178. data/test/test_helper.rb +0 -122
@@ -0,0 +1 @@
1
+ require "searchlogic"
@@ -0,0 +1,69 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{searchlogic}
5
+ s.version = "2.1.0"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Ben Johnson of Binary Logic"]
9
+ s.date = %q{2009-06-27}
10
+ s.email = %q{bjohnson@binarylogic.com}
11
+ s.extra_rdoc_files = [
12
+ "LICENSE",
13
+ "README.rdoc"
14
+ ]
15
+ s.files = [
16
+ ".gitignore",
17
+ "CHANGELOG.rdoc",
18
+ "LICENSE",
19
+ "README.rdoc",
20
+ "Rakefile",
21
+ "VERSION.yml",
22
+ "init.rb",
23
+ "lib/searchlogic.rb",
24
+ "lib/searchlogic/core_ext/object.rb",
25
+ "lib/searchlogic/core_ext/proc.rb",
26
+ "lib/searchlogic/named_scopes/alias_scope.rb",
27
+ "lib/searchlogic/named_scopes/associations.rb",
28
+ "lib/searchlogic/named_scopes/conditions.rb",
29
+ "lib/searchlogic/named_scopes/ordering.rb",
30
+ "lib/searchlogic/rails_helpers.rb",
31
+ "lib/searchlogic/search.rb",
32
+ "rails/init.rb",
33
+ "searchlogic.gemspec",
34
+ "spec/core_ext/object_spec.rb",
35
+ "spec/core_ext/proc_spec.rb",
36
+ "spec/named_scopes/alias_scope_spec.rb",
37
+ "spec/named_scopes/associations_spec.rb",
38
+ "spec/named_scopes/conditions_spec.rb",
39
+ "spec/named_scopes/ordering_spec.rb",
40
+ "spec/search_spec.rb",
41
+ "spec/spec_helper.rb"
42
+ ]
43
+ s.homepage = %q{http://github.com/binarylogic/searchlogic}
44
+ s.rdoc_options = ["--charset=UTF-8"]
45
+ s.require_paths = ["lib"]
46
+ s.rubyforge_project = %q{searchlogic}
47
+ s.rubygems_version = %q{1.3.4}
48
+ s.summary = %q{Searchlogic provides common named scopes and object based searching for ActiveRecord.}
49
+ s.test_files = [
50
+ "spec/core_ext/object_spec.rb",
51
+ "spec/core_ext/proc_spec.rb",
52
+ "spec/named_scopes/alias_scope_spec.rb",
53
+ "spec/named_scopes/associations_spec.rb",
54
+ "spec/named_scopes/conditions_spec.rb",
55
+ "spec/named_scopes/ordering_spec.rb",
56
+ "spec/search_spec.rb",
57
+ "spec/spec_helper.rb"
58
+ ]
59
+
60
+ if s.respond_to? :specification_version then
61
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
62
+ s.specification_version = 3
63
+
64
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
65
+ else
66
+ end
67
+ else
68
+ end
69
+ end
@@ -0,0 +1,7 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
+
3
+ describe "Object" do
4
+ it "should accept and pass the argument to the searchlogic_arg_type" do
5
+ searchlogic_lambda(:integer) {}.searchlogic_arg_type.should == :integer
6
+ end
7
+ end
@@ -0,0 +1,9 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
+
3
+ describe "Proc" do
4
+ it "should have a searchlogic_arg_type accessor" do
5
+ p = Proc.new {}
6
+ p.searchlogic_arg_type = :integer
7
+ p.searchlogic_arg_type.should == :integer
8
+ end
9
+ end
@@ -0,0 +1,15 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
+
3
+ describe "AliasScope" do
4
+ it "should allow alias scopes" do
5
+ User.create(:username => "bjohnson")
6
+ User.create(:username => "thunt")
7
+ User.username_has("bjohnson").all.should == User.find_all_by_username("bjohnson")
8
+ end
9
+
10
+ it "should allow alias scopes from the search object" do
11
+ search = User.search
12
+ search.username_has = "bjohnson"
13
+ search.username_has.should == "bjohnson"
14
+ end
15
+ end
@@ -0,0 +1,120 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
+
3
+ describe "Associations" 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 not allowed named scopes on non existent association columns" do
13
+ lambda { User.users_whatever_like("bjohnson") }.should raise_error(NoMethodError)
14
+ end
15
+
16
+ it "should not allowed named scopes on non existent deep association columns" do
17
+ lambda { User.users_orders_whatever_like("bjohnson") }.should raise_error(NoMethodError)
18
+ end
19
+
20
+ it "should allow named scopes to be called multiple times and reflect the value passed" do
21
+ Company.users_username_like("bjohnson").proxy_options.should == User.username_like("bjohnson").proxy_options.merge(:joins => :users)
22
+ Company.users_username_like("thunt").proxy_options.should == User.username_like("thunt").proxy_options.merge(:joins => :users)
23
+ end
24
+
25
+ it "should allow deep named scopes to be called multiple times and reflect the value passed" do
26
+ Company.users_orders_total_greater_than(10).proxy_options.should == Order.total_greater_than(10).proxy_options.merge(:joins => {:users => :orders})
27
+ Company.users_orders_total_greater_than(20).proxy_options.should == Order.total_greater_than(20).proxy_options.merge(:joins => {:users => :orders})
28
+ end
29
+
30
+ it "should have an arity of 1 if the underlying scope has an arity of 1" do
31
+ Company.users_orders_total_greater_than(10)
32
+ Company.named_scope_arity("users_orders_total_greater_than").should == Order.named_scope_arity("total_greater_than")
33
+ end
34
+
35
+ it "should have an arity of nil if the underlying scope has an arity of nil" do
36
+ Company.users_orders_total_null
37
+ Company.named_scope_arity("users_orders_total_null").should == Order.named_scope_arity("total_null")
38
+ end
39
+
40
+ it "should have an arity of -1 if the underlying scope has an arity of -1" do
41
+ Company.users_id_equals_any
42
+ Company.named_scope_arity("users_id_equals_any").should == User.named_scope_arity("id_equals_any")
43
+ end
44
+
45
+ it "should allow aliases" do
46
+ Company.users_username_contains("bjohnson").proxy_options.should == User.username_contains("bjohnson").proxy_options.merge(:joins => :users)
47
+ end
48
+
49
+ it "should allow deep aliases" do
50
+ Company.users_orders_total_gt(10).proxy_options.should == Order.total_gt(10).proxy_options.merge(:joins => {:users => :orders})
51
+ end
52
+
53
+ it "should allow ascending" do
54
+ Company.ascend_by_users_username.proxy_options.should == User.ascend_by_username.proxy_options.merge(:joins => :users)
55
+ end
56
+
57
+ it "should allow descending" do
58
+ Company.descend_by_users_username.proxy_options.should == User.descend_by_username.proxy_options.merge(:joins => :users)
59
+ end
60
+
61
+ it "should allow deep ascending" do
62
+ Company.ascend_by_users_orders_total.proxy_options.should == Order.ascend_by_total.proxy_options.merge(:joins => {:users => :orders})
63
+ end
64
+
65
+ it "should allow deep descending" do
66
+ Company.descend_by_users_orders_total.proxy_options.should == Order.descend_by_total.proxy_options.merge(:joins => {:users => :orders})
67
+ end
68
+
69
+ it "should include optional associations" do
70
+ pending # this is a problem with using inner joins and left outer joins
71
+ Company.create
72
+ company = Company.create
73
+ user = company.users.create
74
+ order = user.orders.create(:total => 20, :taxes => 3)
75
+ Company.ascend_by_users_orders_total.all.should == Company.all
76
+ end
77
+
78
+ it "should not create the same join twice" do
79
+ company = Company.create
80
+ user = company.users.create
81
+ order = user.orders.create(:total => 20, :taxes => 3)
82
+ Company.users_orders_total_gt(10).users_orders_taxes_lt(5).ascend_by_users_orders_total.all.should == Company.all
83
+ end
84
+
85
+ it "should not create the same join twice when traveling through the duplicate join" do
86
+ Company.users_username_like("bjohnson").users_orders_total_gt(100).all.should == Company.all
87
+ end
88
+
89
+ it "should not create the same join twice when traveling through the duplicate join 2" do
90
+ Company.users_orders_total_gt(100).users_orders_line_items_price_gt(20).all.should == Company.all
91
+ end
92
+
93
+ it "should allow the use of :include when a join was created" do
94
+ company = Company.create
95
+ user = company.users.create
96
+ order = user.orders.create(:total => 20, :taxes => 3)
97
+ Company.users_orders_total_gt(10).users_orders_taxes_lt(5).ascend_by_users_orders_total.all(:include => :users).should == Company.all
98
+ end
99
+
100
+ it "should allow the use of deep :include when a join was created" do
101
+ company = Company.create
102
+ user = company.users.create
103
+ order = user.orders.create(:total => 20, :taxes => 3)
104
+ Company.users_orders_total_gt(10).users_orders_taxes_lt(5).ascend_by_users_orders_total.all(:include => {:users => :orders}).should == Company.all
105
+ end
106
+
107
+ it "should allow the use of :include when traveling through the duplicate join" do
108
+ company = Company.create
109
+ user = company.users.create(:username => "bjohnson")
110
+ order = user.orders.create(:total => 20, :taxes => 3)
111
+ Company.users_username_like("bjohnson").users_orders_taxes_lt(5).ascend_by_users_orders_total.all(:include => :users).should == Company.all
112
+ end
113
+
114
+ it "should allow the use of deep :include when traveling through the duplicate join" do
115
+ company = Company.create
116
+ user = company.users.create(:username => "bjohnson")
117
+ order = user.orders.create(:total => 20, :taxes => 3)
118
+ Company.users_orders_taxes_lt(50).ascend_by_users_orders_total.all(:include => {:users => :orders}).should == Company.all
119
+ end
120
+ end
@@ -0,0 +1,253 @@
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
+ end
19
+
20
+ it "should have does not equal" do
21
+ (5..7).each { |age| User.create(:age => age) }
22
+ User.age_does_not_equal(6).all.should == User.find_all_by_age([5,7])
23
+ end
24
+
25
+ it "should have less than" do
26
+ (5..7).each { |age| User.create(:age => age) }
27
+ User.age_less_than(6).all.should == User.find_all_by_age(5)
28
+ end
29
+
30
+ it "should have less than or equal to" do
31
+ (5..7).each { |age| User.create(:age => age) }
32
+ User.age_less_than_or_equal_to(6).all.should == User.find_all_by_age([5, 6])
33
+ end
34
+
35
+ it "should have greater than" do
36
+ (5..7).each { |age| User.create(:age => age) }
37
+ User.age_greater_than(6).all.should == User.find_all_by_age(7)
38
+ end
39
+
40
+ it "should have greater than or equal to" do
41
+ (5..7).each { |age| User.create(:age => age) }
42
+ User.age_greater_than_or_equal_to(6).all.should == User.find_all_by_age([6, 7])
43
+ end
44
+ end
45
+
46
+ context "wildcard conditions" do
47
+ it "should have like" do
48
+ %w(bjohnson thunt).each { |username| User.create(:username => username) }
49
+ User.username_like("john").all.should == User.find_all_by_username("bjohnson")
50
+ end
51
+
52
+ it "should have begins with" do
53
+ %w(bjohnson thunt).each { |username| User.create(:username => username) }
54
+ User.username_begins_with("bj").all.should == User.find_all_by_username("bjohnson")
55
+ end
56
+
57
+ it "should have ends with" do
58
+ %w(bjohnson thunt).each { |username| User.create(:username => username) }
59
+ User.username_ends_with("son").all.should == User.find_all_by_username("bjohnson")
60
+ end
61
+ end
62
+
63
+ context "boolean conditions" do
64
+ it "should have null" do
65
+ ["bjohnson", nil].each { |username| User.create(:username => username) }
66
+ User.username_null.all.should == User.find_all_by_username(nil)
67
+ end
68
+
69
+ it "should have empty" do
70
+ ["bjohnson", ""].each { |username| User.create(:username => username) }
71
+ User.username_empty.all.should == User.find_all_by_username("")
72
+ end
73
+ end
74
+
75
+ context "any and all conditions" do
76
+ it "should do nothing if no arguments are passed" do
77
+ User.username_equals_any.proxy_options.should == {}
78
+ end
79
+
80
+ it "should have equals any" do
81
+ %w(bjohnson thunt dgainor).each { |username| User.create(:username => username) }
82
+ User.username_equals_any("bjohnson", "thunt").all == User.find_all_by_username(["bjohnson", "thunt"])
83
+ end
84
+
85
+ it "should have equals all" do
86
+ %w(bjohnson thunt dainor).each { |username| User.create(:username => username) }
87
+ User.username_equals_all("bjohnson", "thunt").all == []
88
+ end
89
+
90
+ it "should have does not equal any" do
91
+ %w(bjohnson thunt dgainor).each { |username| User.create(:username => username) }
92
+ User.username_does_not_equal_any("bjohnson", "thunt").all == User.find_all_by_username("dgainor")
93
+ end
94
+
95
+ it "should have does not equal all" do
96
+ %w(bjohnson thunt dgainor).each { |username| User.create(:username => username) }
97
+ User.username_does_not_equal_all("bjohnson", "thunt").all == User.find_all_by_username("dgainor")
98
+ end
99
+
100
+ it "should have less than any" do
101
+ (5..7).each { |age| User.create(:age => age) }
102
+ User.age_less_than_any(7,6).all == User.find_all_by_age([5, 6])
103
+ end
104
+
105
+ it "should have less than all" do
106
+ (5..7).each { |age| User.create(:age => age) }
107
+ User.age_less_than_all(7,6).all == User.find_all_by_age(5)
108
+ end
109
+
110
+ it "should have less than or equal to any" do
111
+ (5..7).each { |age| User.create(:age => age) }
112
+ User.age_less_than_or_equal_to_any(7,6).all == User.find_all_by_age([5, 6, 7])
113
+ end
114
+
115
+ it "should have less than or equal to all" do
116
+ (5..7).each { |age| User.create(:age => age) }
117
+ User.age_less_than_or_equal_to_all(7,6).all == User.find_all_by_age([5, 6])
118
+ end
119
+
120
+ it "should have less than any" do
121
+ (5..7).each { |age| User.create(:age => age) }
122
+ User.age_greater_than_any(5,6).all == User.find_all_by_age([6, 7])
123
+ end
124
+
125
+ it "should have greater than all" do
126
+ (5..7).each { |age| User.create(:age => age) }
127
+ User.age_greater_than_all(5,6).all == User.find_all_by_age(7)
128
+ end
129
+
130
+ it "should have greater than or equal to any" do
131
+ (5..7).each { |age| User.create(:age => age) }
132
+ User.age_greater_than_or_equal_to_any(5,6).all == User.find_all_by_age([5, 6, 7])
133
+ end
134
+
135
+ it "should have greater than or equal to all" do
136
+ (5..7).each { |age| User.create(:age => age) }
137
+ User.age_greater_than_or_equal_to_all(5,6).all == User.find_all_by_age([6, 7])
138
+ end
139
+
140
+ it "should have like all" do
141
+ %w(bjohnson thunt dgainor).each { |username| User.create(:username => username) }
142
+ User.username_like_all("bjohnson", "thunt").all == []
143
+ User.username_like_all("n", "o").all == User.find_all_by_username(["bjohnson", "thunt"])
144
+ end
145
+
146
+ it "should have like any" do
147
+ %w(bjohnson thunt dgainor).each { |username| User.create(:username => username) }
148
+ User.username_like_all("bjohnson", "thunt").all == User.find_all_by_username(["bjohnson", "thunt"])
149
+ end
150
+
151
+ it "should have begins with all" do
152
+ %w(bjohnson thunt dgainor).each { |username| User.create(:username => username) }
153
+ User.username_begins_with_all("bjohnson", "thunt").all == []
154
+ end
155
+
156
+ it "should have begins with any" do
157
+ %w(bjohnson thunt dgainor).each { |username| User.create(:username => username) }
158
+ User.username_begins_with_any("bj", "th").all == User.find_all_by_username(["bjohnson", "thunt"])
159
+ end
160
+
161
+ it "should have ends with all" do
162
+ %w(bjohnson thunt dgainor).each { |username| User.create(:username => username) }
163
+ User.username_ends_with_all("n", "r").all == []
164
+ end
165
+
166
+ it "should have ends with any" do
167
+ %w(bjohnson thunt dgainor).each { |username| User.create(:username => username) }
168
+ User.username_ends_with_any("n", "r").all == User.find_all_by_username(["bjohnson", "dgainor"])
169
+ end
170
+ end
171
+
172
+ context "alias conditions" do
173
+ it "should have is" do
174
+ User.age_is(5).proxy_options.should == User.age_equals(5).proxy_options
175
+ end
176
+
177
+ it "should have eq" do
178
+ User.age_eq(5).proxy_options.should == User.age_equals(5).proxy_options
179
+ end
180
+
181
+ it "should have not_equal_to" do
182
+ User.age_not_equal_to(5).proxy_options.should == User.age_does_not_equal(5).proxy_options
183
+ end
184
+
185
+ it "should have is_not" do
186
+ # This is matching "not" first. How do you give priority in a regex? Because it's matching the
187
+ # 'not' condition and thinking the column is 'age_is'.
188
+ pending
189
+ User.age_is_not(5).proxy_options.should == User.age_does_not_equal(5).proxy_options
190
+ end
191
+
192
+ it "should have not" do
193
+ User.age_not(5).proxy_options.should == User.age_does_not_equal(5).proxy_options
194
+ end
195
+
196
+ it "should have ne" do
197
+ User.age_ne(5).proxy_options.should == User.age_does_not_equal(5).proxy_options
198
+ end
199
+
200
+ it "should have lt" do
201
+ User.age_lt(5).proxy_options.should == User.age_less_than(5).proxy_options
202
+ end
203
+
204
+ it "should have lte" do
205
+ User.age_lte(5).proxy_options.should == User.age_less_than_or_equal_to(5).proxy_options
206
+ end
207
+
208
+ it "should have gt" do
209
+ User.age_gt(5).proxy_options.should == User.age_greater_than(5).proxy_options
210
+ end
211
+
212
+ it "should have gte" do
213
+ User.age_gte(5).proxy_options.should == User.age_greater_than_or_equal_to(5).proxy_options
214
+ end
215
+
216
+ it "should have contains" do
217
+ User.username_contains(5).proxy_options.should == User.username_like(5).proxy_options
218
+ end
219
+
220
+ it "should have contains" do
221
+ User.username_includes(5).proxy_options.should == User.username_like(5).proxy_options
222
+ end
223
+
224
+ it "should have bw" do
225
+ User.username_bw(5).proxy_options.should == User.username_begins_with(5).proxy_options
226
+ end
227
+
228
+ it "should have ew" do
229
+ User.username_ew(5).proxy_options.should == User.username_ends_with(5).proxy_options
230
+ end
231
+
232
+ it "should have nil" do
233
+ User.username_nil.proxy_options.should == User.username_nil.proxy_options
234
+ end
235
+ end
236
+
237
+ context "searchlogic lambda" do
238
+ it "should be a string" do
239
+ User.username_like("test")
240
+ User.named_scope_options(:username_like).searchlogic_arg_type.should == :string
241
+ end
242
+
243
+ it "should be an integer" do
244
+ User.id_gt(10)
245
+ User.named_scope_options(:id_gt).searchlogic_arg_type.should == :integer
246
+ end
247
+
248
+ it "should be a float" do
249
+ Order.total_gt(10)
250
+ Order.named_scope_options(:total_gt).searchlogic_arg_type.should == :float
251
+ end
252
+ end
253
+ end