1
0
Fork 0
mirror of https://github.com/aasm/aasm synced 2023-03-27 23:22:41 -04:00
This commit is contained in:
Thorsten Böttger 2015-06-23 20:58:09 +12:00
parent d8405cbeb3
commit d1e7c8fd4f
4 changed files with 59 additions and 1 deletions

View file

@ -5,6 +5,10 @@ ActiveRecord::Migration.suppress_messages do
end
end
ActiveRecord::Migration.create_table "cards", :force => true do |t|
t.string "status"
end
ActiveRecord::Migration.create_table "simple_new_dsls", :force => true do |t|
t.string "status"
end

View file

@ -0,0 +1,24 @@
class WithEnum < ActiveRecord::Base
include AASM
enum :status => {
:opened => 0,
:closed => 1
}
# Fake this column for testing purposes
# attr_accessor :aasm_state
def self.test
{}
end
aasm :enum => true, :column => :status, :skip_validation_on_save => true, :no_direct_assignment => true do
state :opened
state :closed
event :close do
transitions :from => :opened, :to => :closed
end
end
end

View file

@ -36,6 +36,29 @@ class FalseState < ActiveRecord::Base
end
end
class Card < ActiveRecord::Base
include AASM
enum status: {
default: 0,
published: 1,
deleted: 2
}
aasm column: :status, enum: true, skip_validation_on_save: true, no_direct_assignment: true do
state :default, initial: true
state :published
state :deleted
event :publish do
transitions from: :default, to: :published
end
event :delete do
transitions from: :published, to: :deleted
end
end
end
class WithEnum < ActiveRecord::Base
include AASM

View file

@ -117,7 +117,7 @@ describe "instance methods" do
end
end
end
end
end # aasm_enum
context "when AASM is configured to use enum" do
let(:state_sym) { :running }
@ -166,6 +166,13 @@ describe "instance methods" do
end
end
describe "enum real life error" do
it "should reproduce the problem" do
card = Card.new
require 'pry'; binding.pry
end
end
describe "aasm_write_state_without_persistence" do
it "delegates state update to the helper method" do
gate.aasm_write_state_without_persistence state_sym