Permalink
Browse files

Added Seedbank::DSL#scope_from_seed_file method.

Signed-off-by: James McCarthy <james2mccarthy@gmail.com>
  • Loading branch information...
1 parent eea84e5 commit dbcbb2e21afb8a684e2fe8bcad013cc8f727efbd @james2m committed Jul 20, 2012
View
@@ -16,7 +16,7 @@ def override_task(*args, &block)
# Creates a task namespaced in @seeds_path
def define_seed_task(seed_file)
- relative_root = seed_file.sub(seeds_root + '/', '')
+ relative_root = seed_file.sub(seeds_root.to_s + '/', '')
scopes = File.dirname(relative_root).gsub(/^\./, '').split('/').unshift('seed')
fq_name = scopes.push(File.basename(seed_file, '.seeds.rb')).join(':')
@@ -27,9 +27,14 @@ def define_seed_task(seed_file)
task.add_description "Load the seed data from #{seed_file}"
fq_name
end
+
+ def scope_from_seed_file(seed_file)
+ pathname = Pathname.new(seed_file).relative_path_from(seeds_root)
+ pathname.dirname.to_s.gsub(File::Separator, ':')
+ end
def seeds_root
- Seedbank.seeds_root
+ Pathname.new Seedbank.seeds_root
end
end
View
@@ -0,0 +1,38 @@
+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 "with an environment directory" do
+
+ let(:seed_file) { File.expand_path('development/users.seeds.rb', Seedbank.seeds_root) }
+ let(:seed_namespace) { 'development' }
+
+ subject {Seedbank::DSL.scope_from_seed_file seed_file }
+
+ it "returns the enviroment scope" do
+ subject.must_equal seed_namespace
+ end
+ end
+
+ describe "with a nested directory" do
+
+ let(:seed_file) { File.expand_path('development/shared/accounts.seeds.rb', Seedbank.seeds_root) }
+ let(:seed_namespace) { 'development:shared' }
+
+ subject {Seedbank::DSL.scope_from_seed_file seed_file }
+
+ it "returns the nested scope" do
+ subject.must_equal seed_namespace
+ end
+ end
+ end
+
+end

0 comments on commit dbcbb2e

Please sign in to comment.