rest-in-peace 1.1.1 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
data/README.md
CHANGED
@@ -87,8 +87,8 @@ class Resource
|
|
87
87
|
end
|
88
88
|
end
|
89
89
|
|
90
|
-
resource = Resource.find(1) # calls "GET /rip/1"
|
91
|
-
resource = Resource.find_on_other(42, 1337) # calls "GET /other/42/rip/1337"
|
90
|
+
resource = Resource.find(id: 1) # calls "GET /rip/1"
|
91
|
+
resource = Resource.find_on_other(other_id: 42, id: 1337) # calls "GET /other/42/rip/1337"
|
92
92
|
```
|
93
93
|
|
94
94
|
#### Pagination
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.2.0
|
@@ -10,19 +10,8 @@ module RESTinPeace
|
|
10
10
|
|
11
11
|
def get(method_name, url_template, default_params = {})
|
12
12
|
@target.rip_registry[:collection] << { method: :get, name: method_name, url: url_template }
|
13
|
-
@target.send(:define_singleton_method, method_name) do
|
14
|
-
|
15
|
-
params = default_params.merge(args.pop)
|
16
|
-
else
|
17
|
-
params = default_params.dup
|
18
|
-
end
|
19
|
-
|
20
|
-
if args.any?
|
21
|
-
tokens = RESTinPeace::TemplateSanitizer.new(url_template, {}).tokens
|
22
|
-
tokens.each do |token|
|
23
|
-
params.merge!(token.to_sym => args.shift)
|
24
|
-
end
|
25
|
-
end
|
13
|
+
@target.send(:define_singleton_method, method_name) do |given_params|
|
14
|
+
params = default_params.merge(given_params)
|
26
15
|
|
27
16
|
call = RESTinPeace::ApiCall.new(api, url_template, self, params)
|
28
17
|
call.extend(params.delete(:paginate_with)) if params[:paginate_with]
|
@@ -41,7 +41,7 @@ describe RESTinPeace::DefinitionProxy::CollectionMethodDefinitions do
|
|
41
41
|
expect(api_call_double).to_not receive(:extend)
|
42
42
|
|
43
43
|
subject.get(:find, '/a/:id', default_params)
|
44
|
-
target.find(1)
|
44
|
+
target.find(id: 1)
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
@@ -50,30 +50,12 @@ describe RESTinPeace::DefinitionProxy::CollectionMethodDefinitions do
|
|
50
50
|
expect(api_call_double).to receive(:extend)
|
51
51
|
|
52
52
|
subject.get(:find, '/a/:id', default_params.merge(paginate_with: Module))
|
53
|
-
target.find(1)
|
53
|
+
target.find(id: 1)
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
57
57
|
describe 'parameter and arguments handling' do
|
58
|
-
it '
|
59
|
-
expect(RESTinPeace::ApiCall).to receive(:new).
|
60
|
-
with(target.api, '/a/:id', target, {id: 1}).
|
61
|
-
and_return(api_call_double)
|
62
|
-
|
63
|
-
subject.get(:find, '/a/:id', default_params)
|
64
|
-
target.find(1)
|
65
|
-
end
|
66
|
-
|
67
|
-
it 'handles mixed parameters' do
|
68
|
-
expect(RESTinPeace::ApiCall).to receive(:new).
|
69
|
-
with(target.api, '/a/:id', target, id: 1, embed: %w(extra_field1)).
|
70
|
-
and_return(api_call_double)
|
71
|
-
|
72
|
-
subject.get(:find, '/a/:id', default_params)
|
73
|
-
target.find(1, embed: %w(extra_field1))
|
74
|
-
end
|
75
|
-
|
76
|
-
it 'appends the given attributes' do
|
58
|
+
it 'uses the given attributes' do
|
77
59
|
expect(RESTinPeace::ApiCall).to receive(:new).
|
78
60
|
with(target.api, '/a', target, {name: 'daniele', last_name: 'in der o'}).
|
79
61
|
and_return(api_call_double)
|
@@ -85,7 +67,7 @@ describe RESTinPeace::DefinitionProxy::CollectionMethodDefinitions do
|
|
85
67
|
it 'does not modify the default params' do
|
86
68
|
default_params = { per_page: 250 }
|
87
69
|
subject.get(:find, '/a/:id', default_params)
|
88
|
-
target.find(1)
|
70
|
+
target.find(id: 1)
|
89
71
|
expect(default_params).to eq({ per_page: 250 })
|
90
72
|
end
|
91
73
|
end
|