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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 52cac4da2cc85c6c496d340cb4cca2c4b6662de2
4
- data.tar.gz: 6009b3cf582247c64c7f34b5b3eec4f4405a23b0
3
+ metadata.gz: f9c93627a25e5ed27edbdeba7fd75e973b556a17
4
+ data.tar.gz: 952b794e9c4c29872063c3345381859c858509a6
5
5
  SHA512:
6
- metadata.gz: 5acbe5cfb9066089acdb1cccf1b663062052196287b28d7f04eae7f16fd47b94b37799b8160a525da52cddd02f42c234e4b9aff3ebb86fae0dd350ab9894cb84
7
- data.tar.gz: d3da9f0ec5bd00b6114fae65cc8fee7cc7f0a6c0707f98815f85e556187a74fa344e8f47d20eab5ecf39c63125aafe2ee6058cc83f25b9dbb5c9af8dc73c23b0
6
+ metadata.gz: bd5b4a8a302f38b114a175ef8cd40d5d5ad7d05129c5231b950f97bdcf255d9dbf3b45cb00e4dc5143a4d73e5cfa639be86d7fad90c582062fe9c86482ee1c62
7
+ data.tar.gz: 9ef3158fa99900f5c0295dba9e1b27ddb47f8f8a2bce39903b83b88309c9295ec70004cf73d05a9856e3f5a06c76eb5f3fd51f0032ecf0a98cac62af44c04a27
data/.gitignore CHANGED
@@ -3,4 +3,4 @@ log/*.log
3
3
  pkg/
4
4
  *.gem
5
5
  .idea
6
- *.iml
6
+ *.iml
data/.rspec CHANGED
@@ -1,2 +1,2 @@
1
1
  --color
2
- --format progress
2
+ --format progress
data/.travis.yml CHANGED
@@ -4,4 +4,5 @@ rvm:
4
4
  - 2.0.0
5
5
  - 2.1.1
6
6
  - 2.1.0
7
- script: bundle exec rspec spec
7
+ - 2.2.0
8
+ script: bundle exec rspec spec
data/Gemfile CHANGED
@@ -1,3 +1,3 @@
1
1
  source "https://rubygems.org"
2
2
 
3
- gemspec
3
+ gemspec
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- api-model (2.3.0)
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.22)
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.1)
41
+ ethon (0.7.3)
42
42
  ffi (>= 1.3.0)
43
43
  ffi (1.9.6)
44
- hash-pipe (0.0.2)
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.6.11)
49
- ice_nine (0.11.0)
50
- json (1.8.1)
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.4.3)
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.6.9)
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.3)
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
@@ -263,4 +263,4 @@ ApiModel::HttpRequest.class_eval do
263
263
  end
264
264
  end
265
265
  end
266
- ```
266
+ ```
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.0"
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
@@ -51,4 +51,4 @@ module ApiModel
51
51
  include InstanceMethods
52
52
  end
53
53
 
54
- end
54
+ end
@@ -17,4 +17,4 @@ module ApiModel
17
17
  end
18
18
 
19
19
  end
20
- end
20
+ end
@@ -8,4 +8,4 @@ module ApiModel
8
8
 
9
9
  end
10
10
  end
11
- end
11
+ end
@@ -11,4 +11,4 @@ module ApiModel
11
11
 
12
12
  end
13
13
  end
14
- end
14
+ end
@@ -45,4 +45,4 @@ module ApiModel
45
45
  end
46
46
 
47
47
  end
48
- end
48
+ end
@@ -55,4 +55,4 @@ module ApiModel
55
55
 
56
56
  end
57
57
  end
58
- end
58
+ end
@@ -45,4 +45,4 @@ module ApiModel
45
45
  end
46
46
 
47
47
  end
48
- end
48
+ end
@@ -15,4 +15,4 @@ module ApiModel
15
15
  end
16
16
 
17
17
  end
18
- end
18
+ end
@@ -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
- obj.errors.add field.to_sym, message
32
+ set_error_on_self_or_child field, message, obj
33
33
  end
34
34
  else
35
- obj.errors.add field.to_sym, messages
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
@@ -106,4 +106,4 @@ module ApiModel
106
106
  end
107
107
 
108
108
  end
109
- end
109
+ end
@@ -11,4 +11,4 @@ module ApiModel
11
11
 
12
12
  end
13
13
  end
14
- end
14
+ end
@@ -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(Ethon::Errors::InvalidOption)
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
@@ -140,4 +140,4 @@ describe ApiModel, "Configuration" do
140
140
  Banana.api_model_configuration.host.should eq "new-host.com"
141
141
  end
142
142
 
143
- end
143
+ end
@@ -82,4 +82,4 @@ describe ApiModel::HttpRequest do
82
82
  request.api_call.success?.should eq true
83
83
  end
84
84
  end
85
- end
85
+ end
@@ -31,4 +31,4 @@ describe ApiModel::Initializer do
31
31
  Banana.new foo: "bar"
32
32
  end
33
33
 
34
- end
34
+ end
@@ -14,4 +14,4 @@ describe ApiModel::ResponseParser::Json do
14
14
  }.to_not raise_error
15
15
  end
16
16
 
17
- end
17
+ end
@@ -211,4 +211,4 @@ describe ApiModel::Response do
211
211
  end
212
212
  end
213
213
 
214
- end
214
+ end
data/spec/spec_helper.rb CHANGED
@@ -21,4 +21,4 @@ RSpec.configure do |config|
21
21
  ApiModel::Base.reset_api_configuration
22
22
  end
23
23
 
24
- end
24
+ end
@@ -27,4 +27,4 @@ http_interactions:
27
27
  encoding: UTF-8
28
28
  string: "{}"
29
29
  http_version:
30
- recorded_at: Thu, 28 Nov 2013 16:02:20 GMT
30
+ recorded_at: Thu, 28 Nov 2013 16:02:20 GMT
@@ -2,4 +2,4 @@ class Banana < ApiModel::Base
2
2
  attribute :color, String
3
3
  attribute :size, String
4
4
  attribute :ripe, Boolean
5
- end
5
+ end
@@ -8,4 +8,4 @@ class BlogPost < ApiModel::Base
8
8
  end
9
9
  end
10
10
 
11
- end
11
+ end
@@ -16,4 +16,4 @@ class Car < ApiModel::Base
16
16
  top_speed > 300
17
17
  end
18
18
 
19
- end
19
+ end
@@ -0,0 +1,4 @@
1
+ class Garage < ApiModel::Base
2
+ attribute :car, Car
3
+ attribute :style, String
4
+ end
@@ -11,4 +11,4 @@ class MultipleHostsBar < ApiModel::Base
11
11
  end
12
12
 
13
13
  class MultipleHostsNone < ApiModel::Base
14
- end
14
+ end
@@ -1,4 +1,4 @@
1
1
  class User < ApiModel::Base
2
2
  attribute :name, String
3
3
  attribute :email_address, String
4
- end
4
+ end
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.0
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: 2014-11-21 00:00:00.000000000 Z
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: