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.
@@ -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,9 +0,0 @@
1
- class AddMostRecentTo<%= migration_class_name %> < ActiveRecord::Migration
2
- def up
3
- add_column :<%= table_name %>, :most_recent, :boolean, null: true
4
- end
5
-
6
- def down
7
- remove_column :<%= table_name %>, :most_recent
8
- end
9
- 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