parse_resource 1.7.3 → 1.8.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.
Files changed (65) hide show
  1. data/.DS_Store +0 -0
  2. data/.travis.yml +1 -1
  3. data/Gemfile +4 -8
  4. data/Gemfile.lock +27 -23
  5. data/README.md +81 -2
  6. data/Rakefile +9 -8
  7. data/VERSION +1 -1
  8. data/fixtures/.DS_Store +0 -0
  9. data/fixtures/vcr_cassettes/.DS_Store +0 -0
  10. data/fixtures/vcr_cassettes/test_all.yml +319 -34
  11. data/fixtures/vcr_cassettes/test_attribute_getters.yml +256 -12
  12. data/fixtures/vcr_cassettes/test_attribute_setters.yml +256 -12
  13. data/fixtures/vcr_cassettes/test_authenticate.yml +260 -32
  14. data/fixtures/vcr_cassettes/test_chained_wheres.yml +320 -35
  15. data/fixtures/vcr_cassettes/test_chunk.yml +1359 -0
  16. data/fixtures/vcr_cassettes/test_count.yml +495 -84
  17. data/fixtures/vcr_cassettes/test_create.yml +154 -12
  18. data/fixtures/vcr_cassettes/test_created_at.yml +256 -12
  19. data/fixtures/vcr_cassettes/test_destroy.yml +364 -32
  20. data/fixtures/vcr_cassettes/test_destroy_all.yml +236 -48
  21. data/fixtures/vcr_cassettes/test_each.yml +488 -56
  22. data/fixtures/vcr_cassettes/test_fetching_closest_10.yml +1509 -0
  23. data/fixtures/vcr_cassettes/test_fetching_closest_by_kilometers.yml +1509 -0
  24. data/fixtures/vcr_cassettes/test_fetching_closest_by_miles.yml +1509 -0
  25. data/fixtures/vcr_cassettes/test_fetching_closest_by_radians.yml +1509 -0
  26. data/fixtures/vcr_cassettes/test_fetching_closest_within_box.yml +489 -0
  27. data/fixtures/vcr_cassettes/test_fetching_geopoint_field.yml +489 -0
  28. data/fixtures/vcr_cassettes/test_find.yml +312 -24
  29. data/fixtures/vcr_cassettes/test_find_all_by.yml +170 -34
  30. data/fixtures/vcr_cassettes/test_find_by.yml +174 -38
  31. data/fixtures/vcr_cassettes/test_first.yml +260 -23
  32. data/fixtures/vcr_cassettes/test_id.yml +256 -12
  33. data/fixtures/vcr_cassettes/test_installation_creation.yml +199 -0
  34. data/fixtures/vcr_cassettes/test_installation_creation_validation_check.yml +297 -0
  35. data/fixtures/vcr_cassettes/test_limit.yml +1138 -179
  36. data/fixtures/vcr_cassettes/test_map.yml +488 -56
  37. data/fixtures/vcr_cassettes/test_order_ascending.yml +395 -0
  38. data/fixtures/vcr_cassettes/test_order_descending.yml +446 -0
  39. data/fixtures/vcr_cassettes/test_save.yml +316 -24
  40. data/fixtures/vcr_cassettes/test_save_all_and_destroy_all.yml +869 -0
  41. data/fixtures/vcr_cassettes/test_saving_geo_point_with_quick_init.yml +395 -0
  42. data/fixtures/vcr_cassettes/test_saving_geopoint_with_coords.yml +395 -0
  43. data/fixtures/vcr_cassettes/test_skip.yml +120 -525
  44. data/fixtures/vcr_cassettes/test_update.yml +316 -24
  45. data/fixtures/vcr_cassettes/test_updated_at.yml +316 -24
  46. data/fixtures/vcr_cassettes/test_username_should_be_unique.yml +311 -21
  47. data/fixtures/vcr_cassettes/test_where.yml +117 -25
  48. data/lib/kaminari_extension.rb +60 -0
  49. data/lib/parse_resource.rb +4 -2
  50. data/lib/parse_resource/base.rb +262 -163
  51. data/lib/parse_resource/client.rb +8 -0
  52. data/lib/parse_resource/parse_error.rb +36 -22
  53. data/lib/parse_resource/query.rb +99 -7
  54. data/lib/parse_resource/query_methods.rb +64 -0
  55. data/lib/parse_resource/types/parse_geopoint.rb +19 -0
  56. data/parse_resource.gemspec +29 -9
  57. data/parse_resource.yml +2 -2
  58. data/test/active_model_lint_test.rb +0 -2
  59. data/test/helper.rb +13 -3
  60. data/test/test_parse_installation.rb +41 -0
  61. data/test/test_parse_resource.rb +108 -20
  62. data/test/test_parse_user.rb +4 -7
  63. data/test/test_query_options.rb +0 -38
  64. data/test/test_types.rb +186 -0
  65. metadata +38 -31
