mirror of
https://github.com/aasm/aasm
synced 2023-03-27 23:22:41 -04:00
refactored ActiveRecord specs
This commit is contained in:
parent
f4ccee8272
commit
7564f87e17
1 changed files with 26 additions and 50 deletions
|
@ -9,93 +9,68 @@ load_schema
|
|||
# ActiveRecord::Base.logger = Logger.new(STDERR)
|
||||
|
||||
shared_examples_for "aasm model" do
|
||||
it "should include AASM::Persistence::ActiveRecordPersistence" do
|
||||
it "should include persistence mixins" do
|
||||
@klass.included_modules.should be_include(AASM::Persistence::ActiveRecordPersistence)
|
||||
end
|
||||
it "should include AASM::Persistence::ActiveRecordPersistence::InstanceMethods" do
|
||||
@klass.included_modules.should be_include(AASM::Persistence::ActiveRecordPersistence::InstanceMethods)
|
||||
end
|
||||
end
|
||||
|
||||
describe Gate, "class methods" do
|
||||
describe "class methods for classes without own read or write state" do
|
||||
before(:each) do
|
||||
@klass = Gate
|
||||
end
|
||||
it_should_behave_like "aasm model"
|
||||
it "should include AASM::Persistence::ActiveRecordPersistence::ReadState" do
|
||||
it "should include all persistence mixins" do
|
||||
@klass.included_modules.should be_include(AASM::Persistence::ActiveRecordPersistence::ReadState)
|
||||
end
|
||||
it "should include AASM::Persistence::ActiveRecordPersistence::WriteState" do
|
||||
@klass.included_modules.should be_include(AASM::Persistence::ActiveRecordPersistence::WriteState)
|
||||
end
|
||||
it "should include AASM::Persistence::ActiveRecordPersistence::WriteStateWithoutPersistence" do
|
||||
@klass.included_modules.should be_include(AASM::Persistence::ActiveRecordPersistence::WriteStateWithoutPersistence)
|
||||
end
|
||||
end
|
||||
|
||||
describe Reader, "class methods" do
|
||||
describe "class methods for classes with own read state" do
|
||||
before(:each) do
|
||||
@klass = Reader
|
||||
end
|
||||
it_should_behave_like "aasm model"
|
||||
it "should not include AASM::Persistence::ActiveRecordPersistence::ReadState" do
|
||||
it "should include all persistence mixins but read state" do
|
||||
@klass.included_modules.should_not be_include(AASM::Persistence::ActiveRecordPersistence::ReadState)
|
||||
end
|
||||
it "should include AASM::Persistence::ActiveRecordPersistence::WriteState" do
|
||||
@klass.included_modules.should be_include(AASM::Persistence::ActiveRecordPersistence::WriteState)
|
||||
end
|
||||
it "should include AASM::Persistence::ActiveRecordPersistence::WriteStateWithoutPersistence" do
|
||||
@klass.included_modules.should be_include(AASM::Persistence::ActiveRecordPersistence::WriteStateWithoutPersistence)
|
||||
end
|
||||
end
|
||||
|
||||
describe Writer, "class methods" do
|
||||
describe "class methods for classes with own write state" do
|
||||
before(:each) do
|
||||
@klass = Writer
|
||||
end
|
||||
it_should_behave_like "aasm model"
|
||||
it "should include AASM::Persistence::ActiveRecordPersistence::ReadState" do
|
||||
it "should include include all persistence mixins but write state" do
|
||||
@klass.included_modules.should be_include(AASM::Persistence::ActiveRecordPersistence::ReadState)
|
||||
end
|
||||
it "should not include AASM::Persistence::ActiveRecordPersistence::WriteState" do
|
||||
@klass.included_modules.should_not be_include(AASM::Persistence::ActiveRecordPersistence::WriteState)
|
||||
end
|
||||
it "should include AASM::Persistence::ActiveRecordPersistence::WriteStateWithoutPersistence" do
|
||||
@klass.included_modules.should be_include(AASM::Persistence::ActiveRecordPersistence::WriteStateWithoutPersistence)
|
||||
end
|
||||
end
|
||||
|
||||
describe Transient, "class methods" do
|
||||
describe "class methods for classes without persistence" do
|
||||
before(:each) do
|
||||
@klass = Transient
|
||||
end
|
||||
it_should_behave_like "aasm model"
|
||||
it "should include AASM::Persistence::ActiveRecordPersistence::ReadState" do
|
||||
it "should include all mixins but persistence" do
|
||||
@klass.included_modules.should be_include(AASM::Persistence::ActiveRecordPersistence::ReadState)
|
||||
end
|
||||
it "should include AASM::Persistence::ActiveRecordPersistence::WriteState" do
|
||||
@klass.included_modules.should be_include(AASM::Persistence::ActiveRecordPersistence::WriteState)
|
||||
end
|
||||
it "should not include AASM::Persistence::ActiveRecordPersistence::WriteStateWithoutPersistence" do
|
||||
@klass.included_modules.should_not be_include(AASM::Persistence::ActiveRecordPersistence::WriteStateWithoutPersistence)
|
||||
end
|
||||
end
|
||||
|
||||
describe Gate, "instance methods" do
|
||||
|
||||
describe "instance methods" do
|
||||
before do
|
||||
@gate = Gate.new
|
||||
end
|
||||
|
||||
it "should respond to aasm read state when not previously defined" do
|
||||
it "should respond to aasm states" do
|
||||
@gate.should respond_to(:aasm_read_state)
|
||||
end
|
||||
|
||||
it "should respond to aasm write state when not previously defined" do
|
||||
@gate.should respond_to(:aasm_write_state)
|
||||
end
|
||||
|
||||
it "should respond to aasm write state without persistence when not previously defined" do
|
||||
@gate.should respond_to(:aasm_write_state_without_persistence)
|
||||
end
|
||||
|
||||
|
@ -137,16 +112,16 @@ describe Gate, "instance methods" do
|
|||
|
||||
end
|
||||
|
||||
describe 'Derivates' do
|
||||
it "should have the same states as its parent" do
|
||||
describe 'subclasses' do
|
||||
it "should have the same states as its parent class" do
|
||||
Derivate.aasm_states.should == Simple.aasm_states
|
||||
end
|
||||
|
||||
it "should have the same events as its parent" do
|
||||
it "should have the same events as its parent class" do
|
||||
Derivate.aasm_events.should == Simple.aasm_events
|
||||
end
|
||||
|
||||
it "should have the same column as its parent" do
|
||||
it "should have the same column as its parent class" do
|
||||
Derivate.aasm_column.should == :status
|
||||
end
|
||||
|
||||
|
@ -156,30 +131,34 @@ describe 'Derivates' do
|
|||
end
|
||||
end
|
||||
|
||||
describe "AASM::Persistence::ActiveRecordPersistence::NamedScopeMethods" do
|
||||
describe "named scopes with the old DSL" do
|
||||
|
||||
context "Old DSL Does not already respond_to? the scope name" do
|
||||
context "Does not already respond_to? the scope name" do
|
||||
it "should add a scope" do
|
||||
Simple.should respond_to(:unknown_scope)
|
||||
Simple.unknown_scope.class.should == ActiveRecord::Relation
|
||||
end
|
||||
end
|
||||
|
||||
context "Old DSL Already respond_to? the scope name" do
|
||||
context "Already respond_to? the scope name" do
|
||||
it "should not add a scope" do
|
||||
Simple.should respond_to(:new)
|
||||
Simple.new.class.should == Simple
|
||||
end
|
||||
end
|
||||
|
||||
context "New DSL Does not already respond_to? the scope name" do
|
||||
end
|
||||
|
||||
describe "named scopes with the new DSL" do
|
||||
|
||||
context "Does not already respond_to? the scope name" do
|
||||
it "should add a scope" do
|
||||
SimpleNewDsl.should respond_to(:unknown_scope)
|
||||
SimpleNewDsl.unknown_scope.class.should == ActiveRecord::Relation
|
||||
end
|
||||
end
|
||||
|
||||
context "New DSL Already respond_to? the scope name" do
|
||||
context "Already respond_to? the scope name" do
|
||||
it "should not add a scope" do
|
||||
SimpleNewDsl.should respond_to(:new)
|
||||
SimpleNewDsl.new.class.should == SimpleNewDsl
|
||||
|
@ -188,13 +167,10 @@ describe "AASM::Persistence::ActiveRecordPersistence::NamedScopeMethods" do
|
|||
|
||||
end
|
||||
|
||||
describe 'Thieves' do
|
||||
describe 'initial states' do
|
||||
|
||||
it 'should be rich if they\'re skilled' do
|
||||
it 'should support conditions' do
|
||||
Thief.new(:skilled => true).aasm_current_state.should == :rich
|
||||
end
|
||||
|
||||
it 'should be jailed if they\'re unskilled' do
|
||||
Thief.new(:skilled => false).aasm_current_state.should == :jailed
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue