parse_resource 1.6.3 → 1.7.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.
- data/README.md +31 -3
- data/VERSION +1 -1
- data/lib/base.rb +128 -29
- data/lib/parse_error.rb +34 -0
- data/lib/parse_resource.rb +2 -0
- data/lib/parse_user.rb +16 -5
- data/lib/parse_user_validator.rb +8 -0
- data/lib/query.rb +5 -0
- data/parse_resource.gemspec +6 -2
- data/test/test_associations.rb +88 -0
- data/test/test_parse_resource.rb +11 -9
- data/test/test_parse_user.rb +51 -0
- metadata +27 -23
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
ParseResource
|
2
2
|
=============
|
3
3
|
|
4
|
-
ParseResource makes it easy to interact with Parse.com's REST API. It adheres to the ActiveRecord pattern.
|
4
|
+
ParseResource makes it easy to interact with Parse.com's REST API. It adheres to the ActiveRecord pattern. ParseResource is fully ActiveModel compliant, meaning you can use validations and Rails forms.
|
5
5
|
|
6
6
|
Ruby/Rails developers should feel right at home.
|
7
7
|
|
@@ -26,7 +26,7 @@ Installation
|
|
26
26
|
Include in your `Gemfile`:
|
27
27
|
|
28
28
|
```ruby
|
29
|
-
gem "parse_resource", "~> 1.6.
|
29
|
+
gem "parse_resource", "~> 1.6.3"
|
30
30
|
```
|
31
31
|
|
32
32
|
Or just gem install:
|
@@ -138,6 +138,34 @@ posts.length #=> 5
|
|
138
138
|
Post.where(:bar => "foo").count #=> 1337
|
139
139
|
```
|
140
140
|
|
141
|
+
Associations
|
142
|
+
|
143
|
+
```ruby
|
144
|
+
class Post < ParseResource::Base
|
145
|
+
belongs_to :author
|
146
|
+
fields :title, :body
|
147
|
+
end
|
148
|
+
|
149
|
+
class Author < ParseResource::Base
|
150
|
+
has_many :posts
|
151
|
+
field :name
|
152
|
+
end
|
153
|
+
|
154
|
+
author = Author.create(:name => "RL Stine")
|
155
|
+
post1 = Post.create(:title => "Goosebumps 1")
|
156
|
+
post2 = Post.create(:title => "Goosebumps 2")
|
157
|
+
|
158
|
+
# assign from parent class
|
159
|
+
author.posts << post1
|
160
|
+
author.posts << post2
|
161
|
+
|
162
|
+
# or assign from child class
|
163
|
+
post3 = Post.create(:title => "Goosebumps 3")
|
164
|
+
post3.author = author
|
165
|
+
post3.save
|
166
|
+
```
|
167
|
+
|
168
|
+
|
141
169
|
Documentation
|
142
170
|
-------------
|
143
171
|
[Here](http://rubydoc.info/gems/parse_resource/)
|
@@ -146,7 +174,7 @@ To-do
|
|
146
174
|
--------------
|
147
175
|
* User authentication
|
148
176
|
* Better documentation
|
149
|
-
* Associations
|
177
|
+
* ~~Associations~~
|
150
178
|
* Callbacks
|
151
179
|
* Push notifications
|
152
180
|
* Better type-casting
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.7.0
|
data/lib/base.rb
CHANGED
@@ -6,8 +6,10 @@ require "rest-client"
|
|
6
6
|
require "json"
|
7
7
|
require "active_support/hash_with_indifferent_access"
|
8
8
|
require "query"
|
9
|
+
require "parse_error"
|
9
10
|
|
10
11
|
module ParseResource
|
12
|
+
|
11
13
|
|
12
14
|
class Base
|
13
15
|
# ParseResource::Base provides an easy way to use Ruby to interace with a Parse.com backend
|
@@ -24,14 +26,14 @@ module ParseResource
|
|
24
26
|
HashWithIndifferentAccess = ActiveSupport::HashWithIndifferentAccess
|
25
27
|
|
26
28
|
define_model_callbacks :save, :create, :update, :destroy
|
27
|
-
|
28
|
-
|
29
|
+
|
29
30
|
# Instantiates a ParseResource::Base object
|
30
31
|
#
|
31
32
|
# @params [Hash], [Boolean] a `Hash` of attributes and a `Boolean` that should be false only if the object already exists
|
32
33
|
# @return [ParseResource::Base] an object that subclasses `Parseresource::Base`
|
33
34
|
def initialize(attributes = {}, new=true)
|
34
|
-
attributes = HashWithIndifferentAccess.new(attributes)
|
35
|
+
#attributes = HashWithIndifferentAccess.new(attributes)
|
36
|
+
|
35
37
|
if new
|
36
38
|
@unsaved_attributes = attributes
|
37
39
|
else
|
@@ -66,37 +68,91 @@ module ParseResource
|
|
66
68
|
def self.fields(*args)
|
67
69
|
args.each {|f| field(f)}
|
68
70
|
end
|
71
|
+
|
72
|
+
def self.belongs_to(parent)
|
73
|
+
field(parent)
|
74
|
+
end
|
75
|
+
|
76
|
+
|
77
|
+
def to_pointer
|
78
|
+
{"__type" => "Pointer", "className" => self.class.model_name, "objectId" => self.id}
|
79
|
+
end
|
69
80
|
|
70
81
|
# Creates getter and setter methods for model fields
|
71
82
|
#
|
72
83
|
def create_setters!
|
73
84
|
@attributes.each_pair do |k,v|
|
85
|
+
|
74
86
|
self.class.send(:define_method, "#{k}=") do |val|
|
75
87
|
if k.is_a?(Symbol)
|
76
88
|
k = k.to_s
|
77
89
|
end
|
90
|
+
|
91
|
+
val = val.to_pointer if val.respond_to?(:to_pointer)
|
92
|
+
|
78
93
|
@attributes[k.to_s] = val
|
79
94
|
@unsaved_attributes[k.to_s] = val
|
95
|
+
|
80
96
|
val
|
81
97
|
end
|
98
|
+
|
82
99
|
self.class.send(:define_method, "#{k}") do
|
83
|
-
|
84
|
-
|
100
|
+
|
101
|
+
case @attributes[k]
|
102
|
+
when Hash
|
103
|
+
|
104
|
+
case @attributes[k]["__type"]
|
105
|
+
when "Pointer"
|
106
|
+
result = @attributes[k]["className"].constantize.find(@attributes[k]["objectId"])
|
107
|
+
end #todo: support Dates and other types https://www.parse.com/docs/rest#objects-types
|
108
|
+
|
109
|
+
else
|
110
|
+
result = @attributes[k]
|
85
111
|
end
|
86
|
-
|
87
|
-
|
88
|
-
case @attributes[k.to_s]["__type"]
|
89
|
-
when "Date"
|
90
|
-
return result = @attributes[k.to_s]["iso"]
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
return @attributes[k.to_s]
|
112
|
+
|
113
|
+
result
|
95
114
|
end
|
115
|
+
|
96
116
|
end
|
97
117
|
end
|
98
118
|
|
99
119
|
class << self
|
120
|
+
|
121
|
+
def has_many(children)
|
122
|
+
parent_klass_name = model_name
|
123
|
+
lowercase_parent_klass_name = parent_klass_name.downcase
|
124
|
+
parent_klass = model_name.constantize
|
125
|
+
child_klass_name = children.to_s.singularize.camelize
|
126
|
+
child_klass = child_klass_name.constantize
|
127
|
+
|
128
|
+
if parent_klass_name == "User"
|
129
|
+
parent_klass_name = "_User"
|
130
|
+
end
|
131
|
+
|
132
|
+
@@parent_klass_name = parent_klass_name
|
133
|
+
#@@parent_instance = self
|
134
|
+
|
135
|
+
send(:define_method, children) do
|
136
|
+
@@parent_id = self.id
|
137
|
+
@@parent_instance = self
|
138
|
+
|
139
|
+
|
140
|
+
singleton = child_klass.where(@@parent_klass_name.downcase => @@parent_instance.to_pointer).all
|
141
|
+
|
142
|
+
class << singleton
|
143
|
+
def <<(child)
|
144
|
+
if @@parent_instance.respond_to?(:to_pointer)
|
145
|
+
child.send("#{@@parent_klass_name.downcase}=", @@parent_instance.to_pointer)
|
146
|
+
child.save
|
147
|
+
end
|
148
|
+
super(child)
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
singleton
|
153
|
+
end
|
154
|
+
|
155
|
+
end
|
100
156
|
|
101
157
|
@@settings ||= nil
|
102
158
|
|
@@ -111,7 +167,8 @@ module ParseResource
|
|
111
167
|
def settings
|
112
168
|
if @@settings.nil?
|
113
169
|
path = "config/parse_resource.yml"
|
114
|
-
environment = defined?(Rails) && Rails.respond_to?(:env) ? Rails.env : ENV["RACK_ENV"]
|
170
|
+
#environment = defined?(Rails) && Rails.respond_to?(:env) ? Rails.env : ENV["RACK_ENV"]
|
171
|
+
environment = ENV["RACK_ENV"]
|
115
172
|
@@settings = YAML.load(ERB.new(File.new(path).read).result)[environment]
|
116
173
|
end
|
117
174
|
@@settings
|
@@ -152,6 +209,13 @@ module ParseResource
|
|
152
209
|
def where(*args)
|
153
210
|
Query.new(self).where(*args)
|
154
211
|
end
|
212
|
+
|
213
|
+
# Include the attributes of a parent ojbect in the results
|
214
|
+
# Similar to ActiveRecord eager loading
|
215
|
+
#
|
216
|
+
def include_object(parent)
|
217
|
+
Query.new(self).include_object(parent)
|
218
|
+
end
|
155
219
|
|
156
220
|
# Add this at the end of a method chain to get the count of objects, instead of an Array of objects
|
157
221
|
def count
|
@@ -223,13 +287,30 @@ module ParseResource
|
|
223
287
|
end
|
224
288
|
|
225
289
|
def create
|
226
|
-
|
227
|
-
@
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
290
|
+
opts = {:content_type => "application/json"}
|
291
|
+
attrs = @unsaved_attributes.to_json
|
292
|
+
result = self.resource.post(attrs, opts) do |resp, req, res, &block|
|
293
|
+
|
294
|
+
case resp.code
|
295
|
+
when 400
|
296
|
+
|
297
|
+
# https://www.parse.com/docs/ios/api/Classes/PFConstants.html
|
298
|
+
error_response = JSON.parse(resp)
|
299
|
+
pe = ParseError.new(error_response["code"]).to_array
|
300
|
+
self.errors.add(pe[0], pe[1])
|
301
|
+
|
302
|
+
else
|
303
|
+
@attributes.merge!(JSON.parse(resp))
|
304
|
+
@attributes.merge!(@unsaved_attributes)
|
305
|
+
attributes = HashWithIndifferentAccess.new(attributes)
|
306
|
+
@unsaved_attributes = {}
|
307
|
+
create_setters!
|
308
|
+
end
|
309
|
+
|
310
|
+
self
|
311
|
+
end
|
312
|
+
|
313
|
+
result
|
233
314
|
end
|
234
315
|
|
235
316
|
def save
|
@@ -244,7 +325,9 @@ module ParseResource
|
|
244
325
|
end
|
245
326
|
|
246
327
|
def update(attributes = {})
|
328
|
+
|
247
329
|
attributes = HashWithIndifferentAccess.new(attributes)
|
330
|
+
|
248
331
|
@unsaved_attributes.merge!(attributes)
|
249
332
|
|
250
333
|
put_attrs = @unsaved_attributes
|
@@ -252,15 +335,31 @@ module ParseResource
|
|
252
335
|
put_attrs.delete('createdAt')
|
253
336
|
put_attrs.delete('updatedAt')
|
254
337
|
put_attrs = put_attrs.to_json
|
338
|
+
|
339
|
+
opts = {:content_type => "application/json"}
|
340
|
+
result = self.instance_resource.put(put_attrs, opts) do |resp, req, res, &block|
|
341
|
+
|
342
|
+
case resp.code
|
343
|
+
when 400
|
344
|
+
|
345
|
+
# https://www.parse.com/docs/ios/api/Classes/PFConstants.html
|
346
|
+
error_response = JSON.parse(resp)
|
347
|
+
pe = ParseError.new(error_response["code"], error_response["error"]).to_array
|
348
|
+
self.errors.add(pe[0], pe[1])
|
349
|
+
|
350
|
+
else
|
255
351
|
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
@unsaved_attributes = {}
|
261
|
-
create_setters!
|
352
|
+
@attributes.merge!(JSON.parse(resp))
|
353
|
+
@attributes.merge!(@unsaved_attributes)
|
354
|
+
@unsaved_attributes = {}
|
355
|
+
create_setters!
|
262
356
|
|
263
|
-
|
357
|
+
self
|
358
|
+
end
|
359
|
+
|
360
|
+
result
|
361
|
+
end
|
362
|
+
|
264
363
|
end
|
265
364
|
|
266
365
|
def update_attributes(attributes = {})
|
data/lib/parse_error.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
class ParseError
|
2
|
+
|
3
|
+
def initialize(code, msg="")
|
4
|
+
@msg = msg
|
5
|
+
case code
|
6
|
+
when 202
|
7
|
+
@error = [:username, "must be unique"]
|
8
|
+
when 111
|
9
|
+
@error = [:base, "field set to incorrect type. Error code #{code}. #{msg}"]
|
10
|
+
when 125
|
11
|
+
@error = [:email, "must be valid"]
|
12
|
+
when 122
|
13
|
+
@error = [:file_name, "contains only a-zA-Z0-9_. characters and is between 1 and 36 characters."]
|
14
|
+
when 204
|
15
|
+
@error = [:email, "must not be missing"]
|
16
|
+
when 203
|
17
|
+
@error = [:email, "has already been taken"]
|
18
|
+
when 200
|
19
|
+
@error = [:username, "is missing or empty"]
|
20
|
+
when 201
|
21
|
+
@error = [:password, "is missing or empty"]
|
22
|
+
when 205
|
23
|
+
@error = [:user, "with specified email not found"]
|
24
|
+
else
|
25
|
+
raise "Parse error #{code}: #{@error}"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def to_array
|
30
|
+
@error[1] = @error[1] + " " + @msg
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
data/lib/parse_resource.rb
CHANGED
data/lib/parse_user.rb
CHANGED
@@ -1,15 +1,26 @@
|
|
1
|
+
require 'parse_user_validator'
|
2
|
+
|
1
3
|
class ParseUser < ParseResource::Base
|
2
4
|
fields :username, :password
|
5
|
+
|
6
|
+
validates_presence_of :username
|
7
|
+
validates_presence_of :password
|
8
|
+
#validates_with ParseUserValidator, :on => :create, :on => :save
|
3
9
|
|
4
|
-
def self.
|
10
|
+
def self.authenticate(username, password)
|
5
11
|
base_uri = "https://api.parse.com/1/login"
|
6
12
|
app_id = settings['app_id']
|
7
13
|
master_key = settings['master_key']
|
8
14
|
resource = RestClient::Resource.new(base_uri, app_id, master_key)
|
9
15
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
16
|
+
begin
|
17
|
+
resp = resource.get(:params => {:username => username, :password => password})
|
18
|
+
user = model_name.constantize.new(JSON.parse(resp), false)
|
19
|
+
|
20
|
+
user
|
21
|
+
rescue
|
22
|
+
false
|
23
|
+
end
|
24
|
+
|
14
25
|
end
|
15
26
|
end
|
data/lib/query.rb
CHANGED
data/parse_resource.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "parse_resource"
|
8
|
-
s.version = "1.
|
8
|
+
s.version = "1.7.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Alan deLevie"]
|
12
|
-
s.date = "2011-12-
|
12
|
+
s.date = "2011-12-30"
|
13
13
|
s.description = ""
|
14
14
|
s.email = "adelevie@gmail.com"
|
15
15
|
s.extra_rdoc_files = [
|
@@ -25,8 +25,10 @@ Gem::Specification.new do |s|
|
|
25
25
|
"Rakefile",
|
26
26
|
"VERSION",
|
27
27
|
"lib/base.rb",
|
28
|
+
"lib/parse_error.rb",
|
28
29
|
"lib/parse_resource.rb",
|
29
30
|
"lib/parse_user.rb",
|
31
|
+
"lib/parse_user_validator.rb",
|
30
32
|
"lib/query.rb",
|
31
33
|
"parse_resource.gemspec",
|
32
34
|
"rdoc/ParseResource.html",
|
@@ -36,7 +38,9 @@ Gem::Specification.new do |s|
|
|
36
38
|
"rdoc/rdoc.css",
|
37
39
|
"test/active_model_lint_test.rb",
|
38
40
|
"test/helper.rb",
|
41
|
+
"test/test_associations.rb",
|
39
42
|
"test/test_parse_resource.rb",
|
43
|
+
"test/test_parse_user.rb",
|
40
44
|
"test/test_query.rb"
|
41
45
|
]
|
42
46
|
s.homepage = "http://github.com/adelevie/parse_resource"
|
@@ -0,0 +1,88 @@
|
|
1
|
+
require 'helper'
|
2
|
+
require 'parse_resource'
|
3
|
+
|
4
|
+
path = "parse_resource.yml"
|
5
|
+
settings = YAML.load(ERB.new(File.new(path).read).result)['test']
|
6
|
+
|
7
|
+
ParseResource::Base.load!(settings['app_id'], settings['master_key'])
|
8
|
+
|
9
|
+
class Post < ParseResource::Base
|
10
|
+
belongs_to :author
|
11
|
+
fields :title, :body
|
12
|
+
end
|
13
|
+
|
14
|
+
class Author < ParseResource::Base
|
15
|
+
has_many :posts
|
16
|
+
field :name
|
17
|
+
end
|
18
|
+
|
19
|
+
class TestAssociations < Test::Unit::TestCase
|
20
|
+
|
21
|
+
def setup
|
22
|
+
Post.destroy_all
|
23
|
+
Author.destroy_all
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
def teardown
|
28
|
+
Post.destroy_all
|
29
|
+
Author.destroy_all
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_responds_to_has_many
|
33
|
+
#author = Author.create(:name => "alan")
|
34
|
+
author = Author.new
|
35
|
+
assert_equal true, author.respond_to?(:posts)
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_has_many_returns_an_array
|
39
|
+
author = Author.create(:name => "alex")
|
40
|
+
assert_equal true, author.posts.is_a?(Array)
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_relational_query
|
44
|
+
a = Author.create(:name => "JK Rowling_relational_query")
|
45
|
+
p = Post.create(:title => "test relational query")
|
46
|
+
p.author = a.to_pointer
|
47
|
+
p.save
|
48
|
+
post = Post.include_object(:author).where(:title => "test relational query").first
|
49
|
+
assert_equal Post, post.class
|
50
|
+
assert_equal true, post.author.is_a?(Author)
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_has_many_parent_getter
|
54
|
+
a = Author.create(:name => "RL Stine")
|
55
|
+
p = Post.create(:title => "Goosebumps_has_many_parent_getter")
|
56
|
+
p.author = a.to_pointer
|
57
|
+
p.save
|
58
|
+
assert_equal a.posts.class, Array
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_has_many_child_getter
|
62
|
+
a = Author.create(:name => "JK Rowling_child_getter")
|
63
|
+
p = Post.create(:title => "test has_many child getter")
|
64
|
+
p.author = a.to_pointer
|
65
|
+
p.save
|
66
|
+
assert_equal p.author.id, a.id
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_belongs_to_setter
|
70
|
+
Author.destroy_all
|
71
|
+
Post.destroy_all
|
72
|
+
aa = Author.create(:name => "Shmalter Kirn")
|
73
|
+
pp = Post.create(:title => "Shmup in the Air")
|
74
|
+
pp.author = aa.to_pointer
|
75
|
+
pp.save
|
76
|
+
assert aa.id
|
77
|
+
assert_equal aa.id, pp.author.id
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_has_many_setter
|
81
|
+
author = Author.create(:name => "R.L. Stine")
|
82
|
+
post = Post.create(:title => "Goosebumps_has_many_setter")
|
83
|
+
author.posts << post
|
84
|
+
assert_equal true, (author.posts.length > 0)
|
85
|
+
assert_equal Post, author.posts[0].class
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
data/test/test_parse_resource.rb
CHANGED
@@ -12,6 +12,7 @@ class Post < ParseResource::Base
|
|
12
12
|
end
|
13
13
|
|
14
14
|
class Author < ParseResource::Base
|
15
|
+
has_many :posts
|
15
16
|
field :name
|
16
17
|
end
|
17
18
|
|
@@ -83,12 +84,12 @@ class TestParseResource < Test::Unit::TestCase
|
|
83
84
|
|
84
85
|
def test_chained_wheres
|
85
86
|
Post.destroy_all
|
86
|
-
p1 = Post.create(:title => "
|
87
|
-
p2 = Post.create(:title => "
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
assert_equal
|
87
|
+
p1 = Post.create(:title => "chained_wheres", :body => "testing")
|
88
|
+
p2 = Post.create(:title => "chained_wheres", :body => "testing_2")
|
89
|
+
query = Post.where(:title => "chained_wheres").where(:body => "testing")
|
90
|
+
p3 = query.first
|
91
|
+
|
92
|
+
assert_equal p3.id, p1.id
|
92
93
|
end
|
93
94
|
|
94
95
|
def test_limit
|
@@ -129,7 +130,7 @@ class TestParseResource < Test::Unit::TestCase
|
|
129
130
|
|
130
131
|
def test_save
|
131
132
|
@post = Post.create(:title => "testing save")
|
132
|
-
|
133
|
+
@post.save
|
133
134
|
assert @post.attributes['objectId']
|
134
135
|
assert @post.attributes['updatedAt']
|
135
136
|
assert @post.attributes['createdAt']
|
@@ -138,7 +139,8 @@ class TestParseResource < Test::Unit::TestCase
|
|
138
139
|
def test_each
|
139
140
|
Post.destroy_all
|
140
141
|
4.times do |i|
|
141
|
-
Post.create(:title => "each", :author => i.to_s)
|
142
|
+
#Post.create(:title => "each", :author => i.to_s)
|
143
|
+
Post.create(:title => "each")
|
142
144
|
end
|
143
145
|
posts = Post.where(:title => "each")
|
144
146
|
posts.each do |p|
|
@@ -149,7 +151,7 @@ class TestParseResource < Test::Unit::TestCase
|
|
149
151
|
def test_map
|
150
152
|
Post.destroy_all
|
151
153
|
4.times do |i|
|
152
|
-
Post.create(:title => "map"
|
154
|
+
Post.create(:title => "map")
|
153
155
|
end
|
154
156
|
posts = Post.where(:title => "map")
|
155
157
|
assert_equal posts.map {|p| p}.class, Array
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'helper'
|
2
|
+
require 'parse_resource'
|
3
|
+
|
4
|
+
path = "parse_resource.yml"
|
5
|
+
settings = YAML.load(ERB.new(File.new(path).read).result)['test']
|
6
|
+
|
7
|
+
ParseResource::Base.load!(settings['app_id'], settings['master_key'])
|
8
|
+
|
9
|
+
class User < ParseUser
|
10
|
+
end
|
11
|
+
|
12
|
+
class TestParseUser < Test::Unit::TestCase
|
13
|
+
def setup
|
14
|
+
User.destroy_all
|
15
|
+
end
|
16
|
+
|
17
|
+
def teardown
|
18
|
+
User.destroy_all
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_user_should_not_save_without_username_and_password
|
22
|
+
u = User.new
|
23
|
+
assert_equal u.valid?, false
|
24
|
+
u.username = "fakename"
|
25
|
+
assert_equal u.valid?, false
|
26
|
+
u.password = "fakepass"
|
27
|
+
assert_equal u.valid?, true
|
28
|
+
assert_not_equal u.save, false
|
29
|
+
assert_equal u.id.class, String
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_username_should_be_unique
|
33
|
+
User.destroy_all
|
34
|
+
u = User.create(:username => "alan", :password => "12345")
|
35
|
+
u2 = User.new(:username => "alan", :password => "56789")
|
36
|
+
u2.save
|
37
|
+
assert_equal u2.errors.count, 1
|
38
|
+
assert_equal nil, u2.id
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_authenticate
|
42
|
+
user = "fake_person"
|
43
|
+
pass = "fake_pass"
|
44
|
+
u1 = User.create(:username => user, :password => pass)
|
45
|
+
u2 = User.authenticate(user, pass)
|
46
|
+
assert_equal u1.id, u2.id
|
47
|
+
u3 = User.authenticate("wrong_username", "wrong_pass")
|
48
|
+
assert_equal u3, false
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: parse_resource
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.7.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-12-
|
12
|
+
date: 2011-12-30 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rest-client
|
16
|
-
requirement: &
|
16
|
+
requirement: &70190990670500 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70190990670500
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: activesupport
|
27
|
-
requirement: &
|
27
|
+
requirement: &70190990669960 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70190990669960
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: activemodel
|
38
|
-
requirement: &
|
38
|
+
requirement: &70190990669100 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70190990669100
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: bundler
|
49
|
-
requirement: &
|
49
|
+
requirement: &70190990668540 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ~>
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: 1.0.0
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70190990668540
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: jeweler
|
60
|
-
requirement: &
|
60
|
+
requirement: &70190990668040 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ~>
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: 1.6.4
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70190990668040
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rcov
|
71
|
-
requirement: &
|
71
|
+
requirement: &70190990667460 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ! '>='
|
@@ -76,10 +76,10 @@ dependencies:
|
|
76
76
|
version: '0'
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *70190990667460
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: reek
|
82
|
-
requirement: &
|
82
|
+
requirement: &70190990666960 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
85
85
|
- - ~>
|
@@ -87,10 +87,10 @@ dependencies:
|
|
87
87
|
version: 1.2.8
|
88
88
|
type: :development
|
89
89
|
prerelease: false
|
90
|
-
version_requirements: *
|
90
|
+
version_requirements: *70190990666960
|
91
91
|
- !ruby/object:Gem::Dependency
|
92
92
|
name: rest-client
|
93
|
-
requirement: &
|
93
|
+
requirement: &70190990666460 !ruby/object:Gem::Requirement
|
94
94
|
none: false
|
95
95
|
requirements:
|
96
96
|
- - ! '>='
|
@@ -98,10 +98,10 @@ dependencies:
|
|
98
98
|
version: '0'
|
99
99
|
type: :development
|
100
100
|
prerelease: false
|
101
|
-
version_requirements: *
|
101
|
+
version_requirements: *70190990666460
|
102
102
|
- !ruby/object:Gem::Dependency
|
103
103
|
name: activesupport
|
104
|
-
requirement: &
|
104
|
+
requirement: &70190990665980 !ruby/object:Gem::Requirement
|
105
105
|
none: false
|
106
106
|
requirements:
|
107
107
|
- - ! '>='
|
@@ -109,10 +109,10 @@ dependencies:
|
|
109
109
|
version: '0'
|
110
110
|
type: :development
|
111
111
|
prerelease: false
|
112
|
-
version_requirements: *
|
112
|
+
version_requirements: *70190990665980
|
113
113
|
- !ruby/object:Gem::Dependency
|
114
114
|
name: activemodel
|
115
|
-
requirement: &
|
115
|
+
requirement: &70190990665440 !ruby/object:Gem::Requirement
|
116
116
|
none: false
|
117
117
|
requirements:
|
118
118
|
- - ! '>='
|
@@ -120,7 +120,7 @@ dependencies:
|
|
120
120
|
version: '0'
|
121
121
|
type: :development
|
122
122
|
prerelease: false
|
123
|
-
version_requirements: *
|
123
|
+
version_requirements: *70190990665440
|
124
124
|
description: ''
|
125
125
|
email: adelevie@gmail.com
|
126
126
|
executables: []
|
@@ -137,8 +137,10 @@ files:
|
|
137
137
|
- Rakefile
|
138
138
|
- VERSION
|
139
139
|
- lib/base.rb
|
140
|
+
- lib/parse_error.rb
|
140
141
|
- lib/parse_resource.rb
|
141
142
|
- lib/parse_user.rb
|
143
|
+
- lib/parse_user_validator.rb
|
142
144
|
- lib/query.rb
|
143
145
|
- parse_resource.gemspec
|
144
146
|
- rdoc/ParseResource.html
|
@@ -148,7 +150,9 @@ files:
|
|
148
150
|
- rdoc/rdoc.css
|
149
151
|
- test/active_model_lint_test.rb
|
150
152
|
- test/helper.rb
|
153
|
+
- test/test_associations.rb
|
151
154
|
- test/test_parse_resource.rb
|
155
|
+
- test/test_parse_user.rb
|
152
156
|
- test/test_query.rb
|
153
157
|
homepage: http://github.com/adelevie/parse_resource
|
154
158
|
licenses:
|
@@ -165,7 +169,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
165
169
|
version: '0'
|
166
170
|
segments:
|
167
171
|
- 0
|
168
|
-
hash:
|
172
|
+
hash: 286800748326139219
|
169
173
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
170
174
|
none: false
|
171
175
|
requirements:
|