spyke 1.4.0 → 1.4.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 +3 -3
- data/lib/spyke/associations.rb +1 -0
- data/lib/spyke/attributes.rb +0 -4
- data/lib/spyke/orm.rb +0 -4
- data/lib/spyke/version.rb +1 -1
- data/test/associations_test.rb +27 -16
- data/test/custom_request_test.rb +3 -2
- data/test/support/fixtures.rb +1 -5
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ccd9957900a277390812c84d78b30985292cb2a9
|
4
|
+
data.tar.gz: c5cdb9be619f68febc8b20a51d339db19fcb7d4e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: af321cc8a304dc3e169ce7d31f113db4a7032de30f4b96e886d3ad8db6961a66b8f88ae932f732aa733b272a69a9840dc5226e9692cb40b3047bc4b44dadbe16
|
7
|
+
data.tar.gz: cddd07072bde4a26fe0bfa5b497747f612f09327f7e7edb35f8f9e428959b32fdbaa90d1bd87e611e500e916e16b730fdfd05460a8e9b7d983ccd4c85ac460c5
|
data/README.md
CHANGED
@@ -5,10 +5,10 @@
|
|
5
5
|
<br/>
|
6
6
|
Interact with remote <strong>REST services</strong> in an <strong>ActiveRecord-like</strong> manner.
|
7
7
|
<br /><br />
|
8
|
-
<a href="
|
8
|
+
<a href="https://rubygems.org/gems/spyke"><img src="https://badge.fury.io/rb/spyke.svg?style=flat" alt="Gem Version"></a>
|
9
|
+
<a href='https://gemnasium.com/balvig/spyke'><img src="https://gemnasium.com/balvig/spyke.svg" /></a>
|
9
10
|
<a href="https://codeclimate.com/github/balvig/spyke"><img src="https://codeclimate.com/github/balvig/spyke/badges/gpa.svg" /></a>
|
10
|
-
<a href='https://
|
11
|
-
<a href='https://coveralls.io/r/balvig/spyke?branch=master'><img src='https://coveralls.io/repos/balvig/spyke/badge.png?branch=master' /></a>
|
11
|
+
<a href='https://coveralls.io/r/balvig/spyke?branch=master'><img src='https://img.shields.io/coveralls/balvig/spyke.svg?style=flat' /></a>
|
12
12
|
<a href="https://travis-ci.org/balvig/spyke"><img src="https://travis-ci.org/balvig/spyke.svg?branch=master" /></a>
|
13
13
|
</p>
|
14
14
|
|
data/lib/spyke/associations.rb
CHANGED
data/lib/spyke/attributes.rb
CHANGED
data/lib/spyke/orm.rb
CHANGED
data/lib/spyke/version.rb
CHANGED
data/test/associations_test.rb
CHANGED
@@ -10,9 +10,9 @@ module Spyke
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def test_initializing_with_has_many_association
|
13
|
-
group = Group.new(ingredients: [Ingredient.new(
|
14
|
-
assert_equal %w{ Water Flour }, group.ingredients.map(&:
|
15
|
-
assert_equal({ 'group' => { 'ingredients' => [{ '
|
13
|
+
group = Group.new(ingredients: [Ingredient.new(name: 'Water'), Ingredient.new(name: 'Flour')])
|
14
|
+
assert_equal %w{ Water Flour }, group.ingredients.map(&:name)
|
15
|
+
assert_equal({ 'group' => { 'ingredients' => [{ 'name' => 'Water' }, { 'name' => 'Flour' }] } }, group.to_params)
|
16
16
|
end
|
17
17
|
|
18
18
|
def test_initializing_with_has_one_association
|
@@ -255,29 +255,40 @@ module Spyke
|
|
255
255
|
assert_equal %w{ nice spicy }, recipe.groups.map(&:description)
|
256
256
|
end
|
257
257
|
|
258
|
-
def
|
259
|
-
|
258
|
+
def test_nested_attributes_has_many_using_hash_syntax
|
259
|
+
recipe = Recipe.new(groups_attributes: { '0' => { title: 'starter' }, '1' => { title: 'sauce' } })
|
260
|
+
assert_equal %w{ starter sauce }, recipe.groups.map(&:title)
|
261
|
+
end
|
262
|
+
|
263
|
+
def test_deeply_nested_attributes_has_many_using_array_syntax
|
264
|
+
params = { groups_attributes: [{ id: 1, ingredients_attributes: [{ id: 1, name: 'Salt' }, { id: 2, name: 'Pepper' } ]}] }
|
260
265
|
recipe = Recipe.new(params)
|
266
|
+
assert_equal %w{ Salt Pepper }, recipe.ingredients.map(&:name)
|
261
267
|
recipe.attributes = params
|
262
|
-
assert_equal
|
263
|
-
skip "ingredients don't get built properly it seems?"
|
264
|
-
assert_equal 'fish', recipe.groups.first.ingredients.first.title
|
268
|
+
assert_equal %w{ Salt Pepper }, recipe.ingredients.map(&:name)
|
265
269
|
end
|
266
270
|
|
267
|
-
def
|
268
|
-
params = { groups_attributes:
|
271
|
+
def test_deeply_nested_attributes_has_many_using_hash_syntax
|
272
|
+
params = { groups_attributes: { '0' => { id: 1, ingredients_attributes: { '0' => { id: 1, name: 'Salt' }, '1' => { id: 2, name: 'Pepper' } } } } }
|
269
273
|
recipe = Recipe.new(params)
|
274
|
+
assert_equal %w{ Salt Pepper }, recipe.ingredients.map(&:name)
|
270
275
|
recipe.attributes = params
|
271
|
-
assert_equal
|
276
|
+
assert_equal %w{ Salt Pepper }, recipe.ingredients.map(&:name)
|
272
277
|
end
|
273
278
|
|
274
|
-
def
|
275
|
-
|
276
|
-
|
279
|
+
def test_deeply_nested_attributes_has_many_with_blank_ids_using_array_syntax
|
280
|
+
params = { groups_attributes: [{ ingredients_attributes: [{ name: 'Salt' }, { name: 'Pepper' }]}] }
|
281
|
+
recipe = Recipe.new(params)
|
282
|
+
assert_equal %w{ Salt Pepper }, recipe.ingredients.map(&:name)
|
283
|
+
recipe.attributes = params
|
284
|
+
assert_equal %w{ Salt Pepper }, recipe.ingredients.map(&:name)
|
277
285
|
end
|
278
286
|
|
279
|
-
def
|
280
|
-
|
287
|
+
def test_deeply_nested_attributes_has_many_with_blank_ids_using_hash_syntax
|
288
|
+
params = { groups_attributes: { '0' => { ingredients_attributes: { '0' => { id: '', name: 'Salt' }, '1' => { id: '', name: 'Pepper' } } } } }
|
289
|
+
recipe = Recipe.new(params)
|
290
|
+
assert_equal %w{ Salt Pepper }, recipe.ingredients.map(&:name)
|
291
|
+
recipe.attributes = params
|
281
292
|
assert_equal %w{ Salt Pepper }, recipe.ingredients.map(&:name)
|
282
293
|
end
|
283
294
|
|
data/test/custom_request_test.rb
CHANGED
@@ -2,9 +2,10 @@ require 'test_helper'
|
|
2
2
|
|
3
3
|
module Spyke
|
4
4
|
class CustomRequestTest < MiniTest::Test
|
5
|
-
def
|
5
|
+
def test_custom_get_request_using_class_method
|
6
6
|
endpoint = stub_request(:get, 'http://sushi.com/recipes/recent').to_return_json(result: [{ id: 1, title: 'Bread' }])
|
7
|
-
|
7
|
+
recipes = Recipe.get('/recipes/recent')
|
8
|
+
assert_equal %w{ Bread }, recipes.map(&:title)
|
8
9
|
assert_requested endpoint
|
9
10
|
end
|
10
11
|
|
data/test/support/fixtures.rb
CHANGED