Skip to content

Instantly share code, notes, and snippets.

@svs
Created July 13, 2012 12:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save svs/3104578 to your computer and use it in GitHub Desktop.
Save svs/3104578 to your computer and use it in GitHub Desktop.
Unit Testing a Workflow
describe Document do
context "with a scan" do
subject {FactoryGirl.build(:scannable)}
it {should have_events([:scan])}
end
context "taggable" do
subject { FactoryGirl.build(:taggable) }
it {should have_events([:to_edit])}
[:complete, :incomplete, :checker_reject, :checker_accept, :user_reject, :user_accept].each do |e|
it {should_not have_event(e)}
end
end
context "editing" do
subject {FactoryGirl.build(:editing)}
it { should have_events([:tag_complete, :tag_incomplete, :tag_illegible, :user_accept])}
end
context "completed" do
subject {FactoryGirl.build(:completed)}
it { should have_events([:to_edit, :checker_accept, :checker_reject])}
end
context "incomplete" do
subject {FactoryGirl.build(:incomplete)}
it { should have_events([:to_edit, :tag_complete, :tag_incomplete, :tag_illegible])}
end
context "checker rejected" do
subject {FactoryGirl.build(:checker_rejected)}
it { should have_events([:to_edit]) }
end
context "checker accepted" do
subject {FactoryGirl.build(:checker_accepted)}
it { should have_events([:to_edit, :user_reject, :user_accept]) }
end
context "user accepted" do
subject {FactoryGirl.build(:user_accepted, :user => @customer)}
it { should have_events([:to_edit])}
end
context "it should check authorization" do
@a = Ability.new
@a.stub(:can?).and_return(false)
@doc = FactoryGirl.create(:document)
expect {@doc.scan!(@a)}.to raise_error
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment