statesman 1.3.1 → 2.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +0 -1
- data/CHANGELOG.md +45 -19
- data/README.md +20 -11
- data/lib/generators/statesman/templates/active_record_transition_model.rb.erb +10 -0
- data/lib/statesman/adapters/active_record.rb +9 -10
- data/lib/statesman/adapters/active_record_queries.rb +3 -63
- data/lib/statesman/adapters/memory.rb +2 -2
- data/lib/statesman/adapters/mongoid.rb +7 -3
- data/lib/statesman/machine.rb +14 -53
- data/lib/statesman/version.rb +1 -1
- data/spec/spec_helper.rb +18 -11
- data/spec/statesman/adapters/active_record_queries_spec.rb +45 -119
- data/spec/statesman/adapters/active_record_spec.rb +43 -14
- data/spec/statesman/adapters/shared_examples.rb +5 -2
- data/spec/statesman/machine_spec.rb +55 -122
- data/spec/support/active_record.rb +28 -4
- data/statesman.gemspec +1 -1
- metadata +39 -49
- data/circle.yml +0 -9
- data/lib/generators/statesman/add_constraints_to_most_recent_generator.rb +0 -28
- data/lib/generators/statesman/add_most_recent_generator.rb +0 -25
- data/lib/generators/statesman/templates/add_constraints_to_most_recent_migration.rb.erb +0 -19
- data/lib/generators/statesman/templates/add_most_recent_migration.rb.erb +0 -9
- data/lib/statesman/event_transitions.rb +0 -15
- data/spec/generators/statesman/add_constraints_to_most_recent_generator_spec.rb +0 -43
- data/spec/generators/statesman/add_most_recent_generator_spec.rb +0 -35
@@ -1,19 +0,0 @@
|
|
1
|
-
class AddConstraintsToMostRecentFor<%= migration_class_name %> < ActiveRecord::Migration
|
2
|
-
disable_ddl_transaction!
|
3
|
-
|
4
|
-
def up
|
5
|
-
<%- if database_supports_partial_indexes? -%>
|
6
|
-
add_index :<%= table_name %>, [:<%= parent_id %>, :most_recent], unique: true, where: "most_recent", name: "index_<%= table_name %>_parent_most_recent", algorithm: :concurrently
|
7
|
-
change_column_null :<%= table_name %>, :most_recent, false
|
8
|
-
<%- else -%>
|
9
|
-
add_index :<%= table_name %>, [:<%= parent_id %>, :most_recent], unique: true, name: "index_<%= table_name %>_parent_most_recent", algorithm: :concurrently
|
10
|
-
<%- end -%>
|
11
|
-
end
|
12
|
-
|
13
|
-
def down
|
14
|
-
remove_index :<%= table_name %>, name: "index_<%= table_name %>_parent_most_recent"
|
15
|
-
<%- if database_supports_partial_indexes? -%>
|
16
|
-
change_column_null :<%= table_name %>, :most_recent, true
|
17
|
-
<%- end -%>
|
18
|
-
end
|
19
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
module Statesman
|
2
|
-
class EventTransitions
|
3
|
-
attr_reader :machine, :event_name
|
4
|
-
|
5
|
-
def initialize(machine, event_name, &block)
|
6
|
-
@machine = machine
|
7
|
-
@event_name = event_name
|
8
|
-
instance_eval(&block)
|
9
|
-
end
|
10
|
-
|
11
|
-
def transition(options = { from: nil, to: nil })
|
12
|
-
machine.transition(options, event_name)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
@@ -1,43 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
require "support/generators_shared_examples"
|
3
|
-
require "generators/statesman/add_constraints_to_most_recent_generator"
|
4
|
-
|
5
|
-
describe Statesman::AddConstraintsToMostRecentGenerator, type: :generator do
|
6
|
-
it_behaves_like "a generator" do
|
7
|
-
let(:migration_name) do
|
8
|
-
'db/migrate/add_constraints_to_most_recent_for_bacon_transitions.rb'
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
describe "the migration contains the correct words" do
|
13
|
-
let(:migration_number) { '5678309' }
|
14
|
-
|
15
|
-
let(:mock_time) do
|
16
|
-
double('Time', utc: double('UTCTime', strftime: migration_number))
|
17
|
-
end
|
18
|
-
|
19
|
-
subject(:migration_file) do
|
20
|
-
file("db/migrate/#{migration_number}_"\
|
21
|
-
"add_constraints_to_most_recent_for_bacon_transitions.rb")
|
22
|
-
end
|
23
|
-
|
24
|
-
let(:fixture_file) do
|
25
|
-
if Statesman::Adapters::ActiveRecord.database_supports_partial_indexes?
|
26
|
-
File.read("spec/fixtures/add_constraints_to_most_recent_for_"\
|
27
|
-
"bacon_transitions_with_partial_index.rb")
|
28
|
-
else
|
29
|
-
File.read("spec/fixtures/add_constraints_to_most_recent_for_"\
|
30
|
-
"bacon_transitions_without_partial_index.rb")
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
before do
|
35
|
-
allow(Time).to receive(:now).and_return(mock_time)
|
36
|
-
run_generator %w(Bacon BaconTransition)
|
37
|
-
end
|
38
|
-
|
39
|
-
it "matches the fixture" do
|
40
|
-
expect(migration_file).to contain(fixture_file)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
@@ -1,35 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
require "support/generators_shared_examples"
|
3
|
-
require "generators/statesman/add_most_recent_generator"
|
4
|
-
|
5
|
-
describe Statesman::AddMostRecentGenerator, type: :generator do
|
6
|
-
it_behaves_like "a generator" do
|
7
|
-
let(:migration_name) do
|
8
|
-
'db/migrate/add_most_recent_to_bacon_transitions.rb'
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
describe "the migration" do
|
13
|
-
let(:migration_number) { '5678309' }
|
14
|
-
|
15
|
-
let(:mock_time) do
|
16
|
-
double('Time', utc: double('UTCTime', strftime: migration_number))
|
17
|
-
end
|
18
|
-
|
19
|
-
subject(:migration_file) do
|
20
|
-
file("db/migrate/#{migration_number}_"\
|
21
|
-
"add_most_recent_to_bacon_transitions.rb")
|
22
|
-
end
|
23
|
-
|
24
|
-
let(:fixture_file) do
|
25
|
-
File.read("spec/fixtures/add_most_recent_to_bacon_transitions.rb")
|
26
|
-
end
|
27
|
-
|
28
|
-
before { allow(Time).to receive(:now).and_return(mock_time) }
|
29
|
-
before { run_generator %w(Bacon BaconTransition) }
|
30
|
-
|
31
|
-
it "matches the fixture" do
|
32
|
-
expect(migration_file).to contain(fixture_file)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|