statesman 4.1.2 → 4.1.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -26,7 +26,7 @@ Gem::Specification.new do |spec|
26
26
  spec.add_development_dependency "pg", "~> 0.18"
27
27
  spec.add_development_dependency "pry"
28
28
  spec.add_development_dependency "rails", ">= 3.2"
29
- spec.add_development_dependency "rake", "~> 12.3.0"
29
+ spec.add_development_dependency "rake", "~> 13.0.0"
30
30
  spec.add_development_dependency "rspec", "~> 3.1"
31
31
  spec.add_development_dependency "rspec-its", "~> 1.1"
32
32
  spec.add_development_dependency "rspec-rails", "~> 3.1"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: statesman
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.1.2
4
+ version: 4.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - GoCardless
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-08-17 00:00:00.000000000 Z
11
+ date: 2019-11-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ammeter
@@ -120,14 +120,14 @@ dependencies:
120
120
  requirements:
121
121
  - - "~>"
122
122
  - !ruby/object:Gem::Version
123
- version: 12.3.0
123
+ version: 13.0.0
124
124
  type: :development
125
125
  prerelease: false
126
126
  version_requirements: !ruby/object:Gem::Requirement
127
127
  requirements:
128
128
  - - "~>"
129
129
  - !ruby/object:Gem::Version
130
- version: 12.3.0
130
+ version: 13.0.0
131
131
  - !ruby/object:Gem::Dependency
132
132
  name: rspec
133
133
  requirement: !ruby/object:Gem::Requirement
@@ -234,10 +234,8 @@ files:
234
234
  - lib/generators/statesman/active_record_transition_generator.rb
235
235
  - lib/generators/statesman/generator_helpers.rb
236
236
  - lib/generators/statesman/migration_generator.rb
237
- - lib/generators/statesman/mongoid_transition_generator.rb
238
237
  - lib/generators/statesman/templates/active_record_transition_model.rb.erb
239
238
  - lib/generators/statesman/templates/create_migration.rb.erb
240
- - lib/generators/statesman/templates/mongoid_transition_model.rb.erb
241
239
  - lib/generators/statesman/templates/update_migration.rb.erb
242
240
  - lib/statesman.rb
243
241
  - lib/statesman/adapters/active_record.rb
@@ -245,8 +243,6 @@ files:
245
243
  - lib/statesman/adapters/active_record_transition.rb
246
244
  - lib/statesman/adapters/memory.rb
247
245
  - lib/statesman/adapters/memory_transition.rb
248
- - lib/statesman/adapters/mongoid.rb
249
- - lib/statesman/adapters/mongoid_transition.rb
250
246
  - lib/statesman/callback.rb
251
247
  - lib/statesman/config.rb
252
248
  - lib/statesman/exceptions.rb
@@ -261,14 +257,12 @@ files:
261
257
  - spec/fixtures/add_most_recent_to_bacon_transitions.rb
262
258
  - spec/generators/statesman/active_record_transition_generator_spec.rb
263
259
  - spec/generators/statesman/migration_generator_spec.rb
264
- - spec/generators/statesman/mongoid_transition_generator_spec.rb
265
260
  - spec/spec_helper.rb
266
261
  - spec/statesman/adapters/active_record_queries_spec.rb
267
262
  - spec/statesman/adapters/active_record_spec.rb
268
263
  - spec/statesman/adapters/active_record_transition_spec.rb
269
264
  - spec/statesman/adapters/memory_spec.rb
270
265
  - spec/statesman/adapters/memory_transition_spec.rb
271
- - spec/statesman/adapters/mongoid_spec.rb
272
266
  - spec/statesman/adapters/shared_examples.rb
273
267
  - spec/statesman/callback_spec.rb
274
268
  - spec/statesman/config_spec.rb
@@ -277,7 +271,6 @@ files:
277
271
  - spec/statesman/utils_spec.rb
278
272
  - spec/support/active_record.rb
279
273
  - spec/support/generators_shared_examples.rb
280
- - spec/support/mongoid.rb
281
274
  - statesman.gemspec
282
275
  homepage: https://github.com/gocardless/statesman
283
276
  licenses:
@@ -299,7 +292,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
299
292
  version: '0'
300
293
  requirements: []
301
294
  rubyforge_project:
302
- rubygems_version: 2.5.2.3
295
+ rubygems_version: 2.5.2
303
296
  signing_key:
304
297
  specification_version: 4
305
298
  summary: A statesman-like state machine library
@@ -309,14 +302,12 @@ test_files:
309
302
  - spec/fixtures/add_most_recent_to_bacon_transitions.rb
