Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Updated the seed_rake_tests to namespace dependencies.

Signed-off-by: James McCarthy <james2mccarthy@gmail.com>
  • Loading branch information...
commit 151b0c9f466f9d3c135bdb5b3f93bf9d1c07e0e3 1 parent 3bf2eb4
@james2m authored
Showing with 137 additions and 2 deletions.
  1. +135 −0 test/lib/seedbank/dsl_test.rb
  2. +2 −2 test/lib/tasks/seed_rake_test.rb
View
135 test/lib/seedbank/dsl_test.rb
@@ -0,0 +1,135 @@
+require 'test_helper'
+
+describe Seedbank::DSL do
+
+ describe "scope_from_seed_file" do
+
+ it "is added to the namesapce" do
+ ns = Rake.application.in_namespace(:seedy) { self }
+
+ ns.must_respond_to :scope_from_seed_file
+ end
+
+ describe "in an environment directory" do
+
+ let(:seed_file) { File.expand_path('development/users.seeds.rb', Seedbank.seeds_root) }
+ let(:seed_namespace) { %w(development) }
+
+ subject { Seedbank::DSL.scope_from_seed_file seed_file }
+
+ it "returns the enviroment scope" do
+ subject.must_equal seed_namespace
+ end
+ end
+
+ describe "in a nested directory" do
+
+ let(:seed_file) { File.expand_path('development/shared/accounts.seeds.rb', Seedbank.seeds_root) }
+ let(:seed_namespace) { %w(development shared) }
+
+ subject { Seedbank::DSL.scope_from_seed_file seed_file }
+
+ it "returns the nested scope" do
+ subject.must_equal seed_namespace
+ end
+ end
+
+ describe "in seeds root" do
+
+ let(:seed_file) { File.expand_path('no_block.seeds.rb', Seedbank.seeds_root) }
+
+ subject { Seedbank::DSL.scope_from_seed_file seed_file }
+
+ it "returns an array" do
+ subject.must_be_instance_of Array
+ end
+
+ it "must be empty" do
+ subject.must_be_empty
+ end
+ end
+
+ end
+
+ describe "seeds_root" do
+
+ let(:seeds_root) { '/my/seeds/directory' }
+
+ subject { Seedbank::DSL.seeds_root }
+
+ it "returns a Pathname" do
+ flexmock(Seedbank).should_receive(:seeds_root).and_return(seeds_root).by_default
+
+ subject.must_equal Pathname.new(seeds_root)
+ end
+
+ end
+
+ describe "glob_seed_files_matching" do
+
+ describe "with no namespace" do
+
+ let(:pattern) { '*.seeds.rb' }
+
+ it "returns all the files matching the pattern in seeds_root" do
+ expected_files = Dir.glob(File.join(Seedbank.seeds_root, pattern))
+
+ Seedbank::DSL.glob_seed_files_matching(pattern).must_equal expected_files
+ end
+
+ end
+
+ describe "with a namespace" do
+
+ let(:pattern) { '*.seeds.rb' }
+ let(:namespace) { 'development' }
+
+ it "returns all the files matching the pattern in seeds_root" do
+ expected_files = Dir.glob(File.join(Seedbank.seeds_root, namespace, pattern))
+
+ Seedbank::DSL.glob_seed_files_matching(namespace, pattern).must_equal expected_files
+ end
+
+ end
+
+ end
+
+ describe "define_seed_task" do
+
+ let(:name) { 'scoped:my_seed' }
+ let(:dependencies) { ['environment'] }
+ let(:seed_file) { File.expand_path('development/users.seeds.rb', Seedbank.seeds_root) }
+
+ it "returns a fully qualified task name" do
+ returned_name = Seedbank::DSL.define_seed_task(seed_file, name => dependencies)
+
+ returned_name.must_equal name
+ end
+
+ it "creates a Rake Task" do
+ Seedbank::DSL.define_seed_task(seed_file, name => dependencies)
+
+ Rake::Task[name].wont_be_nil
+ end
+
+ it "sets Rake Task dependencies" do
+ Seedbank::DSL.define_seed_task(seed_file, name => dependencies)
+
+ Rake::Task[name].prerequisite_tasks.must_equal dependencies.map { |dependency| Rake::Task[dependency] }
+ end
+
+ it "sets Rake Task description" do
+ Seedbank::DSL.define_seed_task(seed_file, name => dependencies)
+
+ Rake::Task[name].comment.must_equal "Load the seed data from #{seed_file}"
+ end
+
+ it "sets Rake Task action to the seed_file contents" do
+ Seedbank::DSL.define_seed_task(seed_file, name => dependencies)
+
+ flexmock(FakeModel).should_receive(:seed).with('development:users').once.ordered
+
+ Rake::Task[name].invoke
+ end
+ end
+end
View
4 test/lib/tasks/seed_rake_test.rb
@@ -37,7 +37,7 @@
it "is dependent on the common seeds and db:seed:original" do
prerequisite_seeds = Dir[File.expand_path('../../../dummy/db/seeds/*.seeds.rb', __FILE__)].map do |seed_file|
- "seed:" + File.basename(seed_file, '.seeds.rb')
+ ['db', 'seed', File.basename(seed_file, '.seeds.rb')].join(':')
end.unshift('db:seed:original')
subject.prerequisites.must_equal prerequisite_seeds
@@ -80,7 +80,7 @@
it "is dependent on the seeds in the environment directory" do
prerequisite_seeds = Dir[File.expand_path("../../../dummy/db/seeds/#{environment}/*.seeds.rb", __FILE__)].map do |seed_file|
- ['seed', environment, File.basename(seed_file, '.seeds.rb')].join(':')
+ ['db', 'seed', environment, File.basename(seed_file, '.seeds.rb')].join(':')
end.unshift('db:seed:common')
subject.prerequisites.must_equal prerequisite_seeds
Please sign in to comment.
Something went wrong with that request. Please try again.