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.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -1
  3. data/.hound.yml +3 -0
  4. data/.rubocop.yml +7 -0
  5. data/.rubocop_todo.yml +29 -0
  6. data/.travis.yml +7 -9
  7. data/Gemfile +5 -4
  8. data/README.md +49 -25
  9. data/Rakefile +2 -1
  10. data/TODO.txt +3 -3
  11. data/gemfiles/rake10.gemfile +0 -2
  12. data/gemfiles/{rake0.9.gemfile → rake11.gemfile} +2 -3
  13. data/lib/seedbank.rb +15 -6
  14. data/lib/seedbank/dsl.rb +65 -43
  15. data/lib/seedbank/railtie.rb +2 -7
  16. data/lib/seedbank/runner.rb +19 -32
  17. data/lib/seedbank/version.rb +2 -1
  18. data/lib/tasks/seed.rake +16 -20
  19. data/seedbank.gemspec +32 -53
  20. data/test/dummy/Rakefile +1 -0
  21. data/test/dummy/app/controllers/application_controller.rb +1 -0
  22. data/test/dummy/config.ru +2 -1
  23. data/test/dummy/config/application.rb +2 -22
  24. data/test/dummy/config/boot.rb +2 -1
  25. data/test/dummy/config/environment.rb +1 -0
  26. data/test/dummy/config/environments/development.rb +3 -7
  27. data/test/dummy/config/environments/test.rb +4 -9
  28. data/test/dummy/config/initializers/secret_token.rb +1 -0
  29. data/test/dummy/config/initializers/session_store.rb +2 -1
  30. data/test/dummy/config/initializers/wrap_parameters.rb +2 -1
  31. data/test/dummy/config/routes.rb +1 -0
  32. data/test/dummy/db/seeds.rb +1 -0
  33. data/test/dummy/db/seeds/circular1.seeds.rb +2 -1
  34. data/test/dummy/db/seeds/circular2.seeds.rb +2 -1
  35. data/test/dummy/db/seeds/dependency.seeds.rb +1 -0
  36. data/test/dummy/db/seeds/dependency2.seeds.rb +1 -0
  37. data/test/dummy/db/seeds/dependent.seeds.rb +2 -1
  38. data/test/dummy/db/seeds/dependent_on_nested.seeds.rb +2 -1
  39. data/test/dummy/db/seeds/dependent_on_several.seeds.rb +2 -1
  40. data/test/dummy/db/seeds/development/users.seeds.rb +1 -0
  41. data/test/dummy/db/seeds/no_block.seeds.rb +2 -1
  42. data/test/dummy/db/seeds/reference_memos.seeds.rb +2 -1
  43. data/test/dummy/db/seeds/with_block_memo.seeds.rb +2 -1
  44. data/test/dummy/db/seeds/with_inline_memo.seeds.rb +1 -0
  45. data/test/dummy/script/rails +3 -2
  46. data/test/lib/seedbank/dsl_test.rb +56 -73
  47. data/test/lib/seedbank/runner_test.rb +39 -46
  48. data/test/lib/tasks/seed_rake_test.rb +88 -51
  49. data/test/test_helper.rb +13 -11
  50. metadata +76 -23
  51. data/test/dummy/lib/tasks/dsl.rake +0 -4
@@ -1,96 +1,138 @@
1
+ # frozen_string_literal: true
1
2
  require 'test_helper'
3
+ using Seedbank::DSL
2
4
 
3
5
  describe 'Seedbank rake.task' do
6
+ def self.dummy_seeds_root
7
+ Pathname.new('../../../dummy/db/seeds').expand_path(__FILE__)
8
+ end
9
+
10
+ def self.glob_dummy_seeds
11
+ Pathname.glob(dummy_seeds_root.join(Seedbank.matcher), Seedbank.nesting)
12
+ end
4
13
 
5
- describe "seeds with dependency" do
14
+ it 'does not pollute the global namespace' do
15
+ Object.new.wont_respond_to :seeds_root
16
+ end
6
17
 
7
- subject { Rake.application.tasks_in_scope(defined?(Rake::Scope) ? Rake::Scope.new('db:seed') : %w[db seed]) }
18
+ describe 'seeds with dependency' do
19
+ subject { Rake.application.tasks_in_scope(defined?(Rake::Scope) ? Rake::Scope.new('db:seed') : %w(db seed)) }
8
20
 
9
- it "creates all the seed tasks" do
21
+ it 'creates all the seed tasks' do
10
22
  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 db:seed:reference_memos db:seed:with_block_memo db:seed:with_inline_memo)
23
+ db:seed:dependent db:seed:dependent_on_nested db:seed:dependent_on_several db:seed:development
24
+ 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
25
 
14
26
  subject.map(&:to_s).must_equal seeds
