subroutine 0.10.0.beta8 → 0.10.0.beta9

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: 4c5dff0a8ab49afebd76be4189b3128c27f6f79786a4745fb01a9b18b023ea44
4
- data.tar.gz: 1329a8feaedde19122bb3afbca4eda13818dcb720b9edc0b01cd58e3422c4463
3
+ metadata.gz: f4e568d027e2b761473b800a74f078576b4abb6f66d507d23bd965348ea189c5
4
+ data.tar.gz: bd172e96b99b247414e12d91e40a3de2c26c1a4875f2dbd60d7f8c240486cb9a
5
5
  SHA512:
6
- metadata.gz: 2acf6bdb0f20e14dbf24155a3e4d80db6715d7eb9ab6869d0ef2b07a7cf7efd2ef9b4287827fcf25d0877c5910e979885e8fa5fe84256d16479bc47340b7cd04
7
- data.tar.gz: b0c826a03266eeafd1db07597c0c70c43065b73780137182129310238e0e74c04505d83a207dc1357ba20c5b00cfd1107c3d9d92152213961c7256ec4fb10fee
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
 
@@ -5,7 +5,7 @@ module Subroutine
5
5
  MAJOR = 0
6
6
  MINOR = 10
7
7
  PATCH = 0
8
- PRE = "beta8"
8
+ PRE = "beta9"
9
9
 
10
10
  VERSION = [MAJOR, MINOR, PATCH, PRE].compact.join(".")
11
11
 
@@ -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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: subroutine
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.0.beta8
4
+ version: 0.10.0.beta9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Nelson