@@ -3,8 +3,8 @@ development:
3
3
  master_key: <%= ENV["PARSE_RESOURCE_MASTER_KEY"] %>
4
4
 
5
5
  test:
6
- app_id: <%= ENV["PARSE_RESOURCE_APPLICATION_ID"] %>
7
- master_key: <%= ENV["PARSE_RESOURCE_MASTER_KEY"] %>
6
+ app_id: tIcrV2dwbkT7AqjU8Cn8FZFU60hk5qCnMXlJnJQq
7
+ master_key: H6xYlZzvwBZHUBjoyrFKXkWZoCVfqrmC3ARXMZjq
8
8
 
9
9
 
10
10
  production:
@@ -1,8 +1,6 @@
1
1
  require 'helper'
2
2
  require 'parse_resource'
3
3
 
4
- #path = "parse_resource.yml"
5
- #settings = YAML.load(ERB.new(File.new(path).read).result)['test']
6
4
  ParseResource::Base.load!(ENV["PARSE_RESOURCE_APPLICATION_ID"], ENV["PARSE_RESOURCE_MASTER_KEY"])
7
5
 
8
6
  class Bowl < ParseResource
@@ -7,10 +7,23 @@ rescue Bundler::BundlerError => e
7
7
  $stderr.puts "Run `bundle install` to install missing gems"
8
8
  exit e.status_code
9
9
  end
10
+ begin
11
+ require 'turn/autorun';
12
+ # Turn.config.trace = 8
13
+ Turn.config.format = :outline
14
+ rescue LoadError
15
+ end
10
16
  require 'test/unit'
11
17
  require 'vcr'
12
18
  require 'webmock/test_unit'
13
19
 
20
+ if ENV["PARSE_RESOURCE_APPLICATION_ID"].nil? && ENV["PARSE_RESOURCE_MASTER_KEY"].nil?
21
+ path = "parse_resource.yml"
22
+ settings = YAML.load(ERB.new(File.new(path).read).result)['test']
23
+ ENV["PARSE_RESOURCE_APPLICATION_ID"] = settings['app_id']
24
+ ENV["PARSE_RESOURCE_MASTER_KEY"] = settings['master_key']
25
+ end
26
+
14
27
  VCR.configure do |c|
15
28
  c.cassette_library_dir = 'fixtures/vcr_cassettes'
16
29
  c.hook_into :webmock # or :fakeweb
@@ -22,8 +35,5 @@ end
22
35
  $LOAD_PATH << File.expand_path( File.dirname(__FILE__) + '/../lib/' )
23
36
  require 'parse_resource'
24
37
 
25
-
26
-
27
-
28
38
  class Test::Unit::TestCase
29
39
  end
@@ -0,0 +1,41 @@
1
+ require 'helper'
2
+ require 'parse_resource'
3
+
4
+ ParseResource::Base.load!(ENV["PARSE_RESOURCE_APPLICATION_ID"], ENV["PARSE_RESOURCE_MASTER_KEY"])
5
+
6
+
7
+ class Installation < ParseResource::Base
8
+ end
9
+
10
+ class TestParseUser < Test::Unit::TestCase
11
+ #def setup
12
+ # User.destroy_all
13
+ #end
14
+
15
+ #def teardown
16
+ # User.destroy_all
17
+ #end
18
+
19
+ def test_installation_creation
20
+ VCR.use_cassette('test_installation_creation', :record => :new_episodes) do
21
+ Installation.destroy_all
22
+ i = Installation.create(:deviceType => "ios",
23
+ :deviceToken => "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef",
24
+ :channels => [""])
25
+ assert_not_nil(i.id)
26
+ assert i.errors.empty?
27
+ end
28
+ end
29
+
30
+ def test_installation_creation_validation_check
31
+ VCR.use_cassette('test_installation_creation_validation_check', :record => :new_episodes) do
32
+ Installation.destroy_all
33
+ # missing deviceType
34
+ i = Installation.create(:deviceToken => "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef",
35
+ :channels => [""])
36
+ assert_equal false, i.errors.empty?
37
+ assert_equal "135".to_sym, i.errors.first.first # deviceType must be specified in this operation
38
+ end
39
+ end
40
+
41
+ end
@@ -1,10 +1,6 @@
1
1
  require 'helper'
