mirror of
https://github.com/aasm/aasm
synced 2023-03-27 23:22:41 -04:00
parent
0faff1fcf0
commit
f2cc91b95a
3 changed files with 33 additions and 24 deletions
|
@ -1,10 +1,12 @@
|
|||
class WithEnumWithoutColumn < ActiveRecord::Base
|
||||
include AASM
|
||||
|
||||
enum status: {
|
||||
opened: 0,
|
||||
closed: 1
|
||||
}
|
||||
if ActiveRecord::VERSION::MAJOR >= 4 && ActiveRecord::VERSION::MINOR >= 1 # won't work with Rails <= 4.1
|
||||
enum status: {
|
||||
opened: 0,
|
||||
closed: 1
|
||||
}
|
||||
end
|
||||
|
||||
aasm :column => :status do
|
||||
state :closed, initial: true
|
||||
|
@ -18,11 +20,12 @@ end
|
|||
|
||||
class MultipleWithEnumWithoutColumn < ActiveRecord::Base
|
||||
include AASM
|
||||
|
||||
enum status: {
|
||||
opened: 0,
|
||||
closed: 1
|
||||
}
|
||||
if ActiveRecord::VERSION::MAJOR >= 4 && ActiveRecord::VERSION::MINOR >= 1 # won't work with Rails <= 4.1
|
||||
enum status: {
|
||||
opened: 0,
|
||||
closed: 1
|
||||
}
|
||||
end
|
||||
|
||||
aasm :left, :column => :status do
|
||||
state :closed, initial: true
|
||||
|
|
|
@ -113,15 +113,18 @@ describe "instance methods" do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "when AASM enum setting is not enabled and aasm column not present" do
|
||||
before :each do
|
||||
@multiple_with_enum_with_column = MultipleWithEnumWithoutColumn.new
|
||||
end
|
||||
|
||||
it "should raise NoMethodError for transitions" do
|
||||
expect{@multiple_with_enum_with_column.send(:view, :left)}.to raise_error(NoMethodError, "undefined method 'status' for MultipleWithEnumWithoutColumn")
|
||||
|
||||
if ActiveRecord::VERSION::MAJOR >= 4 && ActiveRecord::VERSION::MINOR >= 1 # won't work with Rails <= 4.1
|
||||
# Enum are introduced from Rails 4.1, therefore enum syntax will not work on Rails <= 4.1
|
||||
context "when AASM enum setting is not enabled and aasm column not present" do
|
||||
|
||||
let(:multiple_with_enum_without_column) {MultipleWithEnumWithoutColumn.new}
|
||||
|
||||
it "should raise NoMethodError for transitions" do
|
||||
expect{multiple_with_enum_without_column.send(:view, :left)}.to raise_error(NoMethodError, "undefined method 'status' for MultipleWithEnumWithoutColumn")
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -114,14 +114,17 @@ describe "instance methods" do
|
|||
end
|
||||
end
|
||||
|
||||
context "when AASM enum setting is not enabled and aasm column not present" do
|
||||
before :each do
|
||||
@with_enum_with_column = WithEnumWithoutColumn.new
|
||||
end
|
||||
|
||||
it "should raise NoMethodError for transitions" do
|
||||
expect{@with_enum_with_column.send(:view)}.to raise_error(NoMethodError, "undefined method 'status' for WithEnumWithoutColumn")
|
||||
if ActiveRecord::VERSION::MAJOR >= 4 && ActiveRecord::VERSION::MINOR >= 1 # won't work with Rails <= 4.1
|
||||
# Enum are introduced from Rails 4.1, therefore enum syntax will not work on Rails <= 4.1
|
||||
context "when AASM enum setting is not enabled and aasm column not present" do
|
||||
|
||||
let(:with_enum_without_column) {WithEnumWithoutColumn.new}
|
||||
|
||||
it "should raise NoMethodError for transitions" do
|
||||
expect{with_enum_without_column.send(:view)}.to raise_error(NoMethodError, "undefined method 'status' for WithEnumWithoutColumn")
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue