rest-in-peace 3.0.0 → 4.0.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/VERSION +1 -1
- data/lib/rest_in_peace/definition_proxy/resource_method_definitions.rb +4 -4
- data/lib/rest_in_peace.rb +8 -4
- data/spec/rest_in_peace/definition_proxy/resource_method_definitions_spec.rb +1 -1
- data/spec/rest_in_peace/response_converter_spec.rb +2 -0
- data/spec/rest_in_peace_spec.rb +12 -12
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
4.0.0
|
@@ -8,7 +8,7 @@ module RESTinPeace
|
|
8
8
|
def get(method_name, url_template, default_params = {})
|
9
9
|
@target.rip_registry[:resource] << { method: :get, name: method_name, url: url_template }
|
10
10
|
@target.send(:define_method, method_name) do
|
11
|
-
call = RESTinPeace::ApiCall.new(api, url_template, self,
|
11
|
+
call = RESTinPeace::ApiCall.new(api, url_template, self, payload)
|
12
12
|
call.get
|
13
13
|
end
|
14
14
|
end
|
@@ -16,7 +16,7 @@ module RESTinPeace
|
|
16
16
|
def patch(method_name, url_template)
|
17
17
|
@target.rip_registry[:resource] << { method: :patch, name: method_name, url: url_template }
|
18
18
|
@target.send(:define_method, method_name) do
|
19
|
-
call = RESTinPeace::ApiCall.new(api, url_template, self,
|
19
|
+
call = RESTinPeace::ApiCall.new(api, url_template, self, payload)
|
20
20
|
call.patch
|
21
21
|
end
|
22
22
|
end
|
@@ -24,7 +24,7 @@ module RESTinPeace
|
|
24
24
|
def post(method_name, url_template)
|
25
25
|
@target.rip_registry[:resource] << { method: :post, name: method_name, url: url_template }
|
26
26
|
@target.send(:define_method, method_name) do
|
27
|
-
call = RESTinPeace::ApiCall.new(api, url_template, self,
|
27
|
+
call = RESTinPeace::ApiCall.new(api, url_template, self, payload)
|
28
28
|
call.post
|
29
29
|
end
|
30
30
|
end
|
@@ -32,7 +32,7 @@ module RESTinPeace
|
|
32
32
|
def put(method_name, url_template)
|
33
33
|
@target.rip_registry[:resource] << { method: :put, name: method_name, url: url_template }
|
34
34
|
@target.send(:define_method, method_name) do
|
35
|
-
call = RESTinPeace::ApiCall.new(api, url_template, self,
|
35
|
+
call = RESTinPeace::ApiCall.new(api, url_template, self, payload)
|
36
36
|
call.put
|
37
37
|
end
|
38
38
|
end
|
data/lib/rest_in_peace.rb
CHANGED
@@ -14,10 +14,10 @@ module RESTinPeace
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def initialize(attributes = {})
|
17
|
-
|
17
|
+
set_attributes attributes
|
18
18
|
end
|
19
19
|
|
20
|
-
def
|
20
|
+
def payload
|
21
21
|
hash_representation = { id: id }
|
22
22
|
changed.each do |key|
|
23
23
|
value = send(key)
|
@@ -57,7 +57,7 @@ module RESTinPeace
|
|
57
57
|
hash_representation
|
58
58
|
end
|
59
59
|
|
60
|
-
def
|
60
|
+
def set_attributes(attributes)
|
61
61
|
attributes.each do |key, value|
|
62
62
|
next unless respond_to?(key)
|
63
63
|
if respond_to?("#{key}=")
|
@@ -66,11 +66,15 @@ module RESTinPeace
|
|
66
66
|
instance_variable_set("@#{key}", value)
|
67
67
|
end
|
68
68
|
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def force_attributes_from_hash(attributes)
|
72
|
+
set_attributes attributes
|
69
73
|
clear_changes
|
70
74
|
end
|
71
75
|
|
72
76
|
def hash_representation_of_object(object)
|
73
|
-
return object.
|
77
|
+
return object.payload if object.respond_to?(:payload)
|
74
78
|
return object.map { |element| hash_representation_of_object(element) } if object.is_a?(Array)
|
75
79
|
object
|
76
80
|
end
|
@@ -41,7 +41,7 @@ describe RESTinPeace::DefinitionProxy::ResourceMethodDefinitions do
|
|
41
41
|
describe 'parameter and arguments handling' do
|
42
42
|
it 'uses the attributes of the class' do
|
43
43
|
expect(RESTinPeace::ApiCall).to receive(:new).
|
44
|
-
with(target.api, url_template, instance, instance.
|
44
|
+
with(target.api, url_template, instance, instance.payload).
|
45
45
|
and_return(api_call_double)
|
46
46
|
|
47
47
|
subject.send(http_verb, method_name, url_template)
|
@@ -26,12 +26,14 @@ describe RESTinPeace::ResponseConverter do
|
|
26
26
|
specify { expect(subject).to be_instance_of(Array) }
|
27
27
|
specify { expect(subject.first).to be_instance_of(extended_class) }
|
28
28
|
specify { expect(subject.map(&:name)).to eq(%w(test1 test2)) }
|
29
|
+
specify { expect(subject.first).to_not be_changed }
|
29
30
|
end
|
30
31
|
|
31
32
|
shared_examples_for 'a hash input' do
|
32
33
|
let(:response_body) { element1 }
|
33
34
|
specify { expect(subject).to be_instance_of(extended_class) }
|
34
35
|
specify { expect(subject.name).to eq('test1') }
|
36
|
+
it { is_expected.to_not be_changed }
|
35
37
|
end
|
36
38
|
|
37
39
|
shared_examples_for 'a string input' do
|
data/spec/rest_in_peace_spec.rb
CHANGED
@@ -102,25 +102,25 @@ describe RESTinPeace do
|
|
102
102
|
specify { expect(subject).to eq(attributes.merge(overridden_attribute: 'something else')) }
|
103
103
|
end
|
104
104
|
|
105
|
-
describe '#
|
105
|
+
describe '#payload' do
|
106
106
|
subject { instance }
|
107
|
-
specify { expect(subject).to respond_to(:
|
107
|
+
specify { expect(subject).to respond_to(:payload).with(0).arguments }
|
108
108
|
|
109
109
|
context 'without a namspace defined' do
|
110
110
|
it 'adds id by default' do
|
111
|
-
expect(subject.
|
111
|
+
expect(subject.payload).to include(id: 1)
|
112
112
|
end
|
113
113
|
|
114
114
|
context 'overridden getter' do
|
115
115
|
before do
|
116
116
|
subject.overridden_attribute = 'new value'
|
117
117
|
end
|
118
|
-
specify { expect(subject.
|
118
|
+
specify { expect(subject.payload).to include(overridden_attribute: 'something else') }
|
119
119
|
end
|
120
120
|
|
121
121
|
context 'self defined methods' do
|
122
122
|
specify { expect(subject).to respond_to(:self_defined_method) }
|
123
|
-
specify { expect(subject.
|
123
|
+
specify { expect(subject.payload).to_not include(:self_defined_method) }
|
124
124
|
end
|
125
125
|
|
126
126
|
context 'hash' do
|
@@ -128,7 +128,7 @@ describe RESTinPeace do
|
|
128
128
|
subject.my_hash = { element1: 'swag' }
|
129
129
|
end
|
130
130
|
|
131
|
-
specify { expect(subject.
|
131
|
+
specify { expect(subject.payload[:my_hash]).to eq(element1: 'swag') }
|
132
132
|
end
|
133
133
|
|
134
134
|
context 'with objects assigned' do
|
@@ -138,14 +138,14 @@ describe RESTinPeace do
|
|
138
138
|
subject.my_hash = new_hash
|
139
139
|
end
|
140
140
|
|
141
|
-
it 'deeply calls
|
142
|
-
expect(new_hash).to receive(:
|
143
|
-
subject.
|
141
|
+
it 'deeply calls payload' do
|
142
|
+
expect(new_hash).to receive(:payload).and_return({})
|
143
|
+
subject.payload
|
144
144
|
end
|
145
145
|
end
|
146
146
|
end
|
147
147
|
|
148
|
-
context 'with a
|
148
|
+
context 'with a namespace defined' do
|
149
149
|
let(:extended_class) do
|
150
150
|
Class.new do
|
151
151
|
include RESTinPeace
|
@@ -165,7 +165,7 @@ describe RESTinPeace do
|
|
165
165
|
subject.name = 'new value'
|
166
166
|
end
|
167
167
|
|
168
|
-
specify { expect(subject.
|
168
|
+
specify { expect(subject.payload).to eq(id: 1, blubb: { id: 1, name: 'new value', description: 'old description' }) }
|
169
169
|
end
|
170
170
|
end
|
171
171
|
|
@@ -227,7 +227,7 @@ describe RESTinPeace do
|
|
227
227
|
subject { instance }
|
228
228
|
|
229
229
|
context 'a new instance' do
|
230
|
-
it { is_expected.
|
230
|
+
it { is_expected.to be_changed }
|
231
231
|
end
|
232
232
|
|
233
233
|
context 'a modified instance' do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rest-in-peace
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 4.0.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-
|
12
|
+
date: 2015-02-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activemodel
|