2
2
  require 'parse_resource'
3
3
 
4
- #path = "parse_resource.yml"
5
- #settings = YAML.load(ERB.new(File.new(path).read).result)['test']
6
- #ParseResource::Base.load!(settings['app_id'], settings['master_key'])
7
-
8
4
  ParseResource::Base.load!(ENV["PARSE_RESOURCE_APPLICATION_ID"], ENV["PARSE_RESOURCE_MASTER_KEY"])
9
5
 
10
6
  class Post < ParseResource::Base
@@ -32,6 +28,10 @@ class Straw < ParseResource::Base
32
28
  fields :title, :body
33
29
  end
34
30
 
31
+ class Event < ParseResource::Base
32
+ field :name
33
+ end
34
+
35
35
  class TestParseResource < Test::Unit::TestCase
36
36
 
37
37
  #def setup
@@ -59,23 +59,24 @@ class TestParseResource < Test::Unit::TestCase
59
59
  Author.destroy_all
60
60
  p1 = Author.create(:name => "bar")
61
61
  p2 = Author.create(:name => "jab")
62
- assert_equal Author.count, 2
63
- assert_equal Author.where(:name => "jab").count, 1
62
+ assert_equal 2, Author.count
63
+ assert_equal 1, Author.where(:name => "jab").count
64
64
  p1.destroy
65
65
  p2.destroy
66
- assert_equal Author.count, 0
66
+ assert_equal 0, Author.count
67
67
  end
68
68
  end
69
69
 
70
70
  def test_initialize_with_args
71
71
  @spoon = Spoon.new(:length => "title1", :width => "ipso")
72
72
  assert @spoon.is_a?(Spoon)
73
- assert_equal @spoon.length, "title1"
74
- assert_equal @spoon.width, "ipso"
73
+ assert_equal "title1", @spoon.length
74
+ assert_equal "ipso", @spoon.width
75
75
  end
76
76
 
77
77
  def test_create
78
78
  VCR.use_cassette('test_create', :record => :new_episodes) do
79
+ Spoon.destroy_all
79
80
  s = Spoon.create(:length => "1234567890created!")
80
81
  assert s.is_a?(Spoon)
81
82
  assert s.id
@@ -85,6 +86,7 @@ class TestParseResource < Test::Unit::TestCase
85
86
 
86
87
  def test_find
87
88
  VCR.use_cassette('test_find', :record => :new_episodes) do
89
+ Spoon.destroy_all
88
90
  p1 = Spoon.create(:length => "Welcome")
89
91
  p2 = Spoon.find(p1.id)
90
92
  assert_equal p2.id, p2.id
@@ -101,6 +103,7 @@ class TestParseResource < Test::Unit::TestCase
101
103
 
102
104
  def test_first
103
105
  VCR.use_cassette('test_first', :record => :new_episodes) do
106
+ Fork.destroy_all
104
107
  f = Fork.create(:points => "firsttt")
105
108
  p = Fork.first
106
109
  assert p.is_a?(Fork)
@@ -146,6 +149,7 @@ class TestParseResource < Test::Unit::TestCase
146
149
 
147
150
  def test_chained_wheres
148
151
  VCR.use_cassette('test_chained_wheres', :record => :new_episodes) do
152
+ Straw.destroy_all
149
153
  p1 = Straw.create(:title => "chained_wheres", :body => "testing")
150
154
  p2 = Straw.create(:title => "chained_wheres", :body => "testing_2")
