seedbank 0.3.0 → 0.4.0.pre
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +6 -14
- data/.gitignore +2 -0
- data/.travis.yml +2 -2
- data/README.md +36 -11
- data/lib/seedbank/dsl.rb +5 -1
- data/lib/seedbank/runner.rb +45 -9
- data/lib/seedbank/version.rb +1 -1
- data/lib/tasks/seed.rake +1 -1
- data/seedbank.gemspec +6 -7
- data/test/dummy/db/seeds/reference_memos.seeds.rb +5 -0
- data/test/dummy/db/seeds/with_block_memo.seeds.rb +5 -0
- data/test/dummy/db/seeds/with_inline_memo.seeds.rb +7 -0
- data/test/lib/seedbank/dsl_test.rb +27 -24
- data/test/lib/seedbank/runner_test.rb +109 -15
- data/test/lib/tasks/seed_rake_test.rb +7 -5
- data/test/test_helper.rb +4 -5
- metadata +27 -37
- data/test/dummy/app/models/fake_model.rb +0 -7
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
metadata.gz: !binary |-
|
9
|
-
MWZkODAzNDBhYTg0MzQ0NDc1MzZkMWI5OTczYzhiZWJjYzAzMjE4MDQxNjU1
|
10
|
-
NmFhZGIyYTM0MDY0OWQ5NDI5NDMxNTJkM2ZiNDczM2IyYTkxN2I1NmEyZTI4
|
11
|
-
MDYyYTlkNmNmODU2MWJiMzRmMGZiOTQ1ZDQzNmZmZTU3OGVkMGQ=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
MmJjZjc4ZjBhNmU0MGFkZGExYjdhYzcxNGE5ZTQ4ZGEzNzMwOGI1NWUwYzE3
|
14
|
-
OGJiMGI5MDY5NWM1Nzc1ZmRiZDhhYTBmNTdmNWQ1OWNhNGQxYTAyZGVkYTJh
|
15
|
-
NTk0N2FiZjUwMTU5NTIyNDQ4MjUxZDQ5YzVmZGJkNDkxZGRhNmU=
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: eb10a690e591a93f925a5a62b4aa641f74117138
|
4
|
+
data.tar.gz: 0ce601ae90ec0e75e3a35b61c8960a240cf9113f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: fe5ae40e4d059b807059998d066f0b75ad897ed5bd6b664613fd0555c8e550bbdfeac9462dda2083a9d9fa9a432e36454f6e34fbb41a9ce190648f5989a5c3fb
|
7
|
+
data.tar.gz: d9062426df7dc228a3a767c1797894669cab812316c4b1ff6d7e226c87c8d00ed8561e53b6ada078e2af31a646a81d298f29b451a6a042ee3b350e627e7095a7
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -1,15 +1,18 @@
|
|
1
1
|
Seedbank
|
2
2
|
========
|
3
3
|
|
4
|
-
Seedbank allows you to structure your Rails seed data instead of having it all dumped into one large file. I find my seed data tended to fall into two categories
|
4
|
+
Seedbank allows you to structure your Rails seed data instead of having it all dumped into one large file. I find my seed data tended to fall into two categories:
|
5
5
|
|
6
|
-
|
6
|
+
1. Stuff that the entire application requires.
|
7
|
+
2. Stuff to populate my development and staging environments.
|
8
|
+
|
9
|
+
Seedbank assumes that your common seed data is kept under db/seeds and any directories under `db/seeds/` are specific to an environment, so `db/seeds/development` contains all your **development-only** seed data.
|
7
10
|
|
8
11
|
The reason behind Seedbank is laziness. When I checkout or re-visit a project I don't want to mess around getting my environment setup I just want the code and a database loaded with data in a known state. Since the Rails core team were good enough to give us rake db:setup it would be rude not to use it.
|
9
12
|
|
10
13
|
rake db:setup # Create the database, load the schema, and initialize with the seed data (use db:reset to also drop the db first)
|
11
14
|
|
12
|
-
To achieve this slothful aim Seedbank renames the original db:seed rake task to db:seed:original, makes it a dependency for all the Seedbank seeds and adds a new db:seed task that loads all the common seeds in db/seeds plus all the seeds for the current Rails environment.
|
15
|
+
To achieve this slothful aim, Seedbank renames the original db:seed rake task to db:seed:original, makes it a dependency for all the Seedbank seeds and adds a new db:seed task that loads all the common seeds in db/seeds plus all the seeds for the current Rails environment.
|
13
16
|
|
14
17
|
Example
|
15
18
|
=======
|
@@ -32,20 +35,20 @@ This would generate the following Rake tasks
|
|
32
35
|
rake db:seed:foo # Load the seed data from db/seeds/foo.seeds.rb
|
33
36
|
rake db:seed:original # Load the seed data from db/seeds.rb
|
34
37
|
|
35
|
-
|
38
|
+
Therefore, assuming `RAILS_ENV` is not set or it is "development":
|
36
39
|
|
37
40
|
$ rake db:seed
|
38
41
|
|
39
|
-
|
42
|
+
will load the seeds in `db/seeds.rb`, `db/seeds/bar.seeds.rb`, `db/seeds/foo.seeds.rb` and `db/seeds/development/users.seeds.rb`. Whereas, setting the `RAILS_ENV` variable, like so:
|
40
43
|
|
41
44
|
$ RAILS_ENV=production db:seed
|
42
45
|
|
43
|
-
|
46
|
+
will load the seeds in `db/seeds.rb`, `db/seeds/bar.seeds.rb` and `db/seeds/foo.seeds.rb`.
|
44
47
|
|
45
48
|
Installation
|
46
49
|
============
|
47
50
|
|
48
|
-
### Rails 3.x
|
51
|
+
### Rails 3.x and 4.x
|
49
52
|
|
50
53
|
Add the seedbank gem to your Gemfile. In Gemfile:
|
51
54
|
|
@@ -63,9 +66,13 @@ Add to your config/environment.rb
|
|
63
66
|
config.gem 'seedbank'
|
64
67
|
```
|
65
68
|
|
66
|
-
Install the gem
|
69
|
+
Install the gem:
|
67
70
|
|
68
71
|
$ rake gems:install
|
72
|
+
|
73
|
+
Or, if you're using Bundler:
|
74
|
+
|
75
|
+
$ bundle install
|
69
76
|
|
70
77
|
Then in the bottom of your application's Rakefile:
|
71
78
|
|
@@ -124,6 +131,23 @@ after "development:companies" do
|
|
124
131
|
end
|
125
132
|
```
|
126
133
|
|
134
|
+
### Defining and using methods
|
135
|
+
|
136
|
+
As seed files are evaluated within blocks, methods need to be defined and used as per below:
|
137
|
+
|
138
|
+
```ruby
|
139
|
+
class << self
|
140
|
+
def create_user name
|
141
|
+
user = User.where(name: name).first_or_create
|
142
|
+
# ...
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
['Greg', 'Daniel'].each do |name|
|
147
|
+
create_user name
|
148
|
+
end
|
149
|
+
```
|
150
|
+
|
127
151
|
*Note* - If you experience any errors like `Don't know how to build task 'db:seed:users'`. Ensure your specifying `after 'development:companies'` like the above example. This is the usual culprit (YMMV).
|
128
152
|
|
129
153
|
Contributors
|
@@ -132,10 +156,10 @@ Contributors
|
|
132
156
|
git log | grep Author | sort | uniq
|
133
157
|
```
|
134
158
|
|
135
|
-
*
|
159
|
+
* Ahmad Sherif
|
136
160
|
* Andy Triggs
|
137
|
-
*
|
138
|
-
*
|
161
|
+
* Corey Purcell
|
162
|
+
* James McCarthy
|
139
163
|
* Joost Baaij
|
140
164
|
* Justin Smestad
|
141
165
|
* Peter Suschlik
|
@@ -145,6 +169,7 @@ git log | grep Author | sort | uniq
|
|
145
169
|
* pivotal-cloudplanner
|
146
170
|
* vkill
|
147
171
|
|
172
|
+
|
148
173
|
Note on Patches/Pull Request
|
149
174
|
============================
|
150
175
|
|
data/lib/seedbank/dsl.rb
CHANGED
@@ -19,9 +19,13 @@ module Seedbank
|
|
19
19
|
Dir.glob(File.join(seeds_root, *args), &block)
|
20
20
|
end
|
21
21
|
|
22
|
+
def runner
|
23
|
+
@_seedbank_runner ||= Seedbank::Runner.new
|
24
|
+
end
|
25
|
+
|
22
26
|
def define_seed_task(seed_file, *args)
|
23
27
|
task = Rake::Task.define_task(*args) do |seed_task|
|
24
|
-
|
28
|
+
runner.evaluate(seed_task, seed_file) if File.exist?(seed_file)
|
25
29
|
end
|
26
30
|
|
27
31
|
task.add_description "Load the seed data from #{seed_file}"
|
data/lib/seedbank/runner.rb
CHANGED
@@ -1,14 +1,36 @@
|
|
1
1
|
module Seedbank
|
2
|
-
class Runner
|
3
|
-
|
4
|
-
def initialize
|
5
|
-
@
|
6
|
-
|
2
|
+
class Runner
|
3
|
+
|
4
|
+
def initialize
|
5
|
+
@_memoized = {}
|
6
|
+
end
|
7
|
+
|
8
|
+
def let(name, &block)
|
9
|
+
name = String(name)
|
10
|
+
|
11
|
+
raise ArgumentError.new("#{name} is already defined") if respond_to?(name, true)
|
12
|
+
|
13
|
+
__eigenclass.instance_exec(name) do |name|
|
14
|
+
define_method(name) do
|
15
|
+
@_memoized.fetch(name) { |key| @_memoized[key] = instance_eval(&block) }
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
def let!(name, &block)
|
22
|
+
let(name, &block)
|
23
|
+
send name
|
24
|
+
end
|
25
|
+
|
26
|
+
def evaluate(seed_task, seed_file)
|
27
|
+
@_seed_task = seed_task
|
28
|
+
instance_eval(File.read(seed_file), seed_file)
|
7
29
|
end
|
8
30
|
|
9
31
|
# Run this seed after the specified dependencies have run
|
10
32
|
# @param dependencies [Array] seeds to run before the block is executed
|
11
|
-
#
|
33
|
+
#
|
12
34
|
# If a block is specified the contents of the block are executed after all the
|
13
35
|
# dependencies have been executed.
|
14
36
|
#
|
@@ -22,10 +44,24 @@ module Seedbank
|
|
22
44
|
def after(*dependencies, &block)
|
23
45
|
dependencies.flatten!
|
24
46
|
dependencies.map! { |dep| "db:seed:#{dep}"}
|
25
|
-
dependent_task_name = @
|
26
|
-
|
47
|
+
dependent_task_name = @_seed_task.name + ':body'
|
48
|
+
|
49
|
+
if Rake::Task.task_defined?(dependent_task_name)
|
50
|
+
dependent_task = Rake::Task[dependent_task_name]
|
51
|
+
else
|
52
|
+
dependent_task = Rake::Task.define_task(dependent_task_name => dependencies, &block)
|
53
|
+
end
|
54
|
+
|
27
55
|
dependent_task.invoke
|
28
56
|
end
|
29
|
-
|
57
|
+
|
58
|
+
private
|
59
|
+
|
60
|
+
def __eigenclass
|
61
|
+
class << self
|
62
|
+
self
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
30
66
|
end
|
31
67
|
end
|
data/lib/seedbank/version.rb
CHANGED
data/lib/tasks/seed.rake
CHANGED
@@ -28,7 +28,7 @@ namespace :db do
|
|
28
28
|
|
29
29
|
if Rails.version > '4'
|
30
30
|
original_seeds_file = Rails.application.paths["db/seeds.rb"].existent.first
|
31
|
-
elsif Rails.version > '3'
|
31
|
+
elsif Rails.version > '3.1'
|
32
32
|
original_seeds_file = Rails.application.paths["db/seeds"].existent.first
|
33
33
|
else
|
34
34
|
original_seeds_file = Rails.root.join("db","seeds").children.first.to_s
|
data/seedbank.gemspec
CHANGED
@@ -35,26 +35,25 @@ Gem::Specification.new do |s|
|
|
35
35
|
"README.md"
|
36
36
|
]
|
37
37
|
|
38
|
-
s.add_development_dependency "minitest", "~>
|
39
|
-
s.add_development_dependency "
|
40
|
-
|
41
|
-
|
38
|
+
s.add_development_dependency "minitest", "~> 5.0"
|
39
|
+
s.add_development_dependency "rails", "~> 3.2"
|
40
|
+
|
42
41
|
s.post_install_message = %q{
|
43
42
|
================================================================================
|
44
43
|
|
45
44
|
Rails 2.x
|
46
45
|
---------
|
47
|
-
If you are using Seedbank with Rails 2.x you will need to place the following at
|
46
|
+
If you are using Seedbank with Rails 2.x you will need to place the following at
|
48
47
|
the end of your Rakefile so Rubygems can load the seedbank tasks;
|
49
48
|
|
50
49
|
require 'seedbank'
|
51
50
|
Seedbank.load_tasks if defined?(Seedbank)
|
52
51
|
|
53
|
-
Rails 3.x
|
52
|
+
Rails 3.x and 4.x
|
54
53
|
---------
|
55
54
|
Your work here is done!
|
56
55
|
|
57
56
|
================================================================================
|
58
|
-
}
|
57
|
+
}
|
59
58
|
end
|
60
59
|
|
@@ -57,9 +57,11 @@ describe Seedbank::DSL do
|
|
57
57
|
subject { Seedbank::DSL.send(:seeds_root) }
|
58
58
|
|
59
59
|
it "returns a Pathname" do
|
60
|
-
|
60
|
+
Seedbank.stub(:seeds_root, seeds_root) do
|
61
61
|
|
62
|
-
|
62
|
+
subject.must_equal Pathname.new(seeds_root)
|
63
|
+
|
64
|
+
end
|
63
65
|
end
|
64
66
|
|
65
67
|
end
|
@@ -95,53 +97,54 @@ describe Seedbank::DSL do
|
|
95
97
|
|
96
98
|
describe "define_seed_task" do
|
97
99
|
|
98
|
-
let(:
|
100
|
+
let(:task_name) { 'scoped:my_seed' }
|
99
101
|
let(:dependencies) { ['environment'] }
|
100
102
|
let(:seed_file) { File.expand_path('development/users.seeds.rb', Seedbank.seeds_root) }
|
101
103
|
|
102
104
|
it "returns a fully qualified task name" do
|
103
|
-
returned_name = Seedbank::DSL.define_seed_task(seed_file,
|
105
|
+
returned_name = Seedbank::DSL.define_seed_task(seed_file, task_name => dependencies)
|
104
106
|
|
105
|
-
returned_name.must_equal
|
107
|
+
returned_name.must_equal task_name
|
106
108
|
end
|
107
109
|
|
108
110
|
it "creates a Rake Task" do
|
109
|
-
Seedbank::DSL.define_seed_task(seed_file,
|
111
|
+
Seedbank::DSL.define_seed_task(seed_file, task_name => dependencies)
|
110
112
|
|
111
|
-
Rake::Task[
|
113
|
+
Rake::Task[task_name].wont_be_nil
|
112
114
|
end
|
113
115
|
|
114
116
|
it "sets Rake Task description" do
|
115
|
-
Seedbank::DSL.define_seed_task(seed_file,
|
117
|
+
Seedbank::DSL.define_seed_task(seed_file, task_name => dependencies)
|
116
118
|
|
117
|
-
Rake::Task[
|
119
|
+
Rake::Task[task_name].comment.must_equal "Load the seed data from #{seed_file}"
|
118
120
|
end
|
119
121
|
|
120
122
|
it "sets Rake Task action to the seed_file contents" do
|
121
|
-
Seedbank::DSL.define_seed_task(seed_file,
|
123
|
+
Seedbank::DSL.define_seed_task(seed_file, task_name => dependencies)
|
122
124
|
|
123
|
-
|
125
|
+
FakeModel.expect :seed, true, ['development:users']
|
124
126
|
|
125
|
-
Rake::Task[
|
127
|
+
Rake::Task[task_name].invoke
|
126
128
|
end
|
127
129
|
|
128
130
|
describe "when db:abort_if_pending_migrations exists" do
|
129
131
|
it "sets Rake Task dependencies" do
|
130
|
-
Seedbank::DSL.define_seed_task(seed_file,
|
132
|
+
Seedbank::DSL.define_seed_task(seed_file, task_name => dependencies)
|
131
133
|
expected_dependencies = dependencies.map { |dependency| Rake::Task[dependency] }
|
132
134
|
expected_dependencies << Rake::Task['db:abort_if_pending_migrations']
|
133
135
|
|
134
|
-
Rake::Task[
|
136
|
+
Rake::Task[task_name].prerequisite_tasks.must_equal expected_dependencies
|
135
137
|
end
|
136
138
|
end
|
137
139
|
|
138
140
|
describe "when db:abort_if_pending_migrations does not exist" do
|
139
141
|
it "sets Rake Task dependencies" do
|
140
|
-
|
142
|
+
Rake.application.clear
|
143
|
+
Rake::Task.define_task 'environment'
|
141
144
|
|
142
|
-
Seedbank::DSL.define_seed_task(seed_file,
|
145
|
+
Seedbank::DSL.define_seed_task(seed_file, task_name => dependencies)
|
143
146
|
|
144
|
-
Rake::Task[
|
147
|
+
Rake::Task[task_name].prerequisite_tasks.must_equal dependencies.map { |dependency| Rake::Task[dependency] }
|
145
148
|
end
|
146
149
|
end
|
147
150
|
end
|
@@ -150,29 +153,29 @@ describe Seedbank::DSL do
|
|
150
153
|
|
151
154
|
describe "when no task exists to override" do
|
152
155
|
|
153
|
-
let(:
|
156
|
+
let(:task_name) { 'my_task' }
|
154
157
|
let(:dependencies) { ['seedy:users'] }
|
155
158
|
|
156
159
|
it "creates a new task" do
|
157
|
-
Seedbank::DSL.override_seed_task(
|
160
|
+
Seedbank::DSL.override_seed_task(task_name => dependencies)
|
158
161
|
|
159
|
-
Rake::Task[
|
162
|
+
Rake::Task[task_name].wont_be_nil
|
160
163
|
end
|
161
164
|
|
162
165
|
it "applies the dependencies" do
|
163
166
|
expected_dependencies = dependencies.map { |dependency| Rake::Task[dependency] }
|
164
|
-
Seedbank::DSL.override_seed_task(
|
167
|
+
Seedbank::DSL.override_seed_task(task_name => dependencies)
|
165
168
|
|
166
|
-
Rake::Task[
|
169
|
+
Rake::Task[task_name].prerequisite_tasks.must_equal expected_dependencies
|
167
170
|
end
|
168
171
|
|
169
172
|
it "applies the description" do
|
170
173
|
description = 'Expected Description'
|
171
174
|
Rake.application.last_description = description
|
172
175
|
|
173
|
-
Seedbank::DSL.override_seed_task(
|
176
|
+
Seedbank::DSL.override_seed_task(task_name => dependencies)
|
174
177
|
|
175
|
-
Rake::Task[
|
178
|
+
Rake::Task[task_name].full_comment.must_equal description
|
176
179
|
end
|
177
180
|
end
|
178
181
|
|
@@ -2,19 +2,33 @@ require 'test_helper'
|
|
2
2
|
|
3
3
|
describe Seedbank::Runner do
|
4
4
|
|
5
|
-
before do
|
6
|
-
flexmock(FakeModel)
|
7
|
-
end
|
8
|
-
|
9
5
|
describe "seeds with dependency" do
|
10
6
|
|
11
7
|
subject { Rake::Task['db:seed:dependent'] }
|
12
8
|
|
13
9
|
it "runs the dependencies in order" do
|
14
|
-
FakeModel.
|
15
|
-
FakeModel.
|
10
|
+
FakeModel.expect :seed, true, ['dependency']
|
11
|
+
FakeModel.expect :seed, true, ['dependent']
|
16
12
|
|
17
13
|
subject.invoke
|
14
|
+
|
15
|
+
FakeModel.verify
|
16
|
+
end
|
17
|
+
|
18
|
+
it "executes the body of the dependencies exactly once per invocation" do
|
19
|
+
FakeModel.expect :seed, true, ['dependency']
|
20
|
+
FakeModel.expect :seed, true, ['dependent']
|
21
|
+
FakeModel.expect :seed, true, ['dependency']
|
22
|
+
FakeModel.expect :seed, true, ['dependent']
|
23
|
+
|
24
|
+
subject.invoke
|
25
|
+
|
26
|
+
# Allow all tasks to be re-executed, including dependencies
|
27
|
+
Rake.application.tasks.each { |t| t.reenable }
|
28
|
+
|
29
|
+
subject.invoke
|
30
|
+
|
31
|
+
FakeModel.verify
|
18
32
|
end
|
19
33
|
end
|
20
34
|
|
@@ -23,11 +37,13 @@ describe Seedbank::Runner do
|
|
23
37
|
subject { Rake::Task['db:seed:dependent_on_several'] }
|
24
38
|
|
25
39
|
it "runs the dependencies in order" do
|
26
|
-
FakeModel.
|
27
|
-
FakeModel.
|
28
|
-
FakeModel.
|
40
|
+
FakeModel.expect :seed, true, ['dependency']
|
41
|
+
FakeModel.expect :seed, true, ['dependency2']
|
42
|
+
FakeModel.expect :seed, true, ['dependent on several']
|
29
43
|
|
30
44
|
subject.invoke
|
45
|
+
|
46
|
+
FakeModel.verify
|
31
47
|
end
|
32
48
|
end
|
33
49
|
|
@@ -36,12 +52,14 @@ describe Seedbank::Runner do
|
|
36
52
|
subject { Rake::Task['db:seed:dependent_on_nested'] }
|
37
53
|
|
38
54
|
it "runs all dependencies in order" do
|
39
|
-
FakeModel.
|
40
|
-
FakeModel.
|
41
|
-
FakeModel.
|
42
|
-
FakeModel.
|
55
|
+
FakeModel.expect :seed, true, ['dependency']
|
56
|
+
FakeModel.expect :seed, true, ['dependent']
|
57
|
+
FakeModel.expect :seed, true, ['dependency2']
|
58
|
+
FakeModel.expect :seed, true, ['dependent on nested']
|
43
59
|
|
44
60
|
subject.invoke
|
61
|
+
|
62
|
+
FakeModel.verify
|
45
63
|
end
|
46
64
|
|
47
65
|
end
|
@@ -51,16 +69,92 @@ describe Seedbank::Runner do
|
|
51
69
|
subject { Rake::Task['db:seed:no_block'] }
|
52
70
|
|
53
71
|
it "runs the dependencies" do
|
54
|
-
FakeModel.
|
72
|
+
FakeModel.expect :seed, true, ['dependency']
|
55
73
|
|
56
74
|
subject.invoke
|
75
|
+
|
76
|
+
FakeModel.verify
|
57
77
|
end
|
58
78
|
end
|
59
79
|
|
60
80
|
describe "let" do
|
61
81
|
|
62
|
-
|
82
|
+
describe "evaluates dependencies in order" do
|
83
|
+
|
84
|
+
subject { Rake::Task['db:seed:reference_memos'] }
|
85
|
+
|
86
|
+
it "runs the dependencies in order" do
|
87
|
+
FakeModel.expect :seed, true, ['with_inline_memo']
|
88
|
+
FakeModel.expect :seed, true, ['with_block_memo']
|
89
|
+
FakeModel.expect :calling_let, true, ['BLOCK_LET']
|
90
|
+
FakeModel.expect :calling_let, true, ['INLINE_LET']
|
91
|
+
|
92
|
+
def FakeModel.calling_let!(*args); end
|
93
|
+
def FakeModel.calling_method(*args); end
|
94
|
+
|
95
|
+
subject.invoke
|
96
|
+
|
97
|
+
FakeModel.verify
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
describe "a previously defined method" do
|
102
|
+
|
103
|
+
let(:runner) { Seedbank::Runner.new }
|
63
104
|
|
105
|
+
before { runner.let(:existing) {} }
|
106
|
+
|
107
|
+
%w(__eigenclass existing let let evaluate after).each do |name|
|
108
|
+
it 'raises ArgumentError' do
|
109
|
+
assert_raises(ArgumentError, Regexp.new(name)) do
|
110
|
+
runner.let(name)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
end
|
117
|
+
|
118
|
+
describe "let!" do
|
119
|
+
|
120
|
+
describe "evaluates dependencies in order" do
|
121
|
+
|
122
|
+
subject { Rake::Task['db:seed:reference_memos'] }
|
123
|
+
|
124
|
+
it "runs the dependencies in order" do
|
125
|
+
FakeModel.expect :calling_let!, true, ['INLINE_LET!']
|
126
|
+
FakeModel.expect :calling_let!, true, ['BLOCK_LET!']
|
127
|
+
|
128
|
+
def FakeModel.seed(*args); end
|
129
|
+
def FakeModel.calling_let(*args); end
|
130
|
+
def FakeModel.calling_method(*args); end
|
131
|
+
|
132
|
+
subject.invoke
|
133
|
+
|
134
|
+
FakeModel.verify
|
135
|
+
end
|
64
136
|
end
|
137
|
+
|
65
138
|
end
|
139
|
+
|
140
|
+
describe "defining an inline method" do
|
141
|
+
|
142
|
+
describe "evaluates dependencies in order" do
|
143
|
+
|
144
|
+
subject { Rake::Task['db:seed:reference_memos'] }
|
145
|
+
|
146
|
+
it "runs the dependencies in order" do
|
147
|
+
FakeModel.expect :calling_method, true, ['inline_method']
|
148
|
+
|
149
|
+
def FakeModel.seed(*args); end
|
150
|
+
def FakeModel.calling_let(*args); end
|
151
|
+
def FakeModel.calling_let!(*args); end
|
152
|
+
|
153
|
+
subject.invoke
|
154
|
+
|
155
|
+
FakeModel.verify
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
66
160
|
end
|
@@ -9,7 +9,7 @@ describe 'Seedbank rake.task' do
|
|
9
9
|
it "creates all the seed tasks" do
|
10
10
|
seeds = %w(db:seed:circular1 db:seed:circular2 db:seed:common db:seed:dependency db:seed:dependency2
|
11
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)
|
12
|
+
db:seed:development:users db:seed:no_block db:seed:original db:seed:reference_memos db:seed:with_block_memo db:seed:with_inline_memo)
|
13
13
|
|
14
14
|
subject.map(&:to_s).must_equal seeds
|
15
15
|
end
|
@@ -114,12 +114,14 @@ describe 'Seedbank rake.task' do
|
|
114
114
|
describe "when environment seeds are defined" do
|
115
115
|
|
116
116
|
it "is dependent on db:seed:common" do
|
117
|
-
|
117
|
+
Rails.stub(:env, 'development') do
|
118
118
|
|
119
|
-
|
120
|
-
|
119
|
+
Rake.application.clear
|
120
|
+
Dummy::Application.load_tasks
|
121
|
+
|
122
|
+
subject.prerequisites.must_equal %w[db:seed:common db:seed:development]
|
121
123
|
|
122
|
-
|
124
|
+
end
|
123
125
|
end
|
124
126
|
end
|
125
127
|
end
|
data/test/test_helper.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
require 'rubygems'
|
2
|
-
require
|
3
|
-
require 'minitest/spec'
|
2
|
+
require 'minitest/autorun'
|
4
3
|
|
5
4
|
# Configure Rails Environment
|
6
5
|
environment = ENV["RAILS_ENV"] = 'test'
|
@@ -14,15 +13,15 @@ Seedbank.seeds_root = File.expand_path('dummy/db/seeds', __FILE__)
|
|
14
13
|
|
15
14
|
class Seedbank::Spec < MiniTest::Spec
|
16
15
|
|
17
|
-
include FlexMock::TestCase
|
18
|
-
|
19
16
|
def setup
|
20
17
|
Rake.application = Rake::Application.new
|
21
18
|
Dummy::Application.load_tasks
|
19
|
+
Object.const_set :FakeModel, MiniTest::Mock.new
|
20
|
+
TOPLEVEL_BINDING.eval('self').send(:instance_variable_set, :@_seedbank_runner, Seedbank::Runner.new)
|
22
21
|
super
|
23
22
|
end
|
24
23
|
|
25
24
|
end
|
26
25
|
|
27
26
|
MiniTest::Spec.register_spec_type(/^Seedbank/i, Seedbank::Spec)
|
28
|
-
MiniTest
|
27
|
+
MiniTest.autorun
|
metadata
CHANGED
@@ -1,58 +1,44 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: seedbank
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0.pre
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James McCarthy
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-11-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ~>
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '5.0'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - ~>
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: flexmock
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - ! '>='
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
34
|
-
type: :development
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - ! '>='
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
26
|
+
version: '5.0'
|
41
27
|
- !ruby/object:Gem::Dependency
|
42
28
|
name: rails
|
43
29
|
requirement: !ruby/object:Gem::Requirement
|
44
30
|
requirements:
|
45
|
-
- - ~>
|
31
|
+
- - "~>"
|
46
32
|
- !ruby/object:Gem::Version
|
47
|
-
version: 3.2
|
33
|
+
version: '3.2'
|
48
34
|
type: :development
|
49
35
|
prerelease: false
|
50
36
|
version_requirements: !ruby/object:Gem::Requirement
|
51
37
|
requirements:
|
52
|
-
- - ~>
|
38
|
+
- - "~>"
|
53
39
|
- !ruby/object:Gem::Version
|
54
|
-
version: 3.2
|
55
|
-
description:
|
40
|
+
version: '3.2'
|
41
|
+
description: "\n Extends Rails seeds to split out complex seeds into multiple\n
|
56
42
|
\ files and lets each environment have it's own seeds.\n "
|
57
43
|
email: james2mccarthy@gmail.com
|
58
44
|
executables: []
|
@@ -61,8 +47,8 @@ extra_rdoc_files:
|
|
61
47
|
- MIT-LICENSE
|
62
48
|
- README.md
|
63
49
|
files:
|
64
|
-
- .gitignore
|
65
|
-
- .travis.yml
|
50
|
+
- ".gitignore"
|
51
|
+
- ".travis.yml"
|
66
52
|
- Gemfile
|
67
53
|
- MIT-LICENSE
|
68
54
|
- README.md
|
@@ -79,7 +65,6 @@ files:
|
|
79
65
|
- seedbank.gemspec
|
80
66
|
- test/dummy/Rakefile
|
81
67
|
- test/dummy/app/controllers/application_controller.rb
|
82
|
-
- test/dummy/app/models/fake_model.rb
|
83
68
|
- test/dummy/config.ru
|
84
69
|
- test/dummy/config/application.rb
|
85
70
|
- test/dummy/config/boot.rb
|
@@ -103,6 +88,9 @@ files:
|
|
103
88
|
- test/dummy/db/seeds/development/shared/accounts.seeds.rb
|
104
89
|
- test/dummy/db/seeds/development/users.seeds.rb
|
105
90
|
- test/dummy/db/seeds/no_block.seeds.rb
|
91
|
+
- test/dummy/db/seeds/reference_memos.seeds.rb
|
92
|
+
- test/dummy/db/seeds/with_block_memo.seeds.rb
|
93
|
+
- test/dummy/db/seeds/with_inline_memo.seeds.rb
|
106
94
|
- test/dummy/lib/tasks/dsl.rake
|
107
95
|
- test/dummy/script/rails
|
108
96
|
- test/lib/seedbank/dsl_test.rb
|
@@ -113,29 +101,29 @@ homepage: http://github.com/james2m/seedbank
|
|
113
101
|
licenses:
|
114
102
|
- MIT
|
115
103
|
metadata: {}
|
116
|
-
post_install_message:
|
104
|
+
post_install_message: "\n ================================================================================\n\n
|
117
105
|
\ Rails 2.x\n ---------\n If you are using Seedbank with Rails 2.x you will need
|
118
|
-
to place the following at
|
119
|
-
|
120
|
-
\ Rails 3.x\n ---------\n Your work here is done!\n\n ================================================================================\n
|
106
|
+
to place the following at\n the end of your Rakefile so Rubygems can load the seedbank
|
107
|
+
tasks;\n\n require 'seedbank'\n Seedbank.load_tasks if defined?(Seedbank)\n\n
|
108
|
+
\ Rails 3.x and 4.x\n ---------\n Your work here is done!\n\n ================================================================================\n
|
121
109
|
\ "
|
122
110
|
rdoc_options:
|
123
|
-
- --charset=UTF-8
|
111
|
+
- "--charset=UTF-8"
|
124
112
|
require_paths:
|
125
113
|
- lib
|
126
114
|
required_ruby_version: !ruby/object:Gem::Requirement
|
127
115
|
requirements:
|
128
|
-
- -
|
116
|
+
- - ">="
|
129
117
|
- !ruby/object:Gem::Version
|
130
118
|
version: '0'
|
131
119
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
132
120
|
requirements:
|
133
|
-
- -
|
121
|
+
- - ">="
|
134
122
|
- !ruby/object:Gem::Version
|
135
123
|
version: 1.2.0
|
136
124
|
requirements: []
|
137
125
|
rubyforge_project:
|
138
|
-
rubygems_version: 2.
|
126
|
+
rubygems_version: 2.2.2
|
139
127
|
signing_key:
|
140
128
|
specification_version: 4
|
141
129
|
summary: Extends Rails seeds to split out complex seeds into their own file and have
|
@@ -143,7 +131,6 @@ summary: Extends Rails seeds to split out complex seeds into their own file and
|
|
143
131
|
test_files:
|
144
132
|
- test/dummy/Rakefile
|
145
133
|
- test/dummy/app/controllers/application_controller.rb
|
146
|
-
- test/dummy/app/models/fake_model.rb
|
147
134
|
- test/dummy/config.ru
|
148
135
|
- test/dummy/config/application.rb
|
149
136
|
- test/dummy/config/boot.rb
|
@@ -167,6 +154,9 @@ test_files:
|
|
167
154
|
- test/dummy/db/seeds/development/shared/accounts.seeds.rb
|
168
155
|
- test/dummy/db/seeds/development/users.seeds.rb
|
169
156
|
- test/dummy/db/seeds/no_block.seeds.rb
|
157
|
+
- test/dummy/db/seeds/reference_memos.seeds.rb
|
158
|
+
- test/dummy/db/seeds/with_block_memo.seeds.rb
|
159
|
+
- test/dummy/db/seeds/with_inline_memo.seeds.rb
|
170
160
|
- test/dummy/lib/tasks/dsl.rake
|
171
161
|
- test/dummy/script/rails
|
172
162
|
- test/lib/seedbank/dsl_test.rb
|