subroutine 2.0.0.beta → 2.0.0.beta2
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/.ruby-version +1 -1
- data/CHANGELOG.MD +1 -1
- data/lib/subroutine/association_fields/configuration.rb +5 -2
- data/lib/subroutine/fields/configuration.rb +1 -0
- data/lib/subroutine/type_caster.rb +9 -0
- data/lib/subroutine/version.rb +1 -1
- data/test/subroutine/association_test.rb +18 -6
- data/test/subroutine/type_caster_test.rb +23 -0
- data/test/support/ops.rb +4 -2
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bc8eb530552fea8e2bacd033372826e11c57734d9695973ebca956c76aa2ed93
|
4
|
+
data.tar.gz: 908764a3fc127881b4c719c2c5523ae280771683e765ea8f47ddda52bed76a33
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4de2ad64fede40a510afe5b0af073eb6fae1800a61e2f9387337c1d46475ec439c1c35cb393ecececb3a5954b7c9e1b32be10e6be963dc7ce3fb840d40a3b368
|
7
|
+
data.tar.gz: 9ec24f1a6ce47edb502bded197096dec4d1ff444c4d3b0fda64291111aa7a29e67e7bd4f8e01a018c72795117c40e16fa3c68131b64db346e3c1073611c8134e
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.5.
|
1
|
+
2.5.7
|
data/CHANGELOG.MD
CHANGED
@@ -81,7 +81,7 @@ class AccountUpdateOp < ::Op
|
|
81
81
|
end
|
82
82
|
```
|
83
83
|
|
84
|
-
ActionController::Parameters from Rails 5+ are now transformed to
|
84
|
+
ActionController::Parameters from Rails 5+ are now transformed to a hash in `Subroutine::Fields` by default. This means strong parameters are essentially unused when passing `Subroutine::Fields`.
|
85
85
|
|
86
86
|
Read more about field management and access in https://github.com/guideline-tech/subroutine/wiki/Param-Usage
|
87
87
|
|
@@ -60,7 +60,7 @@ module Subroutine
|
|
60
60
|
end
|
61
61
|
|
62
62
|
def build_foreign_key_field
|
63
|
-
build_child_field(foreign_key_method)
|
63
|
+
build_child_field(foreign_key_method, type: :foreign_key, foreign_key_type: config[:foreign_key_type])
|
64
64
|
end
|
65
65
|
|
66
66
|
def build_foreign_type_field
|
@@ -78,7 +78,10 @@ module Subroutine
|
|
78
78
|
protected
|
79
79
|
|
80
80
|
def build_child_field(name, opts = {})
|
81
|
-
|
81
|
+
child_opts = inheritable_options
|
82
|
+
child_opts.merge!(opts)
|
83
|
+
child_opts[:association_name] = as
|
84
|
+
ComponentConfiguration.new(name, child_opts)
|
82
85
|
end
|
83
86
|
|
84
87
|
end
|
@@ -63,6 +63,15 @@ end
|
|
63
63
|
String(value)
|
64
64
|
end
|
65
65
|
|
66
|
+
::Subroutine::TypeCaster.register :foreign_key do |value, options = {}|
|
67
|
+
next nil if value.blank?
|
68
|
+
|
69
|
+
next ::Subroutine::TypeCaster.cast(value, type: options[:foreign_key_type]) if options[:foreign_key_type]
|
70
|
+
next ::Subroutine::TypeCaster.cast(value, type: :integer) if options[:name] && options[:name].to_s.end_with?("_id")
|
71
|
+
|
72
|
+
value
|
73
|
+
end
|
74
|
+
|
66
75
|
::Subroutine::TypeCaster.register :boolean, :bool do |value, _options = {}|
|
67
76
|
!!(String(value) =~ /^(yes|true|1|ok)$/)
|
68
77
|
end
|
data/lib/subroutine/version.rb
CHANGED
@@ -83,20 +83,32 @@ module Subroutine
|
|
83
83
|
def test_it_allows_foreign_key_to_be_set
|
84
84
|
all_mock = mock
|
85
85
|
::User.expects(:all).returns(all_mock)
|
86
|
-
all_mock.expects(:find_by!).with(id:
|
86
|
+
all_mock.expects(:find_by!).with(id: 10).returns(doug)
|
87
87
|
|
88
|
-
op = ::AssociationWithForeignKeyOp.new(
|
88
|
+
op = ::AssociationWithForeignKeyOp.new(owner_id: 10)
|
89
89
|
assert_equal doug, op.user
|
90
|
-
assert_equal "
|
90
|
+
assert_equal "owner_id", op.field_configurations[:user][:foreign_key]
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_the_foreign_key_is_cast
|
94
|
+
all_mock = mock
|
95
|
+
::User.expects(:all).returns(all_mock)
|
96
|
+
all_mock.expects(:find_by!).with(id: 10).returns(doug)
|
97
|
+
|
98
|
+
op = ::AssociationWithForeignKeyOp.new(owner_id: "10")
|
99
|
+
assert_equal doug, op.user
|
100
|
+
assert_equal 10, op.owner_id
|
101
|
+
assert_equal "owner_id", op.field_configurations[:user][:foreign_key]
|
91
102
|
end
|
92
103
|
|
93
104
|
def test_it_allows_a_foreign_key_and_find_by_to_be_set
|
94
105
|
all_mock = mock
|
95
106
|
::User.expects(:all).returns(all_mock)
|
96
|
-
all_mock.expects(:find_by!).with(email_address:
|
107
|
+
all_mock.expects(:find_by!).with(email_address: "foo@bar.com").returns(doug)
|
97
108
|
|
98
|
-
op = ::AssociationWithFindByAndForeignKeyOp.new(email_address:
|
109
|
+
op = ::AssociationWithFindByAndForeignKeyOp.new(email_address: "foo@bar.com")
|
99
110
|
assert_equal doug, op.user
|
111
|
+
assert_equal "foo@bar.com", op.email_address
|
100
112
|
assert_equal "email_address", op.field_configurations[:user][:find_by]
|
101
113
|
end
|
102
114
|
|
@@ -119,7 +131,7 @@ module Subroutine
|
|
119
131
|
def test_values_are_correct_for_foreign_key_usage
|
120
132
|
op = ::AssociationWithForeignKeyOp.new(user: doug)
|
121
133
|
assert_equal doug, op.user
|
122
|
-
assert_equal doug.id, op.
|
134
|
+
assert_equal doug.id, op.owner_id
|
123
135
|
end
|
124
136
|
|
125
137
|
def test_values_are_correct_for_both_foreign_key_and_find_by_usage
|
@@ -261,5 +261,28 @@ module Subroutine
|
|
261
261
|
op.date_input = "2015-13-01"
|
262
262
|
end
|
263
263
|
end
|
264
|
+
|
265
|
+
def test_foreign_key_inputs
|
266
|
+
op.fk_input_owner_id = nil
|
267
|
+
assert_nil op.fk_input_owner_id
|
268
|
+
|
269
|
+
op.fk_input_owner_id = ""
|
270
|
+
assert_nil op.fk_input_owner_id
|
271
|
+
|
272
|
+
op.fk_input_owner_id = "19402"
|
273
|
+
assert_equal 19402, op.fk_input_owner_id
|
274
|
+
|
275
|
+
op.fk_input_owner_id = "19402.0"
|
276
|
+
assert_equal 19402, op.fk_input_owner_id
|
277
|
+
|
278
|
+
op.fk_input_email_address = nil
|
279
|
+
assert_nil op.fk_input_email_address
|
280
|
+
|
281
|
+
op.fk_input_email_address = ""
|
282
|
+
assert_nil op.fk_input_email_address
|
283
|
+
|
284
|
+
op.fk_input_email_address = "foo@bar.com"
|
285
|
+
assert_equal "foo@bar.com", op.fk_input_email_address
|
286
|
+
end
|
264
287
|
end
|
265
288
|
end
|
data/test/support/ops.rb
CHANGED
@@ -166,6 +166,8 @@ class TypeCastOp < ::Subroutine::Op
|
|
166
166
|
array :array_input, default: "foo"
|
167
167
|
array :type_array_input, of: :integer
|
168
168
|
file :file_input
|
169
|
+
foreign_key :fk_input_owner_id
|
170
|
+
foreign_key :fk_input_email_address, foreign_key_type: :string
|
169
171
|
|
170
172
|
end
|
171
173
|
|
@@ -314,13 +316,13 @@ end
|
|
314
316
|
|
315
317
|
class AssociationWithForeignKeyOp < ::OpWithAssociation
|
316
318
|
|
317
|
-
association :user, foreign_key: "
|
319
|
+
association :user, foreign_key: "owner_id"
|
318
320
|
|
319
321
|
end
|
320
322
|
|
321
323
|
class AssociationWithFindByKeyOp < ::OpWithAssociation
|
322
324
|
|
323
|
-
association :user, find_by: "email_address"
|
325
|
+
association :user, find_by: "email_address", foreign_key_type: :string
|
324
326
|
|
325
327
|
end
|
326
328
|
|
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.0.0.
|
4
|
+
version: 2.0.0.beta2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Nelson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-02-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -218,7 +218,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
218
218
|
- !ruby/object:Gem::Version
|
219
219
|
version: 1.3.1
|
220
220
|
requirements: []
|
221
|
-
rubygems_version: 3.
|
221
|
+
rubygems_version: 3.3.7
|
222
222
|
signing_key:
|
223
223
|
specification_version: 4
|
224
224
|
summary: Feature-driven operation objects.
|