From d1e7c8fd4f3c8dd50697ccd57616add5d123d2e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorsten=20B=C3=B6ttger?= Date: Tue, 23 Jun 2015 20:58:09 +1200 Subject: [PATCH] playing --- spec/database.rb | 4 ++++ spec/models/active_record/with_enum.rb | 24 +++++++++++++++++++ spec/models/persistence.rb | 23 ++++++++++++++++++ .../active_record_persistence_spec.rb | 9 ++++++- 4 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 spec/models/active_record/with_enum.rb diff --git a/spec/database.rb b/spec/database.rb index 4e7ccbd..561d85f 100644 --- a/spec/database.rb +++ b/spec/database.rb @@ -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 diff --git a/spec/models/active_record/with_enum.rb b/spec/models/active_record/with_enum.rb new file mode 100644 index 0000000..a5f3634 --- /dev/null +++ b/spec/models/active_record/with_enum.rb @@ -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 diff --git a/spec/models/persistence.rb b/spec/models/persistence.rb index 2cf11fd..90e584c 100644 --- a/spec/models/persistence.rb +++ b/spec/models/persistence.rb @@ -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 diff --git a/spec/unit/persistence/active_record_persistence_spec.rb b/spec/unit/persistence/active_record_persistence_spec.rb index b7ca0fd..0befa42 100644 --- a/spec/unit/persistence/active_record_persistence_spec.rb +++ b/spec/unit/persistence/active_record_persistence_spec.rb @@ -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