spyke 1.8.0 → 1.8.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: aae9497db570bde9804ea90d14418f739aa9b739
4
- data.tar.gz: 33ded16c0322550c0694cbc36f6a64ca6b46ce6f
3
+ metadata.gz: 8b082d1446203954e1b830026060e1474ee432cc
4
+ data.tar.gz: 237102ecfff1e95fa2c58fb717e6effa7d0df68f
5
5
  SHA512:
6
- metadata.gz: bcaf128e92e898c6036b080afc1a8ae73b328bf17c5dfa2c4480dff9a9e38038a58792aa7fc6beacf3a3bba3f6a7f5d962602ba113e26675939851cfc25e14c6
7
- data.tar.gz: 2ed6ec2a7c5cb0203d78fde3addde56192f72777a2387695b92944caca91ea70cb68eb0d8646cce4e0d00f1d1b57ad0486cd743b0be34e48a2250044f0999986
6
+ metadata.gz: 0cd6f05027b7b3a583855d4d3e4052a968358a108f9970fc630dd861f33d09defbaecb3c078853cbf9430e3fa60448704c647fe3d63c4f231c9906733f3e1227
7
+ data.tar.gz: 1eff94f334fa7d5a8a14a23741dd6c3a16c6da9b1ff4e7ac3a424ed712663ce07383126d79ae4833864f228f4972a1e8d7b8899f6286a91c71808ff0c0b25896
data/README.md CHANGED
@@ -22,7 +22,7 @@ We therefore made Spyke which adds a few fixes/features needed for our projects:
22
22
  - Proper support for scopes
23
23
  - Ability to define custom URIs for associations
24
24
  - ActiveRecord-like log output
25
- - Handling of server side validations
25
+ - Handling of API-side validations
26
26
  - Googlable name! :)
27
27
 
28
28
  ## Configuration
@@ -36,10 +36,10 @@ gem 'spyke'
36
36
  Spyke uses Faraday to handle requests and expects it to parse the response body into a hash in the following format:
37
37
 
38
38
  ```ruby
39
- { data: { id: 1, name: 'Bob' }, metadata: {}, errors: [] }
39
+ { data: { id: 1, name: 'Bob' }, metadata: {}, errors: {} }
40
40
  ```
41
41
 
42
- So, for example for an API that returns JSON in the following format:
42
+ So, for example for an API that returns JSON like this:
43
43
 
44
44
  ```json
45
45
  { "result": { "id": 1, "name": "Bob" }, "extra": {}, "errors": {} }
@@ -140,7 +140,7 @@ Processing by PostsController#index as HTML
140
140
  Completed 200 OK in 75ms (Views: 64.6ms | Spyke: 40.3ms | ActiveRecord: 0ms)
141
141
  ```
142
142
 
143
- ### Server-side validations
143
+ ### API-side validations
144
144
 
145
145
  Spyke expects errors to be formatted in the same way as the
146
146
  ActiveModel::Errors hash, ie:
@@ -156,5 +156,5 @@ show errors returned from the server in forms and f.ex using
156
156
 
157
157
  ## Contributing
158
158
 
159
- If possible please take a look at the [tests marked "wishlisted"](https://github.com/balvig/spyke/search?utf8=%E2%9C%93&q=wishlisted)!
159
+ If possible please take a look at the [tests marked "wishlisted"](https://github.com/balvig/spyke/search?l=ruby&q=wishlisted&utf8=%E2%9C%93)!
160
160
  These are features/fixes we want to implement but haven't gotten around to doing yet :)
@@ -36,6 +36,10 @@ module Spyke
36
36
 
37
37
  def belongs_to(name, options = {})
38
38
  self.associations = associations.merge(name => options.merge(type: BelongsTo))
39
+
40
+ define_method "build_#{name}" do |attributes = nil|
41
+ association(name).build(attributes)
42
+ end
39
43
  end
40
44
 
41
45
  def accepts_nested_attributes_for(*names)
@@ -1,3 +1,3 @@
1
1
  module Spyke
2
- VERSION = '1.8.0'
2
+ VERSION = '1.8.1'
3
3
  end
@@ -118,6 +118,19 @@ module Spyke
118
118
  assert_equal 1, recipe.groups.first.recipe_id
119
119
  end
120
120
 
121
+ def test_build_belongs_to_association
122
+ recipe = Recipe.new(id: 1)
123
+ recipe.build_user(name: 'Alice')
124
+ assert_equal recipe.user.name, 'Alice'
125
+ end
126
+
127
+ def test_build_has_one_association
128
+ recipe = Recipe.new(id: 1)
129
+ image = recipe.build_image
130
+ assert_equal 1, image.recipe_id
131
+ assert_equal 1, recipe.image.recipe_id
132
+ end
133
+
121
134
  def test_multiple_builds
122
135
  recipe = Recipe.new
123
136
  recipe.groups.build(name: 'Condiments')
@@ -187,13 +200,6 @@ module Spyke
187
200
  assert_equal [2], user.recipe_ids
188
201
  end
189
202
 
190
- def test_build_has_one_association
191
- recipe = Recipe.new(id: 1)
192
- image = recipe.build_image
193
- assert_equal 1, image.recipe_id
194
- assert_equal 1, recipe.image.recipe_id
195
- end
196
-
197
203
  def test_custom_class_name
198
204
  stub_request(:get, 'http://sushi.com/recipes/1').to_return_json(result: { background_image: { url: 'bob.jpg' } })
199
205
 
@@ -80,12 +80,12 @@ module Spyke
80
80
  end
81
81
 
82
82
  def test_create_with_server_returning_validation_errors
83
- endpoint = stub_request(:put, 'http://sushi.com/recipes/1').to_return_json(id: 'write_error:400', errors: { title: [{ error: 'too_short', count: 4 }] })
83
+ endpoint = stub_request(:put, 'http://sushi.com/recipes/1').to_return_json(id: 'write_error:400', errors: { title: [{ error: 'too_short', count: 4 }], groups: [{ error: 'blank' }] })
84
84
 
85
85
  recipe = Recipe.create(id: 1, title: 'sus')
86
86
 
87
87
  assert_equal 'sus', recipe.title
88
- assert_equal ['Title is too short (minimum is 4 characters)'], recipe.errors.full_messages
88
+ assert_equal ['Title is too short (minimum is 4 characters)', "Groups can't be blank"], recipe.errors.full_messages
89
89
  assert_requested endpoint
90
90
  end
91
91
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spyke
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.0
4
+ version: 1.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jens Balvig
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-28 00:00:00.000000000 Z
11
+ date: 2015-02-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport