mirror of
https://github.com/aasm/aasm
synced 2023-03-27 23:22:41 -04:00
playing
This commit is contained in:
parent
d8405cbeb3
commit
d1e7c8fd4f
4 changed files with 59 additions and 1 deletions
|
@ -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
|
||||
|
|
24
spec/models/active_record/with_enum.rb
Normal file
24
spec/models/active_record/with_enum.rb
Normal 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
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue