activeinteractor 1.0.0.beta.6 → 1.0.0.beta.7
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/CHANGELOG.md +17 -1
- data/README.md +1 -1
- data/lib/active_interactor/rails/{active_record.rb → models.rb} +21 -19
- data/lib/active_interactor/rails/orm/active_record.rb +5 -0
- data/lib/active_interactor/rails/railtie.rb +0 -4
- data/lib/active_interactor/rails.rb +1 -1
- data/lib/active_interactor/version.rb +1 -1
- data/lib/rails/generators/active_interactor/install_generator.rb +2 -0
- data/lib/rails/generators/active_interactor/templates/initializer.erb +8 -0
- data/spec/integration/active_record_integration_spec.rb +207 -210
- metadata +6 -7
- data/spec/active_interactor/rails/active_record_spec.rb +0 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6fc8ba19ece1da4ceed9d40d07e248dd77294c23c0b90b4a4012f74bce2726f9
|
4
|
+
data.tar.gz: f785b96877bab8eaed1f7cc612aad65d75bfa723170221cd54d46270e820f152
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 589bd2fe219fc23e75eb2319242de9692ff17b157c09987495ee5931ee66137415b9c9d8291a6cd1dbcd8dc3bb7a8df8c206ecfec93c01249296c49ba590ccde
|
7
|
+
data.tar.gz: d699de2f8be391922a8d26ca96767ca654547760724f732a2396e367d3cf903fac8c6d6b4c6d3a704f928d94671c3beec6292747c202020507a92e96dadba8d5
|
data/CHANGELOG.md
CHANGED
@@ -7,6 +7,20 @@ and this project adheres to [Semantic Versioning].
|
|
7
7
|
|
8
8
|
## [Unreleased]
|
9
9
|
|
10
|
+
## [v1.0.0-beta.7] - 2020-01-21
|
11
|
+
|
12
|
+
### Added
|
13
|
+
|
14
|
+
- [#127] `ActiveInteractor::Rails::Models`
|
15
|
+
|
16
|
+
### Fixed
|
17
|
+
|
18
|
+
- [#127] #126 `act_as_context` not working
|
19
|
+
|
20
|
+
### Removed
|
21
|
+
|
22
|
+
- [#127] `ActiveInteractor::Rails::ActiveRecord`
|
23
|
+
|
10
24
|
## [v1.0.0-beta.6] - 2020-01-21
|
11
25
|
|
12
26
|
### Added
|
@@ -194,7 +208,8 @@ and this project adheres to [Semantic Versioning].
|
|
194
208
|
|
195
209
|
<!-- versions -->
|
196
210
|
|
197
|
-
[Unreleased]: https://github.com/aaronmallen/activeinteractor/compare/v1.0.0-beta.
|
211
|
+
[Unreleased]: https://github.com/aaronmallen/activeinteractor/compare/v1.0.0-beta.7...HEAD
|
212
|
+
[v1.0.0-beta.7]: https://github.com/aaronmallen/activeinteractor/compare/v1.0.0-beta.6...v1.0.0-beta.7
|
198
213
|
[v1.0.0-beta.6]: https://github.com/aaronmallen/activeinteractor/compare/v1.0.0-beta.5...v1.0.0-beta.6
|
199
214
|
[v1.0.0-beta.5]: https://github.com/aaronmallen/activeinteractor/compare/v1.0.0-beta.4...v1.0.0-beta.5
|
200
215
|
[v1.0.0-beta.4]: https://github.com/aaronmallen/activeinteractor/compare/v1.0.0-beta.3...v1.0.0-beta.4
|
@@ -235,3 +250,4 @@ and this project adheres to [Semantic Versioning].
|
|
235
250
|
[#115]: https://github.com/aaronmallen/activeinteractor/pull/115
|
236
251
|
[#122]: https://github.com/aaronmallen/activeinteractor/pull/122
|
237
252
|
[#124]: https://github.com/aaronmallen/activeinteractor/pull/124
|
253
|
+
[#127]: https://github.com/aaronmallen/activeinteractor/pull/127
|
data/README.md
CHANGED
@@ -51,7 +51,7 @@ see [v0.1.7](https://github.com/aaronmallen/activeinteractor/tree/0-1-stable)**
|
|
51
51
|
Add this line to your application's Gemfile:
|
52
52
|
|
53
53
|
```ruby
|
54
|
-
gem 'activeinteractor', '~> 1.0.0.beta.
|
54
|
+
gem 'activeinteractor', '~> 1.0.0.beta.7'
|
55
55
|
```
|
56
56
|
|
57
57
|
And then execute:
|
@@ -2,18 +2,11 @@
|
|
2
2
|
|
3
3
|
module ActiveInteractor
|
4
4
|
module Rails
|
5
|
-
#
|
5
|
+
# Model helper methods
|
6
6
|
# @author Aaron Allen <hello@aaronmallen.me>
|
7
7
|
# @since 1.0.0
|
8
|
-
module
|
9
|
-
#
|
10
|
-
def self.include_helpers
|
11
|
-
ActiveSupport.on_load(:active_record_base) do
|
12
|
-
extend ClassMethods
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
# ActiveRecord class helper methods
|
8
|
+
module Models
|
9
|
+
# Model class helper methods
|
17
10
|
# @author Aaron Allen <hello@aaronmallen.me>
|
18
11
|
# @since 1.0.0
|
19
12
|
module ClassMethods
|
@@ -27,19 +20,21 @@ module ActiveInteractor
|
|
27
20
|
end
|
28
21
|
end
|
29
22
|
|
23
|
+
# Model instance helper methods
|
24
|
+
# @author Aaron Allen <hello@aaronmallen.me>
|
25
|
+
# @since 1.0.0
|
30
26
|
module InstanceMethods
|
31
|
-
# Override
|
27
|
+
# Override initialize method to ensure
|
32
28
|
# context flags are copied to the new instance
|
33
|
-
# @param
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
super(attributes, options)
|
29
|
+
# @param attributes [Hash|nil] attributes to assign to the class
|
30
|
+
def initialize(attributes = nil)
|
31
|
+
copy_flags!(attributes) if attributes
|
32
|
+
copy_called!(attributes) if attributes
|
33
|
+
attributes_as_hash = attributes_as_hash(attributes)
|
34
|
+
super(attributes_as_hash)
|
40
35
|
end
|
41
36
|
|
42
|
-
# Merge an
|
37
|
+
# Merge an instance and ensure
|
43
38
|
# context flags are copied to the new instance
|
44
39
|
# @param context [*] the instance to be merged
|
45
40
|
# @return [*] the merged instance
|
@@ -50,6 +45,13 @@ module ActiveInteractor
|
|
50
45
|
end
|
51
46
|
self
|
52
47
|
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
def attributes_as_hash(attributes)
|
52
|
+
return attributes.to_h if attributes&.respond_to?(:to_h)
|
53
|
+
return attributes.attributes.to_h if attributes.respond_to?(:attributes)
|
54
|
+
end
|
53
55
|
end
|
54
56
|
end
|
55
57
|
end
|
@@ -14,10 +14,6 @@ module ActiveInteractor
|
|
14
14
|
|
15
15
|
config.eager_load_namespaces << ActiveInteractor
|
16
16
|
|
17
|
-
initializer 'active_interactor.active_record_helpers' do
|
18
|
-
ActiveInteractor::Rails::ActiveRecord.include_helpers
|
19
|
-
end
|
20
|
-
|
21
17
|
config.to_prepare do
|
22
18
|
ActiveInteractor.configure do |c|
|
23
19
|
c.logger = ::Rails.logger
|
@@ -1,8 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'active_interactor'
|
4
|
-
require 'active_interactor/rails/active_record'
|
5
4
|
require 'active_interactor/rails/config'
|
5
|
+
require 'active_interactor/rails/models'
|
6
6
|
require 'active_interactor/rails/railtie'
|
7
7
|
|
8
8
|
module ActiveInteractor
|
@@ -6,7 +6,9 @@ module ActiveInteractor
|
|
6
6
|
module Generators
|
7
7
|
class InstallGenerator < Base
|
8
8
|
source_root File.expand_path('templates', __dir__)
|
9
|
+
|
9
10
|
desc 'Install ActiveInteractor'
|
11
|
+
class_option :orm
|
10
12
|
argument :directory, type: :string, default: 'interactors', banner: 'directory'
|
11
13
|
|
12
14
|
def create_initializer
|
@@ -3,6 +3,14 @@
|
|
3
3
|
require 'active_interactor'
|
4
4
|
|
5
5
|
ActiveInteractor::Rails.configure do |config|
|
6
|
+
# ORM configuration
|
7
|
+
# Load and configure the ORM. Supports :active_record (default)
|
8
|
+
# Other ORMs may be available as additional gems.
|
9
|
+
<%- if options[:orm] -%>
|
10
|
+
require 'active_interactor/rails/orm/<%= options[:orm] %>'
|
11
|
+
<%- else -%>
|
12
|
+
# require 'active_interactor/rails/orm/<MY_ORM>'
|
13
|
+
<%- end -%>
|
6
14
|
|
7
15
|
# set the default directory for interactors
|
8
16
|
<%- if directory != 'interactors' -%>
|
@@ -3,6 +3,7 @@
|
|
3
3
|
require 'spec_helper'
|
4
4
|
begin
|
5
5
|
require 'active_interactor/rails'
|
6
|
+
require 'active_interactor/rails/orm/active_record'
|
6
7
|
|
7
8
|
RSpec.describe 'ActiveRecord Integration', type: :integration do
|
8
9
|
let!(:active_record_base_mock) do
|
@@ -42,321 +43,317 @@ begin
|
|
42
43
|
end
|
43
44
|
end
|
44
45
|
|
45
|
-
context 'after
|
46
|
-
before {
|
46
|
+
context 'after ActiveSupport.run_load_hooks has been invoked with :active_record' do
|
47
|
+
before { ActiveSupport.run_load_hooks(:active_record, active_record_base_mock) }
|
47
48
|
|
48
|
-
|
49
|
-
|
49
|
+
describe 'an ActiveRecord model class with .acts_as_context' do
|
50
|
+
let(:model_mock) do
|
51
|
+
build_class('ModelMock', active_record_base_mock) do
|
52
|
+
attr_accessor :foo
|
53
|
+
acts_as_context
|
54
|
+
end
|
55
|
+
end
|
50
56
|
|
51
|
-
describe 'an
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
+
describe 'as an instance' do
|
58
|
+
subject { model_mock.new }
|
59
|
+
|
60
|
+
it { is_expected.to respond_to :called! }
|
61
|
+
it { is_expected.to respond_to :fail! }
|
62
|
+
it { is_expected.to respond_to :fail? }
|
63
|
+
it { is_expected.to respond_to :failure? }
|
64
|
+
it { is_expected.to respond_to :merge! }
|
65
|
+
it { is_expected.to respond_to :rollback! }
|
66
|
+
it { is_expected.to respond_to :success? }
|
67
|
+
it { is_expected.to respond_to :successful? }
|
68
|
+
end
|
69
|
+
|
70
|
+
describe '.new' do
|
71
|
+
subject { model_mock.new(attributes) }
|
72
|
+
let(:attributes) { nil }
|
73
|
+
|
74
|
+
it 'is expected not to receive #copy_flags!' do
|
75
|
+
expect_any_instance_of(model_mock).not_to receive(:copy_flags!)
|
76
|
+
subject
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'is expected not to receive #copy_called!' do
|
80
|
+
expect_any_instance_of(model_mock).not_to receive(:copy_called!)
|
81
|
+
subject
|
57
82
|
end
|
58
83
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
it { is_expected.to respond_to :called! }
|
63
|
-
it { is_expected.to respond_to :fail! }
|
64
|
-
it { is_expected.to respond_to :fail? }
|
65
|
-
it { is_expected.to respond_to :failure? }
|
66
|
-
it { is_expected.to respond_to :merge! }
|
67
|
-
it { is_expected.to respond_to :rollback! }
|
68
|
-
it { is_expected.to respond_to :success? }
|
69
|
-
it { is_expected.to respond_to :successful? }
|
84
|
+
it 'is expected to invoke super on parent class with nil attributes' do
|
85
|
+
expect(active_record_base_mock).to receive(:new).with(nil)
|
86
|
+
subject
|
70
87
|
end
|
71
88
|
|
72
|
-
|
73
|
-
|
74
|
-
let(:attributes) { nil }
|
89
|
+
context 'with attributes { :foo => "foo" }' do
|
90
|
+
let(:attributes) { { foo: 'foo' } }
|
75
91
|
|
76
|
-
it
|
77
|
-
|
92
|
+
it { expect { subject }.not_to raise_error }
|
93
|
+
|
94
|
+
it 'is expected to receive #copy_flags!' do
|
95
|
+
expect_any_instance_of(model_mock).to receive(:copy_flags!).with(foo: 'foo')
|
78
96
|
subject
|
79
97
|
end
|
80
98
|
|
81
|
-
it 'is expected
|
82
|
-
expect_any_instance_of(model_mock).
|
99
|
+
it 'is expected to receive #copy_called!' do
|
100
|
+
expect_any_instance_of(model_mock).to receive(:copy_called!).with(foo: 'foo')
|
83
101
|
subject
|
84
102
|
end
|
85
103
|
|
86
|
-
it 'is expected to invoke super on parent class with
|
87
|
-
expect(active_record_base_mock).to receive(:new).with(
|
104
|
+
it 'is expected to invoke super on parent class with { :foo => "foo" }' do
|
105
|
+
expect(active_record_base_mock).to receive(:new).with(foo: 'foo')
|
88
106
|
subject
|
89
107
|
end
|
108
|
+
end
|
109
|
+
|
110
|
+
context 'with attributes being an instance of ModelMock having attributes { :foo => "foo" }' do
|
111
|
+
let(:previous_instance) { model_mock.new(foo: 'foo') }
|
112
|
+
let(:attributes) { previous_instance }
|
90
113
|
|
91
|
-
|
92
|
-
let(:attributes) { { foo: 'foo' } }
|
114
|
+
it { is_expected.to have_attributes(foo: 'foo') }
|
93
115
|
|
94
|
-
|
116
|
+
context 'with _failed equal to true on previous instance' do
|
117
|
+
before { previous_instance.instance_variable_set('@_failed', true) }
|
95
118
|
|
96
|
-
it
|
97
|
-
|
98
|
-
subject
|
99
|
-
end
|
119
|
+
it { is_expected.to be_failure }
|
120
|
+
end
|
100
121
|
|
101
|
-
|
102
|
-
|
103
|
-
|
122
|
+
context 'with _rolled_back equal to true on previous instance' do
|
123
|
+
before { previous_instance.instance_variable_set('@_rolled_back', true) }
|
124
|
+
|
125
|
+
it 'is expected to have instance_variable @_rolled_back eq to true' do
|
126
|
+
expect(subject.instance_variable_get('@_rolled_back')).to eq true
|
104
127
|
end
|
128
|
+
end
|
105
129
|
|
106
|
-
|
107
|
-
|
108
|
-
|
130
|
+
context 'with _called eq to ["foo"] on previous instance' do
|
131
|
+
before { previous_instance.instance_variable_set('@_called', %w[foo]) }
|
132
|
+
|
133
|
+
it 'is expected to have instance_variable @_called eq to ["foo"]' do
|
134
|
+
expect(subject.instance_variable_get('@_called')).to eq %w[foo]
|
109
135
|
end
|
110
136
|
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
describe '#merge!' do
|
141
|
+
subject { model_mock.new(attributes).merge!(merge_instance) }
|
142
|
+
context 'having attributes { :foo => nil }' do
|
143
|
+
let(:attributes) { { foo: nil } }
|
111
144
|
|
112
|
-
context 'with
|
113
|
-
let(:
|
114
|
-
let(:attributes) { previous_instance }
|
145
|
+
context 'with merging instance having attributes { :foo => "foo" }' do
|
146
|
+
let(:merge_instance) { model_mock.new(foo: 'foo') }
|
115
147
|
|
116
148
|
it { is_expected.to have_attributes(foo: 'foo') }
|
117
149
|
|
118
|
-
context 'with _failed equal to true on
|
119
|
-
before {
|
150
|
+
context 'with _failed equal to true on merging instance' do
|
151
|
+
before { merge_instance.instance_variable_set('@_failed', true) }
|
120
152
|
|
121
153
|
it { is_expected.to be_failure }
|
122
154
|
end
|
123
155
|
|
124
|
-
context 'with _rolled_back equal to true on
|
125
|
-
before {
|
156
|
+
context 'with _rolled_back equal to true on merging instance' do
|
157
|
+
before { merge_instance.instance_variable_set('@_rolled_back', true) }
|
126
158
|
|
127
159
|
it 'is expected to have instance_variable @_rolled_back eq to true' do
|
128
160
|
expect(subject.instance_variable_get('@_rolled_back')).to eq true
|
129
161
|
end
|
130
162
|
end
|
131
|
-
|
132
|
-
context 'with _called eq to ["foo"] on previous instance' do
|
133
|
-
before { previous_instance.instance_variable_set('@_called', %w[foo]) }
|
134
|
-
|
135
|
-
it 'is expected to have instance_variable @_called eq to ["foo"]' do
|
136
|
-
expect(subject.instance_variable_get('@_called')).to eq %w[foo]
|
137
|
-
end
|
138
|
-
end
|
139
163
|
end
|
140
164
|
end
|
141
165
|
|
142
|
-
|
143
|
-
|
144
|
-
context 'having attributes { :foo => nil }' do
|
145
|
-
let(:attributes) { { foo: nil } }
|
166
|
+
context 'having attributes { :foo => "foo"}' do
|
167
|
+
let(:attributes) { { foo: 'foo' } }
|
146
168
|
|
147
|
-
|
148
|
-
|
169
|
+
context 'with merging instance having attributes { :foo => "bar" }' do
|
170
|
+
let(:merge_instance) { model_mock.new(foo: 'bar') }
|
149
171
|
|
150
|
-
|
172
|
+
it { is_expected.to have_attributes(foo: 'bar') }
|
151
173
|
|
152
|
-
|
153
|
-
|
174
|
+
context 'with _failed equal to true on merging instance' do
|
175
|
+
before { merge_instance.instance_variable_set('@_failed', true) }
|
154
176
|
|
155
|
-
|
156
|
-
|
177
|
+
it { is_expected.to be_failure }
|
178
|
+
end
|
157
179
|
|
158
|
-
|
159
|
-
|
180
|
+
context 'with _rolled_back equal to true on merging instance' do
|
181
|
+
before { merge_instance.instance_variable_set('@_rolled_back', true) }
|
160
182
|
|
161
|
-
|
162
|
-
|
163
|
-
end
|
183
|
+
it 'is expected to have instance_variable @_rolled_back eq to true' do
|
184
|
+
expect(subject.instance_variable_get('@_rolled_back')).to eq true
|
164
185
|
end
|
165
186
|
end
|
166
187
|
end
|
188
|
+
end
|
189
|
+
end
|
190
|
+
end
|
167
191
|
|
168
|
-
|
169
|
-
|
192
|
+
describe 'a basic interactor using an ActiveRecord model class as context' do
|
193
|
+
let!(:model_mock) do
|
194
|
+
require 'active_model'
|
195
|
+
build_class('ModelMock', active_record_base_mock) do
|
196
|
+
include ActiveModel::Validations
|
197
|
+
attr_accessor :foo
|
198
|
+
acts_as_context
|
199
|
+
end
|
200
|
+
end
|
170
201
|
|
171
|
-
|
172
|
-
|
202
|
+
let(:interactor_class) do
|
203
|
+
build_interactor do
|
204
|
+
contextualize_with :model_mock
|
173
205
|
|
174
|
-
|
206
|
+
def perform
|
207
|
+
context.foo = 'foo'
|
208
|
+
end
|
209
|
+
end
|
210
|
+
end
|
175
211
|
|
176
|
-
|
177
|
-
|
212
|
+
include_examples 'a class with interactor methods'
|
213
|
+
include_examples 'a class with interactor callback methods'
|
214
|
+
include_examples 'a class with interactor context methods'
|
178
215
|
|
179
|
-
|
180
|
-
|
216
|
+
describe '.context_class' do
|
217
|
+
subject { interactor_class.context_class }
|
181
218
|
|
182
|
-
|
183
|
-
|
219
|
+
it { is_expected.to eq model_mock }
|
220
|
+
end
|
184
221
|
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
end
|
222
|
+
describe '.perform' do
|
223
|
+
subject { interactor_class.perform }
|
224
|
+
|
225
|
+
it { is_expected.to be_a model_mock }
|
226
|
+
it { is_expected.to be_successful }
|
227
|
+
it { is_expected.to have_attributes(foo: 'foo') }
|
192
228
|
end
|
193
229
|
|
194
|
-
describe '
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
end
|
230
|
+
describe '.perform!' do
|
231
|
+
subject { interactor_class.perform! }
|
232
|
+
|
233
|
+
it { expect { subject }.not_to raise_error }
|
234
|
+
it { is_expected.to be_a model_mock }
|
235
|
+
it { is_expected.to be_successful }
|
236
|
+
it { is_expected.to have_attributes(foo: 'foo') }
|
237
|
+
end
|
203
238
|
|
239
|
+
context 'failing the context on #perform' do
|
204
240
|
let(:interactor_class) do
|
205
241
|
build_interactor do
|
206
242
|
contextualize_with :model_mock
|
207
243
|
|
208
244
|
def perform
|
209
|
-
context.
|
245
|
+
context.fail!
|
210
246
|
end
|
211
247
|
end
|
212
248
|
end
|
213
249
|
|
214
|
-
include_examples 'a class with interactor methods'
|
215
|
-
include_examples 'a class with interactor callback methods'
|
216
|
-
include_examples 'a class with interactor context methods'
|
217
|
-
|
218
|
-
describe '.context_class' do
|
219
|
-
subject { interactor_class.context_class }
|
220
|
-
|
221
|
-
it { is_expected.to eq model_mock }
|
222
|
-
end
|
223
|
-
|
224
250
|
describe '.perform' do
|
225
251
|
subject { interactor_class.perform }
|
226
252
|
|
253
|
+
it { expect { subject }.not_to raise_error }
|
227
254
|
it { is_expected.to be_a model_mock }
|
228
|
-
it { is_expected.to
|
229
|
-
it
|
255
|
+
it { is_expected.to be_failure }
|
256
|
+
it 'is expected to #rollback' do
|
257
|
+
expect_any_instance_of(interactor_class).to receive(:rollback)
|
258
|
+
subject
|
259
|
+
end
|
230
260
|
end
|
231
261
|
|
232
262
|
describe '.perform!' do
|
233
263
|
subject { interactor_class.perform! }
|
234
264
|
|
235
|
-
it { expect { subject }.
|
236
|
-
it { is_expected.to be_a model_mock }
|
237
|
-
it { is_expected.to be_successful }
|
238
|
-
it { is_expected.to have_attributes(foo: 'foo') }
|
239
|
-
end
|
240
|
-
|
241
|
-
context 'failing the context on #perform' do
|
242
|
-
let(:interactor_class) do
|
243
|
-
build_interactor do
|
244
|
-
contextualize_with :model_mock
|
245
|
-
|
246
|
-
def perform
|
247
|
-
context.fail!
|
248
|
-
end
|
249
|
-
end
|
250
|
-
end
|
251
|
-
|
252
|
-
describe '.perform' do
|
253
|
-
subject { interactor_class.perform }
|
254
|
-
|
255
|
-
it { expect { subject }.not_to raise_error }
|
256
|
-
it { is_expected.to be_a model_mock }
|
257
|
-
it { is_expected.to be_failure }
|
258
|
-
it 'is expected to #rollback' do
|
259
|
-
expect_any_instance_of(interactor_class).to receive(:rollback)
|
260
|
-
subject
|
261
|
-
end
|
262
|
-
end
|
263
|
-
|
264
|
-
describe '.perform!' do
|
265
|
-
subject { interactor_class.perform! }
|
266
|
-
|
267
|
-
it { expect { subject }.to raise_error(ActiveInteractor::Error::ContextFailure) }
|
268
|
-
end
|
265
|
+
it { expect { subject }.to raise_error(ActiveInteractor::Error::ContextFailure) }
|
269
266
|
end
|
270
267
|
end
|
268
|
+
end
|
271
269
|
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
end
|
270
|
+
describe 'a basic organizer using an ActiveRecord model class as context' do
|
271
|
+
let!(:model_mock) do
|
272
|
+
require 'active_model'
|
273
|
+
build_class('ModelMock', active_record_base_mock) do
|
274
|
+
include ActiveModel::Validations
|
275
|
+
attr_accessor :first_name, :last_name
|
276
|
+
acts_as_context
|
280
277
|
end
|
278
|
+
end
|
281
279
|
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
280
|
+
context 'with each organized interactor using the model' do
|
281
|
+
let!(:test_interactor_1) do
|
282
|
+
build_interactor('TestInteractor1') do
|
283
|
+
contextualize_with :model_mock
|
286
284
|
|
287
|
-
|
288
|
-
|
289
|
-
end
|
285
|
+
def perform
|
286
|
+
context.first_name = 'Test'
|
290
287
|
end
|
291
288
|
end
|
289
|
+
end
|
292
290
|
|
293
|
-
|
294
|
-
|
295
|
-
|
291
|
+
let!(:test_interactor_2) do
|
292
|
+
build_interactor('TestInteractor2') do
|
293
|
+
contextualize_with :model_mock
|
296
294
|
|
297
|
-
|
298
|
-
|
299
|
-
end
|
295
|
+
def perform
|
296
|
+
context.last_name = 'User'
|
300
297
|
end
|
301
298
|
end
|
299
|
+
end
|
302
300
|
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
end
|
301
|
+
let(:interactor_class) do
|
302
|
+
build_organizer do
|
303
|
+
contextualize_with :model_mock
|
304
|
+
organize :test_interactor_1, :test_interactor_2
|
308
305
|
end
|
306
|
+
end
|
309
307
|
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
308
|
+
include_examples 'a class with interactor methods'
|
309
|
+
include_examples 'a class with interactor callback methods'
|
310
|
+
include_examples 'a class with interactor context methods'
|
311
|
+
include_examples 'a class with organizer callback methods'
|
314
312
|
|
315
|
-
|
316
|
-
|
313
|
+
describe '.perform' do
|
314
|
+
subject { interactor_class.perform }
|
317
315
|
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
end
|
316
|
+
it { is_expected.to be_a model_mock }
|
317
|
+
it { is_expected.to be_successful }
|
318
|
+
it { is_expected.to have_attributes(first_name: 'Test', last_name: 'User') }
|
322
319
|
end
|
320
|
+
end
|
323
321
|
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
end
|
322
|
+
context 'with each organized interactor using their default context' do
|
323
|
+
let!(:test_interactor_1) do
|
324
|
+
build_interactor('TestInteractor1') do
|
325
|
+
def perform
|
326
|
+
context.first_name = 'Test'
|
330
327
|
end
|
331
328
|
end
|
329
|
+
end
|
332
330
|
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
end
|
331
|
+
let!(:test_interactor_2) do
|
332
|
+
build_interactor('TestInteractor2') do
|
333
|
+
def perform
|
334
|
+
context.last_name = 'User'
|
338
335
|
end
|
339
336
|
end
|
337
|
+
end
|
340
338
|
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
end
|
339
|
+
let(:interactor_class) do
|
340
|
+
build_organizer do
|
341
|
+
contextualize_with :model_mock
|
342
|
+
organize :test_interactor_1, :test_interactor_2
|
346
343
|
end
|
344
|
+
end
|
347
345
|
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
346
|
+
include_examples 'a class with interactor methods'
|
347
|
+
include_examples 'a class with interactor callback methods'
|
348
|
+
include_examples 'a class with interactor context methods'
|
349
|
+
include_examples 'a class with organizer callback methods'
|
352
350
|
|
353
|
-
|
354
|
-
|
351
|
+
describe '.perform' do
|
352
|
+
subject { interactor_class.perform }
|
355
353
|
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
end
|
354
|
+
it { is_expected.to be_a model_mock }
|
355
|
+
it { is_expected.to be_successful }
|
356
|
+
it { is_expected.to have_attributes(first_name: 'Test', last_name: 'User') }
|
360
357
|
end
|
361
358
|
end
|
362
359
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activeinteractor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0.beta.
|
4
|
+
version: 1.0.0.beta.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aaron Allen
|
@@ -122,8 +122,9 @@ files:
|
|
122
122
|
- lib/active_interactor/organizer/interactor_interface.rb
|
123
123
|
- lib/active_interactor/organizer/interactor_interface_collection.rb
|
124
124
|
- lib/active_interactor/rails.rb
|
125
|
-
- lib/active_interactor/rails/active_record.rb
|
126
125
|
- lib/active_interactor/rails/config.rb
|
126
|
+
- lib/active_interactor/rails/models.rb
|
127
|
+
- lib/active_interactor/rails/orm/active_record.rb
|
127
128
|
- lib/active_interactor/rails/railtie.rb
|
128
129
|
- lib/active_interactor/version.rb
|
129
130
|
- lib/rails/generators/active_interactor.rb
|
@@ -156,7 +157,6 @@ files:
|
|
156
157
|
- spec/active_interactor/organizer/interactor_interface_collection_spec.rb
|
157
158
|
- spec/active_interactor/organizer/interactor_interface_spec.rb
|
158
159
|
- spec/active_interactor/organizer_spec.rb
|
159
|
-
- spec/active_interactor/rails/active_record_spec.rb
|
160
160
|
- spec/active_interactor/rails/config_spec.rb
|
161
161
|
- spec/active_interactor/rails_spec.rb
|
162
162
|
- spec/active_interactor_spec.rb
|
@@ -177,10 +177,10 @@ licenses:
|
|
177
177
|
- MIT
|
178
178
|
metadata:
|
179
179
|
bug_tracker_uri: https://github.com/aaronmallen/activeinteractor/issues
|
180
|
-
changelog_uri: https://github.com/aaronmallen/activeinteractor/blob/v1.0.0.beta.
|
181
|
-
documentation_uri: https://www.rubydoc.info/gems/activeinteractor/1.0.0.beta.
|
180
|
+
changelog_uri: https://github.com/aaronmallen/activeinteractor/blob/v1.0.0.beta.7/CHANGELOG.md
|
181
|
+
documentation_uri: https://www.rubydoc.info/gems/activeinteractor/1.0.0.beta.7
|
182
182
|
hompage_uri: https://github.com/aaronmallen/activeinteractor
|
183
|
-
source_code_uri: https://github.com/aaronmallen/activeinteractor/tree/v1.0.0.beta.
|
183
|
+
source_code_uri: https://github.com/aaronmallen/activeinteractor/tree/v1.0.0.beta.7
|
184
184
|
wiki_uri: https://github.com/aaronmallen/activeinteractor/wiki
|
185
185
|
post_install_message:
|
186
186
|
rdoc_options: []
|
@@ -221,7 +221,6 @@ test_files:
|
|
221
221
|
- spec/active_interactor/organizer_spec.rb
|
222
222
|
- spec/active_interactor/organizer/interactor_interface_spec.rb
|
223
223
|
- spec/active_interactor/organizer/interactor_interface_collection_spec.rb
|
224
|
-
- spec/active_interactor/rails/active_record_spec.rb
|
225
224
|
- spec/active_interactor/rails/config_spec.rb
|
226
225
|
- spec/active_interactor/rails_spec.rb
|
227
226
|
- spec/active_interactor/interactor/worker_spec.rb
|
@@ -1,23 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
begin
|
5
|
-
require 'active_interactor/rails'
|
6
|
-
|
7
|
-
RSpec.describe ActiveInteractor::Rails::ActiveRecord do
|
8
|
-
describe '.include_helpers' do
|
9
|
-
subject { described_class.include_helpers }
|
10
|
-
let!(:active_record_mock) { build_class('ActiveRecordBaseMock') }
|
11
|
-
|
12
|
-
it 'is expected to extend ClassMethods' do
|
13
|
-
subject
|
14
|
-
ActiveSupport.run_load_hooks(:active_record_base, active_record_mock)
|
15
|
-
expect(active_record_mock).to respond_to :acts_as_context
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
rescue LoadError
|
20
|
-
RSpec.describe 'ActiveInteractor::Rails::ActiveRecord' do
|
21
|
-
pending 'Rails not found skipping specs...'
|
22
|
-
end
|
23
|
-
end
|