spyke 2.0.0 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +18 -0
- data/lib/spyke/associations/association.rb +1 -1
- data/lib/spyke/associations/belongs_to.rb +1 -1
- data/lib/spyke/associations/has_many.rb +1 -1
- data/lib/spyke/http.rb +1 -1
- data/lib/spyke/version.rb +1 -1
- data/test/associations_test.rb +13 -2
- data/test/{relation_test.rb → scopes_test.rb} +1 -1
- data/test/support/fixtures.rb +2 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e544879dfca5f90ba78e73e05f7370170445fff8
|
4
|
+
data.tar.gz: 991433596aec9c35a3f7065d0c71dcb798c58f12
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1f9f7d0219671080bb9d91e083d763eb10c15ed624d77c40ff5691c0e3e0880960d7d2b97175473213d8df290ccfdde20333a1e2721301c7720a17e0cb55bf9d
|
7
|
+
data.tar.gz: 4eed190ef156ea97ea07e4d0911a98d75f48f70d7692f3a1d908bc3126c92df064adb7ae33f2738a27342cfbcdbbf8e0a8b047f63f70017b3bd501673090fd8b
|
data/README.md
CHANGED
@@ -167,6 +167,24 @@ remap it in Faraday to match the above. Doing this will allow you to
|
|
167
167
|
show errors returned from the server in forms and f.ex using
|
168
168
|
`@post.errors.full_messages` just like ActiveRecord.
|
169
169
|
|
170
|
+
### Attributes-wrapping
|
171
|
+
|
172
|
+
Spyke, like Rails, by default wraps sent attributes in a root element,
|
173
|
+
but this can be disabled or customized:
|
174
|
+
|
175
|
+
```ruby
|
176
|
+
class Article < Spyke::Base
|
177
|
+
# Default
|
178
|
+
include_root_in_json true # { article: { title: ...} }
|
179
|
+
|
180
|
+
# Custom
|
181
|
+
include_root_in_json :post # { post: { title: ...} }
|
182
|
+
|
183
|
+
# Disabled
|
184
|
+
include_root_in_json false # { title: ... }
|
185
|
+
end
|
186
|
+
```
|
187
|
+
|
170
188
|
### Using multiple APIs
|
171
189
|
|
172
190
|
If you need to use different APIs, instead of configuring `Spyke::Base`
|
@@ -3,7 +3,7 @@ module Spyke
|
|
3
3
|
class BelongsTo < Association
|
4
4
|
def initialize(*args)
|
5
5
|
super
|
6
|
-
@options.reverse_merge!(uri: "#{@name.to_s.pluralize}/:id", foreign_key: "#{klass.model_name.
|
6
|
+
@options.reverse_merge!(uri: "#{@name.to_s.pluralize}/:id", foreign_key: "#{klass.model_name.element}_id")
|
7
7
|
@params[:id] = parent.try(foreign_key)
|
8
8
|
end
|
9
9
|
end
|
@@ -3,7 +3,7 @@ module Spyke
|
|
3
3
|
class HasMany < Association
|
4
4
|
def initialize(*args)
|
5
5
|
super
|
6
|
-
@options.reverse_merge!(uri: "#{parent.class.model_name.
|
6
|
+
@options.reverse_merge!(uri: "#{parent.class.model_name.element.pluralize}/:#{foreign_key}/#{@name}/(:id)")
|
7
7
|
@params[foreign_key] = parent.id
|
8
8
|
end
|
9
9
|
|
data/lib/spyke/http.rb
CHANGED
data/lib/spyke/version.rb
CHANGED
data/test/associations_test.rb
CHANGED
@@ -391,12 +391,23 @@ module Spyke
|
|
391
391
|
|
392
392
|
def test_namespaced_model
|
393
393
|
tip_endpoint = stub_request(:get, 'http://sushi.com/tips/1').to_return_json(result: { id: 1 })
|
394
|
-
|
395
|
-
|
394
|
+
nested_likes_endpoint = stub_request(:get, 'http://sushi.com/tips/1/likes')
|
395
|
+
likes_endpoint = stub_request(:get, 'http://sushi.com/likes')
|
396
|
+
|
397
|
+
Cookbook::Tip.new(id: 1).likes.first
|
398
|
+
Cookbook::Like.new(tip_id: 1).tip
|
399
|
+
Cookbook::Like.all.to_a
|
400
|
+
|
396
401
|
assert_requested tip_endpoint
|
402
|
+
assert_requested nested_likes_endpoint
|
397
403
|
assert_requested likes_endpoint
|
398
404
|
end
|
399
405
|
|
406
|
+
def test_namespaced_foreign_key
|
407
|
+
like = Cookbook::Tip.new(id: 1).likes.build
|
408
|
+
assert_equal 1, like.tip_id
|
409
|
+
end
|
410
|
+
|
400
411
|
def test_namespaced_association_class_auto_detect
|
401
412
|
favorite = Cookbook::Tip.new.favorites.build
|
402
413
|
assert_equal Cookbook::Favorite, favorite.class
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
3
|
module Spyke
|
4
|
-
class
|
4
|
+
class ScopesTest < MiniTest::Test
|
5
5
|
def test_all
|
6
6
|
stub_request(:get, 'http://sushi.com/recipes').to_return_json(result: [{ id: 1, title: 'Sushi' }, { id: 2, title: 'Nigiri' }], metadata: 'meta')
|
7
7
|
|
data/test/support/fixtures.rb
CHANGED
@@ -130,13 +130,14 @@ end
|
|
130
130
|
module Cookbook
|
131
131
|
class Tip < Spyke::Base
|
132
132
|
uri 'tips/(:id)'
|
133
|
-
has_many :likes, class_name: 'Cookbook::Like'
|
133
|
+
has_many :likes, class_name: 'Cookbook::Like'
|
134
134
|
has_many :favorites
|
135
135
|
has_many :votes
|
136
136
|
has_many :photos, class_name: 'Photo'
|
137
137
|
end
|
138
138
|
|
139
139
|
class Like < Spyke::Base
|
140
|
+
belongs_to :tip
|
140
141
|
end
|
141
142
|
|
142
143
|
class Favorite < Spyke::Base
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spyke
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jens Balvig
|
@@ -295,7 +295,7 @@ files:
|
|
295
295
|
- test/custom_request_test.rb
|
296
296
|
- test/orm_test.rb
|
297
297
|
- test/path_test.rb
|
298
|
-
- test/
|
298
|
+
- test/scopes_test.rb
|
299
299
|
- test/support/fixtures.rb
|
300
300
|
- test/support/webmock.rb
|
301
301
|
- test/test_helper.rb
|
@@ -330,7 +330,7 @@ test_files:
|
|
330
330
|
- test/custom_request_test.rb
|
331
331
|
- test/orm_test.rb
|
332
332
|
- test/path_test.rb
|
333
|
-
- test/
|
333
|
+
- test/scopes_test.rb
|
334
334
|
- test/support/fixtures.rb
|
335
335
|
- test/support/webmock.rb
|
336
336
|
- test/test_helper.rb
|