subroutine 0.3.2 → 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/subroutine/op.rb +6 -1
- data/lib/subroutine/version.rb +1 -1
- data/test/subroutine/association_test.rb +38 -0
- data/test/support/ops.rb +12 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 02db9f879b81621b4bf0eb6825644ccb513b7883
|
4
|
+
data.tar.gz: 6e557fb324b506ed9462fed4825228ff664fdcb7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4c39b6b9e07615d075b497bee62db14fda475cd72e7fe8843d5346e3ce9e99d9c7b251e8fa8984b2b4702d51d4d1f55c5ad51ebd405d32fbc7453bc33fb81460
|
7
|
+
data.tar.gz: 0d17dca16db07d8873a5701be92f820127de198c6e0c3a02d4db578becb69592f678885d3e675081d12f36015bbdfd7a3dae156e8372115cf691dcfe793dcf60
|
data/lib/subroutine/op.rb
CHANGED
@@ -51,7 +51,12 @@ module Subroutine
|
|
51
51
|
def inputs_from(*ops)
|
52
52
|
ops.each do |op|
|
53
53
|
op._fields.each_pair do |field_name, options|
|
54
|
-
|
54
|
+
if options[:association]
|
55
|
+
include ::Subroutine::Association unless included_modules.include?(::Subroutine::Association)
|
56
|
+
association(field_name, options)
|
57
|
+
else
|
58
|
+
field(field_name, options)
|
59
|
+
end
|
55
60
|
end
|
56
61
|
end
|
57
62
|
end
|
data/lib/subroutine/version.rb
CHANGED
@@ -64,5 +64,43 @@ module Subroutine
|
|
64
64
|
assert_equal "AdminUser", op.admin_type
|
65
65
|
end
|
66
66
|
|
67
|
+
def test_it_inherits_associations_via_inputs_from
|
68
|
+
all_mock = mock
|
69
|
+
|
70
|
+
::User.expects(:all).returns(all_mock)
|
71
|
+
all_mock.expects(:find).with(1).returns(doug)
|
72
|
+
|
73
|
+
op = ::InheritedSimpleAssociation.new(user_type: "User", user_id: doug.id)
|
74
|
+
assert_equal doug, op.user
|
75
|
+
assert_equal "User", op.user_type
|
76
|
+
assert_equal doug.id, op.user_id
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_it_inherits_associations_via_inputs_from_and_preserves_options
|
80
|
+
all_mock = mock
|
81
|
+
unscoped_mock = mock
|
82
|
+
|
83
|
+
::User.expects(:all).returns(all_mock)
|
84
|
+
all_mock.expects(:unscoped).returns(unscoped_mock)
|
85
|
+
unscoped_mock.expects(:find).with(1).returns(doug)
|
86
|
+
|
87
|
+
op = ::InheritedUnscopedAssociation.new(user_type: "User", user_id: doug.id)
|
88
|
+
assert_equal doug, op.user
|
89
|
+
assert_equal "User", op.user_type
|
90
|
+
assert_equal doug.id, op.user_id
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_it_inherits_polymorphic_associations_via_inputs_from
|
94
|
+
all_mock = mock
|
95
|
+
::User.expects(:all).never
|
96
|
+
::AdminUser.expects(:all).returns(all_mock)
|
97
|
+
all_mock.expects(:find).with(1).returns(doug)
|
98
|
+
|
99
|
+
op = ::InheritedPolymorphicAssociationOp.new(admin_type: "AdminUser", admin_id: doug.id)
|
100
|
+
assert_equal doug, op.admin
|
101
|
+
assert_equal "AdminUser", op.admin_type
|
102
|
+
assert_equal doug.id, op.admin_id
|
103
|
+
end
|
104
|
+
|
67
105
|
end
|
68
106
|
end
|
data/test/support/ops.rb
CHANGED
@@ -189,3 +189,15 @@ end
|
|
189
189
|
class AssociationWithClassOp < ::OpWithAssociation
|
190
190
|
association :admin, class_name: "AdminUser"
|
191
191
|
end
|
192
|
+
|
193
|
+
class InheritedSimpleAssociation < ::Subroutine::Op
|
194
|
+
inputs_from SimpleAssociationOp
|
195
|
+
end
|
196
|
+
|
197
|
+
class InheritedUnscopedAssociation < ::Subroutine::Op
|
198
|
+
inputs_from UnscopedSimpleAssociationOp
|
199
|
+
end
|
200
|
+
|
201
|
+
class InheritedPolymorphicAssociationOp < ::Subroutine::Op
|
202
|
+
inputs_from PolymorphicAssociationOp
|
203
|
+
end
|