Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
alto committed Dec 29, 2011
1 parent ee9b1cd commit 996f7e9
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 73 deletions.
5 changes: 5 additions & 0 deletions spec/schema.rb
Expand Up @@ -4,4 +4,9 @@
create_table table_name, :force => true
end

create_table "validators", :force => true do |t|
t.string "name"
t.string "status"
end

end
73 changes: 1 addition & 72 deletions spec/unit/aasm_spec.rb
Expand Up @@ -103,75 +103,16 @@
end
end

describe AASM, '- event firing with persistence' do
it 'should update the current state' do
foo = Foo.new
foo.close!

foo.aasm_current_state.should == :closed
end

describe AASM, 'success callbacks' do
it 'should call the success callback if one was provided' do
foo = Foo.new

foo.should_receive(:success_callback)

foo.close!
end

it 'should attempt to persist if aasm_write_state is defined' do
foo = Foo.new

def foo.aasm_write_state
end

foo.should_receive(:aasm_write_state)

foo.close!
end

it 'should return true if aasm_write_state is defined and returns true' do
foo = Foo.new

def foo.aasm_write_state(state)
true
end

foo.close!.should be_true
end

it 'should return false if aasm_write_state is defined and returns false' do
foo = Foo.new

def foo.aasm_write_state(state)
false
end

foo.close!.should be_false
end

it "should not update the aasm_current_state if the write fails" do
foo = Foo.new

def foo.aasm_write_state
false
end

foo.should_receive(:aasm_write_state)

foo.close!
foo.aasm_current_state.should == :open
end
end

describe AASM, '- event firing without persistence' do
it 'should update the current state' do
foo = Foo.new
foo.close

foo.aasm_current_state.should == :closed
end

it 'should attempt to persist if aasm_write_state is defined' do
foo = Foo.new

Expand All @@ -184,18 +125,6 @@ def foo.aasm_write_state
end
end

describe AASM, '- persistence' do
it 'should read the state if it has not been set and aasm_read_state is defined' do
foo = Foo.new
def foo.aasm_read_state
end

foo.should_receive(:aasm_read_state)

foo.aasm_current_state
end
end

describe AASM, '- getting events for a state' do
it '#aasm_events_for_current_state should use current state' do
foo = Foo.new
Expand Down
43 changes: 43 additions & 0 deletions spec/unit/active_record_persistence_spec.rb
Expand Up @@ -68,6 +68,21 @@ class Thief < ActiveRecord::Base
attr_accessor :skilled, :aasm_state
end

class Validator < ActiveRecord::Base
include AASM
aasm :column => :status do
state :sleeping, :initial => true
state :running
event :run do
transitions :to => :running, :from => :sleeping
end
event :sleep do
transitions :to => :sleeping, :from => :running
end
end
validates_presence_of :name
end

shared_examples_for "aasm model" do
it "should include AASM::Persistence::ActiveRecordPersistence" do
@klass.included_modules.should be_include(AASM::Persistence::ActiveRecordPersistence)
Expand Down Expand Up @@ -246,3 +261,31 @@ class Thief < ActiveRecord::Base
Thief.new(:skilled => false).aasm_current_state.should == :jailed
end
end

describe 'transitions with persistence' do

it 'should succeed and store the new state' do
validator = Validator.create(:name => 'name')
validator.should be_valid
validator.should be_sleeping

# validator.name = nil
# validator.should_not be_valid
# validator.run!.should be_false
# validator.should be_running
#
# validator.reload
# validator.should_not be_running
# validator.should be_sleeping

validator.name = 'another name'
validator.should be_valid
validator.run!.should be_true
validator.should be_running

validator.reload
validator.should be_running
validator.should_not be_sleeping
end

end
2 changes: 1 addition & 1 deletion spec/unit/localizer_spec.rb
Expand Up @@ -31,7 +31,7 @@ class LocalizerTestModel < ActiveRecord::Base

context 'aasm_human_state' do
it 'should return translated state value' do
foo_opened.aasm_human_state.should == "It's opened now!"
foo_opened.aasm_human_state.should == "It's opened now!"
end

it 'should return humanized value if not localized' do
Expand Down

0 comments on commit 996f7e9

Please sign in to comment.