parse-ruby-client 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +15 -0
  2. data/.travis.yml +2 -1
  3. data/Gemfile +4 -6
  4. data/Gemfile.lock +18 -18
  5. data/README.md +1 -1
  6. data/Rakefile +1 -1
  7. data/VERSION +1 -1
  8. data/example.rb +2 -1
  9. data/fixtures/vcr_cassettes/test_batch_update_nils_delete_keys.yml +57 -0
  10. data/fixtures/vcr_cassettes/test_empty_response.yml +72 -0
  11. data/fixtures/vcr_cassettes/test_get_missing.yml +95 -38
  12. data/fixtures/vcr_cassettes/test_image_file_associate_with_object.yml +2089 -0
  13. data/fixtures/vcr_cassettes/test_image_file_save.yml +1928 -0
  14. data/fixtures/vcr_cassettes/test_object_id.yml +56 -0
  15. data/fixtures/vcr_cassettes/test_reset_password.yml +109 -0
  16. data/fixtures/vcr_cassettes/test_retries.yml +357 -0
  17. data/fixtures/vcr_cassettes/test_retries_404.yml +72 -0
  18. data/fixtures/vcr_cassettes/test_retries_404_correct.yml +72 -0
  19. data/fixtures/vcr_cassettes/test_retries_json_error.yml +357 -0
  20. data/fixtures/vcr_cassettes/test_retries_server_error.yml +357 -0
  21. data/fixtures/vcr_cassettes/test_server_update.yml +248 -191
  22. data/fixtures/vcr_cassettes/test_user_login.yml +276 -0
  23. data/fixtures/vcr_cassettes/test_xget.yml +280 -0
  24. data/lib/faraday/better_retry.rb +94 -0
  25. data/lib/faraday/extended_parse_json.rb +39 -0
  26. data/lib/faraday/get_method_override.rb +32 -0
  27. data/lib/parse-ruby-client.rb +9 -9
  28. data/lib/parse/batch.rb +2 -3
  29. data/lib/parse/client.rb +72 -161
  30. data/lib/parse/cloud.rb +2 -1
  31. data/lib/parse/datatypes.rb +6 -1
  32. data/lib/parse/error.rb +7 -3
  33. data/lib/parse/installation.rb +18 -0
  34. data/lib/parse/model.rb +2 -1
  35. data/lib/parse/object.rb +7 -1
  36. data/lib/parse/protocol.rb +10 -0
  37. data/lib/parse/push.rb +3 -0
  38. data/lib/parse/query.rb +5 -2
  39. data/lib/parse/user.rb +1 -0
  40. data/lib/parse/util.rb +2 -0
  41. data/parse-ruby-client.gemspec +35 -15
  42. data/test/helper.rb +55 -1
  43. data/test/middleware/better_retry_test.rb +57 -0
  44. data/test/middleware/extend_parse_json_test.rb +55 -0
  45. data/test/test_client.rb +78 -28
  46. data/test/test_datatypes.rb +14 -0
  47. data/test/test_object.rb +16 -0
  48. metadata +39 -34
  49. data/lib/parse/http_client.rb +0 -84
@@ -2,63 +2,113 @@ require 'helper'
2
2
 
3
3
  class TestClient < ParseTestCase
4
4
 
5
+ def stubbed_client(&block)
6
+ stubs = Faraday::Adapter::Test::Stubs.new do |stub|
7
+ yield(stub)
8
+ end
9
+
10
+ client = Parse.init(
11
+ :logger => Logger.new(STDERR).tap {
12
+ |l| l.level = Logger::ERROR
13
+ }
14
+ ) do |b|
15
+ b.adapter :test, stubs
16
+ end
17
+
18
+ [stubs, client]
19
+ end
20
+
5
21
  def test_retries
6
22
  VCR.use_cassette('test_retries', :record => :new_episodes) do
7
- response = mock()
8
- response.stubs(:body).returns({'code' => Parse::Protocol::ERROR_TIMEOUT}.to_json)
9
- response.stubs(:status).returns(500)
10
- @client.session.expects(:request).times(@client.max_retries + 1).returns(response)
23
+
24
+ stubs, client = stubbed_client do |stub|
25
+ (@client.max_retries + 1).times do
26
+ stub.get('/') {[ 500, {}, {
27
+ 'code' => Parse::Protocol::ERROR_TIMEOUT}.to_json
28
+ ]}
29
+ end
30
+ end
31
+
11
32
  assert_raise do
12
- @client.request(nil)
33
+ client.request('/')
13
34
  end
35
+
36
+ stubs.verify_stubbed_calls
14
37
  end
