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 +4 -4
- data/lib/subroutine/type_caster.rb +5 -3
- data/lib/subroutine/version.rb +1 -1
- data/test/subroutine/association_test.rb +17 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c3571693a24dd9d341127e6de4d29cd242d2afc31e5e569728d4dc9101dcd11d
|
4
|
+
data.tar.gz: 72efb048aa00d5ba7be9c8a5c48fa6dd84c69ca71a6e1544373c96e85b3b0869
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
70
|
-
|
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
|
data/lib/subroutine/version.rb
CHANGED
@@ -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.
|
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-
|
11
|
+
date: 2023-03-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|