subroutine 0.10.0.beta8 → 0.10.0.beta9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/subroutine/association_fields.rb +18 -0
- data/lib/subroutine/version.rb +1 -1
- data/test/subroutine/association_test.rb +12 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f4e568d027e2b761473b800a74f078576b4abb6f66d507d23bd965348ea189c5
|
4
|
+
data.tar.gz: bd172e96b99b247414e12d91e40a3de2c26c1a4875f2dbd60d7f8c240486cb9a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 40c066cafed1fad6c4ac256f71d96cb8be990691b5b325b0e22b2f324317916bca80d17cc9721790956061474cb133775d31aa9f19b77bc7c50469b6593423c2
|
7
|
+
data.tar.gz: b442d7d9ff5fe6e1ded23624fc069b1fa5752116450273e4f874607a7b5024fb3bd7e7a68c695c8944fd81fd3484a789c1a2fcd683a7a11cfc64cfb59c0f840a
|
@@ -93,6 +93,24 @@ module Subroutine
|
|
93
93
|
setup_fields_without_association(*args)
|
94
94
|
end
|
95
95
|
|
96
|
+
def params_with_associations
|
97
|
+
association_fields = field_configurations.select { |_name, config| config.behavior == :association }
|
98
|
+
return params if association_fields.empty?
|
99
|
+
|
100
|
+
excepts = []
|
101
|
+
association_fields.each_pair do |_name, config|
|
102
|
+
excepts << config.foreign_key_method
|
103
|
+
excepts << config.foreign_type_method if config.polymorphic?
|
104
|
+
end
|
105
|
+
|
106
|
+
out = params.except(*excepts)
|
107
|
+
association_fields.each_pair do |field_name, _config|
|
108
|
+
out[field_name] = send(field_name) if field_provided?(field_name)
|
109
|
+
end
|
110
|
+
|
111
|
+
out
|
112
|
+
end
|
113
|
+
|
96
114
|
def set_field_with_association(field_name, value, opts = {})
|
97
115
|
config = get_field_config(field_name)
|
98
116
|
|
data/lib/subroutine/version.rb
CHANGED
@@ -198,5 +198,17 @@ module Subroutine
|
|
198
198
|
assert_equal({ "admin_id" => 1, "admin_type" => "User" }, op.params)
|
199
199
|
end
|
200
200
|
|
201
|
+
def test_params_can_be_accessed_with_associations_loaded
|
202
|
+
user = User.new(id: 1)
|
203
|
+
op = SimpleAssociationOp.new(user: user)
|
204
|
+
|
205
|
+
assert_equal({ "user_id" => 1 }, op.params)
|
206
|
+
assert_equal({ "user" => user }, op.params_with_associations)
|
207
|
+
|
208
|
+
op = PolymorphicAssociationOp.new(admin: user)
|
209
|
+
assert_equal({ "admin_id" => 1, "admin_type" => "User" }, op.params)
|
210
|
+
assert_equal({ "admin" => user }, op.params_with_associations)
|
211
|
+
end
|
212
|
+
|
201
213
|
end
|
202
214
|
end
|