151
155
  query = Straw.where(:title => "chained_wheres").where(:body => "testing")
@@ -157,6 +161,7 @@ class TestParseResource < Test::Unit::TestCase
157
161
 
158
162
  def test_limit
159
163
  VCR.use_cassette('test_limit', :record => :new_episodes) do
164
+ Post.destroy_all
160
165
  15.times do |i|
161
166
  Post.create(:title => "foo_"+i.to_s)
162
167
  end
@@ -165,16 +170,44 @@ class TestParseResource < Test::Unit::TestCase
165
170
  end
166
171
  end
167
172
 
168
- #def test_skip
169
- # 15.times do |i|
170
- # Post.create(:title => "skip", :author => i)
171
- # end
172
- # post = Post.where(:title => "skip").skip(14).first
173
- # assert_equal post.author, 15
174
- #end
173
+ def test_order_descending
174
+ VCR.use_cassette('test_order_descending', :record => :new_episodes) do
175
+ Event.destroy_all
176
+ e1 = Event.create(:name => "1st")
177
+ e2 = Event.create(:name => "2nd")
178
+ events = Event.order("name desc").all
179
+ assert_equal "2nd", events.first.name
180
+ end
181
+ end
182
+
183
+ def test_order_ascending
184
+ VCR.use_cassette('test_order_ascending', :record => :new_episodes) do
185
+ Author.destroy_all
186
+ e1 = Author.create(:name => "1st")
187
+ e2 = Author.create(:name => "2nd")
188
+ events = Author.order("name asc").all
189
+ assert_equal "1st", events.first.name
190
+ end
191
+ end
192
+
193
+ def test_skip
194
+ VCR.use_cassette('test_skip', :record => :new_episodes) do
195
+ Post.destroy_all
196
+ posts = []
197
+ 15.times do |i|
198
+ posts << Post.new(:title => "skip", :author => "#{i}-author")
199
+ end
200
+ Post.save_all(posts)
201
+ assert_equal 15, Post.count # Sanity check
202
+
203
+ post = Post.where(:title => "skip").skip(14).first
204
+ assert_equal "14-author", post.author # Starts at 0, so this is the next one
205
+ end
206
+ end
175
207
 
176
208
  def test_all
177
209
  VCR.use_cassette('test_all', :record => :new_episodes) do
210
+ Post.destroy_all
178
211
  Post.create(:title => "11222")
179
212
  Post.create(:title => "112ssd22")
180
213
  posts = Post.all
@@ -185,6 +218,7 @@ class TestParseResource < Test::Unit::TestCase
185
218
 
186
219
  def test_attribute_getters
187
220
  VCR.use_cassette('test_attribute_getters', :record => :new_episodes) do
221
+ Post.destroy_all
188
222
  @post = Post.create(:title => "title1")
189
223
  assert_equal @post.attributes['title'], "title1"
190
224
  assert_equal @post.attributes['title'], @post.title
@@ -193,6 +227,7 @@ class TestParseResource < Test::Unit::TestCase
193
227
 
194
228
  def test_attribute_setters
195
229
  VCR.use_cassette('test_attribute_setters', :record => :new_episodes) do
230
+ Post.destroy_all
196
231
  @post = Post.create(:title => "1")
197
232
  @post.body = "newerbody"
198
233
  assert_equal @post.body, "newerbody"
@@ -201,6 +236,7 @@ class TestParseResource < Test::Unit::TestCase
201
236
 
202
237
  def test_save
203
238
  VCR.use_cassette('test_save', :record => :new_episodes) do
239
+ Post.destroy_all
204
240
  @post = Post.create(:title => "testing save")
205
241
  @post.save
206
242
  assert @post.attributes['objectId']
@@ -211,11 +247,12 @@ class TestParseResource < Test::Unit::TestCase
211
247
 
212
248
  def test_each
213
249
  VCR.use_cassette('test_each', :record => :new_episodes) do
214
- #Post.destroy_all
250
+ Post.destroy_all
251
+ ps = []
215
252
  4.times do |i|
216
- #Post.create(:title => "each", :author => i.to_s)
217
- Post.create(:title => "each")
253
+ ps << Post.create(:title => "each")
218
254
  end
255
+ Post.save_all(ps)
219
256
  posts = Post.where(:title => "each")
220
257
  posts.each do |p|
221
258
  assert_equal p.title, "each"
@@ -225,7 +262,7 @@ class TestParseResource < Test::Unit::TestCase
225
262
 
226
263
  def test_map
227
264
  VCR.use_cassette('test_map', :record => :new_episodes) do
228
- #Post.destroy_all
265
+ Post.destroy_all
229
266
  4.times do |i|
230
267
  Post.create(:title => "map")
231
268
  end
@@ -236,6 +273,7 @@ class TestParseResource < Test::Unit::TestCase
236
273
 
237
274
  def test_id
238
275
  VCR.use_cassette('test_id', :record => :new_episodes) do
276
+ Post.destroy_all
239
277
  @post = Post.create(:title => "testing id")
240
278
  assert @post.respond_to?(:id)
241
279
  assert @post.id
@@ -245,6 +283,7 @@ class TestParseResource < Test::Unit::TestCase
245
283
 
246
284
  def test_created_at
247
285
  VCR.use_cassette('test_created_at', :record => :new_episodes) do
286
+ Post.destroy_all
248
287
  @post = Post.create(:title => "testing created_at")
249
288
  assert @post.respond_to?(:created_at)
250
289
  assert @post.created_at
@@ -254,6 +293,7 @@ class TestParseResource < Test::Unit::TestCase
254
293
 
255
294
  def test_updated_at
256
295
  VCR.use_cassette('test_updated_at', :record => :new_episodes) do
296
+ Post.destroy_all
257
297
  @post = Post.create(:title => "testing updated_at")
258
298
  @post.title = "something else"
259
299
  @post.save
@@ -263,6 +303,7 @@ class TestParseResource < Test::Unit::TestCase
263
303
 
264
304
  def test_update
265
305
  VCR.use_cassette('test_update', :record => :new_episodes) do
306
+ Post.destroy_all
266
307
  @post = Post.create(:title => "stale title")
267
308
  updated_once = @post.updated_at
268
309
  @post.update(:title => "updated title")
@@ -275,6 +316,7 @@ class TestParseResource < Test::Unit::TestCase
275
316
 
276
317
  def test_destroy
277
318
  VCR.use_cassette('test_destroy', :record => :new_episodes) do
319
+ Post.destroy_all
278
320
  p = Post.create(:title => "hello1234567890abc!")
279
321
  id = p.id
280
322
  p.destroy
@@ -290,4 +332,50 @@ class TestParseResource < Test::Unit::TestCase
290
332
  assert p.valid?
291
333
  end
292
334
 
335
+ def test_to_pointer
336
+ VCR.use_cassette('test_to_pointer', :record => :new_episodes) do
337
+ p = Post.create
338
+ array = {"__type" => "Pointer", "className"=>"Post", "objectId" => p.id}
339
+ assert_equal array, p.to_pointer
340
+ end
341
+ end
342
+
343
+ def test_to_date_object
344
+ VCR.use_cassette('test_to_date_object', :record => :new_episodes) do
345
+ date = DateTime.strptime("Thu, 11 Oct 2012 10:20:40 -0700", '%a, %d %b %Y %H:%M:%S %z')
346
+ array = {"__type"=>"Date", "iso"=>"2012-10-11T10:20:40-07:00"}
347
+ date_pointer = Post.to_date_object(date)
348
+ assert_equal array["__type"], date_pointer["__type"]
349
+ assert date_pointer["iso"].start_with?("2012-10-11") # TODO: figure out a way around the time zone issue
350
+ end
351
+ end
352
+
353
+ def test_save_all_and_destroy_all
354
+ VCR.use_cassette('test_save_all_and_destroy_all', :record => :new_episodes) do
355
+ Post.destroy_all
356
+ objs = []
357
+ 25.times { |t| objs << Post.new(:title => "post #{t}") }
358
+ Post.save_all(objs)
359
+ assert_equal 25, Post.count
360
+ Post.destroy_all(objs)
361
+ assert_equal 0, Post.count
362
+ end
363
+ end
364
+
365
+ def test_chunk
366
+ VCR.use_cassette('test_chunk', :record => :new_episodes) do
367
+ Post.destroy_all
368
+ objs = []
369
+ 25.times { |t| objs << Post.new(:title => "post") }
370
+ Post.save_all(objs)
371
+ assert_equal 25, Post.count
372
+
373
+ posts = Post.where(:title => "post").limit(1000).chunk(5).all
374
+ assert_equal 25, posts.length
375
+
376
+ Post.destroy_all(objs)
377
+ assert_equal 0, Post.count
378
+ end
379
+ end
380
+
293
381
  end
