statesman 3.4.1 → 3.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.circleci/config.yml +9 -9
- data/.rubocop_todo.yml +67 -2
- data/CHANGELOG.md +7 -0
- data/Gemfile +0 -4
- data/README.md +15 -1
- data/lib/generators/statesman/active_record_transition_generator.rb +1 -1
- data/lib/generators/statesman/migration_generator.rb +1 -1
- data/lib/generators/statesman/mongoid_transition_generator.rb +1 -1
- data/lib/generators/statesman/templates/create_migration.rb.erb +3 -3
- data/lib/generators/statesman/templates/update_migration.rb.erb +2 -2
- data/lib/statesman/adapters/active_record.rb +3 -3
- data/lib/statesman/adapters/active_record_queries.rb +7 -7
- data/lib/statesman/adapters/memory.rb +2 -2
- data/lib/statesman/adapters/mongoid.rb +1 -1
- data/lib/statesman/config.rb +0 -1
- data/lib/statesman/machine.rb +1 -1
- data/lib/statesman/version.rb +1 -1
- data/spec/generators/statesman/active_record_transition_generator_spec.rb +14 -9
- data/spec/generators/statesman/migration_generator_spec.rb +9 -9
- data/spec/generators/statesman/mongoid_transition_generator_spec.rb +7 -5
- data/spec/statesman/adapters/active_record_queries_spec.rb +17 -15
- data/spec/statesman/adapters/active_record_spec.rb +14 -4
- data/spec/statesman/adapters/memory_spec.rb +1 -0
- data/spec/statesman/{transition_spec.rb → adapters/memory_transition_spec.rb} +0 -0
- data/spec/statesman/adapters/mongoid_spec.rb +5 -1
- data/spec/statesman/adapters/shared_examples.rb +18 -9
- data/spec/statesman/callback_spec.rb +18 -6
- data/spec/statesman/config_spec.rb +6 -3
- data/spec/statesman/guard_spec.rb +3 -1
- data/spec/statesman/machine_spec.rb +52 -14
- data/spec/support/generators_shared_examples.rb +3 -1
- data/statesman.gemspec +12 -12
- metadata +23 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9fb352daa2f2ec337dd202cc2615a7e0925741a4
|
4
|
+
data.tar.gz: 9de7812c9356e6e9f98a317b503220b3a7f7709b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fbd8b2b4b822b2f7148cb7b47111153e6cd18831e227cf6c72ca073904866025eb3e1d433f503e778853734c0f522e674ad29cad44ec5bc29fdfda7e55130275
|
7
|
+
data.tar.gz: d55e7635f0773babcc1b5ef9da6f75a4144c8812ce305b93e1762e6100e658bd73f2989bb867efcb0be42225f1dfa49a67aeb064c1c287df62720c8afc693d4b
|
data/.circleci/config.yml
CHANGED
@@ -36,7 +36,7 @@ jobs:
|
|
36
36
|
environment:
|
37
37
|
- RAILS_VERSION=4.2.9
|
38
38
|
- DATABASE_DEPENDENCY_PORT=27017
|
39
|
-
- image: circleci/mongo:3
|
39
|
+
- image: circleci/mongo:3
|
40
40
|
steps: *steps
|
41
41
|
build-ruby241-rails-429-mysql:
|
42
42
|
docker:
|
@@ -72,7 +72,7 @@ jobs:
|
|
72
72
|
environment:
|
73
73
|
- RAILS_VERSION=5.0.5
|
74
74
|
- DATABASE_DEPENDENCY_PORT=27017
|
75
|
-
- image: circleci/mongo:3
|
75
|
+
- image: circleci/mongo:3
|
76
76
|
steps: *steps
|
77
77
|
build-ruby241-rails-505-mysql:
|
78
78
|
docker:
|
@@ -108,7 +108,7 @@ jobs:
|
|
108
108
|
environment:
|
109
109
|
- RAILS_VERSION=5.1.3
|
110
110
|
- DATABASE_DEPENDENCY_PORT=27017
|
111
|
-
- image: circleci/mongo:3
|
111
|
+
- image: circleci/mongo:3
|
112
112
|
steps: *steps
|
113
113
|
build-ruby241-rails-513-mysql:
|
114
114
|
docker:
|
@@ -144,7 +144,7 @@ jobs:
|
|
144
144
|
environment:
|
145
145
|
- RAILS_VERSION=4.2.9
|
146
146
|
- DATABASE_DEPENDENCY_PORT=27017
|
147
|
-
- image: circleci/mongo:3
|
147
|
+
- image: circleci/mongo:3
|
148
148
|
steps: *steps
|
149
149
|
build-ruby233-rails-429-mysql:
|
150
150
|
docker:
|
@@ -180,7 +180,7 @@ jobs:
|
|
180
180
|
environment:
|
181
181
|
- RAILS_VERSION=5.0.5
|
182
182
|
- DATABASE_DEPENDENCY_PORT=27017
|
183
|
-
- image: circleci/mongo:3
|
183
|
+
- image: circleci/mongo:3
|
184
184
|
steps: *steps
|
185
185
|
build-ruby233-rails-505-mysql:
|
186
186
|
docker:
|
@@ -216,7 +216,7 @@ jobs:
|
|
216
216
|
environment:
|
217
217
|
- RAILS_VERSION=5.1.3
|
218
218
|
- DATABASE_DEPENDENCY_PORT=27017
|
219
|
-
- image: circleci/mongo:3
|
219
|
+
- image: circleci/mongo:3
|
220
220
|
steps: *steps
|
221
221
|
build-ruby233-rails-513-mysql:
|
222
222
|
docker:
|
@@ -252,7 +252,7 @@ jobs:
|
|
252
252
|
environment:
|
253
253
|
- RAILS_VERSION=4.2.9
|
254
254
|
- DATABASE_DEPENDENCY_PORT=27017
|
255
|
-
- image: circleci/mongo:3
|
255
|
+
- image: circleci/mongo:3
|
256
256
|
steps: *steps
|
257
257
|
build-ruby227-rails-429-mysql:
|
258
258
|
docker:
|
@@ -288,7 +288,7 @@ jobs:
|
|
288
288
|
environment:
|
289
289
|
- RAILS_VERSION=5.0.5
|
290
290
|
- DATABASE_DEPENDENCY_PORT=27017
|
291
|
-
- image: circleci/mongo:3
|
291
|
+
- image: circleci/mongo:3
|
292
292
|
steps: *steps
|
293
293
|
build-ruby227-rails-505-mysql:
|
294
294
|
docker:
|
@@ -324,7 +324,7 @@ jobs:
|
|
324
324
|
environment:
|
325
325
|
- RAILS_VERSION=5.1.3
|
326
326
|
- DATABASE_DEPENDENCY_PORT=27017
|
327
|
-
- image: circleci/mongo:3
|
327
|
+
- image: circleci/mongo:3
|
328
328
|
steps: *steps
|
329
329
|
build-ruby227-rails-513-mysql:
|
330
330
|
docker:
|
data/.rubocop_todo.yml
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
# This configuration was generated by
|
2
2
|
# `rubocop --auto-gen-config`
|
3
|
-
# on
|
3
|
+
# on 2018-06-07 12:21:30 +0100 using RuboCop version 0.56.0.
|
4
4
|
# The point is for the user to remove these configuration records
|
5
5
|
# one by one as the offenses are removed from the code base.
|
6
6
|
# Note that changes in the inspected code, or installation of new
|
7
7
|
# versions of RuboCop, may require this file to be generated again.
|
8
8
|
|
9
|
-
# Offense count:
|
9
|
+
# Offense count: 4
|
10
10
|
Metrics/AbcSize:
|
11
11
|
Max: 18
|
12
12
|
|
@@ -14,3 +14,68 @@ Metrics/AbcSize:
|
|
14
14
|
# Configuration parameters: CountComments.
|
15
15
|
Metrics/MethodLength:
|
16
16
|
Max: 14
|
17
|
+
|
18
|
+
# Offense count: 7
|
19
|
+
# Configuration parameters: Max.
|
20
|
+
RSpec/ExampleLength:
|
21
|
+
Exclude:
|
22
|
+
- 'spec/statesman/adapters/active_record_spec.rb'
|
23
|
+
- 'spec/statesman/adapters/shared_examples.rb'
|
24
|
+
- 'spec/statesman/machine_spec.rb'
|
25
|
+
|
26
|
+
# Offense count: 7
|
27
|
+
RSpec/ExpectInHook:
|
28
|
+
Exclude:
|
29
|
+
- 'spec/statesman/adapters/active_record_spec.rb'
|
30
|
+
- 'spec/statesman/machine_spec.rb'
|
31
|
+
|
32
|
+
# Offense count: 1
|
33
|
+
# Configuration parameters: AssignmentOnly.
|
34
|
+
RSpec/InstanceVariable:
|
35
|
+
Exclude:
|
36
|
+
- 'spec/statesman/config_spec.rb'
|
37
|
+
|
38
|
+
# Offense count: 1
|
39
|
+
RSpec/IteratedExpectation:
|
40
|
+
Exclude:
|
41
|
+
- 'spec/statesman/machine_spec.rb'
|
42
|
+
|
43
|
+
# Offense count: 3
|
44
|
+
RSpec/LetSetup:
|
45
|
+
Exclude:
|
46
|
+
- 'spec/statesman/adapters/active_record_spec.rb'
|
47
|
+
- 'spec/statesman/adapters/shared_examples.rb'
|
48
|
+
|
49
|
+
# Offense count: 1
|
50
|
+
# Configuration parameters: EnforcedStyle.
|
51
|
+
# SupportedStyles: have_received, receive
|
52
|
+
RSpec/MessageSpies:
|
53
|
+
Exclude:
|
54
|
+
- 'spec/statesman/callback_spec.rb'
|
55
|
+
|
56
|
+
# Offense count: 9
|
57
|
+
# Configuration parameters: AggregateFailuresByDefault.
|
58
|
+
RSpec/MultipleExpectations:
|
59
|
+
Max: 3
|
60
|
+
|
61
|
+
# Offense count: 50
|
62
|
+
RSpec/NestedGroups:
|
63
|
+
Max: 6
|
64
|
+
|
65
|
+
# Offense count: 16
|
66
|
+
RSpec/ScatteredSetup:
|
67
|
+
Exclude:
|
68
|
+
- 'spec/statesman/adapters/active_record_spec.rb'
|
69
|
+
- 'spec/statesman/adapters/mongoid_spec.rb'
|
70
|
+
- 'spec/statesman/adapters/shared_examples.rb'
|
71
|
+
- 'spec/statesman/machine_spec.rb'
|
72
|
+
|
73
|
+
# Offense count: 8
|
74
|
+
# Configuration parameters: IgnoreSymbolicNames.
|
75
|
+
RSpec/VerifiedDoubles:
|
76
|
+
Exclude:
|
77
|
+
- 'spec/generators/statesman/active_record_transition_generator_spec.rb'
|
78
|
+
- 'spec/generators/statesman/migration_generator_spec.rb'
|
79
|
+
- 'spec/statesman/adapters/active_record_spec.rb'
|
80
|
+
- 'spec/statesman/adapters/mongoid_spec.rb'
|
81
|
+
- 'spec/statesman/adapters/shared_examples.rb'
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
## v3.5.0, 2 November 2018
|
2
|
+
|
3
|
+
- Expose `most_recent_transition_join` - ActiveRecords `or` requires that both
|
4
|
+
sides of the query match up. Exposing this methods makes things easier if
|
5
|
+
one side of the `or` uses `in_state` or `not_in_state`. (patch by [@adambutler](https://github.com/adambutler))
|
6
|
+
- Various Readme and CI related changes.
|
7
|
+
|
1
8
|
## v3.4.1, 14 February 2018 ❤️
|
2
9
|
|
3
10
|
- Support ActiveRecord transition classes which don't include `Statesman::Adapters::ActiveRecordTransition`, and thus don't have a `.updated_timestamp_column` method (see #310 for further details) (patch by [@timrogers](https://github.com/timrogers))
|
data/Gemfile
CHANGED
@@ -10,7 +10,3 @@ group :development do
|
|
10
10
|
# test/unit is no longer bundled with Ruby 2.2, but required by Rails
|
11
11
|
gem "test-unit", "~> 3.0" if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("2.2.0")
|
12
12
|
end
|
13
|
-
|
14
|
-
group :development, :test do
|
15
|
-
gem "gc_ruboconfig", "~> 2.1.0"
|
16
|
-
end
|
data/README.md
CHANGED
@@ -5,9 +5,10 @@ A statesmanlike state machine library.
|
|
5
5
|
For our policy on compatibility with Ruby and Rails versions, see [COMPATIBILITY.md](docs/COMPATIBILITY.md).
|
6
6
|
|
7
7
|
[![Gem Version](https://badge.fury.io/rb/statesman.svg)](http://badge.fury.io/rb/statesman)
|
8
|
-
[![CircleCI](https://circleci.com/gh/gocardless/statesman.svg?style=
|
8
|
+
[![CircleCI](https://circleci.com/gh/gocardless/statesman.svg?style=shield)](https://circleci.com/gh/gocardless/statesman)
|
9
9
|
[![Code Climate](https://codeclimate.com/github/gocardless/statesman.svg)](https://codeclimate.com/github/gocardless/statesman)
|
10
10
|
[![Gitter](https://badges.gitter.im/join.svg)](https://gitter.im/gocardless/statesman?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
11
|
+
[![SemVer](https://api.dependabot.com/badges/compatibility_score?dependency-name=statesman&package-manager=bundler&version-scheme=semver)](https://dependabot.com/compatibility-score.html?dependency-name=statesman&package-manager=bundler&version-scheme=semver)
|
11
12
|
|
12
13
|
Statesman is an opinionated state machine library designed to provide a robust
|
13
14
|
audit trail and data integrity. It decouples the state machine logic from the
|
@@ -100,6 +101,8 @@ Next, you'll need to create a further model to represent state transitions:
|
|
100
101
|
class OrderTransition < ActiveRecord::Base
|
101
102
|
include Statesman::Adapters::ActiveRecordTransition
|
102
103
|
|
104
|
+
validates :to_state, inclusion: { in: OrderStateMachine.states }
|
105
|
+
|
103
106
|
belongs_to :order, inverse_of: :order_transitions
|
104
107
|
end
|
105
108
|
```
|
@@ -371,6 +374,17 @@ Returns all models currently in any of the supplied states.
|
|
371
374
|
#### `Model.not_in_state(:state_1, :state_2, etc)`
|
372
375
|
Returns all models not currently in any of the supplied states.
|
373
376
|
|
377
|
+
|
378
|
+
### `Model.most_recent_transition_join`
|
379
|
+
This joins the model to its most recent transition whatever that may be.
|
380
|
+
We expose this method to ease use of ActiveRecord's `or` e.g
|
381
|
+
|
382
|
+
```ruby
|
383
|
+
Model.in_state(:state_1).or(
|
384
|
+
Model.most_recent_transition_join.where(model_field: 123)
|
385
|
+
)
|
386
|
+
```
|
387
|
+
|
374
388
|
## Frequently Asked Questions
|
375
389
|
|
376
390
|
#### Storing the state on the model object
|
@@ -11,7 +11,7 @@ module Statesman
|
|
11
11
|
argument :parent, type: :string, desc: "Your parent model name"
|
12
12
|
argument :klass, type: :string, desc: "Your transition model name"
|
13
13
|
|
14
|
-
source_root File.expand_path("
|
14
|
+
source_root File.expand_path("templates", __dir__)
|
15
15
|
|
16
16
|
def create_model_file
|
17
17
|
template("create_migration.rb.erb", migration_file_name)
|
@@ -11,7 +11,7 @@ module Statesman
|
|
11
11
|
argument :parent, type: :string, desc: "Your parent model name"
|
12
12
|
argument :klass, type: :string, desc: "Your transition model name"
|
13
13
|
|
14
|
-
source_root File.expand_path("
|
14
|
+
source_root File.expand_path("templates", __dir__)
|
15
15
|
|
16
16
|
def create_model_file
|
17
17
|
template("update_migration.rb.erb", file_name)
|
@@ -10,7 +10,7 @@ module Statesman
|
|
10
10
|
argument :parent, type: :string, desc: "Your parent model name"
|
11
11
|
argument :klass, type: :string, desc: "Your transition model name"
|
12
12
|
|
13
|
-
source_root File.expand_path("
|
13
|
+
source_root File.expand_path("templates", __dir__)
|
14
14
|
|
15
15
|
def create_model_file
|
16
16
|
template("mongoid_transition_model.rb.erb", model_file_name)
|
@@ -17,13 +17,13 @@ class Create<%= migration_class_name %> < ActiveRecord::Migration<%= "[#{ActiveR
|
|
17
17
|
add_foreign_key :<%= table_name %>, :<%= parent_table_name %>
|
18
18
|
|
19
19
|
add_index(:<%= table_name %>,
|
20
|
-
|
20
|
+
%i(<%= parent_id %> sort_key),
|
21
21
|
unique: true,
|
22
22
|
name: "<%= index_name :parent_sort %>")
|
23
23
|
add_index(:<%= table_name %>,
|
24
|
-
|
24
|
+
%i(<%= parent_id %> most_recent),
|
25
25
|
unique: true,
|
26
|
-
<%=
|
26
|
+
<%= 'where: "most_recent",' if database_supports_partial_indexes? %>
|
27
27
|
name: "<%= index_name :parent_most_recent %>")
|
28
28
|
end
|
29
29
|
end
|
@@ -8,7 +8,7 @@ class AddStatesmanTo<%= migration_class_name %> < ActiveRecord::Migration<%= "[#
|
|
8
8
|
add_column :<%= table_name %>, :created_at, :datetime, null: false
|
9
9
|
add_column :<%= table_name %>, :updated_at, :datetime, null: false
|
10
10
|
|
11
|
-
add_index :<%= table_name %>,
|
12
|
-
add_index :<%= table_name %>,
|
11
|
+
add_index :<%= table_name %>, %i(<%= parent_id %> sort_key), unique: true, name: "<%= index_name :parent_sort %>"
|
12
|
+
add_index :<%= table_name %>, %i(<%= parent_id %> most_recent), unique: true, <%= 'where: "most_recent", ' if database_supports_partial_indexes? %>name: "<%= index_name :parent_most_recent %>"
|
13
13
|
end
|
14
14
|
end
|
@@ -117,9 +117,9 @@ module Statesman
|
|
117
117
|
end
|
118
118
|
end
|
119
119
|
|
120
|
-
def transition_conflict_error?(
|
121
|
-
|
122
|
-
(
|
120
|
+
def transition_conflict_error?(err)
|
121
|
+
err.message.include?(@transition_class.table_name) &&
|
122
|
+
(err.message.include?("sort_key") || err.message.include?("most_recent"))
|
123
123
|
end
|
124
124
|
|
125
125
|
def with_updated_timestamp(params)
|
@@ -21,6 +21,13 @@ module Statesman
|
|
21
21
|
states)
|
22
22
|
end
|
23
23
|
|
24
|
+
def most_recent_transition_join
|
25
|
+
"LEFT OUTER JOIN #{model_table} AS #{most_recent_transition_alias}
|
26
|
+
ON #{table_name}.id =
|
27
|
+
#{most_recent_transition_alias}.#{model_foreign_key}
|
28
|
+
AND #{most_recent_transition_alias}.most_recent = #{db_true}"
|
29
|
+
end
|
30
|
+
|
24
31
|
private
|
25
32
|
|
26
33
|
def transition_class
|
@@ -55,13 +62,6 @@ module Statesman
|
|
55
62
|
transition_reflection.table_name
|
56
63
|
end
|
57
64
|
|
58
|
-
def most_recent_transition_join
|
59
|
-
"LEFT OUTER JOIN #{model_table} AS #{most_recent_transition_alias}
|
60
|
-
ON #{table_name}.id =
|
61
|
-
#{most_recent_transition_alias}.#{model_foreign_key}
|
62
|
-
AND #{most_recent_transition_alias}.most_recent = #{db_true}"
|
63
|
-
end
|
64
|
-
|
65
65
|
def states_where(temporary_table_name, states)
|
66
66
|
if initial_state.to_s.in?(states.map(&:to_s))
|
67
67
|
"#{temporary_table_name}.to_state IN (?) OR " \
|
@@ -8,7 +8,7 @@ module Statesman
|
|
8
8
|
|
9
9
|
# We only accept mode as a parameter to maintain a consistent interface
|
10
10
|
# with other adapters which require it.
|
11
|
-
def initialize(transition_class, parent_model, observer,
|
11
|
+
def initialize(transition_class, parent_model, observer, _opts = {})
|
12
12
|
@history = []
|
13
13
|
@transition_class = transition_class
|
14
14
|
@parent_model = parent_model
|
@@ -28,7 +28,7 @@ module Statesman
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def last(*)
|
31
|
-
@history.
|
31
|
+
@history.max_by(&:sort_key)
|
32
32
|
end
|
33
33
|
|
34
34
|
def history(*)
|
@@ -6,7 +6,7 @@ module Statesman
|
|
6
6
|
attr_reader :transition_class
|
7
7
|
attr_reader :parent_model
|
8
8
|
|
9
|
-
def initialize(transition_class, parent_model, observer,
|
9
|
+
def initialize(transition_class, parent_model, observer, _opts = {})
|
10
10
|
@transition_class = transition_class
|
11
11
|
@parent_model = parent_model
|
12
12
|
@observer = observer
|
data/lib/statesman/config.rb
CHANGED
data/lib/statesman/machine.rb
CHANGED
@@ -100,7 +100,7 @@ module Statesman
|
|
100
100
|
|
101
101
|
# Check that the 'from' state is not terminal
|
102
102
|
def validate_not_from_terminal_state(from)
|
103
|
-
unless from.nil? || successors.
|
103
|
+
unless from.nil? || successors.key?(from)
|
104
104
|
raise InvalidTransitionError,
|
105
105
|
"Cannot transition away from terminal state '#{from}'"
|
106
106
|
end
|
data/lib/statesman/version.rb
CHANGED
@@ -8,40 +8,45 @@ describe Statesman::ActiveRecordTransitionGenerator, type: :generator do
|
|
8
8
|
end
|
9
9
|
|
10
10
|
describe "creates a migration" do
|
11
|
-
subject { file("db/migrate/#{time}_create_bacon_transitions.rb") }
|
11
|
+
subject(:migration) { file("db/migrate/#{time}_create_bacon_transitions.rb") }
|
12
12
|
|
13
|
-
before
|
14
|
-
|
13
|
+
before do
|
14
|
+
allow(Time).to receive(:now).and_return(mock_time)
|
15
|
+
run_generator %w[Yummy::Bacon Yummy::BaconTransition]
|
16
|
+
end
|
15
17
|
|
16
18
|
let(:mock_time) { double("Time", utc: double("UTCTime", strftime: time)) }
|
17
19
|
let(:time) { "5678309" }
|
18
20
|
|
19
21
|
it "includes a foreign key" do
|
20
|
-
expect(
|
22
|
+
expect(migration).to contain("add_foreign_key :bacon_transitions, :bacons")
|
21
23
|
end
|
22
24
|
end
|
23
25
|
|
24
26
|
describe "properly adds class names" do
|
25
|
-
before { run_generator %w[Yummy::Bacon Yummy::BaconTransition] }
|
26
27
|
subject { file("app/models/yummy/bacon_transition.rb") }
|
27
28
|
|
29
|
+
before { run_generator %w[Yummy::Bacon Yummy::BaconTransition] }
|
30
|
+
|
28
31
|
it { is_expected.to contain(/:bacon_transition/) }
|
29
|
-
it { is_expected.
|
32
|
+
it { is_expected.to_not contain(%r{:yummy/bacon}) }
|
30
33
|
it { is_expected.to contain(/class_name: 'Yummy::Bacon'/) }
|
31
34
|
end
|
32
35
|
|
33
36
|
describe "properly formats without class names" do
|
34
|
-
before { run_generator %w[Bacon BaconTransition] }
|
35
37
|
subject { file("app/models/bacon_transition.rb") }
|
36
38
|
|
37
|
-
|
39
|
+
before { run_generator %w[Bacon BaconTransition] }
|
40
|
+
|
41
|
+
it { is_expected.to_not contain(/class_name:/) }
|
38
42
|
it { is_expected.to contain(/class BaconTransition/) }
|
39
43
|
end
|
40
44
|
|
41
45
|
describe "it doesn't create any double-spacing" do
|
42
|
-
before { run_generator %w[Yummy::Bacon Yummy::BaconTransition] }
|
43
46
|
subject { file("app/models/yummy/bacon_transition.rb") }
|
44
47
|
|
48
|
+
before { run_generator %w[Yummy::Bacon Yummy::BaconTransition] }
|
49
|
+
|
45
50
|
it { is_expected.to_not contain(/\n\n\n/) }
|
46
51
|
end
|
47
52
|
end
|
@@ -8,34 +8,34 @@ describe Statesman::MigrationGenerator, type: :generator do
|
|
8
8
|
end
|
9
9
|
|
10
10
|
describe "the model contains the correct words" do
|
11
|
+
subject(:migration) do
|
12
|
+
file(
|
13
|
+
"db/migrate/#{migration_number}_add_statesman_to_bacon_transitions.rb",
|
14
|
+
)
|
15
|
+
end
|
16
|
+
|
11
17
|
let(:migration_number) { "5678309" }
|
12
18
|
|
13
19
|
let(:mock_time) do
|
14
20
|
double("Time", utc: double("UTCTime", strftime: migration_number))
|
15
21
|
end
|
16
22
|
|
17
|
-
subject do
|
18
|
-
file(
|
19
|
-
"db/migrate/#{migration_number}_add_statesman_to_bacon_transitions.rb",
|
20
|
-
)
|
21
|
-
end
|
22
|
-
|
23
23
|
before do
|
24
24
|
allow(Time).to receive(:now).and_return(mock_time)
|
25
25
|
run_generator %w[Yummy::Bacon Yummy::BaconTransition]
|
26
26
|
end
|
27
27
|
|
28
28
|
it { is_expected.to contain(/:bacon_transition/) }
|
29
|
-
it { is_expected.
|
29
|
+
it { is_expected.to_not contain(%r{:yummy/bacon}) }
|
30
30
|
it { is_expected.to contain(/null: false/) }
|
31
31
|
|
32
32
|
it "names the sorting index appropriately" do
|
33
|
-
expect(
|
33
|
+
expect(migration).
|
34
34
|
to contain("name: \"index_bacon_transitions_parent_sort\"")
|
35
35
|
end
|
36
36
|
|
37
37
|
it "names the most_recent index appropriately" do
|
38
|
-
expect(
|
38
|
+
expect(migration).
|
39
39
|
to contain("name: \"index_bacon_transitions_parent_most_recent\"")
|
40
40
|
end
|
41
41
|
end
|