Skip to content

Commit

Permalink
Merge pull request #51 from gocardless/after-transition-current-state
Browse files Browse the repository at this point in the history
New transition visible for all after callbacks
  • Loading branch information
appleton committed May 21, 2014
2 parents ae8ed2a + 01f703d commit 5cb9c19
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/statesman/adapters/active_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def create(from, to, metadata = {})
::ActiveRecord::Base.transaction do
@observer.execute(:before, from, to, transition)
transition.save!
@last_transition = transition
@observer.execute(:after, from, to, transition)
@last_transition = nil
end
Expand Down
1 change: 1 addition & 0 deletions lib/statesman/adapters/mongoid.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def create(from, to, metadata = {})

@observer.execute(:before, from, to, transition)
transition.save!
@last_transition = transition
@observer.execute(:after, from, to, transition)
@observer.execute(:after_commit, from, to, transition)
@last_transition = nil
Expand Down
11 changes: 11 additions & 0 deletions spec/statesman/adapters/shared_examples.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
describe "#create" do
let(:from) { :x }
let(:to) { :y }
let(:there) { :z }
let(:create) { adapter.create(from, to) }
subject { -> { create } }

Expand Down Expand Up @@ -71,6 +72,16 @@
end.once
adapter.create(from, to)
end

it "exposes the new transition for subsequent transitions" do
adapter.create(from, to)

observer.should_receive(:execute).with do
|phase, from_state, to_state, transition|
expect(adapter.last).to eq(transition) if phase == :after
end.once
adapter.create(to, there)
end
end

context "with metadata" do
Expand Down

0 comments on commit 5cb9c19

Please sign in to comment.