Fix specs for #265

Run enum specs only for Rails version >= 4.1
This commit is contained in:
Anil 2015-10-16 01:08:05 +05:30
parent 0faff1fcf0
commit f2cc91b95a
3 changed files with 33 additions and 24 deletions

View File

@ -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

View File

@ -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

View File

@ -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