johnbender-rquery 0.1.2 → 0.2.0

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.
@@ -1,199 +0,0 @@
1
- module ActiveRecord
2
- class Base
3
- def Base.find(limit, conditions)
4
- return [limit, conditions]
5
- end
6
- end
7
- end
8
-
9
- require File.expand_path(File.dirname(__FILE__) + "/../lib/rquery.rb")
10
-
11
- describe ActiveRecord do
12
-
13
- before(:all) do
14
- RQuery.adapter = RQuery::Adapters::Sqlite
15
- end
16
-
17
- #should really set up the find method defined above to use the ruby db libraries and
18
- #create the final sql string
19
- #all run with default adapter
20
-
21
- it "should set up a where method" do
22
- ActiveRecord::Base.respond_to?(:where).should == true
23
- end
24
-
25
- it "should return sql with foo, the operations, and the values for :foo.is <operation> <value>" do
26
-
27
- ActiveRecord::Base.where{
28
- :foo.is == "bar"
29
- }.should == [:all, {:conditions => ["foo = ?", "bar"]}]
30
-
31
- ActiveRecord::Base.where{
32
- :foo.is > 1
33
- }.should == [:all, {:conditions => ["foo > ?", 1]}]
34
-
35
- ActiveRecord::Base.where{
36
- :foo.is < 2
37
- }.should == [:all, {:conditions => ["foo < ?", 2]}]
38
-
39
- ActiveRecord::Base.where{
40
- :foo.is >= 3
41
- }.should == [:all, {:conditions => ["foo >= ?", 3]}]
42
-
43
- ActiveRecord::Base.where{
44
- :foo.is <= 4
45
- }.should == [:all, {:conditions => ["foo <= ?", 4]}]
46
-
47
- end
48
-
49
- it "should return sql with foo, the operations, and the values for :foo.is_not <operation> <value>" do
50
- ActiveRecord::Base.where{
51
- :foo.is_not == "bar"
52
- }.should == [:all, {:conditions => ["foo <> ?", "bar"]}]
53
-
54
- ActiveRecord::Base.where{
55
- :foo.is_not.in 1,2
56
- }.should == [:all, {:conditions => ["foo not in (?)", [1,2]]}]
57
-
58
- ActiveRecord::Base.where{
59
- :foo.is_not.between 1..3
60
- }.should == [:all, {:conditions => ["foo not between ? and ?", 1, 3]}]
61
-
62
- ActiveRecord::Base.where{
63
- :foo.is_not.from 1..3
64
- }.should == [:all, {:conditions => ["foo not between ? and ?", 1, 3]}]
65
-
66
- end
67
-
68
- it "should return sql with foo, the operations, and values for :foo.is.in and :foo.in when used with a list of args, array, and range" do
69
-
70
- resulting_conditions = [:all, {:conditions => ["foo in (?)", [1,2,3,4]]}]
71
-
72
- ActiveRecord::Base.where{
73
- :foo.is.in 1,2,3,4
74
- }.should == resulting_conditions
75
-
76
- ActiveRecord::Base.where{
77
- :foo.is.in [1,2,3,4]
78
- }.should == resulting_conditions
79
-
80
- ActiveRecord::Base.where{
81
- :foo.is.in 1..4
82
- }.should == [:all, {:conditions => ["foo in (?)", 1..4]}]
83
-
84
- ActiveRecord::Base.where{
85
- :foo.in 1,2,3,4
86
- }.should == resulting_conditions
87
-
88
- ActiveRecord::Base.where{
89
- :foo.in [1,2,3,4]
90
- }.should == resulting_conditions
91
-
92
- ActiveRecord::Base.where{
93
- :foo.in 1..4
94
- }.should == [:all, {:conditions => ["foo in (?)", 1..4]}]
95
-
96
- end
97
-
98
- it "should return sql with foo, operations, and values for :foo.is.between and :foo.between when used with a list of args, array, and range" do
99
-
100
- resulting_conditions = [:all, {:conditions => ["foo between ? and ?", 1, 2]}]
101
-
102
- ActiveRecord::Base.where{
103
- :foo.is.between 1,2
104
- }.should == resulting_conditions
105
-
106
- ActiveRecord::Base.where{
107
- :foo.is.between [1,2]
108
- }.should == resulting_conditions
109
-
110
- ActiveRecord::Base.where{
111
- :foo.is.between 1..2
112
- }.should == resulting_conditions
113
-
114
- ActiveRecord::Base.where{
115
- :foo.between 1,2
116
- }.should == resulting_conditions
117
-
118
- ActiveRecord::Base.where{
119
- :foo.between [1,2]
120
- }.should == resulting_conditions
121
-
122
- ActiveRecord::Base.where{
123
- :foo.between 1..2
124
- }.should == resulting_conditions
125
-
126
- end
127
-
128
- it "should return sql with foo, operations, and values for :foo.is.from when used with a list of args, array, and range" do
129
-
130
- resulting_conditions = [:all, {:conditions => ["foo between ? and ?", 1, 2]}]
131
-
132
- ActiveRecord::Base.where{
133
- :foo.is.from 1,2
134
- }.should == resulting_conditions
135
-
136
- ActiveRecord::Base.where{
137
- :foo.is.from [1,2]
138
- }.should == resulting_conditions
139
-
140
- ActiveRecord::Base.where{
141
- :foo.is.from 1..2
142
- }.should == resulting_conditions
143
-
144
- ActiveRecord::Base.where{
145
- :foo.from 1,2
146
- }.should == resulting_conditions
147
-
148
- ActiveRecord::Base.where{
149
- :foo.from [1,2]
150
- }.should == resulting_conditions
151
-
152
- ActiveRecord::Base.where{
153
- :foo.from 1..2
154
- }.should == resulting_conditions
155
-
156
-
157
- end
158
-
159
- it "should return sql with foo, operations, and values for :foo.contains when used with a range, array, and list" do
160
-
161
- resulting_conditions = [:all, {:conditions => ["foo like '%' || ? || '%'", "bar"]}]
162
-
163
- ActiveRecord::Base.where{
164
- :foo.contains "bar"
165
- }.should == resulting_conditions
166
-
167
- end
168
-
169
-
170
- it "should return return the correct group of joined sql after multiple operations" do
171
-
172
- ActiveRecord::Base.where{
173
- :foo.is == "bar"
174
- :foo.is_not.in 1,2,3,4,5
175
- }.should == [:all, {:conditions => ["foo = ? and foo not in (?)", "bar", [1,2,3,4,5]]}]
176
-
177
- end
178
-
179
- it "should return return the correct limit value passed" do
180
-
181
- ActiveRecord::Base.where(:first){
182
- :foo.is == "bar"
183
- :foo.is_not.in 1,2,3,4,5
184
- }.should == [:first, {:conditions => ["foo = ? and foo not in (?)", "bar", [1,2,3,4,5]]}]
185
-
186
- end
187
-
188
- it "should have the correct 'not' keywords in alternating operations" do
189
-
190
- ActiveRecord::Base.where(:first){
191
- :foo.is == "bar"
192
- :foo.is_not.in 1,2,3,4,5
193
- :foo.is > 3
194
- }.should == [:first, {:conditions => ["foo = ? and foo not in (?) and foo > ?", "bar", [1,2,3,4,5], 3]}]
195
-
196
- end
197
-
198
-
199
- end