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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 18786d5a16e1af110485c81e9c7174507bad9ffc
4
- data.tar.gz: a12316a477c6c9baf8dc95985ac0c378279cc88f
3
+ metadata.gz: ccd9957900a277390812c84d78b30985292cb2a9
4
+ data.tar.gz: c5cdb9be619f68febc8b20a51d339db19fcb7d4e
5
5
  SHA512:
6
- metadata.gz: caa7363096f246e4a8547499545b288262c6cae186f6130071284619d7f7ccd1f3ddddaa48f840134d7748e88b2c670a532759dcc161e6d21658809bd538529d
7
- data.tar.gz: 02a3ece5fbcba5c35723b40459cb85593c5e72be3a3ada1d1840a1b628ec08c9aca6a2bfeb20086aa6c55526cfa673dec54adfa88c375b9765cdcd398d7fae96
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="http://badge.fury.io/rb/spyke"><img src="https://badge.fury.io/rb/spyke.svg" alt="Gem Version" height="18"></a>
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://gemnasium.com/balvig/spyke'><img src="http://img.shields.io/gemnasium/balvig/spyke.svg" /></a>
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
 
@@ -28,6 +28,7 @@ module Spyke
28
28
 
29
29
  def has_one(name, options = {})
30
30
  self.associations = associations.merge(name => options.merge(type: HasOne))
31
+
31
32
  define_method "build_#{name}" do |attributes = nil|
32
33
  association(name).build(attributes)
33
34
  end
@@ -46,10 +46,6 @@ module Spyke
46
46
 
47
47
  private
48
48
 
49
- def default_attributes
50
- self.class.default_attributes
51
- end
52
-
53
49
  def parse(attributes)
54
50
  attributes.each_with_object({}) do |(key, value), parameters|
55
51
  parameters[key] = parse_value(value)
data/lib/spyke/orm.rb CHANGED
@@ -43,10 +43,6 @@ module Spyke
43
43
  new(id: id).destroy
44
44
  end
45
45
 
46
- def build(attributes = {})
47
- new(attributes)
48
- end
49
-
50
46
  def strip_slug(id)
51
47
  id.to_s.split('-').first
52
48
  end
data/lib/spyke/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Spyke
2
- VERSION = '1.4.0'
2
+ VERSION = '1.4.1'
3
3
  end
@@ -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(title: 'Water'), Ingredient.new(title: 'Flour')])
14
- assert_equal %w{ Water Flour }, group.ingredients.map(&:title)
15
- assert_equal({ 'group' => { 'ingredients' => [{ 'title' => 'Water' }, { 'title' => 'Flour' }] } }, group.to_params)
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 test_deeply_nested_attributes_using_array_style
259
- params = { groups_attributes: [{ id: 1, ingredient_attributes: [{ title: 'fish' }, { title: 'sauce' } ]}] }
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 1, recipe.groups.size
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 test_deeply_nested_attributes_with_no_ids
268
- params = { groups_attributes: [{ ingredient_attributes: [{ title: 'fish' }, { title: 'sauce' }]}] }
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 1, recipe.groups.size
276
+ assert_equal %w{ Salt Pepper }, recipe.ingredients.map(&:name)
272
277
  end
273
278
 
274
- def test_nested_attributes_has_many_using_hash_syntax
275
- recipe = Recipe.new(groups_attributes: { '0' => { title: 'starter' }, '1' => { title: 'sauce' } })
276
- assert_equal %w{ starter sauce }, recipe.groups.map(&:title)
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 test_deeply_nested_attributes_with_blank_ids
280
- recipe = Recipe.new(groups_attributes: { '0' => { ingredients_attributes: { '0' => { id: '', name: 'Salt' }, '1' => { id: '', name: 'Pepper' } } } })
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
 
@@ -2,9 +2,10 @@ require 'test_helper'
2
2
 
3
3
  module Spyke
4
4
  class CustomRequestTest < MiniTest::Test
5
- def test_custom_get_request_from_class
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
- assert_equal %w{ Bread }, Recipe.get('/recipes/recent').map(&:title)
7
+ recipes = Recipe.get('/recipes/recent')
8
+ assert_equal %w{ Bread }, recipes.map(&:title)
8
9
  assert_requested endpoint
9
10
  end
10
11
 
@@ -16,11 +16,7 @@ class Recipe < Spyke::Base
16
16
  accepts_nested_attributes_for :image, :user, :groups
17
17
 
18
18
  def self.page(number)
19
- if number.present?
20
- where(page: number)
21
- else
22
- all
23
- end
19
+ where(page: number)
24
20
  end
25
21
 
26
22
  def ingredients
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: 1.4.0
4
+ version: 1.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jens Balvig