seed_builder 1.0.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/Gemfile.lock +1 -1
- data/README.md +1 -1
- data/lib/generators/templates/seed.rb.tt +1 -1
- data/lib/seed_builder/config.rb +6 -6
- data/lib/seed_builder.rb +1 -1
- data/spec/generator_spec.rb +25 -3
- data/spec/seed_builder/config_spec.rb +3 -3
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d9c742827b3295c564267030107d2f26638923eedd268ee11b55dbbf845e245c
|
4
|
+
data.tar.gz: 0ee2ad8cdb1f2ccfcd1a5a912981d93bb7f2e742d9a33f78d358e5de2ff2c02a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bbe89a5cc1a60c7eaf07399e07d12c18e5ea4caca20aceebd25f5e09967bd92ad23bfa75d2ae5582d7a6bb8a5fbf1581c7517556d9d603bbea4ab3983bfac175
|
7
|
+
data.tar.gz: 32f13630724be1890a49d30d005ff673363dc61971b41e609986034890848e72c5eaa55385f1e9e25e7d97decd09aae7ac0813a37bad84989470f5d206798890
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -57,7 +57,7 @@ SeedBuilder.config.load_default_seeds = false
|
|
57
57
|
Absolute path will be resolved by using `Rails.root`.
|
58
58
|
|
59
59
|
```ruby
|
60
|
-
SeedBuilder.config.
|
60
|
+
SeedBuilder.config.seeds_path = "db/seeds"
|
61
61
|
```
|
62
62
|
|
63
63
|
### Turn off test script generation
|
@@ -6,7 +6,7 @@ end
|
|
6
6
|
<%- if SeedBuilder.config.generate_spec? %>
|
7
7
|
|
8
8
|
# TESTING:
|
9
|
-
# - bin/rspec <%= SeedBuilder.config.
|
9
|
+
# - bin/rspec <%= SeedBuilder.config.seeds_path %>/<%= migration_number %>_<%= migration_file_name %>.rb
|
10
10
|
if Rails.env.test? && Object.const_defined?(:RSpec)
|
11
11
|
require "rails_helper"
|
12
12
|
|
data/lib/seed_builder/config.rb
CHANGED
@@ -7,16 +7,16 @@ module SeedBuilder
|
|
7
7
|
|
8
8
|
attr_writer :seeds_path
|
9
9
|
def seeds_path
|
10
|
-
@seeds_path ||=
|
10
|
+
@seeds_path ||= "db/seeds"
|
11
11
|
end
|
12
12
|
|
13
|
-
|
14
|
-
|
13
|
+
attr_writer :seeds_full_path
|
14
|
+
def seeds_full_path
|
15
|
+
@seeds_full_path ||= Rails.root.join(seeds_path)
|
15
16
|
end
|
16
17
|
|
17
|
-
|
18
|
-
|
19
|
-
@seeds_relative_path ||= "db/seeds"
|
18
|
+
def seeds_path_glob
|
19
|
+
"#{seeds_full_path}/*.rb"
|
20
20
|
end
|
21
21
|
|
22
22
|
attr_writer :load_default_seeds
|
data/lib/seed_builder.rb
CHANGED
data/spec/generator_spec.rb
CHANGED
@@ -7,12 +7,18 @@ describe SeedGenerator, type: :generator do
|
|
7
7
|
|
8
8
|
subject(:generator) { described_class.start params }
|
9
9
|
let(:destination_root) { File.expand_path("../../tmp/rspec", __FILE__) }
|
10
|
+
let(:seeds_path) { rails_root.join("db/seeds") }
|
10
11
|
|
11
|
-
let(:
|
12
|
+
let(:seed_name) { "create_users" }
|
13
|
+
let(:params) { [seed_name] }
|
14
|
+
|
15
|
+
let(:created_files) { Dir["#{seeds_path}/*_#{seed_name}.rb"] }
|
16
|
+
let(:file_contents) { File.readlines(created_files.first).map(&:strip).reject(&:blank?) }
|
12
17
|
|
13
18
|
before do
|
14
19
|
mkdir_p destination_root
|
15
20
|
|
21
|
+
allow(SeedBuilder.config).to receive(:seeds_path).and_return(seeds_path)
|
16
22
|
allow(Rails).to receive(:root).and_return(rails_root(destination_root))
|
17
23
|
end
|
18
24
|
|
@@ -22,7 +28,23 @@ describe SeedGenerator, type: :generator do
|
|
22
28
|
|
23
29
|
it "creates a migration file" do
|
24
30
|
generator
|
25
|
-
|
26
|
-
expect(
|
31
|
+
|
32
|
+
expect(created_files).not_to be_empty
|
33
|
+
expect(file_contents).to include("class CreateUsers")
|
34
|
+
expect(file_contents).not_to include("RSpec.describe CreateUsers")
|
35
|
+
end
|
36
|
+
|
37
|
+
context "when generate_spec is false" do
|
38
|
+
before do
|
39
|
+
allow(SeedBuilder.config).to receive(:generate_spec?).and_return(false)
|
40
|
+
end
|
41
|
+
|
42
|
+
it "does not create a spec file" do
|
43
|
+
generator
|
44
|
+
|
45
|
+
expect(created_files).not_to be_empty
|
46
|
+
expect(file_contents).to include("class CreateUsers")
|
47
|
+
expect(file_contents).not_to include("RSpec.describe CreateUsers")
|
48
|
+
end
|
27
49
|
end
|
28
50
|
end
|
@@ -8,7 +8,7 @@ describe SeedBuilder::Config do
|
|
8
8
|
end
|
9
9
|
|
10
10
|
it "has default seeds path" do
|
11
|
-
expect(config.
|
11
|
+
expect(config.seeds_path).to eq "db/seeds"
|
12
12
|
end
|
13
13
|
|
14
14
|
it "has default load_seeds" do
|
@@ -23,8 +23,8 @@ describe SeedBuilder::Config do
|
|
23
23
|
expect(config.generate_spec?).to be true
|
24
24
|
end
|
25
25
|
|
26
|
-
it "has default
|
27
|
-
expect(config.
|
26
|
+
it "has default seeds_full_path" do
|
27
|
+
expect(config.seeds_full_path).to eq Rails.root.join("db/seeds")
|
28
28
|
end
|
29
29
|
|
30
30
|
it "has default seeds_path_glob" do
|