15
38
  end
16
39
 
17
40
  def test_retries_json_error
18
41
  VCR.use_cassette('test_retries_json_error', :record => :new_episodes) do
19
- bad_response = mock()
20
- bad_response.stubs(:body).returns("<HTML>this is not json</HTML>")
21
- bad_response.stubs(:status).returns(500)
42
+ stubs, client = stubbed_client do |stub|
43
+ stub.get('/') {[ 500, {}, '<HTML>this is not json</HTML>' ]}
44
+ stub.get('/') {[ 200, {}, '{"foo":100}' ]}
45
+ end
22
46
 
23
- good_response = mock()
24
- good_response.stubs(:body).returns('{"foo":100}')
25
- good_response.stubs(:status).returns(200)
26
- @client.session.expects(:request).twice.returns(bad_response, good_response)
47
+ assert_equal({ "foo" => 100 }, client.request('/'))
27
48
 
28
- assert_equal({ "foo" => 100 }, @client.request(nil))
49
+ stubs.verify_stubbed_calls
29
50
  end
30
51
  end
31
52
 
32
53
  def test_retries_server_error
33
54
  VCR.use_cassette('test_retries_server_error', :record => :new_episodes) do
34
- bad_response = mock()
35
- bad_response.stubs(:body).returns("{}")
36
- bad_response.stubs(:status).returns(500)
37
55
 
38
- good_response = mock()
39
- good_response.stubs(:body).returns('{"foo":100}')
40
- good_response.stubs(:status).returns(200)
41
- @client.session.expects(:request).twice.returns(bad_response, good_response)
56
+ stubs, client = stubbed_client do |stub|
57
+ stub.get('/') {[ 500, {}, '{}' ]}
58
+ stub.get('/') {[ 200, {}, '{"foo":100}' ]}
59
+ end
60
+
61
+ assert_equal({ "foo" => 100 }, client.request('/'))
42
62
 
43
- assert_equal({ "foo" => 100 }, @client.request(nil))
63
+ stubs.verify_stubbed_calls
64
+ end
65
+ end
66
+
67
+ def test_not_retries_404
68
+ VCR.use_cassette('test_retries_404', :record => :new_episodes) do
69
+
70
+ stubs, client = stubbed_client do |stub|
71
+ stub.get('/') {[ 404, {}, 'Not found' ]}
72
+ stub.get('/') {[ 200, {}, '{"foo":100}' ]}
73
+ end
74
+
75
+ assert_raise do
76
+ client.request('/')
77
+ end
78
+ end
79
+ end
80
+
81
+ def test_not_retries_404_with_correct_json
82
+ VCR.use_cassette('test_retries_404_correct', :record => :new_episodes) do
83
+
84
+ stubs, client = stubbed_client do |stub|
85
+ stub.get('/') {[ 404, {}, '{"foo":100}' ]}
86
+ stub.get('/') {[ 200, {}, '{"foo":100}' ]}
87
+ end
88
+
89
+ assert_raise do
90
+ client.request('/')
91
+ end
44
92
  end
45
93
  end
46
94
 
47
95
  def test_empty_response
48
96
  VCR.use_cassette('test_empty_response', :record => :new_episodes) do
49
- bad_response = mock()
50
- bad_response.stubs(:body).returns('')
51
- JSON.stubs(:parse).returns(nil) # some json parsers return nil instead of raising
52
- bad_response.stubs(:status).returns(403)
97
+ stubs, client = stubbed_client do |stub|
98
+ stub.get('/') {[ 403, {}, 'nonparseable' ]}
99
+ end
53
100
 
54
- @client.session.stubs(:request).returns(bad_response)
101
+ # some json parsers return nil instead of raising
102
+ JSON.stubs(:parse).returns(nil)
55
103
 
56
104
  begin
57
- @client.request(nil)
105
+ client.request('/')
58
106
  raise "client error response should have raised"
59
107
  rescue Parse::ParseProtocolError => e
60
- assert_equal "HTTP Status 403 Body ", e.error
108
+ assert_equal "HTTP Status 403 Body nonparseable", e.error
61
109
  end
110
+
111
+ stubs.verify_stubbed_calls
62
112
  end
63
113
  end
64
114
 
@@ -36,6 +36,20 @@ class TestDatatypes < Test::Unit::TestCase
36
36
  assert_equal parse_date.to_time.utc.to_datetime.iso8601(3), q["time"].to_time.utc.to_datetime.iso8601(3)
37
37
  end
38
38
 
