leancloud-ruby-client 0.1.1 → 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.
- checksums.yaml +4 -4
- data/Gemfile +1 -0
- data/README.md +144 -116
- data/VERSION +1 -1
- data/example.rb +7 -7
- data/leancloud-ruby-client.gemspec +1 -3
- data/lib/faraday/extended_parse_json.rb +6 -6
- data/lib/leancloud-ruby-client.rb +15 -15
- data/lib/leancloud/application.rb +2 -2
- data/lib/leancloud/batch.rb +6 -6
- data/lib/leancloud/client.rb +39 -14
- data/lib/leancloud/cloud.rb +4 -4
- data/lib/leancloud/datatypes.rb +7 -7
- data/lib/leancloud/error.rb +6 -6
- data/lib/leancloud/installation.rb +5 -5
- data/lib/leancloud/model.rb +3 -3
- data/lib/leancloud/object.rb +15 -15
- data/lib/leancloud/protocol.rb +10 -5
- data/lib/leancloud/push.rb +2 -2
- data/lib/leancloud/query.rb +22 -22
- data/lib/leancloud/user.rb +12 -6
- data/lib/leancloud/util.rb +18 -18
- data/test/helper.rb +5 -7
- data/test/test_batch.rb +18 -18
- data/test/test_client.rb +17 -17
- data/test/test_cloud.rb +7 -7
- data/test/test_datatypes.rb +23 -23
- data/test/test_file.rb +5 -5
- data/test/test_init.rb +4 -4
- data/test/test_init_from_cloud_code.rb +2 -2
- data/test/test_installation.rb +6 -6
- data/test/test_model.rb +4 -4
- data/test/test_object.rb +45 -45
- data/test/test_push.rb +7 -7
- data/test/test_query.rb +39 -39
- data/test/test_throttle.rb +1 -1
- data/test/test_user.rb +9 -9
- metadata +23 -24
- data/Gemfile.lock +0 -86
@@ -2,7 +2,7 @@ require 'helper'
|
|
2
2
|
|
3
3
|
class TestInitFromCloudCode < Test::Unit::TestCase
|
4
4
|
def test_init
|
5
|
-
client =
|
6
|
-
assert_equal
|
5
|
+
client = LC.init_from_cloud_code("test/config/global.json")
|
6
|
+
assert_equal LC::Client, client.class
|
7
7
|
end
|
8
8
|
end
|
data/test/test_installation.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
|
-
class TestInstallation <
|
3
|
+
class TestInstallation < LCTestCase
|
4
4
|
def test_retrieving_installation_data
|
5
5
|
installation_data = {
|
6
6
|
"appIdentifier"=>"net.project_name",
|
7
|
-
"appName"=>"
|
7
|
+
"appName"=>"LC Project",
|
8
8
|
"appVersion"=>"35",
|
9
9
|
"badge"=>9,
|
10
10
|
"channels"=>["", "channel1"],
|
@@ -19,25 +19,25 @@ class TestInstallation < AVTestCase
|
|
19
19
|
}
|
20
20
|
|
21
21
|
VCR.use_cassette('test_get_installation') do
|
22
|
-
installation =
|
22
|
+
installation = LC::Installation.get "987"
|
23
23
|
assert_equal installation_data, installation
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
27
|
def test_changing_channels
|
28
|
-
installation =
|
28
|
+
installation = LC::Installation.new "987"
|
29
29
|
installation.channels = ["", "my-channel"]
|
30
30
|
assert_equal ["", "my-channel"], installation["channels"]
|
31
31
|
end
|
32
32
|
|
33
33
|
def test_changing_badges
|
34
|
-
installation =
|
34
|
+
installation = LC::Installation.new "987"
|
35
35
|
installation.badge = 5
|
36
36
|
assert_equal 5, installation["badge"]
|
37
37
|
end
|
38
38
|
|
39
39
|
def test_updating_installation_data
|
40
|
-
installation =
|
40
|
+
installation = LC::Installation.new "987"
|
41
41
|
installation.channels = ["", "my-channel"]
|
42
42
|
installation.badge = 5
|
43
43
|
|
data/test/test_model.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
|
-
class TestModelObject <
|
3
|
+
class TestModelObject < LC::Model
|
4
4
|
end
|
5
5
|
|
6
|
-
class TestModel <
|
6
|
+
class TestModel < LCTestCase
|
7
7
|
|
8
8
|
def test_new
|
9
9
|
VCR.use_cassette('test_new_model', :record => :new_episodes) do
|
@@ -16,7 +16,7 @@ class TestModel < AVTestCase
|
|
16
16
|
|
17
17
|
def test_superclass
|
18
18
|
tmo = TestModelObject
|
19
|
-
assert_equal tmo.superclass,
|
20
|
-
assert_equal tmo.superclass.superclass,
|
19
|
+
assert_equal tmo.superclass, LC::Model
|
20
|
+
assert_equal tmo.superclass.superclass, LC::Object
|
21
21
|
end
|
22
22
|
end
|
data/test/test_object.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
|
-
class TestObject <
|
3
|
+
class TestObject < LCTestCase
|
4
4
|
|
5
5
|
def test_new?
|
6
6
|
VCR.use_cassette('test_new_object', :record => :new_episodes) do
|
7
|
-
post =
|
7
|
+
post = LC::Object.new "Post"
|
8
8
|
assert_equal post.new?, true
|
9
9
|
post.save
|
10
10
|
assert_equal post.new?, false
|
@@ -13,7 +13,7 @@ class TestObject < AVTestCase
|
|
13
13
|
|
14
14
|
def test_object_id
|
15
15
|
#VCR.use_cassette('test_object_id', :record => :new_episodes) do
|
16
|
-
post =
|
16
|
+
post = LC::Object.new "Post"
|
17
17
|
assert_equal post.id, nil
|
18
18
|
post["title"] = "hello world"
|
19
19
|
post.save
|
@@ -23,7 +23,7 @@ class TestObject < AVTestCase
|
|
23
23
|
|
24
24
|
def test_pointer
|
25
25
|
VCR.use_cassette('test_pointer', :record => :new_episodes) do
|
26
|
-
post =
|
26
|
+
post = LC::Object.new "Post"
|
27
27
|
assert_nil post.pointer
|
28
28
|
|
29
29
|
post.save
|
@@ -35,8 +35,8 @@ class TestObject < AVTestCase
|
|
35
35
|
|
36
36
|
def test_equality
|
37
37
|
VCR.use_cassette('test_equality', :record => :new_episodes) do
|
38
|
-
foo_1 =
|
39
|
-
foo_2 =
|
38
|
+
foo_1 = LC::Object.new("Foo")
|
39
|
+
foo_2 = LC::Object.new("Foo")
|
40
40
|
|
41
41
|
assert foo_1 != foo_2
|
42
42
|
assert foo_1 == foo_1
|
@@ -54,14 +54,14 @@ class TestObject < AVTestCase
|
|
54
54
|
assert foo_1 == foo_1.pointer
|
55
55
|
assert foo_1.pointer == foo_1
|
56
56
|
|
57
|
-
other_foo_1 =
|
57
|
+
other_foo_1 = LC.get("Foo", foo_1.id)
|
58
58
|
assert foo_1 == other_foo_1
|
59
59
|
end
|
60
60
|
end
|
61
61
|
|
62
62
|
def test_created_at
|
63
63
|
VCR.use_cassette('test_created_at', :record => :new_episodes) do
|
64
|
-
post =
|
64
|
+
post = LC::Object.new "Post"
|
65
65
|
assert_equal post.created_at, nil
|
66
66
|
post.save
|
67
67
|
assert_equal post.created_at.class, DateTime
|
@@ -70,7 +70,7 @@ class TestObject < AVTestCase
|
|
70
70
|
|
71
71
|
def test_updated_at
|
72
72
|
VCR.use_cassette('test_updated_at', :record => :new_episodes) do
|
73
|
-
post =
|
73
|
+
post = LC::Object.new "Post"
|
74
74
|
assert_equal post.updated_at, nil
|
75
75
|
post["title"] = "hello"
|
76
76
|
post.save
|
@@ -83,65 +83,65 @@ class TestObject < AVTestCase
|
|
83
83
|
|
84
84
|
def test_parse_delete
|
85
85
|
VCR.use_cassette('test_parse_delete', :record => :new_episodes) do
|
86
|
-
post =
|
86
|
+
post = LC::Object.new "Post"
|
87
87
|
post.save
|
88
88
|
assert_equal post.id.class, String
|
89
89
|
|
90
|
-
q =
|
90
|
+
q = LC.get("Post", post.id)
|
91
91
|
assert_equal q.id, post.id
|
92
92
|
|
93
93
|
post.parse_delete
|
94
94
|
|
95
|
-
q =
|
95
|
+
q = LC.get("Post", post.id)
|
96
96
|
assert_true q.empty?
|
97
97
|
end
|
98
98
|
end
|
99
99
|
|
100
100
|
def test_deep_parse
|
101
101
|
VCR.use_cassette('test_deep_parse', :record => :new_episodes) do
|
102
|
-
other =
|
102
|
+
other = LC::Object.new "Post"
|
103
103
|
other.save
|
104
|
-
post =
|
104
|
+
post = LC::Object.new "Post"
|
105
105
|
post["other"] = other.pointer
|
106
106
|
post.save
|
107
107
|
|
108
|
-
q =
|
109
|
-
assert_equal
|
108
|
+
q = LC.get("Post", post.id)
|
109
|
+
assert_equal LC::Pointer, q["other"].class
|
110
110
|
assert_equal other.pointer, q["other"]
|
111
111
|
end
|
112
112
|
end
|
113
113
|
|
114
114
|
def test_acls_arent_objects
|
115
115
|
VCR.use_cassette('test_acls_arent_objects', :record => :new_episodes) do
|
116
|
-
post =
|
116
|
+
post = LC::Object.new("Post", "ACL" => {"*" => {"read"=>true}})
|
117
117
|
assert_equal Hash, post['ACL'].class
|
118
118
|
post.save
|
119
119
|
#assert_equal Hash, post.refresh['ACL'].class
|
120
120
|
|
121
|
-
post =
|
121
|
+
post = LC.get("Post", post.id)
|
122
122
|
#assert_equal Hash, post['ACL'].class
|
123
123
|
end
|
124
124
|
end
|
125
125
|
|
126
126
|
def test_to_json_uses_rest_api_hash
|
127
|
-
post =
|
127
|
+
post = LC::Object.new "Post"
|
128
128
|
hash = { 'post' => [post] }
|
129
129
|
parsed = JSON.parse(hash.to_json)
|
130
|
-
assert_equal "Post", parsed['post'][0][
|
130
|
+
assert_equal "Post", parsed['post'][0][LC::Protocol::KEY_CLASS_NAME]
|
131
131
|
end
|
132
132
|
|
133
133
|
def test_deep_as_json
|
134
134
|
VCR.use_cassette('test_deep_as_json', :record => :new_episodes) do
|
135
|
-
other =
|
136
|
-
other['date'] =
|
135
|
+
other = LC::Object.new "Post"
|
136
|
+
other['date'] = LC::Date.new(DateTime.now)
|
137
137
|
assert other.as_json['date']['iso']
|
138
138
|
end
|
139
139
|
end
|
140
140
|
|
141
141
|
def test_deep_as_json_with_array
|
142
142
|
VCR.use_cassette('test_deep_as_json', :record => :new_episodes) do
|
143
|
-
other =
|
144
|
-
other['date'] =
|
143
|
+
other = LC::Object.new "Post"
|
144
|
+
other['date'] = LC::Date.new(DateTime.now)
|
145
145
|
other['array'] = [1, 2]
|
146
146
|
assert other.as_json['date']['iso']
|
147
147
|
end
|
@@ -149,7 +149,7 @@ class TestObject < AVTestCase
|
|
149
149
|
|
150
150
|
def test_nils_delete_keys
|
151
151
|
VCR.use_cassette('test_nils_delete_keys', :record => :new_episodes) do
|
152
|
-
post =
|
152
|
+
post = LC::Object.new "Post"
|
153
153
|
post["title"] = "hello"
|
154
154
|
post.save
|
155
155
|
post["title"] = nil
|
@@ -160,14 +160,14 @@ class TestObject < AVTestCase
|
|
160
160
|
|
161
161
|
def test_saving_nested_objects
|
162
162
|
VCR.use_cassette('test_saving_nested_objects', :record => :new_episodes) do
|
163
|
-
post =
|
164
|
-
post["comment"] =
|
163
|
+
post = LC::Object.new "Post"
|
164
|
+
post["comment"] = LC::Object.new("Comment", "text" => "testing")
|
165
165
|
assert_raise{post.save}
|
166
166
|
end
|
167
167
|
end
|
168
168
|
|
169
169
|
def test_boolean_values_as_json
|
170
|
-
post =
|
170
|
+
post = LC::Object.new "Post"
|
171
171
|
post["read"] = false
|
172
172
|
post["published"] = true
|
173
173
|
safe_json_hash = JSON.parse post.safe_hash.to_json
|
@@ -177,11 +177,11 @@ class TestObject < AVTestCase
|
|
177
177
|
|
178
178
|
def test_saving_boolean_values
|
179
179
|
VCR.use_cassette('test_saving_boolean_values', :record => :new_episodes) do
|
180
|
-
post =
|
180
|
+
post = LC::Object.new "Post"
|
181
181
|
post["read"] = false
|
182
182
|
post["published"] = true
|
183
183
|
post.save
|
184
|
-
retrieved_post =
|
184
|
+
retrieved_post = LC::Query.new("Post")
|
185
185
|
.eq("objectId", post["objectId"]).get.first
|
186
186
|
assert_equal false, retrieved_post["read"]
|
187
187
|
assert_equal true, retrieved_post["published"]
|
@@ -190,7 +190,7 @@ class TestObject < AVTestCase
|
|
190
190
|
|
191
191
|
def test_array_add
|
192
192
|
VCR.use_cassette('test_array_add', :record => :new_episodes) do
|
193
|
-
post =
|
193
|
+
post = LC::Object.new "Post"
|
194
194
|
post.array_add("chapters", "hello")
|
195
195
|
assert_equal ["hello"], post["chapters"]
|
196
196
|
post.save
|
@@ -205,16 +205,16 @@ class TestObject < AVTestCase
|
|
205
205
|
|
206
206
|
def test_array_add_pointerizing
|
207
207
|
VCR.use_cassette('test_array_add_pointerizing', :record => :new_episodes) do
|
208
|
-
post =
|
208
|
+
post = LC::Object.new "Post"
|
209
209
|
|
210
|
-
comment =
|
210
|
+
comment = LC::Object.new("Comment", "text" => "great post!")
|
211
211
|
comment.save
|
212
212
|
post.array_add("comments", comment)
|
213
213
|
assert_equal "great post!", post['comments'][0]['text']
|
214
214
|
post.save
|
215
215
|
assert_equal "great post!", post['comments'][0]['text']
|
216
216
|
|
217
|
-
post =
|
217
|
+
post = LC::Query.new("Post").eq("objectId", post.id).tap { |q| q.include = 'comments' }.get.first
|
218
218
|
assert_equal "great post!", post['comments'][0]['text']
|
219
219
|
#post.save
|
220
220
|
assert_equal "great post!", post['comments'][0]['text']
|
@@ -223,23 +223,23 @@ class TestObject < AVTestCase
|
|
223
223
|
|
224
224
|
def test_array_add_unique
|
225
225
|
VCR.use_cassette('test_array_add_unique', :record => :new_episodes) do
|
226
|
-
post =
|
226
|
+
post = LC::Object.new "Post"
|
227
227
|
post.save
|
228
228
|
|
229
|
-
comment =
|
229
|
+
comment = LC::Object.new("Comment", "text" => "great post!")
|
230
230
|
comment.save
|
231
231
|
|
232
232
|
post.array_add_unique("comments", comment)
|
233
233
|
assert_equal "great post!", post['comments'][0]['text']
|
234
234
|
post.save
|
235
235
|
assert_equal comment, post['comments'][0]
|
236
|
-
assert post['comments'][0].instance_of?(
|
236
|
+
assert post['comments'][0].instance_of?(LC::Pointer) # save returns array pointerized
|
237
237
|
end
|
238
238
|
end
|
239
239
|
|
240
240
|
def test_decrement
|
241
241
|
VCR.use_cassette('test_decrement', :record => :new_episodes) do
|
242
|
-
post =
|
242
|
+
post = LC::Object.new "Post", 'count' => 1
|
243
243
|
post.save
|
244
244
|
|
245
245
|
post.decrement('count')
|
@@ -248,19 +248,19 @@ class TestObject < AVTestCase
|
|
248
248
|
end
|
249
249
|
|
250
250
|
def test_array_add_relation
|
251
|
-
omit("broken test, saving Post results in
|
251
|
+
omit("broken test, saving Post results in LCProtocolError: 111: can't add a relation to an non-relation field")
|
252
252
|
|
253
253
|
VCR.use_cassette('test_array_add_relation', :record => :new_episodes) do
|
254
|
-
post =
|
254
|
+
post = LC::Object.new "Post"
|
255
255
|
post.save
|
256
256
|
|
257
|
-
comment =
|
257
|
+
comment = LC::Object.new "Comment"
|
258
258
|
comment.save
|
259
259
|
|
260
260
|
post.array_add_relation("comments", comment.pointer)
|
261
261
|
post.save
|
262
262
|
|
263
|
-
q =
|
263
|
+
q = LC::Query.new("Comment")
|
264
264
|
q.related_to("comments", post.pointer)
|
265
265
|
comments = q.get
|
266
266
|
assert_equal comments.first["objectId"], comment["objectId"]
|
@@ -269,16 +269,16 @@ class TestObject < AVTestCase
|
|
269
269
|
|
270
270
|
def test_save_with_sub_objects
|
271
271
|
VCR.use_cassette('test_save_with_sub_objects', :record => :new_episodes) do
|
272
|
-
bar =
|
272
|
+
bar = LC::Object.new("Bar", "foobar" => "foobar")
|
273
273
|
bar.save
|
274
274
|
|
275
|
-
foo =
|
275
|
+
foo = LC::Object.new("Foo", "bar" => bar, "bars" => [bar])
|
276
276
|
foo.save
|
277
277
|
|
278
278
|
assert_equal "foobar", foo['bar']['foobar']
|
279
279
|
assert_equal "foobar", foo['bars'][0]['foobar']
|
280
280
|
|
281
|
-
foo =
|
281
|
+
foo = LC::Query.new("Foo").eq("objectId", foo.id).tap { |q| q.include = 'bar,bars' }.get.first
|
282
282
|
|
283
283
|
#foo.save
|
284
284
|
|
data/test/test_push.rb
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
|
-
class TestPush <
|
3
|
+
class TestPush < LCTestCase
|
4
4
|
|
5
5
|
def test_save_without_where
|
6
6
|
data = {:foo => 'bar',
|
7
7
|
:alert => 'message'}
|
8
|
-
pf_push =
|
8
|
+
pf_push = LC::Push.new(data, "some_chan")
|
9
9
|
pf_push.type = 'ios'
|
10
10
|
|
11
|
-
query =
|
11
|
+
query = LC::Query.new(LC::Protocol::CLASS_INSTALLATION).eq('deviceToken', 'baz')
|
12
12
|
|
13
|
-
|
13
|
+
LC::Client.any_instance.expects(:request).with do |uri, method, body, query|
|
14
14
|
hash = JSON.parse(body)
|
15
15
|
assert_equal :post, method
|
16
16
|
assert has_entries('type' => 'ios', 'channel' => "some_chan").matches?([hash])
|
@@ -26,13 +26,13 @@ class TestPush < AVTestCase
|
|
26
26
|
def test_save_with_where_removes_channel
|
27
27
|
data = {:foo => 'bar',
|
28
28
|
:alert => 'message'}
|
29
|
-
pf_push =
|
29
|
+
pf_push = LC::Push.new(data, "some_chan")
|
30
30
|
pf_push.type = 'ios'
|
31
31
|
|
32
|
-
query =
|
32
|
+
query = LC::Query.new(LC::Protocol::CLASS_INSTALLATION).eq('deviceToken', 'baz')
|
33
33
|
pf_push.where = query.where
|
34
34
|
|
35
|
-
|
35
|
+
LC::Client.any_instance.expects(:request).with do |uri, method, body, query|
|
36
36
|
hash = JSON.parse(body)
|
37
37
|
assert_false has_entries('channel' => "some_chan").matches?([hash])
|
38
38
|
assert has_entries('deviceToken' => 'baz').matches?([hash['where']])
|
data/test/test_query.rb
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
|
-
class TestQuery <
|
3
|
+
class TestQuery < LCTestCase
|
4
4
|
|
5
|
-
EMPTY_QUERY_RESPONSE = {
|
5
|
+
EMPTY_QUERY_RESPONSE = {LC::Protocol::KEY_RESULTS => []}
|
6
6
|
|
7
7
|
def test_get
|
8
8
|
VCR.use_cassette('test_get', :record => :new_episodes) do
|
9
|
-
post =
|
9
|
+
post = LC::Object.new "Post"
|
10
10
|
post["title"] = "foo"
|
11
11
|
post.save
|
12
12
|
|
13
|
-
q =
|
13
|
+
q = LC.get("Post", post.id)
|
14
14
|
|
15
15
|
assert_equal q.id, post.id
|
16
16
|
assert_equal q["title"], post["title"]
|
@@ -23,7 +23,7 @@ class TestQuery < AVTestCase
|
|
23
23
|
# I'd rather test this one method than pointlessly test many others.
|
24
24
|
# Thus is life.
|
25
25
|
|
26
|
-
q =
|
26
|
+
q = LC::Query.new "TestQuery"
|
27
27
|
q.add_constraint("points", 5)
|
28
28
|
assert_equal q.where["points"], 5
|
29
29
|
q.add_constraint("player", { "$regex" => "regex voodoo"})
|
@@ -31,8 +31,8 @@ class TestQuery < AVTestCase
|
|
31
31
|
end
|
32
32
|
|
33
33
|
def test_related_to
|
34
|
-
q =
|
35
|
-
pointer =
|
34
|
+
q = LC::Query.new "Comment"
|
35
|
+
pointer = LC::Pointer.new(class_name: "Post", parse_object_id: '1234')
|
36
36
|
q.related_to("comments", pointer)
|
37
37
|
|
38
38
|
assert_not_nil q.where["$relatedTo"]
|
@@ -41,7 +41,7 @@ class TestQuery < AVTestCase
|
|
41
41
|
end
|
42
42
|
|
43
43
|
def test_eq
|
44
|
-
q =
|
44
|
+
q = LC::Query.new "TestQuery"
|
45
45
|
q.eq("points", 5)
|
46
46
|
assert_equal q.where, {"points" => 5}
|
47
47
|
q.eq("player", "michael@jordan.com")
|
@@ -50,33 +50,33 @@ class TestQuery < AVTestCase
|
|
50
50
|
|
51
51
|
def test_eq_pointerize
|
52
52
|
VCR.use_cassette('test_eq_pointerize', :record => :new_episodes) do
|
53
|
-
foo =
|
53
|
+
foo = LC::Object.new("Foo")
|
54
54
|
foo.save
|
55
|
-
bar =
|
55
|
+
bar = LC::Object.new("Bar", "foo" => foo.pointer, "bar" => "bar")
|
56
56
|
bar.save
|
57
57
|
|
58
|
-
assert_equal "bar",
|
59
|
-
assert_equal "bar",
|
58
|
+
assert_equal "bar", LC::Query.new("Bar").eq("foo", foo.pointer).get.first["bar"]
|
59
|
+
assert_equal "bar", LC::Query.new("Bar").eq("foo", foo).get.first["bar"]
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
63
63
|
def test_limit_skip
|
64
64
|
VCR.use_cassette('test_limit_skip', :record => :new_episodes) do
|
65
|
-
q =
|
65
|
+
q = LC::Query.new "TestQuery"
|
66
66
|
q.limit = 2
|
67
67
|
q.skip = 3
|
68
68
|
query_matcher = has_entries(:limit => 2, :skip => 3)
|
69
|
-
|
69
|
+
LC::Client.any_instance.expects(:request).with(anything, :get, nil, query_matcher).returns(EMPTY_QUERY_RESPONSE)
|
70
70
|
q.get
|
71
71
|
end
|
72
72
|
end
|
73
73
|
|
74
74
|
def test_count
|
75
75
|
VCR.use_cassette('test_count', :record => :new_episodes) do
|
76
|
-
q =
|
76
|
+
q = LC::Query.new "TestQuery"
|
77
77
|
q.count = true
|
78
78
|
query_matcher = has_entries(:count => true)
|
79
|
-
|
79
|
+
LC::Client.any_instance.expects(:request).with(anything, :get, nil, query_matcher).returns(EMPTY_QUERY_RESPONSE.merge("count" => 1000))
|
80
80
|
results = q.get
|
81
81
|
assert_equal 1000, results['count']
|
82
82
|
end
|
@@ -84,16 +84,16 @@ class TestQuery < AVTestCase
|
|
84
84
|
|
85
85
|
def test_include
|
86
86
|
VCR.use_cassette('test_include', :record => :new_episodes) do
|
87
|
-
post_1 =
|
87
|
+
post_1 = LC::Object.new "Post"
|
88
88
|
post_1['title'] = 'foo'
|
89
89
|
post_1.save
|
90
90
|
|
91
|
-
post_2 =
|
91
|
+
post_2 = LC::Object.new "Post"
|
92
92
|
post_2['title'] = 'bar'
|
93
93
|
post_2['other'] = post_1.pointer
|
94
94
|
post_2.save
|
95
95
|
|
96
|
-
q =
|
96
|
+
q = LC::Query.new "Post"
|
97
97
|
q.eq('objectId', post_2.parse_object_id)
|
98
98
|
q.include = 'other'
|
99
99
|
|
@@ -103,16 +103,16 @@ class TestQuery < AVTestCase
|
|
103
103
|
|
104
104
|
def test_or
|
105
105
|
#VCR.use_cassette('test_or', :record => :new_episodes) do
|
106
|
-
foo =
|
106
|
+
foo = LC::Object.new "Post"
|
107
107
|
foo["random"] = rand
|
108
108
|
foo.save
|
109
|
-
foo_query =
|
109
|
+
foo_query = LC::Query.new("Post").eq("random", foo["random"])
|
110
110
|
assert_equal 1, foo_query.get.size
|
111
111
|
|
112
|
-
bar =
|
112
|
+
bar = LC::Object.new "Post"
|
113
113
|
bar["random"] = rand
|
114
114
|
bar.save
|
115
|
-
bar_query =
|
115
|
+
bar_query = LC::Query.new("Post").eq("random", bar["random"])
|
116
116
|
assert_equal 1, foo_query.get.size
|
117
117
|
|
118
118
|
query = foo_query.or(bar_query)
|
@@ -121,8 +121,8 @@ class TestQuery < AVTestCase
|
|
121
121
|
end
|
122
122
|
|
123
123
|
def test_in_query
|
124
|
-
outer_query =
|
125
|
-
inner_query =
|
124
|
+
outer_query = LC::Query.new "Outer"
|
125
|
+
inner_query = LC::Query.new "Inner"
|
126
126
|
inner_query.eq("foo", "bar")
|
127
127
|
outer_query.in_query("inner", inner_query)
|
128
128
|
assert_equal({"inner"=>{"$inQuery"=>{"className"=>"Inner", "where"=>{"foo"=>"bar"}}}}, outer_query.where)
|
@@ -130,23 +130,23 @@ class TestQuery < AVTestCase
|
|
130
130
|
|
131
131
|
def test_large_value_in_xget
|
132
132
|
VCR.use_cassette('test_xget', :record => :new_episodes) do
|
133
|
-
post =
|
133
|
+
post = LC::Object.new("Post")
|
134
134
|
post['title']= 'foo'
|
135
135
|
post.save
|
136
136
|
|
137
|
-
other_post =
|
137
|
+
other_post = LC::Object.new("Post")
|
138
138
|
other_post['title']= 'foo'
|
139
139
|
other_post.save
|
140
140
|
|
141
|
-
assert_equal [post],
|
141
|
+
assert_equal [post], LC::Query.new("Post").value_in("objectId", [post.id] + 100.times.map { "x" }).get
|
142
142
|
end
|
143
143
|
end
|
144
144
|
|
145
145
|
def test_bad_response
|
146
146
|
VCR.use_cassette('test_bad_response', :record => :new_episodes) do
|
147
|
-
|
147
|
+
LC::Client.any_instance.expects(:request).returns("crap")
|
148
148
|
assert_raises do
|
149
|
-
|
149
|
+
LC::Query.new("Post").get
|
150
150
|
end
|
151
151
|
end
|
152
152
|
end
|
@@ -155,42 +155,42 @@ class TestQuery < AVTestCase
|
|
155
155
|
VCR.use_cassette('test_contains_all', :record => :new_episodes) do
|
156
156
|
|
157
157
|
#ensure cacti from the previous test to not hang around
|
158
|
-
q =
|
158
|
+
q = LC::Query.new "Cactus"
|
159
159
|
cacti = q.get
|
160
160
|
cacti.each do |cactus|
|
161
161
|
cactus.parse_delete
|
162
162
|
end
|
163
163
|
#end ensure
|
164
164
|
|
165
|
-
cactus =
|
165
|
+
cactus = LC::Object.new "Cactus"
|
166
166
|
cactus['array'] = [1, 2, 5, 6, 7]
|
167
167
|
cactus.save
|
168
168
|
|
169
|
-
second_cactus =
|
169
|
+
second_cactus = LC::Object.new "Cactus"
|
170
170
|
second_cactus['array'] = [3, 4, 5, 6]
|
171
171
|
second_cactus.save
|
172
172
|
|
173
|
-
contains_query =
|
173
|
+
contains_query = LC::Query.new("Cactus").contains_all('array', [5, 6])
|
174
174
|
assert_equal 2, contains_query.get.size
|
175
175
|
|
176
|
-
with_one_query =
|
176
|
+
with_one_query = LC::Query.new("Cactus").contains_all('array', [1,5,6])
|
177
177
|
assert_equal 1, with_one_query.get.size
|
178
178
|
assert_equal [cactus], with_one_query.get
|
179
179
|
|
180
|
-
with_four_query =
|
180
|
+
with_four_query = LC::Query.new("Cactus").contains_all('array', [4,5,6])
|
181
181
|
assert_equal 1, with_four_query.get.size
|
182
182
|
assert_equal [second_cactus], with_four_query.get
|
183
183
|
|
184
|
-
with_nine_query =
|
184
|
+
with_nine_query = LC::Query.new("Cactus").contains_all('array', [9])
|
185
185
|
assert_equal 0, with_nine_query.get.size
|
186
186
|
end
|
187
187
|
end
|
188
188
|
|
189
189
|
def test_cql
|
190
190
|
VCR.use_cassette('test_cql', :record => :new_episodes) do
|
191
|
-
post =
|
191
|
+
post = LC::Object.new 'Post',:title => 'foo'
|
192
192
|
post.save
|
193
|
-
ret =
|
193
|
+
ret = LC::Query.do_cloud_query('select *,count(*) from Post')
|
194
194
|
assert_true ret[:count] > 0
|
195
195
|
assert_true ret[:results].size>0
|
196
196
|
end
|