15
27
  end
16
28
  end
17
29
 
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|
30
+ describe 'common seeds in the root directory' do
31
+ glob_dummy_seeds.each do |seed_file|
21
32
  seed = File.basename(seed_file, '.seeds.rb')
22
33
 
23
34
  describe seed do
24
-
25
35
  subject { Rake.application.lookup(['db', 'seed', seed].join(':')) }
26
36
 
27
- it "is dependent on db:abort_if_pending_migrations" do
28
- subject.prerequisites.must_equal %w[db:abort_if_pending_migrations]
37
+ it 'is dependent on db:abort_if_pending_migrations' do
38
+ subject.prerequisites.must_equal %w(db:abort_if_pending_migrations)
29
39
  end
30
40
  end
31
41
  end
32
42
  end
33
43
 
34
- describe "db:seed:common" do
35
-
44
+ describe 'db:seed:common' do
36
45
  subject { Rake::Task['db:seed:common'] }
37
46
 
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__)].sort.map do |seed_file|
40
- ['db', 'seed', File.basename(seed_file, '.seeds.rb')].join(':')
41
- end.unshift('db:seed:original')
47
+ describe 'when db/seeds.rb exists' do
48
+ it 'is dependent on the common seeds and db:seed:original' do
49
+ prerequisite_seeds = self.class.glob_dummy_seeds.sort.map do |seed_file|
50
+ ['db', 'seed', File.basename(seed_file, '.seeds.rb')].join(':')
51
+ end.unshift('db:seed:original')
52
+
53
+ subject.prerequisites.must_equal prerequisite_seeds
54
+ end
55
+ end
56
+
57
+ describe 'when db/seeds.rb does not exist' do
58
+ def setup
59
+ main = TOPLEVEL_BINDING.eval('class << self; self; end')
60
+ orig = original_seeds_file
61
+ main.send(:undef_method, :original_seeds_file) if main.respond_to?(:original_seeds_file, true)
62
+ main.send(:define_method, :original_seeds_file) { nil }
63
+ super
64
+ main.send(:undef_method, :original_seeds_file)
65
+ main.send(:define_method, :original_seeds_file) { orig }
66
+ end
42
67
 
43
- subject.prerequisites.must_equal prerequisite_seeds
68
+ it 'is dependent on only the common seeds' do
69
+ prerequisite_seeds = self.class.glob_dummy_seeds.sort.map do |seed_file|
70
+ ['db', 'seed', File.basename(seed_file, '.seeds.rb')].join(':')
71
+ end
72
+
73
+ subject.prerequisites.must_equal prerequisite_seeds
74
+ end
44
75
  end
45
76
  end
46
77
 
47
- describe "db:seed:original" do
48
-
78
+ describe 'db:seed:original' do
49
79
  subject { Rake::Task['db:seed:original'] }
50
80
 
51
- it "has no dependencies" do
52
- subject.prerequisites.must_equal %w[db:abort_if_pending_migrations]
81
+ it 'is only dependent on db:abort_if_pending_migrations' do
82
+ subject.prerequisites.must_equal %w(db:abort_if_pending_migrations)
53
83
  end
54
84
 
55
- describe "when seeds are reloaded" do
85
+ it 'runs within Seedbank::Runner' do
86
+ FakeModel.expect :seed, true, ['db/seeds.rb']
56
87
 
88
+ subject.invoke
89
+
90
+ FakeModel.verify
91
+ end
92
+
93
+ describe 'when seeds are reloaded' do
57
94
  before do
58
- Dummy::Application.load_tasks
95
+ silence_warnings { Dummy::Application.load_tasks }
96
+ end
97
+
98
+ it 'is still only dependent on db:abort_if_pending_migrations' do
99
+ subject.prerequisites.must_equal %w(db:abort_if_pending_migrations)
59
100
  end
60
101
 
61
- it "still has no dependencies" do
62
- subject.prerequisites.must_equal %w[db:abort_if_pending_migrations]
102
+ it 'still runs within Seedbank::Runner' do
103
+ skip 'TODO: Appears that it gets invoked twice after reloading.'
104
+ FakeModel.expect :seed, true, ['db/seeds.rb']
105
+
106
+ subject.invoke
107
+
108
+ FakeModel.verify
63
109
  end
64
110
  end
65
111
  end
66
112
 
67
- describe "environment seeds" do
68
-
69
- Dir[File.expand_path('../../../dummy/db/seeds', __FILE__) + '/*/'].each do |environment_directory|
113
+ describe 'environment seeds ' do
114
+ dummy_seeds_root.each_child.select(&:directory?).each do |environment_directory|
70
115
  environment = File.basename(environment_directory)
