seedbank 0.1.3 → 0.2.0.pre
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -1
- data/TODO.txt +2 -2
- data/lib/seedbank/dsl.rb +25 -16
- data/lib/seedbank/rename_task.rb +2 -2
- data/lib/seedbank/task_manager.rb +13 -2
- data/lib/seedbank/version.rb +1 -1
- data/lib/tasks/seed.rake +17 -23
- data/test/dummy/db/seeds/development/shared/accounts.seeds.rb +0 -0
- data/test/dummy/db/seeds/development/users.seeds.rb +1 -0
- data/test/dummy/lib/tasks/dsl.rake +4 -0
- data/test/lib/seedbank/dsl_test.rb +146 -0
- data/test/lib/seedbank/rename_task_test.rb +19 -0
- data/test/{seedbank → lib/seedbank}/runner_test.rb +0 -0
- data/test/lib/seedbank/task_manager_test.rb +104 -0
- data/test/lib/tasks/seed_rake_test.rb +126 -0
- data/test/test_helper.rb +3 -2
- metadata +19 -5
data/Rakefile
CHANGED
data/TODO.txt
CHANGED
@@ -1,4 +1,4 @@
|
|
1
1
|
* Add generator for seeds directories
|
2
2
|
* Add generator for seeds data
|
3
|
-
*
|
4
|
-
*
|
3
|
+
* Add ability add or update records in place
|
4
|
+
* Make framework agnostic
|
data/lib/seedbank/dsl.rb
CHANGED
@@ -2,35 +2,44 @@ module Seedbank
|
|
2
2
|
module DSL
|
3
3
|
|
4
4
|
def self.included(base)
|
5
|
-
Rake::Task.
|
5
|
+
Rake::Task.send(:include, Seedbank::RenameTask)
|
6
6
|
Rake::Application.send(:include, Seedbank::TaskManager)
|
7
7
|
end
|
8
8
|
|
9
|
-
def
|
10
|
-
|
11
|
-
fq_name = Rake.application.instance_variable_get(:@scope).dup.push(name).join(':')
|
12
|
-
new_name = "#{fq_name}:original"
|
13
|
-
Rake::Task.rename_task(fq_name, new_name)
|
14
|
-
Rake::Task.define_task(*args, &block)
|
9
|
+
def override_seed_task(*args, &block)
|
10
|
+
Rake.application.override_task(*args, &block)
|
15
11
|
end
|
16
12
|
|
17
|
-
|
18
|
-
|
19
|
-
relative_root = seed_file.sub(seeds_root + '/', '')
|
20
|
-
scopes = File.dirname(relative_root).gsub(/^\./, '').split('/').unshift('seed')
|
13
|
+
def seed_task_from_file(seed_file)
|
14
|
+
scopes = scope_from_seed_file(seed_file)
|
21
15
|
fq_name = scopes.push(File.basename(seed_file, '.seeds.rb')).join(':')
|
16
|
+
args = Rake::Task.task_defined?('db:abort_if_pending_migrations') ? { fq_name => 'db:abort_if_pending_migrations' } : fq_name
|
22
17
|
|
23
|
-
args
|
24
|
-
|
18
|
+
define_seed_task(seed_file, args)
|
19
|
+
end
|
20
|
+
|
21
|
+
def glob_seed_files_matching(*args, &block)
|
22
|
+
Dir.glob(File.join(seeds_root, *args), &block)
|
23
|
+
end
|
24
|
+
|
25
|
+
def define_seed_task(seed_file, *args)
|
26
|
+
task = Rake::Task.define_task(*args) do |seed_task|
|
25
27
|
Seedbank::Runner.new(seed_task).module_eval(File.read(seed_file)) if File.exist?(seed_file)
|
26
28
|
end
|
27
29
|
task.add_description "Load the seed data from #{seed_file}"
|
28
|
-
|
30
|
+
task.name
|
31
|
+
end
|
32
|
+
|
33
|
+
def scope_from_seed_file(seed_file)
|
34
|
+
dirname = Pathname.new(seed_file).dirname
|
35
|
+
return [] if dirname == seeds_root
|
36
|
+
relative = dirname.relative_path_from(seeds_root)
|
37
|
+
relative.to_s.split(File::Separator)
|
29
38
|
end
|
30
39
|
|
31
40
|
def seeds_root
|
32
|
-
Seedbank.seeds_root
|
41
|
+
Pathname.new Seedbank.seeds_root
|
33
42
|
end
|
34
43
|
|
35
44
|
end
|
36
|
-
end
|
45
|
+
end
|
data/lib/seedbank/rename_task.rb
CHANGED
@@ -1,9 +1,20 @@
|
|
1
1
|
module Seedbank
|
2
2
|
module TaskManager
|
3
3
|
|
4
|
+
def override_task(*args, &block)
|
5
|
+
name, params, deps = resolve_args(args.dup)
|
6
|
+
fq_name = current_scope.push(name).join(':')
|
7
|
+
new_name = "#{fq_name}:original"
|
8
|
+
unless Rake::Task.task_defined?(new_name)
|
9
|
+
rename_task(fq_name, new_name)
|
10
|
+
define_task(Rake::Task, *args, &block)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
4
14
|
def rename_task(fq_name, new_name)
|
5
|
-
|
6
|
-
|
15
|
+
task = @tasks.delete(fq_name)
|
16
|
+
task.rename(new_name)
|
17
|
+
@tasks[new_name] = task
|
7
18
|
end
|
8
19
|
|
9
20
|
end
|
data/lib/seedbank/version.rb
CHANGED
data/lib/tasks/seed.rake
CHANGED
@@ -4,34 +4,28 @@ namespace :db do
|
|
4
4
|
|
5
5
|
base_dependencies = ['db:seed:original']
|
6
6
|
override_dependency = []
|
7
|
-
common_dependencies = []
|
8
7
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
common_dependencies
|
13
|
-
end
|
8
|
+
namespace :seed do
|
9
|
+
# Create seed tasks for all the seeds in seeds_path and add them to the dependency
|
10
|
+
# list along with the original db/seeds.rb.
|
11
|
+
common_dependencies = glob_seed_files_matching('*.seeds.rb').map { |seed_file| seed_task_from_file(seed_file) }
|
14
12
|
|
15
|
-
|
16
|
-
|
13
|
+
desc "Load the seed data from db/seeds.rb and db/seeds/*.seeds.rb."
|
14
|
+
task 'common' => base_dependencies + common_dependencies
|
17
15
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
16
|
+
# Glob through the directories under seeds_path assuming they are all environments
|
17
|
+
# and create a task for each and add it to the dependency list. Then create a task
|
18
|
+
# for the environment
|
19
|
+
glob_seed_files_matching('/*/').each do |directory|
|
20
|
+
environment = File.basename(directory)
|
23
21
|
|
24
|
-
|
25
|
-
Dir.glob(File.join(seeds_root, environment, '*.seeds.rb')).sort.each do |seed_file|
|
26
|
-
environment_dependencies << define_seed_task(seed_file)
|
27
|
-
end
|
22
|
+
environment_dependencies = glob_seed_files_matching(environment, '*.seeds.rb').sort.map { |seed_file| seed_task_from_file(seed_file) }
|
28
23
|
|
29
|
-
|
30
|
-
|
31
|
-
EOT
|
32
|
-
task ['seed', environment] => ['db:seed:common'] + environment_dependencies
|
24
|
+
desc "Load the seed data from db/seeds.rb, db/seeds/*.seeds.rb and db/seeds/#{environment}/*.seeds.rb."
|
25
|
+
task environment => ['db:seed:common'] + environment_dependencies
|
33
26
|
|
34
|
-
|
27
|
+
override_dependency << "db:seed:#{environment}" if Rails.env == environment
|
28
|
+
end
|
35
29
|
end
|
36
30
|
|
37
31
|
# Change db:seed task to run all the base seeds tasks defined above.
|
@@ -39,6 +33,6 @@ namespace :db do
|
|
39
33
|
Load the seed data from db/seeds.rb, db/seeds/*.seeds.rb and db/seeds/ENVIRONMENT/*.seeds.rb.
|
40
34
|
ENVIRONMENT is the current environment in Rails.env.
|
41
35
|
EOT
|
42
|
-
|
36
|
+
override_seed_task :seed => ['db:seed:common'] + override_dependency
|
43
37
|
|
44
38
|
end
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
FakeModel.seed('development:users')
|
@@ -0,0 +1,146 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
describe Seedbank::DSL do
|
4
|
+
|
5
|
+
describe "scope_from_seed_file" do
|
6
|
+
|
7
|
+
it "is added to the namesapce" do
|
8
|
+
ns = Rake.application.in_namespace(:seedy) { self }
|
9
|
+
|
10
|
+
ns.must_respond_to :scope_from_seed_file
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "in an environment directory" do
|
14
|
+
|
15
|
+
let(:seed_file) { File.expand_path('development/users.seeds.rb', Seedbank.seeds_root) }
|
16
|
+
let(:seed_namespace) { %w(development) }
|
17
|
+
|
18
|
+
subject { Seedbank::DSL.scope_from_seed_file seed_file }
|
19
|
+
|
20
|
+
it "returns the enviroment scope" do
|
21
|
+
subject.must_equal seed_namespace
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "in a nested directory" do
|
26
|
+
|
27
|
+
let(:seed_file) { File.expand_path('development/shared/accounts.seeds.rb', Seedbank.seeds_root) }
|
28
|
+
let(:seed_namespace) { %w(development shared) }
|
29
|
+
|
30
|
+
subject { Seedbank::DSL.scope_from_seed_file seed_file }
|
31
|
+
|
32
|
+
it "returns the nested scope" do
|
33
|
+
subject.must_equal seed_namespace
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe "in seeds root" do
|
38
|
+
|
39
|
+
let(:seed_file) { File.expand_path('no_block.seeds.rb', Seedbank.seeds_root) }
|
40
|
+
|
41
|
+
subject { Seedbank::DSL.scope_from_seed_file seed_file }
|
42
|
+
|
43
|
+
it "returns an array" do
|
44
|
+
subject.must_be_instance_of Array
|
45
|
+
end
|
46
|
+
|
47
|
+
it "must be empty" do
|
48
|
+
subject.must_be_empty
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe "seeds_root" do
|
54
|
+
|
55
|
+
let(:seeds_root) { '/my/seeds/directory' }
|
56
|
+
|
57
|
+
subject { Seedbank::DSL.seeds_root }
|
58
|
+
|
59
|
+
it "returns a Pathname" do
|
60
|
+
flexmock(Seedbank).should_receive(:seeds_root).and_return(seeds_root).by_default
|
61
|
+
|
62
|
+
subject.must_equal Pathname.new(seeds_root)
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
describe "glob_seed_files_matching" do
|
68
|
+
|
69
|
+
describe "with no namespace" do
|
70
|
+
|
71
|
+
let(:pattern) { '*.seeds.rb' }
|
72
|
+
|
73
|
+
it "returns all the files matching the pattern in seeds_root" do
|
74
|
+
expected_files = Dir.glob(File.join(Seedbank.seeds_root, pattern))
|
75
|
+
|
76
|
+
Seedbank::DSL.glob_seed_files_matching(pattern).must_equal expected_files
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
|
81
|
+
describe "with a namespace" do
|
82
|
+
|
83
|
+
let(:pattern) { '*.seeds.rb' }
|
84
|
+
let(:namespace) { 'development' }
|
85
|
+
|
86
|
+
it "returns all the files matching the pattern in seeds_root" do
|
87
|
+
expected_files = Dir.glob(File.join(Seedbank.seeds_root, namespace, pattern))
|
88
|
+
|
89
|
+
Seedbank::DSL.glob_seed_files_matching(namespace, pattern).must_equal expected_files
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
95
|
+
|
96
|
+
describe "define_seed_task" do
|
97
|
+
|
98
|
+
let(:name) { 'scoped:my_seed' }
|
99
|
+
let(:dependencies) { ['environment'] }
|
100
|
+
let(:seed_file) { File.expand_path('development/users.seeds.rb', Seedbank.seeds_root) }
|
101
|
+
|
102
|
+
it "returns a fully qualified task name" do
|
103
|
+
returned_name = Seedbank::DSL.define_seed_task(seed_file, name => dependencies)
|
104
|
+
|
105
|
+
returned_name.must_equal name
|
106
|
+
end
|
107
|
+
|
108
|
+
it "creates a Rake Task" do
|
109
|
+
Seedbank::DSL.define_seed_task(seed_file, name => dependencies)
|
110
|
+
|
111
|
+
Rake::Task[name].wont_be_nil
|
112
|
+
end
|
113
|
+
|
114
|
+
it "sets Rake Task dependencies" do
|
115
|
+
Seedbank::DSL.define_seed_task(seed_file, name => dependencies)
|
116
|
+
|
117
|
+
Rake::Task[name].prerequisite_tasks.must_equal dependencies.map { |dependency| Rake::Task[dependency] }
|
118
|
+
end
|
119
|
+
|
120
|
+
it "sets Rake Task description" do
|
121
|
+
Seedbank::DSL.define_seed_task(seed_file, name => dependencies)
|
122
|
+
|
123
|
+
Rake::Task[name].comment.must_equal "Load the seed data from #{seed_file}"
|
124
|
+
end
|
125
|
+
|
126
|
+
it "sets Rake Task action to the seed_file contents" do
|
127
|
+
Seedbank::DSL.define_seed_task(seed_file, name => dependencies)
|
128
|
+
|
129
|
+
flexmock(FakeModel).should_receive(:seed).with('development:users').once.ordered
|
130
|
+
|
131
|
+
Rake::Task[name].invoke
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
describe "override_seed_task" do
|
136
|
+
|
137
|
+
let(:arguments) { 'my_task' }
|
138
|
+
|
139
|
+
it "calls Rake::TaskManager#override_task" do
|
140
|
+
block = proc {}
|
141
|
+
flexmock(Rake.application).should_receive(:override_task).with(arguments, block).once
|
142
|
+
|
143
|
+
Seedbank::DSL.override_seed_task(arguments, &block)
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
describe Seedbank::RenameTask do
|
4
|
+
|
5
|
+
describe "rename" do
|
6
|
+
|
7
|
+
let(:original_name) { 'original_name' }
|
8
|
+
let(:new_name) { 'new_name' }
|
9
|
+
|
10
|
+
subject { Rake::Task.define_task(original_name) }
|
11
|
+
|
12
|
+
before { subject.rename(new_name) }
|
13
|
+
|
14
|
+
it "changes the tasks name" do
|
15
|
+
subject.name.must_equal new_name
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
File without changes
|
@@ -0,0 +1,104 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
describe Seedbank::TaskManager do
|
4
|
+
|
5
|
+
describe "override_task" do
|
6
|
+
|
7
|
+
let(:task_name) { 'my_task' }
|
8
|
+
|
9
|
+
describe "with no original version of the task exists" do
|
10
|
+
|
11
|
+
it "appends :original to the task name" do
|
12
|
+
task = Rake::Task.define_task(task_name)
|
13
|
+
|
14
|
+
Rake.application.override_task(task_name)
|
15
|
+
|
16
|
+
task.must_equal Rake.application.lookup('original', [task_name])
|
17
|
+
end
|
18
|
+
|
19
|
+
it "creates a new task in place of the original" do
|
20
|
+
Rake::Task.define_task(task_name)
|
21
|
+
task = Rake.application.override_task(task_name => [:dependency])
|
22
|
+
|
23
|
+
task.must_be_instance_of Rake::Task
|
24
|
+
end
|
25
|
+
|
26
|
+
it "adds the supplied dependencies to the new task" do
|
27
|
+
dependency = ['db:seed:dependency']
|
28
|
+
|
29
|
+
Rake::Task.define_task(task_name)
|
30
|
+
task = Rake.application.override_task(task_name => dependency)
|
31
|
+
|
32
|
+
task.prerequisites.must_equal dependency
|
33
|
+
end
|
34
|
+
|
35
|
+
it "adds the supplied action to the new task" do
|
36
|
+
action = proc {}
|
37
|
+
Rake::Task.define_task(task_name)
|
38
|
+
task = Rake.application.override_task(task_name, &action)
|
39
|
+
|
40
|
+
task.actions.must_equal [action]
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe "when the original version of the task exists" do
|
45
|
+
|
46
|
+
let(:original_name) { [task_name, 'original'].join(':') }
|
47
|
+
|
48
|
+
it "leaves the original task in place" do
|
49
|
+
task = Rake::Task.define_task(task_name)
|
50
|
+
original = Rake::Task.define_task(original_name)
|
51
|
+
new_task = Rake.application.override_task(task_name)
|
52
|
+
|
53
|
+
Rake::Task[task_name].must_equal task
|
54
|
+
end
|
55
|
+
|
56
|
+
it "leaves the task:original task in place" do
|
57
|
+
task = Rake::Task.define_task(task_name)
|
58
|
+
original = Rake::Task.define_task(original_name)
|
59
|
+
new_task = Rake.application.override_task(task_name)
|
60
|
+
|
61
|
+
Rake::Task[original].must_equal original
|
62
|
+
end
|
63
|
+
|
64
|
+
it "does not create a new task" do
|
65
|
+
task = Rake::Task.define_task(task_name)
|
66
|
+
original = Rake::Task.define_task(original_name)
|
67
|
+
new_task = Rake.application.override_task(task_name)
|
68
|
+
|
69
|
+
new_task.must_be_nil
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
describe "rename_task" do
|
75
|
+
|
76
|
+
let(:original_name) { 'original_name' }
|
77
|
+
let(:new_name) { 'new_name' }
|
78
|
+
|
79
|
+
before do
|
80
|
+
Rake::Task.define_task(original_name)
|
81
|
+
end
|
82
|
+
|
83
|
+
it "changes the tasks name" do
|
84
|
+
task = Rake::Task[original_name]
|
85
|
+
flexmock(task).should_receive(:rename).with(new_name).once
|
86
|
+
|
87
|
+
Rake.application.rename_task(original_name, new_name)
|
88
|
+
end
|
89
|
+
|
90
|
+
it "removes the original task name" do
|
91
|
+
Rake.application.rename_task(original_name, new_name)
|
92
|
+
|
93
|
+
Rake.application.lookup(original_name).must_be_nil
|
94
|
+
end
|
95
|
+
|
96
|
+
it "give the original task the new name" do
|
97
|
+
original_task = Rake::Task[original_name]
|
98
|
+
|
99
|
+
Rake.application.rename_task(original_name, new_name)
|
100
|
+
|
101
|
+
Rake.application.lookup(new_name).must_equal original_task
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
@@ -0,0 +1,126 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
describe 'Seedbank rake.task' do
|
4
|
+
|
5
|
+
describe "seeds with dependency" do
|
6
|
+
|
7
|
+
subject { Rake.application.tasks_in_scope %w[db seed] }
|
8
|
+
|
9
|
+
it "creates all the seed tasks" do
|
10
|
+
seeds = %w(db:seed:circular1 db:seed:circular2 db:seed:common db:seed:dependency db:seed:dependency2
|
11
|
+
db:seed:dependent db:seed:dependent_on_nested db:seed:dependent_on_several db:seed:development
|
12
|
+
db:seed:development:users db:seed:no_block db:seed:original)
|
13
|
+
|
14
|
+
subject.map(&:to_s).must_equal seeds
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "common seeds in the root directory" do
|
19
|
+
|
20
|
+
Dir[File.expand_path('../../../dummy/db/seeds/*.seeds.rb', __FILE__)].each do |seed_file|
|
21
|
+
seed = File.basename(seed_file, '.seeds.rb')
|
22
|
+
|
23
|
+
describe seed do
|
24
|
+
|
25
|
+
subject { Rake.application.lookup(seed, %w[db seed]) }
|
26
|
+
|
27
|
+
it "is dependent on db:abort_if_pending_migrations" do
|
28
|
+
subject.prerequisites.must_equal %w[db:abort_if_pending_migrations]
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "db:seed:common" do
|
35
|
+
|
36
|
+
subject { Rake::Task['db:seed:common'] }
|
37
|
+
|
38
|
+
it "is dependent on the common seeds and db:seed:original" do
|
39
|
+
prerequisite_seeds = Dir[File.expand_path('../../../dummy/db/seeds/*.seeds.rb', __FILE__)].map do |seed_file|
|
40
|
+
['db', 'seed', File.basename(seed_file, '.seeds.rb')].join(':')
|
41
|
+
end.unshift('db:seed:original')
|
42
|
+
|
43
|
+
subject.prerequisites.must_equal prerequisite_seeds
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe "db:seed:original" do
|
48
|
+
|
49
|
+
subject { Rake::Task['db:seed:original'] }
|
50
|
+
|
51
|
+
it "has no dependencies" do
|
52
|
+
subject.prerequisites.must_be_empty
|
53
|
+
end
|
54
|
+
|
55
|
+
describe "when seeds are reloaded" do
|
56
|
+
|
57
|
+
before do
|
58
|
+
Dummy::Application.load_tasks
|
59
|
+
end
|
60
|
+
|
61
|
+
it "still has no dependencies" do
|
62
|
+
subject.prerequisites.must_be_empty
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
describe "environment seeds" do
|
68
|
+
|
69
|
+
Dir[File.expand_path('../../../dummy/db/seeds', __FILE__) + '/*/'].each do |environment_directory|
|
70
|
+
environment = File.basename(environment_directory)
|
71
|
+
|
72
|
+
describe "seeds in the #{environment} environment" do
|
73
|
+
|
74
|
+
Dir[File.expand_path("../../../dummy/db/seeds/#{environment}/*.seeds.rb", __FILE__)].each do |seed_file|
|
75
|
+
seed = File.basename(seed_file, '.seeds.rb')
|
76
|
+
|
77
|
+
describe seed do
|
78
|
+
|
79
|
+
subject { Rake.application.lookup(seed, ['db', 'seed', environment]) }
|
80
|
+
|
81
|
+
it "is dependent on db:abort_if_pending_migrations" do
|
82
|
+
subject.prerequisites.must_equal %w[db:abort_if_pending_migrations]
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
describe "db:seed:#{environment}" do
|
89
|
+
|
90
|
+
subject { Rake.application.lookup(environment, %w[db seed]) }
|
91
|
+
|
92
|
+
it "is dependent on the seeds in the environment directory" do
|
93
|
+
prerequisite_seeds = Dir[File.expand_path("../../../dummy/db/seeds/#{environment}/*.seeds.rb", __FILE__)].map do |seed_file|
|
94
|
+
['db', 'seed', environment, File.basename(seed_file, '.seeds.rb')].join(':')
|
95
|
+
end.unshift('db:seed:common')
|
96
|
+
|
97
|
+
subject.prerequisites.must_equal prerequisite_seeds
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
describe "db:seed task" do
|
104
|
+
|
105
|
+
subject { Rake::Task['db:seed'] }
|
106
|
+
|
107
|
+
describe "when no environment seeds are defined" do
|
108
|
+
|
109
|
+
it "is dependent on db:seed:common" do
|
110
|
+
subject.prerequisites.must_equal %w[db:seed:common]
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
describe "when environment seeds are defined" do
|
115
|
+
|
116
|
+
it "is dependent on db:seed:common" do
|
117
|
+
flexmock(Rails).should_receive(:env).and_return('development').once
|
118
|
+
|
119
|
+
Rake.application.clear
|
120
|
+
Dummy::Application.load_tasks
|
121
|
+
|
122
|
+
subject.prerequisites.must_equal %w[db:seed:common db:seed:development]
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
data/test/test_helper.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require "flexmock"
|
3
|
-
require 'minitest/
|
3
|
+
require 'minitest/spec'
|
4
4
|
|
5
5
|
# Configure Rails Environment
|
6
6
|
environment = ENV["RAILS_ENV"] = 'test'
|
@@ -24,4 +24,5 @@ class Seedbank::Spec < MiniTest::Spec
|
|
24
24
|
|
25
25
|
end
|
26
26
|
|
27
|
-
MiniTest::Spec.register_spec_type(/^Seedbank
|
27
|
+
MiniTest::Spec.register_spec_type(/^Seedbank/i, Seedbank::Spec)
|
28
|
+
MiniTest::Unit.autorun
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: seedbank
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.2.0.pre
|
5
|
+
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- James McCarthy
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-07-
|
12
|
+
date: 2012-07-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: minitest
|
@@ -107,9 +107,16 @@ files:
|
|
107
107
|
- test/dummy/db/seeds/dependent.seeds.rb
|
108
108
|
- test/dummy/db/seeds/dependent_on_nested.seeds.rb
|
109
109
|
- test/dummy/db/seeds/dependent_on_several.seeds.rb
|
110
|
+
- test/dummy/db/seeds/development/shared/accounts.seeds.rb
|
111
|
+
- test/dummy/db/seeds/development/users.seeds.rb
|
110
112
|
- test/dummy/db/seeds/no_block.seeds.rb
|
113
|
+
- test/dummy/lib/tasks/dsl.rake
|
111
114
|
- test/dummy/script/rails
|
112
|
-
- test/seedbank/
|
115
|
+
- test/lib/seedbank/dsl_test.rb
|
116
|
+
- test/lib/seedbank/rename_task_test.rb
|
117
|
+
- test/lib/seedbank/runner_test.rb
|
118
|
+
- test/lib/seedbank/task_manager_test.rb
|
119
|
+
- test/lib/tasks/seed_rake_test.rb
|
113
120
|
- test/test_helper.rb
|
114
121
|
homepage: http://github.com/james2m/seedbank
|
115
122
|
licenses: []
|
@@ -166,7 +173,14 @@ test_files:
|
|
166
173
|
- test/dummy/db/seeds/dependent.seeds.rb
|
167
174
|
- test/dummy/db/seeds/dependent_on_nested.seeds.rb
|
168
175
|
- test/dummy/db/seeds/dependent_on_several.seeds.rb
|
176
|
+
- test/dummy/db/seeds/development/shared/accounts.seeds.rb
|
177
|
+
- test/dummy/db/seeds/development/users.seeds.rb
|
169
178
|
- test/dummy/db/seeds/no_block.seeds.rb
|
179
|
+
- test/dummy/lib/tasks/dsl.rake
|
170
180
|
- test/dummy/script/rails
|
171
|
-
- test/seedbank/
|
181
|
+
- test/lib/seedbank/dsl_test.rb
|
182
|
+
- test/lib/seedbank/rename_task_test.rb
|
183
|
+
- test/lib/seedbank/runner_test.rb
|
184
|
+
- test/lib/seedbank/task_manager_test.rb
|
185
|
+
- test/lib/tasks/seed_rake_test.rb
|
172
186
|
- test/test_helper.rb
|