sinatra_resource 0.4.7 → 0.4.8
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/examples/datacatalog/resources/sources.rb +1 -1
- data/examples/datacatalog/test/resources/sources/sources_get_many_filter_test.rb +2 -2
- data/examples/datacatalog/test/resources/sources/sources_get_many_search_test.rb +1 -1
- data/examples/datacatalog/test/resources/sources/sources_get_many_test.rb +1 -1
- data/examples/datacatalog/test/resources/sources/sources_get_one_test.rb +13 -4
- data/examples/datacatalog/test/resources/sources/sources_post_test.rb +2 -2
- data/examples/datacatalog/test/resources/sources/sources_put_test.rb +4 -4
- data/lib/builder/helpers.rb +13 -3
- data/lib/builder.rb +1 -0
- data/lib/resource.rb +4 -1
- data/sinatra_resource.gemspec +2 -2
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.4.
|
1
|
+
0.4.8
|
@@ -59,7 +59,7 @@ class SourcesGetManyFilterResourceTest < ResourceTestCase
|
|
59
59
|
end
|
60
60
|
|
61
61
|
test "members should only have correct attributes" do
|
62
|
-
correct = %w(title url
|
62
|
+
correct = %w(title url categories id created_at updated_at)
|
63
63
|
@members.each do |member|
|
64
64
|
assert_properties(correct, member)
|
65
65
|
end
|
@@ -92,7 +92,7 @@ class SourcesGetManyFilterResourceTest < ResourceTestCase
|
|
92
92
|
end
|
93
93
|
|
94
94
|
test "members should only have correct attributes" do
|
95
|
-
correct = %w(title url
|
95
|
+
correct = %w(title url categories id created_at updated_at)
|
96
96
|
@members.each do |member|
|
97
97
|
assert_properties(correct, member)
|
98
98
|
end
|
@@ -88,7 +88,7 @@ class SourcesGetManySearchResourceTest < ResourceTestCase
|
|
88
88
|
end
|
89
89
|
|
90
90
|
test "members should only have correct attributes" do
|
91
|
-
correct = %w(title url
|
91
|
+
correct = %w(title url categories id created_at updated_at)
|
92
92
|
@members.each do |member|
|
93
93
|
assert_properties(correct, member)
|
94
94
|
end
|
@@ -55,7 +55,7 @@ class SourcesGetManyResourceTest < ResourceTestCase
|
|
55
55
|
end
|
56
56
|
|
57
57
|
test "members should only have correct attributes" do
|
58
|
-
correct = %w(title url
|
58
|
+
correct = %w(title url categories id created_at updated_at)
|
59
59
|
@members.each do |member|
|
60
60
|
assert_properties(correct, member)
|
61
61
|
end
|
@@ -50,15 +50,15 @@ class SourcesGetOneResourceTest < ResourceTestCase
|
|
50
50
|
)
|
51
51
|
get "/#{@source.id}", :api_key => api_key_for(role)
|
52
52
|
end
|
53
|
-
|
53
|
+
|
54
54
|
after do
|
55
55
|
@category.destroy
|
56
56
|
@categorization.destroy
|
57
57
|
end
|
58
|
-
|
58
|
+
|
59
59
|
use "return 200 Ok"
|
60
|
-
doc_properties %w(title url
|
61
|
-
|
60
|
+
doc_properties %w(title url categories id created_at updated_at)
|
61
|
+
|
62
62
|
test "body should have correct categories" do
|
63
63
|
expected = [
|
64
64
|
{
|
@@ -70,6 +70,15 @@ class SourcesGetOneResourceTest < ResourceTestCase
|
|
70
70
|
assert_equal expected, parsed_response_body["categories"]
|
71
71
|
end
|
72
72
|
end
|
73
|
+
|
74
|
+
context "#{role} : get /:id?show=all" do
|
75
|
+
before do
|
76
|
+
get "/#{@source.id}?show=all", :api_key => api_key_for(role)
|
77
|
+
end
|
78
|
+
|
79
|
+
use "return 200 Ok"
|
80
|
+
doc_properties %w(title url raw categories id created_at updated_at)
|
81
|
+
end
|
73
82
|
end
|
74
83
|
|
75
84
|
end
|
@@ -105,7 +105,7 @@ class SourcesPostResourceTest < ResourceTestCase
|
|
105
105
|
use "return 201 Created"
|
106
106
|
location_header "sources"
|
107
107
|
use "one new source"
|
108
|
-
doc_properties %w(title url
|
108
|
+
doc_properties %w(title url id created_at updated_at categories)
|
109
109
|
|
110
110
|
test "should set all fields in database" do
|
111
111
|
source = Source.find_by_id(parsed_response_body["id"])
|
@@ -156,7 +156,7 @@ class SourcesPostResourceTest < ResourceTestCase
|
|
156
156
|
use "return 201 Created"
|
157
157
|
location_header "sources"
|
158
158
|
use "one new source"
|
159
|
-
doc_properties %w(title url
|
159
|
+
doc_properties %w(title url id created_at updated_at categories)
|
160
160
|
|
161
161
|
test "should set all fields in database" do
|
162
162
|
source = Source.find_by_id(parsed_response_body["id"])
|
@@ -137,7 +137,7 @@ class SourcesPutResourceTest < ResourceTestCase
|
|
137
137
|
end
|
138
138
|
|
139
139
|
use "return 200 Ok"
|
140
|
-
doc_properties %w(title url
|
140
|
+
doc_properties %w(title url id created_at updated_at categories)
|
141
141
|
|
142
142
|
test "should change correct fields in database" do
|
143
143
|
source = Source.find_by_id(@source.id)
|
@@ -164,7 +164,7 @@ class SourcesPutResourceTest < ResourceTestCase
|
|
164
164
|
end
|
165
165
|
|
166
166
|
use "return 200 Ok"
|
167
|
-
doc_properties %w(title url
|
167
|
+
doc_properties %w(title url id created_at updated_at categories)
|
168
168
|
|
169
169
|
test "should change correct fields in database" do
|
170
170
|
source = Source.find_by_id(@source.id)
|
@@ -242,7 +242,7 @@ class SourcesPutResourceTest < ResourceTestCase
|
|
242
242
|
end
|
243
243
|
|
244
244
|
use "return 200 Ok"
|
245
|
-
doc_properties %w(title url
|
245
|
+
doc_properties %w(title url id created_at updated_at categories)
|
246
246
|
|
247
247
|
test "should change correct fields in database" do
|
248
248
|
source = Source.find_by_id(@source.id)
|
@@ -269,7 +269,7 @@ class SourcesPutResourceTest < ResourceTestCase
|
|
269
269
|
end
|
270
270
|
|
271
271
|
use "return 200 Ok"
|
272
|
-
doc_properties %w(title url
|
272
|
+
doc_properties %w(title url id created_at updated_at categories)
|
273
273
|
|
274
274
|
test "should change all fields in database" do
|
275
275
|
source = Source.find_by_id(@source.id)
|
data/lib/builder/helpers.rb
CHANGED
@@ -17,7 +17,12 @@ module SinatraResource
|
|
17
17
|
def build_resource(role, document, resource_config)
|
18
18
|
resource = {}
|
19
19
|
resource_config[:properties].each_pair do |property, hash|
|
20
|
-
if
|
20
|
+
hide = if params[SHOW_KEY] == "all"
|
21
|
+
false
|
22
|
+
else
|
23
|
+
resource_config[:properties][property][:hide_by_default]
|
24
|
+
end
|
25
|
+
if authorized?(:read, role, resource_config, property) && !hide
|
21
26
|
resource[property.to_s] = value(property, document, hash)
|
22
27
|
end
|
23
28
|
end
|
@@ -388,7 +393,12 @@ module SinatraResource
|
|
388
393
|
error 400, convert(body_for(:non_empty_params))
|
389
394
|
end
|
390
395
|
when :read
|
391
|
-
|
396
|
+
p = params.reject { |k, v| k == SHOW_KEY }
|
397
|
+
unless [nil, "all"].include?(params[SHOW_KEY])
|
398
|
+
error 400, convert(body_for(:invalid_params,
|
399
|
+
{ SHOW_KEY => params[SHOW_KEY] }))
|
400
|
+
end
|
401
|
+
unless p.empty?
|
392
402
|
error 400, convert(body_for(:non_empty_params))
|
393
403
|
end
|
394
404
|
when :create
|
@@ -422,7 +432,7 @@ module SinatraResource
|
|
422
432
|
def params_check_action_and_role(action, role, resource_config)
|
423
433
|
invalid = []
|
424
434
|
params.each_pair do |property, value|
|
425
|
-
next if [FILTER_KEY, SEARCH_KEY].include?(property)
|
435
|
+
next if [FILTER_KEY, SEARCH_KEY, SHOW_KEY].include?(property)
|
426
436
|
if !authorized?(action, role, resource_config, property.intern)
|
427
437
|
invalid << property
|
428
438
|
end
|
data/lib/builder.rb
CHANGED
data/lib/resource.rb
CHANGED
@@ -142,7 +142,9 @@ module SinatraResource
|
|
142
142
|
# @param [Hash] access_rules
|
143
143
|
#
|
144
144
|
# @return [undefined]
|
145
|
-
def property(name,
|
145
|
+
def property(name, options={}, &block)
|
146
|
+
hide = options.delete(:hide_by_default) || false
|
147
|
+
access_rules = options
|
146
148
|
if @resource_config[:properties][name]
|
147
149
|
raise DefinitionError, "property #{name.inspect} already declared in #{self}"
|
148
150
|
end
|
@@ -160,6 +162,7 @@ module SinatraResource
|
|
160
162
|
access_rules.each_pair do |kind, role|
|
161
163
|
@resource_config[:roles].validate_role(role)
|
162
164
|
@resource_config[:properties][name][kind] = role
|
165
|
+
@resource_config[:properties][name][:hide_by_default] = hide
|
163
166
|
end
|
164
167
|
end
|
165
168
|
|
data/sinatra_resource.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{sinatra_resource}
|
8
|
-
s.version = "0.4.
|
8
|
+
s.version = "0.4.8"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["David James"]
|
12
|
-
s.date = %q{
|
12
|
+
s.date = %q{2010-01-14}
|
13
13
|
s.description = %q{A DSL for creating RESTful actions with Sinatra and MongoMapper. It embraces the Resource Oriented Architecture as explained by Leonard Richardson and Sam Ruby.}
|
14
14
|
s.email = %q{djames@sunlightfoundation.com}
|
15
15
|
s.extra_rdoc_files = [
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sinatra_resource
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David James
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date:
|
12
|
+
date: 2010-01-14 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|