71
116
 
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|
117
+ describe "in the #{environment} environment " do
118
+ Pathname.glob(environment_directory.join(Seedbank.matcher), Seedbank.nesting).each do |seed_file|
75
119
  seed = File.basename(seed_file, '.seeds.rb')
76
120
 
77
121
  describe seed do
78
-
79
122
  subject { Rake.application.lookup(['db', 'seed', environment, seed].join(':')) }
80
123
 
81
- it "is dependent on db:abort_if_pending_migrations" do
82
- subject.prerequisites.must_equal %w[db:abort_if_pending_migrations]
124
+ it 'is dependent on db:abort_if_pending_migrations' do
125
+ subject.prerequisites.must_equal %w(db:abort_if_pending_migrations) if subject
83
126
  end
84
127
  end
85
128
  end
86
129
  end
87
130
 
88
131
  describe "db:seed:#{environment}" do
89
-
90
132
  subject { Rake.application.lookup(['db', 'seed', environment].join(':')) }
91
133
 
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__)].sort.map do |seed_file|
134
+ it 'is dependent on the seeds in the environment directory' do
135
+ prerequisite_seeds = Pathname.glob(environment_directory.join(Seedbank.matcher), Seedbank.nesting).sort.map do |seed_file|
94
136
  ['db', 'seed', environment, File.basename(seed_file, '.seeds.rb')].join(':')
95
137
  end.unshift('db:seed:common')
96
138
 
@@ -100,27 +142,22 @@ describe 'Seedbank rake.task' do
100
142
  end
101
143
  end
102
144
 
103
- describe "db:seed task" do
104
-
145
+ describe 'db:seed task' do
105
146
  subject { Rake::Task['db:seed'] }
106
147
 
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]
148
+ describe 'when no environment seeds are defined' do
149
+ it 'is dependent on db:seed:common' do
150
+ subject.prerequisites.must_equal %w(db:abort_if_pending_migrations db:seed:common)
111
151
  end
112
152
  end
113
153
 
114
- describe "when environment seeds are defined" do
115
-
116
- it "is dependent on db:seed:common" do
154
+ describe 'when environment seeds are defined' do
155
+ it 'is dependent on db:seed:common' do
117
156
  Rails.stub(:env, 'development') do
118
-
119
157
  Rake.application.clear
120
- Dummy::Application.load_tasks
121
-
122
- subject.prerequisites.must_equal %w[db:seed:common db:seed:development]
158
+ silence_warnings { Dummy::Application.load_tasks }
123
159
 
160
+ subject.prerequisites.must_equal %w(db:abort_if_pending_migrations db:seed:common db:seed:development)
124
161
  end
125
162
  end
126
163
  end
@@ -1,26 +1,28 @@
1
- require 'rubygems'
1
+ # frozen_string_literal: true
2
+ require 'rake'
2
3
  require 'minitest/autorun'
4
+ require 'active_record/railtie'
3
5
 
4
6
  # Configure Rails Environment
5
- environment = ENV["RAILS_ENV"] = 'test'
6
- rails_root = File.expand_path('../dummy', __FILE__)
7
+ ENV['RAILS_ENV'] = 'test'
7
8
 
8
- require File.expand_path('config/environment.rb', rails_root)
9
+ require 'dummy/config/application'
9
10
 
10
11
  Rails.backtrace_cleaner.remove_silencers!
11
12
 
12
- Seedbank.seeds_root = File.expand_path('dummy/db/seeds', __FILE__)
13
+ Seedbank.application_root = Pathname.new(File.expand_path('../dummy', __FILE__))
13
14
 
14
15
  class Seedbank::Spec < MiniTest::Spec
15
-
16
16
  def setup
17
- Rake.application = Rake::Application.new
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)
17
+ silence_warnings do
18
+ Rake.application = Rake::Application.new
19
+ Dummy::Application.load_tasks
20
+ Object.const_set :FakeModel, MiniTest::Mock.new
21
+ TOPLEVEL_BINDING.eval('self').send(:instance_variable_set, :@_seedbank_runner, Seedbank::Runner.new)
22
+ end
23
+
21
24
  super
22
25
  end
23
-
24
26
  end
25
27
 
26
28
  MiniTest::Spec.register_spec_type(/^Seedbank/i, Seedbank::Spec)
metadata CHANGED
@@ -1,15 +1,57 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: seedbank
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.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: 2016-08-10 00:00:00.000000000 Z
11
+ date: 2017-02-12 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '10.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '10.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.11'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.11'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rails
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '4.2'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '4.2'
13
55
  - !ruby/object:Gem::Dependency
14
56
  name: minitest
15
57
  requirement: !ruby/object:Gem::Requirement
@@ -25,22 +67,38 @@ dependencies:
25
67
  - !ruby/object:Gem::Version
