seedbank 0.4.0 → 0.5.0.pre
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -1
- data/.hound.yml +3 -0
- data/.rubocop.yml +7 -0
- data/.rubocop_todo.yml +29 -0
- data/.travis.yml +7 -9
- data/Gemfile +5 -4
- data/README.md +49 -25
- data/Rakefile +2 -1
- data/TODO.txt +3 -3
- data/gemfiles/rake10.gemfile +0 -2
- data/gemfiles/{rake0.9.gemfile → rake11.gemfile} +2 -3
- data/lib/seedbank.rb +15 -6
- data/lib/seedbank/dsl.rb +65 -43
- data/lib/seedbank/railtie.rb +2 -7
- data/lib/seedbank/runner.rb +19 -32
- data/lib/seedbank/version.rb +2 -1
- data/lib/tasks/seed.rake +16 -20
- data/seedbank.gemspec +32 -53
- data/test/dummy/Rakefile +1 -0
- data/test/dummy/app/controllers/application_controller.rb +1 -0
- data/test/dummy/config.ru +2 -1
- data/test/dummy/config/application.rb +2 -22
- data/test/dummy/config/boot.rb +2 -1
- data/test/dummy/config/environment.rb +1 -0
- data/test/dummy/config/environments/development.rb +3 -7
- data/test/dummy/config/environments/test.rb +4 -9
- data/test/dummy/config/initializers/secret_token.rb +1 -0
- data/test/dummy/config/initializers/session_store.rb +2 -1
- data/test/dummy/config/initializers/wrap_parameters.rb +2 -1
- data/test/dummy/config/routes.rb +1 -0
- data/test/dummy/db/seeds.rb +1 -0
- data/test/dummy/db/seeds/circular1.seeds.rb +2 -1
- data/test/dummy/db/seeds/circular2.seeds.rb +2 -1
- data/test/dummy/db/seeds/dependency.seeds.rb +1 -0
- data/test/dummy/db/seeds/dependency2.seeds.rb +1 -0
- data/test/dummy/db/seeds/dependent.seeds.rb +2 -1
- data/test/dummy/db/seeds/dependent_on_nested.seeds.rb +2 -1
- data/test/dummy/db/seeds/dependent_on_several.seeds.rb +2 -1
- data/test/dummy/db/seeds/development/users.seeds.rb +1 -0
- data/test/dummy/db/seeds/no_block.seeds.rb +2 -1
- data/test/dummy/db/seeds/reference_memos.seeds.rb +2 -1
- data/test/dummy/db/seeds/with_block_memo.seeds.rb +2 -1
- data/test/dummy/db/seeds/with_inline_memo.seeds.rb +1 -0
- data/test/dummy/script/rails +3 -2
- data/test/lib/seedbank/dsl_test.rb +56 -73
- data/test/lib/seedbank/runner_test.rb +39 -46
- data/test/lib/tasks/seed_rake_test.rb +88 -51
- data/test/test_helper.rb +13 -11
- metadata +76 -23
- data/test/dummy/lib/tasks/dsl.rake +0 -4
@@ -1 +1,2 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
after :dependency
|
data/test/dummy/script/rails
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
2
3
|
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
|
3
4
|
|
4
|
-
APP_PATH = File.expand_path('../../config/application',
|
5
|
-
require File.expand_path('../../config/boot',
|
5
|
+
APP_PATH = File.expand_path('../../config/application', __FILE__)
|
6
|
+
require File.expand_path('../../config/boot', __FILE__)
|
6
7
|
require 'rails/commands'
|
@@ -1,135 +1,119 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'test_helper'
|
2
3
|
|
3
|
-
|
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
|
4
|
+
using Seedbank::DSL
|
12
5
|
|
13
|
-
|
6
|
+
describe Seedbank::DSL do
|
7
|
+
# TODO: This is private so should really be tested indirectly.
|
8
|
+
describe 'scope_from_seed_file' do
|
9
|
+
subject { scope_from_seed_file(seed_file) }
|
14
10
|
|
11
|
+
describe 'in an environment directory' do
|
15
12
|
let(:seed_file) { File.expand_path('development/users.seeds.rb', Seedbank.seeds_root) }
|
16
13
|
let(:seed_namespace) { %w(development) }
|
17
14
|
|
18
|
-
|
19
|
-
|
20
|
-
it "returns the enviroment scope" do
|
15
|
+
it 'returns the enviroment scope' do
|
21
16
|
subject.must_equal seed_namespace
|
22
17
|
end
|
23
18
|
end
|
24
19
|
|
25
|
-
describe
|
26
|
-
|
20
|
+
describe 'in a nested directory' do
|
27
21
|
let(:seed_file) { File.expand_path('development/shared/accounts.seeds.rb', Seedbank.seeds_root) }
|
28
22
|
let(:seed_namespace) { %w(development shared) }
|
29
23
|
|
30
|
-
|
31
|
-
|
32
|
-
it "returns the nested scope" do
|
24
|
+
it 'returns the nested scope' do
|
33
25
|
subject.must_equal seed_namespace
|
34
26
|
end
|
35
27
|
end
|
36
28
|
|
37
|
-
describe
|
38
|
-
|
29
|
+
describe 'in seeds root' do
|
39
30
|
let(:seed_file) { File.expand_path('no_block.seeds.rb', Seedbank.seeds_root) }
|
40
31
|
|
41
|
-
|
42
|
-
|
43
|
-
it "returns an array" do
|
32
|
+
it 'returns an array' do
|
44
33
|
subject.must_be_instance_of Array
|
45
34
|
end
|
46
35
|
|
47
|
-
it
|
36
|
+
it 'must be empty' do
|
48
37
|
subject.must_be_empty
|
49
38
|
end
|
50
39
|
end
|
51
40
|
end
|
52
41
|
|
53
|
-
describe
|
54
|
-
|
42
|
+
describe 'seeds_root' do
|
55
43
|
let(:seeds_root) { '/my/seeds/directory' }
|
56
44
|
|
57
|
-
subject { Seedbank::DSL.
|
45
|
+
subject { Seedbank::DSL.seeds_root }
|
58
46
|
|
59
|
-
it
|
47
|
+
it 'returns a Pathname' do
|
60
48
|
Seedbank.stub(:seeds_root, seeds_root) do
|
61
|
-
|
62
49
|
subject.must_equal Pathname.new(seeds_root)
|
63
|
-
|
64
50
|
end
|
65
51
|
end
|
66
|
-
|
67
52
|
end
|
68
53
|
|
69
|
-
describe
|
70
|
-
|
71
|
-
describe "with no namespace" do
|
72
|
-
|
54
|
+
describe 'glob_seed_files_matching' do
|
55
|
+
describe 'with no namespace' do
|
73
56
|
let(:pattern) { '*.seeds.rb' }
|
74
57
|
|
75
|
-
it
|
58
|
+
it 'returns all the files matching the pattern in seeds_root' do
|
76
59
|
expected_files = Dir.glob(File.join(Seedbank.seeds_root, pattern))
|
77
60
|
|
78
61
|
Seedbank::DSL.glob_seed_files_matching(pattern).must_equal expected_files
|
79
62
|
end
|
80
|
-
|
81
63
|
end
|
82
64
|
|
83
|
-
describe
|
84
|
-
|
65
|
+
describe 'with a namespace' do
|
85
66
|
let(:pattern) { '*.seeds.rb' }
|
86
67
|
let(:namespace) { 'development' }
|
87
68
|
|
88
|
-
it
|
69
|
+
it 'returns all the files matching the pattern in seeds_root' do
|
89
70
|
expected_files = Dir.glob(File.join(Seedbank.seeds_root, namespace, pattern))
|
90
71
|
|
91
72
|
Seedbank::DSL.glob_seed_files_matching(namespace, pattern).must_equal expected_files
|
92
73
|
end
|
93
|
-
|
94
74
|
end
|
95
|
-
|
96
75
|
end
|
97
76
|
|
98
|
-
describe
|
77
|
+
describe 'define_seed_task' do
|
78
|
+
subject { Seedbank::DSL.define_seed_task(seed_file, task_name => dependencies) }
|
99
79
|
|
100
80
|
let(:task_name) { 'scoped:my_seed' }
|
101
|
-
let(:dependencies) { ['
|
81
|
+
let(:dependencies) { ['scoped:another_seed'] }
|
102
82
|
let(:seed_file) { File.expand_path('development/users.seeds.rb', Seedbank.seeds_root) }
|
103
83
|
|
104
|
-
|
105
|
-
|
84
|
+
def define_prerequisite_task
|
85
|
+
Rake::Task.define_task('scoped:another_seed')
|
86
|
+
end
|
106
87
|
|
107
|
-
|
88
|
+
before do
|
89
|
+
define_prerequisite_task
|
108
90
|
end
|
109
91
|
|
110
|
-
it
|
111
|
-
|
92
|
+
it 'returns a fully qualified task name' do
|
93
|
+
subject.must_equal task_name
|
94
|
+
end
|
112
95
|
|
96
|
+
it 'creates a Rake Task' do
|
97
|
+
subject
|
113
98
|
Rake::Task[task_name].wont_be_nil
|
114
99
|
end
|
115
100
|
|
116
|
-
it
|
117
|
-
|
101
|
+
it 'sets Rake Task description' do
|
102
|
+
subject
|
103
|
+
relative_file = Pathname.new(seed_file).relative_path_from(Rails.root)
|
118
104
|
|
119
|
-
Rake::Task[task_name].comment.must_equal "Load the seed data from #{
|
105
|
+
Rake::Task[task_name].comment.must_equal "Load the seed data from #{relative_file}"
|
120
106
|
end
|
121
107
|
|
122
|
-
it
|
123
|
-
|
124
|
-
|
108
|
+
it 'sets Rake Task action to the seed_file contents' do
|
109
|
+
subject
|
125
110
|
FakeModel.expect :seed, true, ['development:users']
|
126
|
-
|
127
111
|
Rake::Task[task_name].invoke
|
128
112
|
end
|
129
113
|
|
130
|
-
describe
|
131
|
-
it
|
132
|
-
|
114
|
+
describe 'when db:abort_if_pending_migrations exists' do
|
115
|
+
it 'sets Rake Task dependencies' do
|
116
|
+
subject
|
133
117
|
expected_dependencies = dependencies.map { |dependency| Rake::Task[dependency] }
|
134
118
|
expected_dependencies << Rake::Task['db:abort_if_pending_migrations']
|
135
119
|
|
@@ -137,39 +121,39 @@ describe Seedbank::DSL do
|
|
137
121
|
end
|
138
122
|
end
|
139
123
|
|
140
|
-
describe
|
141
|
-
it
|
124
|
+
describe 'when db:abort_if_pending_migrations does not exist' do
|
125
|
+
it 'adds environment dependency' do
|
142
126
|
Rake.application.clear
|
143
|
-
|
127
|
+
define_prerequisite_task
|
144
128
|
|
145
|
-
|
129
|
+
expected_dependencies = dependencies.map { |dependency| Rake::Task[dependency] }
|
130
|
+
expected_dependencies << Rake::Task.define_task('environment')
|
131
|
+
subject
|
146
132
|
|
147
|
-
Rake::Task[task_name].prerequisite_tasks.must_equal
|
133
|
+
Rake::Task[task_name].prerequisite_tasks.must_equal expected_dependencies
|
148
134
|
end
|
149
135
|
end
|
150
136
|
end
|
151
137
|
|
152
|
-
describe
|
153
|
-
|
154
|
-
describe "when no task exists to override" do
|
155
|
-
|
138
|
+
describe 'override_seed_task' do
|
139
|
+
describe 'when no task exists to override' do
|
156
140
|
let(:task_name) { 'my_task' }
|
157
|
-
let(:dependencies) { ['
|
141
|
+
let(:dependencies) { ['db:abort_if_pending_migrations'] }
|
158
142
|
|
159
|
-
it
|
143
|
+
it 'creates a new task' do
|
160
144
|
Seedbank::DSL.override_seed_task(task_name => dependencies)
|
161
145
|
|
162
146
|
Rake::Task[task_name].wont_be_nil
|
163
147
|
end
|
164
148
|
|
165
|
-
it
|
149
|
+
it 'applies the dependencies' do
|
166
150
|
expected_dependencies = dependencies.map { |dependency| Rake::Task[dependency] }
|
167
151
|
Seedbank::DSL.override_seed_task(task_name => dependencies)
|
168
152
|
|
169
153
|
Rake::Task[task_name].prerequisite_tasks.must_equal expected_dependencies
|
170
154
|
end
|
171
155
|
|
172
|
-
it
|
156
|
+
it 'applies the description' do
|
173
157
|
description = 'Expected Description'
|
174
158
|
Rake.application.last_description = description
|
175
159
|
|
@@ -178,6 +162,5 @@ describe Seedbank::DSL do
|
|
178
162
|
Rake::Task[task_name].full_comment.must_equal description
|
179
163
|
end
|
180
164
|
end
|
181
|
-
|
182
165
|
end
|
183
166
|
end
|
@@ -1,12 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'test_helper'
|
2
3
|
|
3
4
|
describe Seedbank::Runner do
|
4
|
-
|
5
|
-
describe "seeds with dependency" do
|
6
|
-
|
5
|
+
describe 'seeds with dependency' do
|
7
6
|
subject { Rake::Task['db:seed:dependent'] }
|
8
7
|
|
9
|
-
it
|
8
|
+
it 'runs the dependencies in order' do
|
10
9
|
FakeModel.expect :seed, true, ['dependency']
|
11
10
|
FakeModel.expect :seed, true, ['dependent']
|
12
11
|
|
@@ -15,7 +14,7 @@ describe Seedbank::Runner do
|
|
15
14
|
FakeModel.verify
|
16
15
|
end
|
17
16
|
|
18
|
-
it
|
17
|
+
it 'executes the body of the dependencies exactly once per invocation' do
|
19
18
|
FakeModel.expect :seed, true, ['dependency']
|
20
19
|
FakeModel.expect :seed, true, ['dependent']
|
21
20
|
FakeModel.expect :seed, true, ['dependency']
|
@@ -24,7 +23,7 @@ describe Seedbank::Runner do
|
|
24
23
|
subject.invoke
|
25
24
|
|
26
25
|
# Allow all tasks to be re-executed, including dependencies
|
27
|
-
Rake.application.tasks.each
|
26
|
+
Rake.application.tasks.each(&:reenable)
|
28
27
|
|
29
28
|
subject.invoke
|
30
29
|
|
@@ -32,11 +31,10 @@ describe Seedbank::Runner do
|
|
32
31
|
end
|
33
32
|
end
|
34
33
|
|
35
|
-
describe
|
36
|
-
|
34
|
+
describe 'seeds with multiple dependencies' do
|
37
35
|
subject { Rake::Task['db:seed:dependent_on_several'] }
|
38
36
|
|
39
|
-
it
|
37
|
+
it 'runs the dependencies in order' do
|
40
38
|
FakeModel.expect :seed, true, ['dependency']
|
41
39
|
FakeModel.expect :seed, true, ['dependency2']
|
42
40
|
FakeModel.expect :seed, true, ['dependent on several']
|
@@ -47,11 +45,10 @@ describe Seedbank::Runner do
|
|
47
45
|
end
|
48
46
|
end
|
49
47
|
|
50
|
-
describe
|
51
|
-
|
48
|
+
describe 'seeds with nested dependencies' do
|
52
49
|
subject { Rake::Task['db:seed:dependent_on_nested'] }
|
53
50
|
|
54
|
-
it
|
51
|
+
it 'runs all dependencies in order' do
|
55
52
|
FakeModel.expect :seed, true, ['dependency']
|
56
53
|
FakeModel.expect :seed, true, ['dependent']
|
57
54
|
FakeModel.expect :seed, true, ['dependency2']
|
@@ -61,14 +58,12 @@ describe Seedbank::Runner do
|
|
61
58
|
|
62
59
|
FakeModel.verify
|
63
60
|
end
|
64
|
-
|
65
61
|
end
|
66
62
|
|
67
|
-
describe
|
68
|
-
|
63
|
+
describe 'after with no block given' do
|
69
64
|
subject { Rake::Task['db:seed:no_block'] }
|
70
65
|
|
71
|
-
it
|
66
|
+
it 'runs the dependencies' do
|
72
67
|
FakeModel.expect :seed, true, ['dependency']
|
73
68
|
|
74
69
|
subject.invoke
|
@@ -77,20 +72,19 @@ describe Seedbank::Runner do
|
|
77
72
|
end
|
78
73
|
end
|
79
74
|
|
80
|
-
describe
|
81
|
-
|
82
|
-
describe "evaluates dependencies in order" do
|
83
|
-
|
75
|
+
describe 'let' do
|
76
|
+
describe 'evaluates dependencies in order' do
|
84
77
|
subject { Rake::Task['db:seed:reference_memos'] }
|
85
78
|
|
86
|
-
it
|
79
|
+
it 'runs the dependencies in order' do
|
87
80
|
FakeModel.expect :seed, true, ['with_inline_memo']
|
88
81
|
FakeModel.expect :seed, true, ['with_block_memo']
|
89
82
|
FakeModel.expect :calling_let, true, ['BLOCK_LET']
|
90
83
|
FakeModel.expect :calling_let, true, ['INLINE_LET']
|
91
84
|
|
92
|
-
def FakeModel.calling_let!(*
|
93
|
-
|
85
|
+
def FakeModel.calling_let!(*_args); end
|
86
|
+
|
87
|
+
def FakeModel.calling_method(*_args); end
|
94
88
|
|
95
89
|
subject.invoke
|
96
90
|
|
@@ -98,13 +92,12 @@ describe Seedbank::Runner do
|
|
98
92
|
end
|
99
93
|
end
|
100
94
|
|
101
|
-
describe
|
102
|
-
|
95
|
+
describe 'a previously defined method' do
|
103
96
|
let(:runner) { Seedbank::Runner.new }
|
104
97
|
|
105
98
|
before { runner.let(:existing) {} }
|
106
99
|
|
107
|
-
%w(
|
100
|
+
%w(existing let! let evaluate after extend).each do |name|
|
108
101
|
it 'raises ArgumentError' do
|
109
102
|
assert_raises(ArgumentError, Regexp.new(name)) do
|
110
103
|
runner.let(name)
|
@@ -112,43 +105,44 @@ describe Seedbank::Runner do
|
|
112
105
|
end
|
113
106
|
end
|
114
107
|
end
|
115
|
-
|
116
108
|
end
|
117
109
|
|
118
|
-
|
119
|
-
|
120
|
-
describe
|
121
|
-
|
110
|
+
# TODO: These don't really test in order. Maybe swap in rspec_mocks
|
111
|
+
describe 'let!' do
|
112
|
+
describe 'evaluates dependencies in order' do
|
122
113
|
subject { Rake::Task['db:seed:reference_memos'] }
|
123
114
|
|
124
|
-
it
|
115
|
+
it 'runs the dependencies in order' do
|
116
|
+
FakeModel.expect :seed, true, ['with_inline_memo']
|
125
117
|
FakeModel.expect :calling_let!, true, ['INLINE_LET!']
|
118
|
+
FakeModel.expect :seed, true, ['with_block_memo']
|
126
119
|
FakeModel.expect :calling_let!, true, ['BLOCK_LET!']
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
def FakeModel.calling_method(*args); end
|
120
|
+
FakeModel.expect :calling_let, true, ['BLOCK_LET']
|
121
|
+
FakeModel.expect :calling_let, true, ['INLINE_LET']
|
122
|
+
FakeModel.expect :calling_method, true, ['inline_method']
|
131
123
|
|
132
124
|
subject.invoke
|
133
125
|
|
134
126
|
FakeModel.verify
|
135
127
|
end
|
136
128
|
end
|
137
|
-
|
138
129
|
end
|
139
130
|
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
131
|
+
# TODO: This doesn't do anything more than the above except for
|
132
|
+
# isolating the inline method call. Would be better served by it's
|
133
|
+
# own seeds in isolation.
|
134
|
+
describe 'defining an inline method' do
|
135
|
+
describe 'evaluates dependencies in order' do
|
144
136
|
subject { Rake::Task['db:seed:reference_memos'] }
|
145
137
|
|
146
|
-
it
|
138
|
+
it 'runs the dependencies in order' do
|
147
139
|
FakeModel.expect :calling_method, true, ['inline_method']
|
148
140
|
|
149
|
-
def FakeModel.seed(*
|
150
|
-
|
151
|
-
def FakeModel.calling_let
|
141
|
+
def FakeModel.seed(*_args); end
|
142
|
+
|
143
|
+
def FakeModel.calling_let(*_args); end
|
144
|
+
|
145
|
+
def FakeModel.calling_let!(*_args); end
|
152
146
|
|
153
147
|
subject.invoke
|
154
148
|
|
@@ -156,5 +150,4 @@ describe Seedbank::Runner do
|
|
156
150
|
end
|
157
151
|
end
|
158
152
|
end
|
159
|
-
|
160
153
|
end
|