sinatra_resource 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/examples/datacatalog/models/user.rb +6 -0
- data/examples/datacatalog/resources/users.rb +4 -0
- data/examples/datacatalog/test/resources/users/users_get_many_test.rb +3 -2
- data/examples/datacatalog/test/resources/users/users_get_one_test.rb +9 -7
- data/examples/datacatalog/test/resources/users/users_post_test.rb +2 -1
- data/examples/datacatalog/test/resources/users/users_put_test.rb +4 -2
- data/lib/resource.rb +9 -4
- data/sinatra_resource.gemspec +1 -1
- metadata +1 -1
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.2
|
@@ -78,7 +78,8 @@ class UsersGetManyResourceTest < ResourceTestCase
|
|
78
78
|
test "body elements should be correct" do
|
79
79
|
parsed_response_body.each do |element|
|
80
80
|
if element["id"] == user_for(role).id
|
81
|
-
assert_properties(%w(name email role _api_key
|
81
|
+
assert_properties(%w(name email role _api_key token
|
82
|
+
id created_at updated_at), element)
|
82
83
|
else
|
83
84
|
assert_properties(%w(name id created_at updated_at), element)
|
84
85
|
end
|
@@ -109,7 +110,7 @@ class UsersGetManyResourceTest < ResourceTestCase
|
|
109
110
|
assert_equal EMAILS, actual.sort
|
110
111
|
end
|
111
112
|
|
112
|
-
docs_properties %w(name email role _api_key id created_at updated_at)
|
113
|
+
docs_properties %w(name email role _api_key token id created_at updated_at)
|
113
114
|
end
|
114
115
|
end
|
115
116
|
|
@@ -47,29 +47,31 @@ class UsersGetOneResourceTest < ResourceTestCase
|
|
47
47
|
before do
|
48
48
|
get "/#{@user.id}", :api_key => api_key_for(role)
|
49
49
|
end
|
50
|
-
|
50
|
+
|
51
51
|
use "return 200 Ok"
|
52
52
|
doc_properties %w(name id created_at updated_at)
|
53
53
|
end
|
54
54
|
end
|
55
|
-
|
55
|
+
|
56
56
|
context "owner : get /:id" do
|
57
57
|
before do
|
58
58
|
get "/#{@user.id}", :api_key => @user._api_key
|
59
59
|
end
|
60
|
-
|
60
|
+
|
61
61
|
use "return 200 Ok"
|
62
|
-
doc_properties %w(name email role _api_key
|
62
|
+
doc_properties %w(name email role _api_key token
|
63
|
+
id created_at updated_at)
|
63
64
|
end
|
64
|
-
|
65
|
+
|
65
66
|
%w(admin).each do |role|
|
66
67
|
context "#{role} : get /:id" do
|
67
68
|
before do
|
68
69
|
get "/#{@user.id}", :api_key => api_key_for(role)
|
69
70
|
end
|
70
|
-
|
71
|
+
|
71
72
|
use "return 200 Ok"
|
72
|
-
doc_properties %w(name email role _api_key
|
73
|
+
doc_properties %w(name email role _api_key token
|
74
|
+
id created_at updated_at)
|
73
75
|
end
|
74
76
|
end
|
75
77
|
|
@@ -110,7 +110,8 @@ class UsersPostResourceTest < ResourceTestCase
|
|
110
110
|
use "return 201 Created"
|
111
111
|
location_header "users"
|
112
112
|
use "one new user"
|
113
|
-
doc_properties %w(name email role _api_key
|
113
|
+
doc_properties %w(name email role _api_key token
|
114
|
+
id created_at updated_at)
|
114
115
|
|
115
116
|
test "should set all fields in database" do
|
116
117
|
user = User.find_by_id(parsed_response_body["id"])
|
@@ -162,7 +162,8 @@ class UsersPutResourceTest < ResourceTestCase
|
|
162
162
|
end
|
163
163
|
|
164
164
|
use "return 200 Ok"
|
165
|
-
doc_properties %w(name email role _api_key
|
165
|
+
doc_properties %w(name email role _api_key token
|
166
|
+
id created_at updated_at)
|
166
167
|
|
167
168
|
test "should change correct fields in database" do
|
168
169
|
user = User.find_by_id(@user.id)
|
@@ -189,7 +190,8 @@ class UsersPutResourceTest < ResourceTestCase
|
|
189
190
|
end
|
190
191
|
|
191
192
|
use "return 200 Ok"
|
192
|
-
doc_properties %w(name email role _api_key
|
193
|
+
doc_properties %w(name email role _api_key token
|
194
|
+
id created_at updated_at)
|
193
195
|
|
194
196
|
test "should change all fields in database" do
|
195
197
|
user = User.find_by_id(@user.id)
|
data/lib/resource.rb
CHANGED
@@ -145,15 +145,20 @@ module SinatraResource
|
|
145
145
|
raise DefinitionError, "property #{name.inspect} already declared in #{self}"
|
146
146
|
end
|
147
147
|
@resource_config[:properties][name] = {}
|
148
|
+
|
148
149
|
if block
|
149
150
|
@resource_config[:properties][name][:w] = :nobody
|
150
151
|
@resource_config[:properties][name][:read_proc] = block
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
@resource_config[:properties][name][kind] = role
|
152
|
+
if access_rules[:w] && access_rules[:w] != :nobody
|
153
|
+
raise DefinitionError, "property #{name.inspect} is using block " +
|
154
|
+
"form. :w => :nobody is assumed and cannot be overridden."
|
155
155
|
end
|
156
156
|
end
|
157
|
+
|
158
|
+
access_rules.each_pair do |kind, role|
|
159
|
+
@resource_config[:roles].validate_role(role)
|
160
|
+
@resource_config[:properties][name][kind] = role
|
161
|
+
end
|
157
162
|
end
|
158
163
|
|
159
164
|
# Declare a relation with a block of code.
|
data/sinatra_resource.gemspec
CHANGED