@@ -1,10 +1,6 @@
1
1
  require 'helper'
2
2
  require 'parse_resource'
3
3
 
4
- #path = "parse_resource.yml"
5
- #settings = YAML.load(ERB.new(File.new(path).read).result)['test']
6
- #ParseResource::Base.load!(settings['app_id'], settings['master_key'])
7
-
8
4
  ParseResource::Base.load!(ENV["PARSE_RESOURCE_APPLICATION_ID"], ENV["PARSE_RESOURCE_MASTER_KEY"])
9
5
 
10
6
 
@@ -24,7 +20,7 @@ class TestParseUser < Test::Unit::TestCase
24
20
  #def test_user_should_not_save_without_username_and_password
25
21
  # u = User.new
26
22
  # assert_equal u.valid?, false
27
- # u.username = "fakename"
23
+ # u.username = "fakename"`
28
24
  # assert_equal u.valid?, false
29
25
  # u.password = "fakepass"
30
26
  # assert_equal u.valid?, true
@@ -33,18 +29,19 @@ class TestParseUser < Test::Unit::TestCase
33
29
  #end
34
30
 
35
31
  def test_username_should_be_unique
36
- #User.destroy_all
37
32
  VCR.use_cassette('test_username_should_be_unique', :record => :new_episodes) do
33
+ User.destroy_all
38
34
  u = User.create(:username => "alan", :password => "12345")
39
35
  u2 = User.new(:username => "alan", :password => "56789")
40
36
  u2.save
41
- assert_equal u2.errors.count, 1
37
+ assert_equal 1, u2.errors.count
42
38
  assert_equal nil, u2.id
43
39
  end
44
40
  end
45
41
 
46
42
  def test_authenticate
47
43
  VCR.use_cassette('test_authenticate', :record => :new_episodes) do
44
+ User.destroy_all
48
45
  user = "fake_person"
49
46
  pass = "fake_pass"
50
47
  u1 = User.create(:username => user, :password => pass)
@@ -1,9 +1,6 @@
1
1
  require 'helper'
2
2
  require 'parse_resource'
3
3
 
4
- #path = "parse_resource.yml"
5
- #settings = YAML.load(ERB.new(File.new(path).read).result)['test']
6
- #ParseResource::Base.load!(settings['app_id'], settings['master_key'])
7
4
  ParseResource::Base.load!(ENV["PARSE_RESOURCE_APPLICATION_ID"], ENV["PARSE_RESOURCE_MASTER_KEY"])
8
5
 
9
6
 
@@ -21,39 +18,4 @@ class TestQueryOptions < Test::Unit::TestCase
21
18
  # Event.destroy_all
22
19
  #end
23
20
 
24
- #def test_order
25
- # e1 = Event.create(:name => "1st")
26
- # e2 = Event.create(:name => "2nd")
27
- # events = Event.order("created_at").all
28
- # puts events[0].created_at
29
- # puts events[1].created_at
30
- # assert_equal true, (events[0].created_at < events[1].created_at)
31
- # Event.destroy_all
32
- #end
33
-
34
- def test_skip
35
- VCR.use_cassette('test_skip', :record => :new_episodes) do
36
- num_to_test = 10
37
- num_to_test.times do |i|
38
- Event.create(:name => "#{i}")
39
- end
40
- all_events = []
41
- count = 0
42
- begin
43
- results = Event.skip(count).limit(2).all
44
- all_events += results
45
- count += results.count
46
- end while not results.empty?
47
-
48
- assert_equal true, (all_events.count == num_to_test)
49
-
50
- found_names = []
51
- all_events.each do |event|
52
- assert_equal false, (found_names.include?(event.name))
53
- found_names.push(event.name)
54
- end
55
- end
56
- #Event.destroy_all
57
- end
58
-
59
21
  end