spyke 5.4.0 → 5.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
  SHA256:
3
- metadata.gz: 7de3203151c0bbf40af24c4ebb7926f60b497e61cd4a7edd3d5b0dcc12f302e5
4
- data.tar.gz: 9cea6becd607f2f4a74258a5984055e619206f0df881c56fb444716e6e91b8af
3
+ metadata.gz: 46c56a1975e770acc9b1e9d40abdfbfd7d59b15705da333d293d0ecb18678628
4
+ data.tar.gz: bbc4a65e7cc6293ce9e93410eae69dd4003ede73364207c17bff79c1736770a2
5
5
  SHA512:
6
- metadata.gz: db5b33e37fe25bc7f2f56215ca904a37c40541804acaa8338c9b63d23ac10e9e7724f65b6abf4ac98501b354fd1d802cd0bff0483b3a2b64673797d299043750
7
- data.tar.gz: 34252e5c0e56a6b7a3fc83343ed955d39f6dc46250da3c8e90817df01609adcb9e09105cc9bb6b96bfd4b8c66bf06d3dbcbc20fbf4ccc7cd11ef016800019c5a
6
+ metadata.gz: 6e741d1302b7a404d2f052329814b74af2aab61f17a5edff94b06f1bb5fadf78a8bbb43c93dbd2ed4a48064721dad8e57a28d53fde35b5d14f7a44f19fe01a31
7
+ data.tar.gz: 9a7cbdf9fd0b504c9772dd5388ff949b1ab5abe666277e11efc8e347e3aae22e5337cba0b506388f90f9cc2b68f5ddb97bf4dd8b08b50694a43e1f2d99c32a9a
@@ -83,7 +83,7 @@ module Spyke
83
83
  # Set id attribute directly if using a custom primary key alongside an attribute named "id" to avoid clobbering
84
84
  set_attribute :id, attributes.delete(:id) if conflicting_ids?(attributes)
85
85
 
86
- attributes.each do |key, value|
86
+ attributes.to_h.each do |key, value|
87
87
  send "#{key}=", value
88
88
  end
89
89
  end
data/lib/spyke/http.rb CHANGED
@@ -50,8 +50,8 @@ module Spyke
50
50
  request.body = params
51
51
  end
52
52
  end
53
- rescue Faraday::ConnectionFailed, Faraday::TimeoutError
54
- raise ConnectionError
53
+ rescue Faraday::ConnectionFailed, Faraday::TimeoutError
54
+ raise ConnectionError
55
55
  end
56
56
 
57
57
  private
data/lib/spyke/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Spyke
2
- VERSION = '5.4.0'
2
+ VERSION = '5.4.1'
3
3
  end
data/spyke.gemspec CHANGED
@@ -24,6 +24,7 @@ Gem::Specification.new do |spec|
24
24
  spec.add_dependency 'faraday_middleware', '>= 0.9.1', '< 2.0'
25
25
  spec.add_dependency 'addressable', '>= 2.5.2'
26
26
 
27
+ spec.add_development_dependency 'actionpack', '>= 4.0.0'
27
28
  spec.add_development_dependency 'bundler', '~> 1.6'
28
29
  spec.add_development_dependency 'coveralls', '~> 0.7'
29
30
  spec.add_development_dependency 'minitest'
@@ -301,6 +301,22 @@ module Spyke
301
301
  assert_equal %w{ starter sauce }, recipe.groups.map(&:title)
302
302
  end
303
303
 
304
+ def test_nested_attributes_has_one_using_strong_params
305
+ recipe = Recipe.new(image_attributes: strong_params(file: 'bob.jpg').permit!)
306
+ assert_equal 'bob.jpg', recipe.image.file
307
+ end
308
+
309
+ def test_nested_attributes_belongs_to_using_strong_params
310
+ recipe = Recipe.new(user_attributes: strong_params({ name: 'Bob' }).permit!)
311
+ assert_equal 'Bob', recipe.user.name
312
+ end
313
+
314
+ def test_nested_attributes_has_many_using_strong_params
315
+ params = strong_params(groups_attributes: [strong_params(title: 'starter').permit!, strong_params(title: 'sauce').permit!]).permit!
316
+ recipe = Recipe.new(params)
317
+ assert_equal %w{ starter sauce }, recipe.groups.map(&:title)
318
+ end
319
+
304
320
  def test_nested_attributes_replacing_existing_when_no_ids_present
305
321
  recipe = Recipe.new(groups_attributes: [{ title: 'starter' }, { title: 'sauce' }])
306
322
  recipe.attributes = { groups_attributes: [{ title: 'flavor' }] }
@@ -325,6 +341,17 @@ module Spyke
325
341
  assert_equal %w{ starter sauce }, recipe.groups.map(&:title)
326
342
  end
327
343
 
344
+ def test_nested_attributes_has_many_using_strong_params_with_hash_syntax
345
+ params = strong_params(
346
+ groups_attributes: strong_params(
347
+ '0' => strong_params(title: 'starter').permit!,
348
+ '1' => strong_params(title: 'sauce').permit!,
349
+ ).permit!
350
+ ).permit!
351
+ recipe = Recipe.new(params)
352
+ assert_equal %w{ starter sauce }, recipe.groups.map(&:title)
353
+ end
354
+
328
355
  def test_deeply_nested_attributes_has_many_using_array_syntax
329
356
  params = { groups_attributes: [{ id: 1, ingredients_attributes: [{ id: 1, name: 'Salt' }, { id: 2, name: 'Pepper' } ]}] }
330
357
  recipe = Recipe.new(params)
@@ -357,6 +384,40 @@ module Spyke
357
384
  assert_equal %w{ Salt Pepper }, recipe.ingredients.map(&:name)
358
385
  end
359
386
 
387
+ def test_deeply_nested_attributes_has_many_using_strong_params_with_array_syntax
388
+ params = strong_params(
389
+ groups_attributes: [
390
+ strong_params(
391
+ ingredients_attributes: [
392
+ strong_params(id: '', name: 'Salt').permit!,
393
+ strong_params(id: '', name: 'Pepper').permit!,
394
+ ]
395
+ ).permit!
396
+ ]
397
+ ).permit!
398
+ recipe = Recipe.new(params)
399
+ assert_equal %w{ Salt Pepper }, recipe.ingredients.map(&:name)
400
+ recipe.attributes = params
401
+ assert_equal %w{ Salt Pepper }, recipe.ingredients.map(&:name)
402
+ end
403
+
404
+ def test_deeply_nested_attributes_has_many_using_strong_params_with_hash_syntax
405
+ params = strong_params(
406
+ groups_attributes: strong_params(
407
+ '0' => strong_params(
408
+ ingredients_attributes: strong_params(
409
+ '0' => strong_params(id: '', name: 'Salt').permit!,
410
+ '1' => strong_params(id: '', name: 'Pepper').permit!,
411
+ ).permit!
412
+ ).permit!
413
+ ).permit!
414
+ ).permit!
415
+ recipe = Recipe.new(params)
416
+ assert_equal %w{ Salt Pepper }, recipe.ingredients.map(&:name)
417
+ recipe.attributes = params
418
+ assert_equal %w{ Salt Pepper }, recipe.ingredients.map(&:name)
419
+ end
420
+
360
421
  def test_reflect_on_association
361
422
  assert_equal Group, Recipe.reflect_on_association(:group).klass
362
423
  assert_equal Cookbook::Like, Cookbook::Tip.reflect_on_association(:like).klass
@@ -11,6 +11,18 @@ module Spyke
11
11
  assert_equal 'Tasty', recipe.description
12
12
  end
13
13
 
14
+ def test_initializing_using_permitted_strong_params
15
+ ingredient = Ingredient.new(strong_params(name: 'Flour').permit!)
16
+
17
+ assert_equal 'Flour', ingredient.name
18
+ end
19
+
20
+ def test_initializing_using_unpermitted_strong_params
21
+ assert_raises ActionController::UnfilteredParameters do
22
+ Ingredient.new(strong_params(name: 'Flour'))
23
+ end
24
+ end
25
+
14
26
  def test_to_params
15
27
  attr = Attributes.new(id: 3, 'title' => 'Fish', groups: [ Group.new(name: 'Starter'), { name: 'Dessert' } ])
16
28
  assert_equal({ 'id' => 3 , 'title' => 'Fish', 'groups' => [{ 'name' => 'Starter' }, { 'name' => 'Dessert' }] }, attr.to_params)
data/test/orm_test.rb CHANGED
@@ -54,6 +54,22 @@ module Spyke
54
54
  assert_requested endpoint
55
55
  end
56
56
 
57
+ def test_save_hash_attribute
58
+ endpoint = stub_request(:post, 'http://sushi.com/recipes').with(body: { recipe: { meta: { foo: 'bar' } } })
59
+
60
+ Recipe.create(meta: { foo: 'bar' })
61
+
62
+ assert_requested endpoint
63
+ end
64
+
65
+ def test_save_hash_attribute_with_strong_params
66
+ endpoint = stub_request(:post, 'http://sushi.com/recipes').with(body: { recipe: { meta: { foo: 'bar' } } })
67
+
68
+ Recipe.create(strong_params(meta: { foo: 'bar' }).permit!)
69
+
70
+ assert_requested endpoint
71
+ end
72
+
57
73
  def test_update_attributes
58
74
  endpoint = stub_request(:put, 'http://sushi.com/recipes/1').with(body: { recipe: { title: 'Sushi' } }).to_return_json(result: { id: 1, title: 'Sushi (saved)' })
59
75
 
data/test/test_helper.rb CHANGED
@@ -18,3 +18,10 @@ Dir[File.expand_path('../support/**/*.rb', __FILE__)].each { |f| require f }
18
18
 
19
19
  # Pretty colors
20
20
  Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new
21
+
22
+ # For testing strong params
23
+ require 'action_controller/metal/strong_parameters'
24
+
25
+ def strong_params(params)
26
+ ActionController::Parameters.new(params)
27
+ end
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: 5.4.0
4
+ version: 5.4.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: 2020-12-09 00:00:00.000000000 Z
11
+ date: 2021-02-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -92,6 +92,20 @@ dependencies:
92
92
  - - ">="
93
93
  - !ruby/object:Gem::Version
94
94
  version: 2.5.2
95
+ - !ruby/object:Gem::Dependency
96
+ name: actionpack
97
+ requirement: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: 4.0.0
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: 4.0.0
95
109
  - !ruby/object:Gem::Dependency
96
110
  name: bundler
97
111
  requirement: !ruby/object:Gem::Requirement