sinatra_resource 0.4.8 → 0.4.9
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/VERSION +1 -1
- data/examples/datacatalog/config/config.rb +1 -1
- data/examples/datacatalog/models/categorization.rb +2 -2
- data/examples/datacatalog/models/note.rb +1 -1
- data/examples/datacatalog/models/user.rb +2 -1
- data/examples/datacatalog/test/helpers/lib/request_helpers.rb +2 -2
- data/examples/datacatalog/test/resources/categories/categories_get_one_test.rb +1 -1
- data/examples/datacatalog/test/resources/categories_sources/categories_sources_delete_test.rb +4 -3
- data/examples/datacatalog/test/resources/categories_sources/categories_sources_post_test.rb +8 -8
- data/examples/datacatalog/test/resources/notes/notes_post_test.rb +1 -1
- data/examples/datacatalog/test/resources/sources/sources_get_one_test.rb +1 -1
- data/examples/datacatalog/test/resources/users/users_get_many_test.rb +1 -1
- data/lib/builder.rb +1 -1
- data/lib/builder/helpers.rb +2 -2
- data/lib/builder/mongo_helpers.rb +5 -2
- data/sinatra_resource.gemspec +2 -2
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.4.
|
1
|
+
0.4.9
|
@@ -8,7 +8,7 @@ module Config
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def self.setup_mongomapper
|
11
|
-
gem '
|
11
|
+
gem 'mongo_mapper', '>= 0.6.10', '< 0.7'
|
12
12
|
require 'mongo_mapper'
|
13
13
|
MongoMapper.connection = new_mongo_connection
|
14
14
|
MongoMapper.database = environment_config['mongo_database']
|
@@ -61,8 +61,8 @@ module RequestHelpers
|
|
61
61
|
base_uri = Config.environment_config["base_uri"]
|
62
62
|
parent = instance_variable_get("@#{parent_ivar}")
|
63
63
|
raise Error unless parent
|
64
|
-
|
65
|
-
|
64
|
+
id = parsed_response_body['id']
|
65
|
+
path = "#{parent_path}/#{parent.id}/#{child_path}/#{id}"
|
66
66
|
expected = URI.join(base_uri, path).to_s
|
67
67
|
assert_equal expected, last_response.headers['Location']
|
68
68
|
end
|
@@ -62,7 +62,7 @@ class CategoriesGetOneResourceTest < ResourceTestCase
|
|
62
62
|
test "body should have correct sources" do
|
63
63
|
expected = [
|
64
64
|
{
|
65
|
-
"id" => @source.id,
|
65
|
+
"id" => @source.id.to_s,
|
66
66
|
"href" => "/sources/#{@source.id}",
|
67
67
|
"title" => @source.title,
|
68
68
|
"url" => @source.url,
|
data/examples/datacatalog/test/resources/categories_sources/categories_sources_delete_test.rb
CHANGED
@@ -48,7 +48,7 @@ class CategoriesSourcesDeleteResourceTest < ResourceTestCase
|
|
48
48
|
use "return 401 because the API key is invalid"
|
49
49
|
end
|
50
50
|
end
|
51
|
-
|
51
|
+
|
52
52
|
%w(basic).each do |role|
|
53
53
|
context "#{role} : delete /:fake_id/sources/:fake_id" do
|
54
54
|
before do
|
@@ -124,7 +124,7 @@ class CategoriesSourcesDeleteResourceTest < ResourceTestCase
|
|
124
124
|
use "return 404 Not Found with empty response body"
|
125
125
|
use "no change in source count"
|
126
126
|
end
|
127
|
-
|
127
|
+
|
128
128
|
context "#{role} : delete /:id/sources/:not_related_id" do
|
129
129
|
before do
|
130
130
|
delete "/#{@category.id}/sources/#{@other_source.id}",
|
@@ -137,7 +137,8 @@ class CategoriesSourcesDeleteResourceTest < ResourceTestCase
|
|
137
137
|
|
138
138
|
context "#{role} : delete /:id/sources/:id" do
|
139
139
|
before do
|
140
|
-
delete "/#{@category.id}/sources/#{@source.id}",
|
140
|
+
delete "/#{@category.id}/sources/#{@source.id}",
|
141
|
+
:api_key => api_key_for(role)
|
141
142
|
end
|
142
143
|
|
143
144
|
use "return 204 No Content"
|
@@ -66,7 +66,7 @@ class CategoriesSourcesPostResourceTest < ResourceTestCase
|
|
66
66
|
use "no change in source count"
|
67
67
|
end
|
68
68
|
end
|
69
|
-
|
69
|
+
|
70
70
|
%w(curator).each do |role|
|
71
71
|
context "#{role} : post /:fake_id/sources" do
|
72
72
|
before do
|
@@ -89,7 +89,7 @@ class CategoriesSourcesPostResourceTest < ResourceTestCase
|
|
89
89
|
missing_param missing
|
90
90
|
end
|
91
91
|
end
|
92
|
-
|
92
|
+
|
93
93
|
[:raw, :id, :created_at, :updated_at, :junk].each do |invalid|
|
94
94
|
context "#{role} : post /:id/sources but with #{invalid}" do
|
95
95
|
before do
|
@@ -102,12 +102,12 @@ class CategoriesSourcesPostResourceTest < ResourceTestCase
|
|
102
102
|
invalid_param invalid
|
103
103
|
end
|
104
104
|
end
|
105
|
-
|
105
|
+
|
106
106
|
context "#{role} : post /:id/sources with valid params" do
|
107
107
|
before do
|
108
108
|
post "/#{@category.id}/sources", valid_params_for(role)
|
109
109
|
end
|
110
|
-
|
110
|
+
|
111
111
|
after do
|
112
112
|
Source.find_by_id(parsed_response_body["id"]).destroy
|
113
113
|
end
|
@@ -123,7 +123,7 @@ class CategoriesSourcesPostResourceTest < ResourceTestCase
|
|
123
123
|
end
|
124
124
|
end
|
125
125
|
end
|
126
|
-
|
126
|
+
|
127
127
|
%w(admin).each do |role|
|
128
128
|
context "#{role} : post /:fake_id/sources" do
|
129
129
|
before do
|
@@ -148,7 +148,7 @@ class CategoriesSourcesPostResourceTest < ResourceTestCase
|
|
148
148
|
missing_param missing
|
149
149
|
end
|
150
150
|
end
|
151
|
-
|
151
|
+
|
152
152
|
[:id, :created_at, :updated_at, :junk].each do |invalid|
|
153
153
|
context "#{role} : post /:id/sources but with #{invalid}" do
|
154
154
|
before do
|
@@ -161,13 +161,13 @@ class CategoriesSourcesPostResourceTest < ResourceTestCase
|
|
161
161
|
invalid_param invalid
|
162
162
|
end
|
163
163
|
end
|
164
|
-
|
164
|
+
|
165
165
|
context "#{role} : post /:id/sources with valid params" do
|
166
166
|
before do
|
167
167
|
post "/#{@category.id}/sources",
|
168
168
|
valid_params_for(role).merge(@extra_admin_params)
|
169
169
|
end
|
170
|
-
|
170
|
+
|
171
171
|
after do
|
172
172
|
Source.find_by_id(parsed_response_body["id"]).destroy
|
173
173
|
end
|
@@ -78,7 +78,7 @@ class UsersGetManyResourceTest < ResourceTestCase
|
|
78
78
|
|
79
79
|
test "body elements should be correct" do
|
80
80
|
@members.each do |element|
|
81
|
-
if element["id"] == user_for(role).id
|
81
|
+
if element["id"] == user_for(role).id.to_s
|
82
82
|
assert_properties(%w(name email role _api_key token
|
83
83
|
id created_at updated_at), element)
|
84
84
|
else
|
data/lib/builder.rb
CHANGED
@@ -175,7 +175,7 @@ module SinatraResource
|
|
175
175
|
parent_document = document_for_get_one(parent_role, parent_model, parent_resource_config, false, parent_id, nil, nil)
|
176
176
|
# ------
|
177
177
|
role = role_for_nested(parent_document, child_assoc, model, id)
|
178
|
-
document_for_delete(role, model, resource_config, true, id, parent_document, child_assoc)
|
178
|
+
document = document_for_delete(role, model, resource_config, true, id, parent_document, child_assoc)
|
179
179
|
display(:delete, "", resource_config, parent_id)
|
180
180
|
end
|
181
181
|
end
|
data/lib/builder/helpers.rb
CHANGED
@@ -355,9 +355,9 @@ module SinatraResource
|
|
355
355
|
path = if c[:parent]
|
356
356
|
raise Error, "expecting parent_id" unless parent_id
|
357
357
|
pc = c[:parent].resource_config
|
358
|
-
pc[:path]
|
358
|
+
"#{pc[:path]}/#{parent_id}/#{c[:path]}/#{o['id']}"
|
359
359
|
else
|
360
|
-
c[:path]
|
360
|
+
"#{c[:path]}/#{o['id']}"
|
361
361
|
end
|
362
362
|
full_uri(path)
|
363
363
|
end
|
@@ -158,7 +158,8 @@ module SinatraResource
|
|
158
158
|
# @return [MongoMapper::EmbeddedDocument]
|
159
159
|
def find_child(children, child_id)
|
160
160
|
raise Error, "children not true" unless children
|
161
|
-
|
161
|
+
child_id = child_id.to_s
|
162
|
+
children.detect { |x| x.id.to_s == child_id }
|
162
163
|
end
|
163
164
|
|
164
165
|
# Find document with +child_id+ in +children+ or raise 404.
|
@@ -443,7 +444,9 @@ module SinatraResource
|
|
443
444
|
# @return [MongoMapper::Document]
|
444
445
|
def select_related(parent, child_assoc, children)
|
445
446
|
children.select do |child|
|
446
|
-
parent.send(child_assoc).detect
|
447
|
+
parent.send(child_assoc).detect do |x|
|
448
|
+
x.id == child.id
|
449
|
+
end
|
447
450
|
end
|
448
451
|
# Note: This has O^2 complexity because of the nesting.
|
449
452
|
# Can it be done more quickly?
|
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.9"
|
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{2010-
|
12
|
+
s.date = %q{2010-02-03}
|
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.9
|
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: 2010-
|
12
|
+
date: 2010-02-03 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|