api-model 2.3.0 → 2.3.1
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.
- checksums.yaml +4 -4
- data/.gitignore +1 -1
- data/.rspec +1 -1
- data/.travis.yml +2 -1
- data/Gemfile +1 -1
- data/Gemfile.lock +10 -10
- data/README.md +1 -1
- data/api-model.gemspec +1 -1
- data/lib/api-model.rb +1 -1
- data/lib/api_model/assignment.rb +1 -1
- data/lib/api_model/builder/hash.rb +1 -1
- data/lib/api_model/cache_stategy/no_cache.rb +1 -1
- data/lib/api_model/class_methods.rb +1 -1
- data/lib/api_model/configuration.rb +1 -1
- data/lib/api_model/http_request.rb +1 -1
- data/lib/api_model/initializer.rb +1 -1
- data/lib/api_model/instance_methods.rb +13 -3
- data/lib/api_model/response.rb +1 -1
- data/lib/api_model/response_parser/json.rb +1 -1
- data/spec/api-model/api_model_spec.rb +20 -2
- data/spec/api-model/configuration_spec.rb +1 -1
- data/spec/api-model/http_request_spec.rb +1 -1
- data/spec/api-model/initializer_spec.rb +1 -1
- data/spec/api-model/json_response_parser_spec.rb +1 -1
- data/spec/api-model/response_spec.rb +1 -1
- data/spec/spec_helper.rb +1 -1
- data/spec/support/fixtures/cookies.yml +1 -1
- data/spec/support/mock_models/banana.rb +1 -1
- data/spec/support/mock_models/blog_post.rb +1 -1
- data/spec/support/mock_models/car.rb +1 -1
- data/spec/support/mock_models/garage.rb +4 -0
- data/spec/support/mock_models/multiple_hosts.rb +1 -1
- data/spec/support/mock_models/user.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f9c93627a25e5ed27edbdeba7fd75e973b556a17
|
4
|
+
data.tar.gz: 952b794e9c4c29872063c3345381859c858509a6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bd5b4a8a302f38b114a175ef8cd40d5d5ad7d05129c5231b950f97bdcf255d9dbf3b45cb00e4dc5143a4d73e5cfa639be86d7fad90c582062fe9c86482ee1c62
|
7
|
+
data.tar.gz: 9ef3158fa99900f5c0295dba9e1b27ddb47f8f8a2bce39903b83b88309c9295ec70004cf73d05a9856e3f5a06c76eb5f3fd51f0032ecf0a98cac62af44c04a27
|
data/.gitignore
CHANGED
data/.rspec
CHANGED
@@ -1,2 +1,2 @@
|
|
1
1
|
--color
|
2
|
-
--format progress
|
2
|
+
--format progress
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
api-model (2.3.
|
4
|
+
api-model (2.3.1)
|
5
5
|
activemodel (~> 4.1)
|
6
6
|
activesupport (~> 4.1)
|
7
7
|
hash-pipe (~> 0.0)
|
@@ -35,21 +35,21 @@ GEM
|
|
35
35
|
descendants_tracker (0.0.4)
|
36
36
|
thread_safe (~> 0.3, >= 0.3.1)
|
37
37
|
diff-lcs (1.2.5)
|
38
|
-
domain_name (0.5.
|
38
|
+
domain_name (0.5.23)
|
39
39
|
unf (>= 0.0.5, < 1.0.0)
|
40
40
|
equalizer (0.0.9)
|
41
|
-
ethon (0.7.
|
41
|
+
ethon (0.7.3)
|
42
42
|
ffi (>= 1.3.0)
|
43
43
|
ffi (1.9.6)
|
44
|
-
hash-pipe (0.0
|
44
|
+
hash-pipe (0.2.0)
|
45
45
|
activesupport (~> 4.1)
|
46
46
|
http-cookie (1.0.2)
|
47
47
|
domain_name (~> 0.5)
|
48
|
-
i18n (0.
|
49
|
-
ice_nine (0.11.
|
50
|
-
json (1.8.
|
48
|
+
i18n (0.7.0)
|
49
|
+
ice_nine (0.11.1)
|
50
|
+
json (1.8.2)
|
51
51
|
method_source (0.8.2)
|
52
|
-
minitest (5.
|
52
|
+
minitest (5.5.1)
|
53
53
|
pry (0.9.12.2)
|
54
54
|
coderay (~> 1.0.5)
|
55
55
|
method_source (~> 0.8)
|
@@ -65,7 +65,7 @@ GEM
|
|
65
65
|
safe_yaml (0.9.7)
|
66
66
|
slop (3.4.6)
|
67
67
|
thread_safe (0.3.4)
|
68
|
-
typhoeus (0.
|
68
|
+
typhoeus (0.7.1)
|
69
69
|
ethon (>= 0.7.1)
|
70
70
|
tzinfo (1.2.2)
|
71
71
|
thread_safe (~> 0.1)
|
@@ -73,7 +73,7 @@ GEM
|
|
73
73
|
unf_ext
|
74
74
|
unf_ext (0.0.6)
|
75
75
|
vcr (2.8.0)
|
76
|
-
virtus (1.0.
|
76
|
+
virtus (1.0.4)
|
77
77
|
axiom-types (~> 0.1)
|
78
78
|
coercible (~> 1.0)
|
79
79
|
descendants_tracker (~> 0.0, >= 0.0.3)
|
data/README.md
CHANGED
data/api-model.gemspec
CHANGED
@@ -2,7 +2,7 @@ $:.push File.expand_path("../lib", __FILE__)
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = "api-model"
|
5
|
-
s.version = "2.3.
|
5
|
+
s.version = "2.3.1"
|
6
6
|
s.authors = ["Damien Timewell", "Erik Rothoff Andersson"]
|
7
7
|
s.email = ["mail@damientimewell.com", "erik.rothoff@gmail.com"]
|
8
8
|
s.licenses = ['MIT']
|
data/lib/api-model.rb
CHANGED
data/lib/api_model/assignment.rb
CHANGED
@@ -29,14 +29,24 @@ module ApiModel
|
|
29
29
|
errors_hash.each do |field,messages|
|
30
30
|
if messages.is_a?(Array)
|
31
31
|
messages.each do |message|
|
32
|
-
|
32
|
+
set_error_on_self_or_child field, message, obj
|
33
33
|
end
|
34
34
|
else
|
35
|
-
|
35
|
+
set_error_on_self_or_child field, messages, obj
|
36
36
|
end
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
|
+
# If the field to apply errors to is another ApiModel instance, call ++set_errors_from_hash++ on it.
|
41
|
+
# Otherwise, go ahead and treat it as a normal ActiveModel error on the current ++obj++ instance.
|
42
|
+
def set_error_on_self_or_child(field, messages, obj = self)
|
43
|
+
if obj.respond_to?(field.to_sym) && obj.send(field.to_sym).respond_to?(:set_error_on_self_or_child)
|
44
|
+
obj.send(field.to_sym).set_errors_from_hash messages
|
45
|
+
else
|
46
|
+
obj.errors.add field.to_sym, messages
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
40
50
|
# Sends a request to the api to update a resource. If the response was successful, then it will
|
41
51
|
# update the instance with any changes which the API has returned. If not, it will set ActiveModel
|
42
52
|
# errors.
|
@@ -82,4 +92,4 @@ module ApiModel
|
|
82
92
|
end
|
83
93
|
|
84
94
|
end
|
85
|
-
end
|
95
|
+
end
|
data/lib/api_model/response.rb
CHANGED
@@ -2,6 +2,7 @@ require 'spec_helper'
|
|
2
2
|
require 'support/mock_models/blog_post'
|
3
3
|
require 'support/mock_models/car'
|
4
4
|
require 'support/mock_models/user'
|
5
|
+
require 'support/mock_models/garage'
|
5
6
|
|
6
7
|
describe ApiModel do
|
7
8
|
|
@@ -164,6 +165,23 @@ describe ApiModel do
|
|
164
165
|
end
|
165
166
|
end
|
166
167
|
|
168
|
+
describe "setting errors on nested models" do
|
169
|
+
let(:car) { Car.new }
|
170
|
+
let(:garage) { Garage.new car: car }
|
171
|
+
|
172
|
+
before do
|
173
|
+
garage.set_errors_from_hash style: "is invalid", car: { name: "sounds funny" }
|
174
|
+
end
|
175
|
+
|
176
|
+
it 'should set errors on the parent normally' do
|
177
|
+
garage.errors[:style].should eq ["is invalid"]
|
178
|
+
end
|
179
|
+
|
180
|
+
it 'should set errors on the child normally' do
|
181
|
+
garage.car.errors[:name].should eq ["sounds funny"]
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
167
185
|
describe "updating attributes from a hash" do
|
168
186
|
let(:car) { Car.new }
|
169
187
|
|
@@ -309,7 +327,7 @@ describe ApiModel do
|
|
309
327
|
it 'should not pass custom cache_ids onto api requests' do
|
310
328
|
expect {
|
311
329
|
VCR.use_cassette('posts') { BlogPost.get_json "http://api-model-specs.com/single_post", {}, cache_id: "custom_key" }
|
312
|
-
}.to_not raise_error
|
330
|
+
}.to_not raise_error
|
313
331
|
end
|
314
332
|
end
|
315
333
|
|
@@ -348,4 +366,4 @@ describe ApiModel do
|
|
348
366
|
end
|
349
367
|
end
|
350
368
|
|
351
|
-
end
|
369
|
+
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: api-model
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.3.
|
4
|
+
version: 2.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Damien Timewell
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2015-03-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -194,6 +194,7 @@ files:
|
|
194
194
|
- spec/support/mock_models/banana.rb
|
195
195
|
- spec/support/mock_models/blog_post.rb
|
196
196
|
- spec/support/mock_models/car.rb
|
197
|
+
- spec/support/mock_models/garage.rb
|
197
198
|
- spec/support/mock_models/multiple_hosts.rb
|
198
199
|
- spec/support/mock_models/user.rb
|
199
200
|
homepage: https://github.com/iZettle/api-model
|
@@ -236,6 +237,6 @@ test_files:
|
|
236
237
|
- spec/support/mock_models/banana.rb
|
237
238
|
- spec/support/mock_models/blog_post.rb
|
238
239
|
- spec/support/mock_models/car.rb
|
240
|
+
- spec/support/mock_models/garage.rb
|
239
241
|
- spec/support/mock_models/multiple_hosts.rb
|
240
242
|
- spec/support/mock_models/user.rb
|
241
|
-
has_rdoc:
|