39
+ def test_date_with_bad_data
40
+ assert_raise do
41
+ Parse::Date.new(2014)
42
+ end
43
+ assert_raise do
44
+ Parse::Date.new(nil)
45
+ end
46
+ end
47
+
48
+ def test_date_with_time
49
+ time = Time.parse("01/01/2012 23:59:59")
50
+ assert_equal time, Parse::Date.new(time).to_time
51
+ end
52
+
39
53
  def test_bytes
40
54
  data = {
41
55
  "base64" => Base64.encode64("testing bytes!")
@@ -124,6 +124,13 @@ class TestObject < ParseTestCase
124
124
  end
125
125
  end
126
126
 
127
+ def test_to_json_uses_rest_api_hash
128
+ post = Parse::Object.new "Post"
129
+ hash = { 'post' => [post] }
130
+ parsed = JSON.parse(hash.to_json)
131
+ assert_equal "Post", parsed['post'][0][Parse::Protocol::KEY_CLASS_NAME]
132
+ end
133
+
127
134
  def test_deep_as_json
128
135
  VCR.use_cassette('test_deep_as_json', :record => :new_episodes) do
129
136
  other = Parse::Object.new "Post"
@@ -132,6 +139,15 @@ class TestObject < ParseTestCase
132
139
  end
133
140
  end
134
141
 
142
+ def test_deep_as_json_with_array
143
+ VCR.use_cassette('test_deep_as_json', :record => :new_episodes) do
144
+ other = Parse::Object.new "Post"
145
+ other['date'] = Parse::Date.new(DateTime.now)
146
+ other['array'] = [1, 2]
147
+ assert other.as_json['date']['iso']
148
+ end
149
+ end
150
+
135
151
  def test_nils_delete_keys
136
152
  VCR.use_cassette('test_nils_delete_keys', :record => :new_episodes) do
137
153
  post = Parse::Object.new "Post"
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: parse-ruby-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
5
- prerelease:
4
+ version: 0.3.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Alan deLevie
@@ -10,12 +9,11 @@ authors:
10
9
  autorequire:
11
10
  bindir: bin
12
11
  cert_chain: []
13
- date: 2013-10-08 00:00:00.000000000 Z
12
+ date: 2014-07-31 00:00:00.000000000 Z
14
13
  dependencies:
15
14
  - !ruby/object:Gem::Dependency
16
- name: patron
15
+ name: faraday
17
16
  requirement: !ruby/object:Gem::Requirement
18
- none: false
19
17
  requirements:
20
18
  - - ! '>='
21
19
  - !ruby/object:Gem::Version
@@ -23,15 +21,13 @@ dependencies:
23
21
  type: :runtime
24
22
  prerelease: false
25
23
  version_requirements: !ruby/object:Gem::Requirement
26
- none: false
27
24
  requirements:
28
25
  - - ! '>='
29
26
  - !ruby/object:Gem::Version
30
27
  version: '0'
31
28
  - !ruby/object:Gem::Dependency
32
- name: iron_mq
29
+ name: faraday_middleware
33
30
  requirement: !ruby/object:Gem::Requirement
34
- none: false
35
31
  requirements:
36
32
  - - ! '>='
37
33
  - !ruby/object:Gem::Version
@@ -39,7 +35,6 @@ dependencies:
39
35
  type: :runtime
40
36
  prerelease: false
41
37
  version_requirements: !ruby/object:Gem::Requirement
42
- none: false
43
38
  requirements:
44
39
  - - ! '>='
45
40
  - !ruby/object:Gem::Version
@@ -47,7 +42,6 @@ dependencies:
47
42
  - !ruby/object:Gem::Dependency
48
43
  name: bundler
49
44
  requirement: !ruby/object:Gem::Requirement
50
- none: false
51
45
  requirements:
52
46
  - - ! '>='
53
47
  - !ruby/object:Gem::Version
@@ -55,7 +49,6 @@ dependencies:
55
49
  type: :development
56
50
  prerelease: false
57
51
  version_requirements: !ruby/object:Gem::Requirement
58
- none: false
59
52
  requirements:
60
53
  - - ! '>='
61
54
  - !ruby/object:Gem::Version
@@ -63,7 +56,6 @@ dependencies:
63
56
  - !ruby/object:Gem::Dependency
64
57
  name: shoulda
65
58
  requirement: !ruby/object:Gem::Requirement
66
- none: false
67
59
  requirements:
68
60
  - - ! '>='
69
61
  - !ruby/object:Gem::Version
@@ -71,7 +63,6 @@ dependencies:
71
63
  type: :development
72
64
  prerelease: false
73
65
  version_requirements: !ruby/object:Gem::Requirement
74
- none: false
75
66
  requirements:
76
67
  - - ! '>='
77
68
  - !ruby/object:Gem::Version
@@ -79,7 +70,6 @@ dependencies:
79
70
  - !ruby/object:Gem::Dependency
80
71
  name: test-unit
81
72
  requirement: !ruby/object:Gem::Requirement
82
- none: false
83
73
  requirements:
84
74
  - - '='
85
75
  - !ruby/object:Gem::Version
@@ -87,7 +77,6 @@ dependencies:
87
77
  type: :development
88
78
  prerelease: false
89
79
  version_requirements: !ruby/object:Gem::Requirement
90
- none: false
91
80
  requirements:
92
81
  - - '='
93
82
  - !ruby/object:Gem::Version
@@ -95,7 +84,6 @@ dependencies:
95
84
  - !ruby/object:Gem::Dependency
96
85
  name: mocha
97
86
  requirement: !ruby/object:Gem::Requirement
98
- none: false
99
87
  requirements:
100
88
  - - '='
101
89
  - !ruby/object:Gem::Version
@@ -103,7 +91,6 @@ dependencies:
103
91
  type: :development
104
92
  prerelease: false
105
93
  version_requirements: !ruby/object:Gem::Requirement
106
- none: false
107
94
  requirements:
108
95
  - - '='
109
96
  - !ruby/object:Gem::Version
@@ -111,7 +98,6 @@ dependencies:
111
98
  - !ruby/object:Gem::Dependency
112
99
  name: jeweler
113
100
  requirement: !ruby/object:Gem::Requirement
114
- none: false
115
101
  requirements:
116
102
  - - ~>
117
103
  - !ruby/object:Gem::Version
@@ -119,7 +105,6 @@ dependencies:
119
105
  type: :development
120
106
  prerelease: false
121
107
  version_requirements: !ruby/object:Gem::Requirement
122
- none: false
123
108
  requirements:
124
109
  - - ~>
125
110
  - !ruby/object:Gem::Version
@@ -127,7 +112,6 @@ dependencies:
127
112
  - !ruby/object:Gem::Dependency
128
113
  name: simplecov
129
114
  requirement: !ruby/object:Gem::Requirement
130
- none: false
131
115
  requirements:
132
116
  - - ! '>='
133
117
  - !ruby/object:Gem::Version
@@ -135,7 +119,6 @@ dependencies:
135
119
  type: :development
136
120
  prerelease: false
137
121
  version_requirements: !ruby/object:Gem::Requirement
138
- none: false
139
122
  requirements:
140
123
  - - ! '>='
141
124
  - !ruby/object:Gem::Version
@@ -143,7 +126,20 @@ dependencies:
143
126
  - !ruby/object:Gem::Dependency
144
127
  name: webmock
145
128
  requirement: !ruby/object:Gem::Requirement
146
- none: false
129
+ requirements:
130
+ - - ~>
131
+ - !ruby/object:Gem::Version
132
+ version: 1.9.0
133
+ type: :development
134
+ prerelease: false
135
+ version_requirements: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ~>
138
+ - !ruby/object:Gem::Version
139
+ version: 1.9.0
140
+ - !ruby/object:Gem::Dependency
141
+ name: vcr
142
+ requirement: !ruby/object:Gem::Requirement
147
143
  requirements:
148
144
  - - ! '>='
149
145
  - !ruby/object:Gem::Version
@@ -151,15 +147,13 @@ dependencies:
151
147
  type: :development
152
148
  prerelease: false
153
149
  version_requirements: !ruby/object:Gem::Requirement
154
- none: false
155
150
  requirements:
156
151
  - - ! '>='
157
152
  - !ruby/object:Gem::Version
158
153
  version: '0'
159
154
  - !ruby/object:Gem::Dependency
160
- name: vcr
155
+ name: pry
161
156
  requirement: !ruby/object:Gem::Requirement
162
- none: false
163
157
  requirements:
164
158
  - - ! '>='
165
159
  - !ruby/object:Gem::Version
@@ -167,7 +161,6 @@ dependencies:
167
161
  type: :development
168
162
  prerelease: false
169
163
  version_requirements: !ruby/object:Gem::Requirement
170
- none: false
171
164
  requirements:
172
165
  - - ! '>='
173
166
  - !ruby/object:Gem::Version
@@ -203,16 +196,26 @@ files:
203
196
  - fixtures/vcr_cassettes/test_decrement.yml
204
197
  - fixtures/vcr_cassettes/test_deep_parse.yml
205
198
  - fixtures/vcr_cassettes/test_destroy.yml
199
+ - fixtures/vcr_cassettes/test_empty_response.yml
206
200
  - fixtures/vcr_cassettes/test_eq_pointerize.yml
207
201
  - fixtures/vcr_cassettes/test_equality.yml
208
202
  - fixtures/vcr_cassettes/test_get.yml
209
203
  - fixtures/vcr_cassettes/test_get_missing.yml
204
+ - fixtures/vcr_cassettes/test_image_file_associate_with_object.yml
205
+ - fixtures/vcr_cassettes/test_image_file_save.yml
210
206
  - fixtures/vcr_cassettes/test_include.yml
211
207
  - fixtures/vcr_cassettes/test_new_model.yml
212
208
  - fixtures/vcr_cassettes/test_new_object.yml
213
209
  - fixtures/vcr_cassettes/test_nils_delete_keys.yml
210
+ - fixtures/vcr_cassettes/test_object_id.yml
214
211
  - fixtures/vcr_cassettes/test_parse_delete.yml
215
212
  - fixtures/vcr_cassettes/test_pointer.yml
213
+ - fixtures/vcr_cassettes/test_reset_password.yml
214
+ - fixtures/vcr_cassettes/test_retries.yml
215
+ - fixtures/vcr_cassettes/test_retries_404.yml
216
+ - fixtures/vcr_cassettes/test_retries_404_correct.yml
217
+ - fixtures/vcr_cassettes/test_retries_json_error.yml
218
+ - fixtures/vcr_cassettes/test_retries_server_error.yml
216
219
  - fixtures/vcr_cassettes/test_save_with_sub_objects.yml
217
220
  - fixtures/vcr_cassettes/test_saving_boolean_values.yml
218
221
  - fixtures/vcr_cassettes/test_saving_nested_objects.yml
@@ -221,15 +224,19 @@ files:
221
224
  - fixtures/vcr_cassettes/test_text_file_save.yml
222
225
  - fixtures/vcr_cassettes/test_update.yml
223
226
  - fixtures/vcr_cassettes/test_updated_at.yml
227
+ - fixtures/vcr_cassettes/test_user_login.yml
224
228
  - fixtures/vcr_cassettes/test_user_save.yml
225
229
  - fixtures/vcr_cassettes/test_xget.yml
230
+ - lib/faraday/better_retry.rb
231
+ - lib/faraday/extended_parse_json.rb
232
+ - lib/faraday/get_method_override.rb
226
233
  - lib/parse-ruby-client.rb
227
234
  - lib/parse/batch.rb
228
235
  - lib/parse/client.rb
229
236
  - lib/parse/cloud.rb
230
237
  - lib/parse/datatypes.rb
231
238
  - lib/parse/error.rb
232
- - lib/parse/http_client.rb
239
+ - lib/parse/installation.rb
233
240
  - lib/parse/model.rb
234
241
  - lib/parse/object.rb
235
242
  - lib/parse/protocol.rb
@@ -241,6 +248,8 @@ files:
241
248
  - test/cloud_functions/MyCloudCode/cloud/main.js
242
249
  - test/config/global.json
243
250
  - test/helper.rb
251
+ - test/middleware/better_retry_test.rb
252
+ - test/middleware/extend_parse_json_test.rb
244
253
  - test/parsers.jpg
245
254
  - test/test_batch.rb
246
255
  - test/test_client.rb
@@ -258,29 +267,25 @@ files:
258
267
  homepage: http://github.com/adelevie/parse-ruby-client
259
268
  licenses:
260
269
  - MIT
270
+ metadata: {}
261
271
  post_install_message:
262
272
  rdoc_options: []
263
273
  require_paths:
264
274
  - lib
265
275
  required_ruby_version: !ruby/object:Gem::Requirement
266
- none: false
267
276
  requirements:
268
277
  - - ! '>='
269
278
  - !ruby/object:Gem::Version
270
279
  version: '0'
271
- segments:
272
- - 0
273
- hash: -2719138252462662058
274
280
  required_rubygems_version: !ruby/object:Gem::Requirement
275
- none: false
276
281
  requirements:
277
282
  - - ! '>='
278
283
  - !ruby/object:Gem::Version
279
284
  version: '0'
280
285
  requirements: []
281
286
  rubyforge_project:
282
- rubygems_version: 1.8.24
287
+ rubygems_version: 2.2.2
283
288
  signing_key:
284
- specification_version: 3
289
+ specification_version: 4
285
290
  summary: A simple Ruby client for the parse.com REST API
286
291
  test_files: []