26
68
  version: '5.0'
27
69
  - !ruby/object:Gem::Dependency
28
- name: rails
70
+ name: m
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.5'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.5'
83
+ - !ruby/object:Gem::Dependency
84
+ name: byebug
29
85
  requirement: !ruby/object:Gem::Requirement
30
86
  requirements:
31
87
  - - "~>"
32
88
  - !ruby/object:Gem::Version
33
- version: '3.2'
89
+ version: '9.0'
34
90
  type: :development
35
91
  prerelease: false
36
92
  version_requirements: !ruby/object:Gem::Requirement
37
93
  requirements:
38
94
  - - "~>"
39
95
  - !ruby/object:Gem::Version
40
- version: '3.2'
41
- description: "\n Extends Rails seeds to split out complex seeds into multiple\n
42
- \ files and lets each environment have it's own seeds.\n "
43
- email: james2mccarthy@gmail.com
96
+ version: '9.0'
97
+ description: "\n Adds simple rake commands for seeding your database. Simple dependencies
98
+ let you organise your seeds.\n If you are using Rails, Seedbank extends Rails
99
+ seeds and lets you add seeds for each environment.\n "
100
+ email:
101
+ - "[james2mccarthy@gmail.com"
44
102
  executables: []
45
103
  extensions: []
46
104
  extra_rdoc_files:
@@ -48,14 +106,17 @@ extra_rdoc_files:
48
106
  - README.md
49
107
  files:
50
108
  - ".gitignore"
109
+ - ".hound.yml"
110
+ - ".rubocop.yml"
111
+ - ".rubocop_todo.yml"
51
112
  - ".travis.yml"
52
113
  - Gemfile
53
114
  - MIT-LICENSE
54
115
  - README.md
55
116
  - Rakefile
56
117
  - TODO.txt
57
- - gemfiles/rake0.9.gemfile
58
118
  - gemfiles/rake10.gemfile
119
+ - gemfiles/rake11.gemfile
59
120
  - lib/seedbank.rb
60
121
  - lib/seedbank/dsl.rb
61
122
  - lib/seedbank/railtie.rb
@@ -91,7 +152,6 @@ files:
91
152
  - test/dummy/db/seeds/reference_memos.seeds.rb
92
153
  - test/dummy/db/seeds/with_block_memo.seeds.rb
93
154
  - test/dummy/db/seeds/with_inline_memo.seeds.rb
94
- - test/dummy/lib/tasks/dsl.rake
95
155
  - test/dummy/script/rails
96
156
  - test/lib/seedbank/dsl_test.rb
97
157
  - test/lib/seedbank/runner_test.rb
@@ -101,12 +161,7 @@ homepage: http://github.com/james2m/seedbank
101
161
  licenses:
102
162
  - MIT
103
163
  metadata: {}
104
- post_install_message: "\n ================================================================================\n\n
105
- \ Rails 2.x\n ---------\n If you are using Seedbank with Rails 2.x you will need
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
109
- \ "
164
+ post_install_message:
110
165
  rdoc_options:
111
166
  - "--charset=UTF-8"
112
167
  require_paths:
@@ -115,19 +170,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
115
170
  requirements:
116
171
  - - ">="
117
172
  - !ruby/object:Gem::Version
118
- version: '0'
173
+ version: '2.1'
119
174
  required_rubygems_version: !ruby/object:Gem::Requirement
120
175
  requirements:
121
- - - ">="
176
+ - - ">"
122
177
  - !ruby/object:Gem::Version
123
- version: 1.2.0
178
+ version: 1.3.1
124
179
  requirements: []
125
180
  rubyforge_project:
126
- rubygems_version: 2.5.1
181
+ rubygems_version: 2.6.9
127
182
  signing_key:
128
183
  specification_version: 4
129
- summary: Extends Rails seeds to split out complex seeds into their own file and have
130
- different seeds for each environment.
184
+ summary: Generate seeds data for your Ruby application.
131
185
  test_files:
132
186
  - test/dummy/Rakefile
133
187
  - test/dummy/app/controllers/application_controller.rb
@@ -157,7 +211,6 @@ test_files:
157
211
  - test/dummy/db/seeds/reference_memos.seeds.rb
158
212
  - test/dummy/db/seeds/with_block_memo.seeds.rb
159
213
  - test/dummy/db/seeds/with_inline_memo.seeds.rb
160
- - test/dummy/lib/tasks/dsl.rake
161
214
  - test/dummy/script/rails
162
215
  - test/lib/seedbank/dsl_test.rb
163
216
  - test/lib/seedbank/runner_test.rb
@@ -1,4 +0,0 @@
1
- namespace :seedy do
2
- include Seedbank::DSL
3
- task :users
4
- end