310
303
  - spec/generators/statesman/active_record_transition_generator_spec.rb
311
304
  - spec/generators/statesman/migration_generator_spec.rb
312
- - spec/generators/statesman/mongoid_transition_generator_spec.rb
313
305
  - spec/spec_helper.rb
314
306
  - spec/statesman/adapters/active_record_queries_spec.rb
315
307
  - spec/statesman/adapters/active_record_spec.rb
316
308
  - spec/statesman/adapters/active_record_transition_spec.rb
317
309
  - spec/statesman/adapters/memory_spec.rb
318
310
  - spec/statesman/adapters/memory_transition_spec.rb
319
- - spec/statesman/adapters/mongoid_spec.rb
320
311
  - spec/statesman/adapters/shared_examples.rb
321
312
  - spec/statesman/callback_spec.rb
322
313
  - spec/statesman/config_spec.rb
@@ -325,4 +316,3 @@ test_files:
325
316
  - spec/statesman/utils_spec.rb
326
317
  - spec/support/active_record.rb
327
318
  - spec/support/generators_shared_examples.rb
328
- - spec/support/mongoid.rb
@@ -1,25 +0,0 @@
1
- require "rails/generators"
2
- require "generators/statesman/generator_helpers"
3
-
4
- module Statesman
5
- class MongoidTransitionGenerator < Rails::Generators::Base
6
- include Statesman::GeneratorHelpers
7
-
8
- desc "Create a Mongoid-based transition model with the required attributes"
9
-
10
- argument :parent, type: :string, desc: "Your parent model name"
11
- argument :klass, type: :string, desc: "Your transition model name"
12
-
13
- source_root File.expand_path("templates", __dir__)
14
-
15
- def create_model_file
16
- template("mongoid_transition_model.rb.erb", model_file_name)
17
- end
18
-
19
- private
20
-
21
- def collection_name
22
- klass.underscore.pluralize
23
- end
24
- end
25
- end
@@ -1,14 +0,0 @@
1
- class <%= klass %>
2
- include Mongoid::Document
3
- include Mongoid::Timestamps
4
-
5
- field :to_state, type: String
6
- field :sort_key, type: Integer
7
- field :statesman_metadata, type: Hash
8
-
9
- include Statesman::Adapters::MongoidTransition
10
-
11
- index({ sort_key: 1 })
12
-
13
- belongs_to :<%= parent %><%= class_name_option %>, index: true
14
- end
@@ -1,66 +0,0 @@
1
- require_relative "../exceptions"
2
-
3
- module Statesman
4
- module Adapters
5
- class Mongoid
6
- attr_reader :transition_class
7
- attr_reader :parent_model
8
-
9
- def initialize(transition_class, parent_model, observer, _opts = {})
10
- @transition_class = transition_class
11
- @parent_model = parent_model
12
- @observer = observer
13
- unless transition_class_hash_fields.include?("statesman_metadata")
14
- raise UnserializedMetadataError, metadata_field_error_message
15
- end
16
- end
17
-
18
- def create(from, to, metadata = {})
19
- from = from.to_s
20
- to = to.to_s
21
- transition = transitions_for_parent.build(to_state: to,
22
- sort_key: next_sort_key,
23
- statesman_metadata: metadata)
24
-
25
- @observer.execute(:before, from, to, transition)
26
- transition.save!
27
- @last_transition = transition
28
- @observer.execute(:after, from, to, transition)
29
- @observer.execute(:after_commit, from, to, transition)
30
- transition
31
- ensure
32
- @last_transition = nil
33
- end
34
-
35
- def history(*)
36
- transitions_for_parent.asc(:sort_key)
37
- end
38
-
39
- def last(force_reload: false)
40
- if force_reload
41
- @last_transition = history.last
42
- else
43
- @last_transition ||= history.last
44
- end
45
- end
46
-
47
- private
48
-
49
- def transition_class_hash_fields
50
- transition_class.fields.select { |_, v| v.type == Hash }.keys
51
- end
52
-
53
- def metadata_field_error_message
54
- "#{transition_class.name}#statesman_metadata is not of type 'Hash'"
55
- end
56
-
57
- def transitions_for_parent
58
- @parent_model.send(@transition_class.collection_name)
59
- end
60
-
61
- def next_sort_key
62
- (last && last.sort_key + 10) || 10
63
- end
64
- end
65
- end
66
- end
@@ -1,10 +0,0 @@
1
- module Statesman
2
- module Adapters
3
- module MongoidTransition
4
- def self.included(base)
5
- base.send(:alias_method, :metadata, :statesman_metadata)
6
- base.send(:alias_method, :metadata=, :statesman_metadata=)
7
- end
8
- end
9
- end
10
- end
@@ -1,23 +0,0 @@
1
- require "spec_helper"
2
- require "support/generators_shared_examples"
3
- require "generators/statesman/mongoid_transition_generator"
4
-
5
- describe Statesman::MongoidTransitionGenerator, type: :generator do
6
- describe "the model contains the correct words" do
7
- subject { file("app/models/yummy/bacon_transition.rb") }
8
-
9
- before { run_generator %w[Yummy::Bacon Yummy::BaconTransition] }
10
-
11
- it { is_expected.to_not contain(%r{:yummy/bacon}) }
12
- it { is_expected.to contain(/class_name: 'Yummy::Bacon'/) }
13
- end
14
-
15
- describe "the model contains the correct words" do
16
- subject { file("app/models/bacon_transition.rb") }
17
-
18
- before { run_generator %w[Bacon BaconTransition] }
19
-
20
- it { is_expected.to_not contain(/class_name:/) }
21
- it { is_expected.to_not contain(/CreateYummy::Bacon/) }
22
- end
23
- end
@@ -1,86 +0,0 @@
1
- require "spec_helper"
2
- require "statesman/adapters/shared_examples"
3
- require "statesman/exceptions"
4
- require "support/mongoid"
5
- require "mongoid"
6
-
7
- describe Statesman::Adapters::Mongoid, mongo: true do
8
- after { Mongoid.purge! }
9
-
10
- let(:observer) { double(Statesman::Machine, execute: nil) }
11
- let(:model) { MyMongoidModel.create(current_state: :pending) }
12
-
13
- it_behaves_like "an adapter", described_class, MyMongoidModelTransition
14
-
15
- describe "#initialize" do
16
- context "with unserialized metadata" do
17
- before do
18
- allow_any_instance_of(described_class).
19
- to receive_messages(transition_class_hash_fields: [])
20
- end
21
-
22
- it "raises an exception if metadata is not serialized" do
23
- expect do
24
- described_class.new(MyMongoidModelTransition, MyMongoidModel,
25
- observer)
26
- end.to raise_exception(Statesman::UnserializedMetadataError)
27
- end
28
- end
29
- end
30
-
31
- describe "#last" do
32
- let(:adapter) do
33
- described_class.new(MyMongoidModelTransition, model, observer)
34
- end
35
-
36
- context "with a previously looked up transition" do
37
- before { adapter.create(:x, :y) }
38
-
39
- before { adapter.last }
40
-
41
- it "caches the transition" do
42
- expect_any_instance_of(MyMongoidModel).
43
- to_not receive(:my_mongoid_model_transitions)
44
- adapter.last
45
- end
46
-
47
- context "and a new transition" do
48
- before { adapter.create(:y, :z) }
49
-
50
- it "retrieves the new transition from the database" do
51
- expect(adapter.last.to_state).to eq("z")
52
- end
53
- end
54
- end
55
-
56
- context "when a new transition has been created elsewhere" do
57
- let(:alternate_adapter) do
58
- described_class.new(MyMongoidModelTransition, model, observer)
59
- end
60
-
61
- context "when explicitly not using the cache" do
62
- context "when the transitions are in memory" do
63
- before do
64
- model.my_mongoid_model_transitions.entries
65
- alternate_adapter.create(:y, :z)
66
- end
67
-
68
- it "reloads the value" do
69
- expect(adapter.last(force_reload: true).to_state).to eq("z")
70
- end
71
- end
72
-
73
- context "when the transitions are not in memory" do
74
- before do
75
- model.my_mongoid_model_transitions.reset
76
- alternate_adapter.create(:y, :z)
77
- end
78
-
79
- it "reloads the value" do
80
- expect(adapter.last(force_reload: true).to_state).to eq("z")
81
- end
82
- end
83
- end
84
- end
85
- end
86
- end
@@ -1,28 +0,0 @@
1
- require "mongoid"
2
-
3
- Mongoid.configure do |config|
4
- config.connect_to("statesman_test")
5
- end
6
-
7
- class MyMongoidModel
8
- include Mongoid::Document
9
-
10
- field :current_state, type: String
11
-
12
- has_many :my_mongoid_model_transitions
13
- end
14
-
15
- class MyMongoidModelTransition
16
- include Mongoid::Document
17
- include Mongoid::Timestamps
18
-
19
- field :to_state, type: String
20
- field :sort_key, type: Integer
21
- field :statesman_metadata, type: Hash
22
-
23
- index(sort_key: 1)
24
-
25
- belongs_to :my_mongoid_model, index: true
26
-
27
- include Statesman::Adapters::MongoidTransition
28
- end