Skip to content

Commit

Permalink
Updated the runner tests to check run order.
Browse files Browse the repository at this point in the history
Signed-off-by: James McCarthy <james2mccarthy@gmail.com>
  • Loading branch information
james2m committed Jun 29, 2012
1 parent 8be12ab commit b0d6197
Show file tree
Hide file tree
Showing 11 changed files with 57 additions and 23 deletions.
7 changes: 7 additions & 0 deletions test/dummy/app/models/fake_model.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class FakeModel

def self.seed(seed)
puts "Running seed: #{seed}"
end

end
7 changes: 0 additions & 7 deletions test/dummy/app/models/post.rb

This file was deleted.

7 changes: 0 additions & 7 deletions test/dummy/app/models/user.rb

This file was deleted.

3 changes: 3 additions & 0 deletions test/dummy/db/seeds/circular1.seeds.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
after :circular2 do
FakeModel.seed('circular1')
end
3 changes: 3 additions & 0 deletions test/dummy/db/seeds/circular2.seeds.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
after :circular1 do
FakeModel.seed('circular2')
end
2 changes: 1 addition & 1 deletion test/dummy/db/seeds/dependency.seeds.rb
Original file line number Diff line number Diff line change
@@ -1 +1 @@
User.create(:email => 'user@example.com')
FakeModel.seed('dependency')
1 change: 1 addition & 0 deletions test/dummy/db/seeds/dependency2.seeds.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
FakeModel.seed('dependency2')
2 changes: 1 addition & 1 deletion test/dummy/db/seeds/dependent.seeds.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
after :dependency do
Post.create(:title => 'title')
FakeModel.seed('dependent')
end
3 changes: 3 additions & 0 deletions test/dummy/db/seeds/dependent_on_nested.seeds.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
after :dependent, :dependency2 do
FakeModel.seed('dependent on nested')
end
3 changes: 3 additions & 0 deletions test/dummy/db/seeds/dependent_on_several.seeds.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
after :dependency, :dependency2 do
FakeModel.seed('dependent on several')
end
42 changes: 35 additions & 7 deletions test/seedbank/runner_test.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,46 @@
require 'test_helper'

describe Seedbank::Runner do


before do
flexmock(FakeModel)
end

describe "seeds with dependency" do

subject { Rake::Task['db:seed:dependent'] }

it "runs the dependent seed" do
Post.expects(:create).with(:title => 'title').returns(true)

it "runs the dependencies in order" do
FakeModel.should_receive(:seed).with('dependency').once.ordered
FakeModel.should_receive(:seed).with('dependent').once.ordered

subject.invoke
end

it "runs the dependency" do
User.expects(:create).with(:email => 'user@example.com').returns(true)
end

describe "seeds with multiple dependencies" do

subject { Rake::Task['db:seed:dependent_on_several'] }

it "runs the dependencies in order" do
FakeModel.should_receive(:seed).with('dependency').once.ordered
FakeModel.should_receive(:seed).with('dependency2').once.ordered
FakeModel.should_receive(:seed).with('dependent on several').once.ordered

subject.invoke
end
end

describe "seeds with nested dependencies" do

subject { Rake::Task['db:seed:dependent_on_nested'] }

it "runs all dependencies in order" do
FakeModel.should_receive(:seed).with('dependency').once.ordered
FakeModel.should_receive(:seed).with('dependent').once.ordered
FakeModel.should_receive(:seed).with('dependency2').once.ordered
FakeModel.should_receive(:seed).with('dependent on nested').once.ordered

subject.invoke
end

Expand Down

0 comments on commit b0d6197

Please sign in to comment.