subroutine 2.3.1 → 2.3.2

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: 0a85a75ee28c2c27b1d144059b1af01681aee27987ca2fdad9a0736b2270c824
4
- data.tar.gz: 73bf392120764aa30da22c18b756ea8483f35b34e14e473fae6f7d495a4cbc9f
3
+ metadata.gz: c3571693a24dd9d341127e6de4d29cd242d2afc31e5e569728d4dc9101dcd11d
4
+ data.tar.gz: 72efb048aa00d5ba7be9c8a5c48fa6dd84c69ca71a6e1544373c96e85b3b0869
5
5
  SHA512:
6
- metadata.gz: ea38c80c4bbf80eb1763f1052b5f0a906268b1eb6416bcd6e4f2f39a678af16395555ddc02b56867671413076680fb65343d7462974e594f112e8cdb2136f52b
7
- data.tar.gz: b5590640ea893a227ef850fb052fb04cac6d46ccc0af2cb33b7b86972518c1b5b7988114fab0faa6472b215f8f927825c9699a08266fd6713ed8c84a88846065
6
+ metadata.gz: 97c717c09a9b7a2e8fcc76240c0cb1a928bb9a3407e5442e126a3cf0aa147f03d747c43ed44da1efa8258b0ade53242c3bf064141d51fe612769fe446b87ec5d
7
+ data.tar.gz: ee2f52b5c450828495d2e5d5f11458edec8243487768570b6dcd09e5606a40637290222187c79344284353baaee206cf4833022d8983c5b5eb909809f037b1b3
@@ -65,9 +65,11 @@ end
65
65
 
66
66
  ::Subroutine::TypeCaster.register :foreign_key do |value, options = {}|
67
67
  next nil if value.blank?
68
-
69
- next ::Subroutine::TypeCaster.cast(value, type: options[:foreign_key_type].call) if options[:foreign_key_type].respond_to?(:call)
70
- next ::Subroutine::TypeCaster.cast(value, type: options[:foreign_key_type]) if options[:foreign_key_type]
68
+
69
+ calculated_type = options[:foreign_key_type].respond_to?(:call)
70
+ calculated_value = calculated_type ? options[:foreign_key_type].call : options[:foreign_key_type]
71
+
72
+ next ::Subroutine::TypeCaster.cast(value, type: calculated_value) if calculated_value
71
73
  next ::Subroutine::TypeCaster.cast(value, type: :integer) if options[:name] && options[:name].to_s.end_with?("_id")
72
74
 
73
75
  value
@@ -4,7 +4,7 @@ module Subroutine
4
4
 
5
5
  MAJOR = 2
6
6
  MINOR = 3
7
- PATCH = 1
7
+ PATCH = 2
8
8
  PRE = nil
9
9
 
10
10
  VERSION = [MAJOR, MINOR, PATCH, PRE].compact.join(".")
@@ -231,6 +231,11 @@ module Subroutine
231
231
  assert_equal true, op.field_provided?(:admin_id)
232
232
  assert_equal true, op.field_provided?(:admin_type)
233
233
 
234
+ op = PolymorphicAssociationOp.new admin_type: doug.class.name, admin_id: doug.id.to_s
235
+ assert_equal true, op.field_provided?(:admin)
236
+ assert_equal true, op.field_provided?(:admin_id)
237
+ assert_equal true, op.field_provided?(:admin_type)
238
+
234
239
  op = PolymorphicAssociationOp.new admin_id: doug.id
235
240
  assert_equal false, op.field_provided?(:admin)
236
241
  assert_equal true, op.field_provided?(:admin_id)
@@ -293,6 +298,18 @@ module Subroutine
293
298
  assert_equal({ "admin_id" => 1, "admin_type" => "User" }, op.params)
294
299
  end
295
300
 
301
+ def test_params_id_type_as_integer_for_polymorphic_associations
302
+ user = ::User.new(id: 1)
303
+
304
+ op = PolymorphicAssociationOp.new(admin_id: user.id)
305
+ op.admin
306
+ assert_equal({ "admin_id" => 1 }, op.params)
307
+
308
+ op = PolymorphicAssociationOp.new(admin_id: user.id.to_s)
309
+ op.admin
310
+ assert_equal({ "admin_id" => 1 }, op.params)
311
+ end
312
+
296
313
  def test_params_can_be_accessed_with_associations_loaded
297
314
  user = User.new(id: 1)
298
315
  op = SimpleAssociationOp.new(user: user)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: subroutine
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.1
4
+ version: 2.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Nelson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-03-15 00:00:00.000000000 Z
11
+ date: 2023-03-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel