subroutine 0.3.2 → 0.3.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: eaf64bc5b7da2f85485bd5e3f22c3e69106da013
4
- data.tar.gz: 65575447d14913aba3e9d6565d168ff5bb0fb202
3
+ metadata.gz: 02db9f879b81621b4bf0eb6825644ccb513b7883
4
+ data.tar.gz: 6e557fb324b506ed9462fed4825228ff664fdcb7
5
5
  SHA512:
6
- metadata.gz: 0d249ab00c1017ac02427e26b6a2bab807b015ed8ab4f5c0ddcb5125a005aa9335cae759b4ddfb5ba766704ee2b5859723ab779bbabfad6675002cc41956dfce
7
- data.tar.gz: 67c4967e9136863e67bfc7d29c0a9358352f54594eff7ec1887d932bf533cc1b1cdeada1d488089fb10b244fa930d4ede7bab75ee95f28a4f162c42f934d95f4
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
- field(field_name, options)
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
@@ -2,7 +2,7 @@ module Subroutine
2
2
 
3
3
  MAJOR = 0
4
4
  MINOR = 3
5
- PATCH = 2
5
+ PATCH = 3
6
6
  PRE = nil
7
7
 
8
8
  VERSION = [MAJOR, MINOR, PATCH, PRE].compact.join('.')
@@ -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
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.3.2
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Nelson