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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4ecee50238e268d48a12368a6120f6e5aacdce21672621a19b6bbdf82215585e
4
- data.tar.gz: '059a0424d354435ef544dc6627541d9ac64de3b25aad0191050a378dbdb81b27'
3
+ metadata.gz: d9c742827b3295c564267030107d2f26638923eedd268ee11b55dbbf845e245c
4
+ data.tar.gz: 0ee2ad8cdb1f2ccfcd1a5a912981d93bb7f2e742d9a33f78d358e5de2ff2c02a
5
5
  SHA512:
6
- metadata.gz: 6d79169514a3b938ad45c8e57e68bb14f6de8e69cae56ac49cbc495fb64b314ea601d2798aebb42233b5b6f36d51d3b6666f9e7cec5746d69eb3a6d140089469
7
- data.tar.gz: e9eb0af111a273efd24f7b883de27ff055ef8c19124475c4492fc7da553aa417135c06fab0506189afa48d327f6e6448b8fbbb00d166ae095479c88dee81d52c
6
+ metadata.gz: bbe89a5cc1a60c7eaf07399e07d12c18e5ea4caca20aceebd25f5e09967bd92ad23bfa75d2ae5582d7a6bb8a5fbf1581c7517556d9d603bbea4ab3983bfac175
7
+ data.tar.gz: 32f13630724be1890a49d30d005ff673363dc61971b41e609986034890848e72c5eaa55385f1e9e25e7d97decd09aae7ac0813a37bad84989470f5d206798890
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ # 1.1.0
2
+
3
+ - Fix `seeds_path` to be relative to Rails root
4
+ - Improve test coverage for generator
5
+
1
6
  # 1.0.1
2
7
 
3
8
  - Fix boolean config options to properly handle `nil` and `false` values
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- seed_builder (1.0.1)
4
+ seed_builder (1.1.0)
5
5
  activerecord (>= 6, < 8.1)
6
6
  rails (>= 6, < 8.1)
7
7
 
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.seeds_relative_path = "db/seeds"
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.seeds_relative_path %>/<%= migration_number %>_<%= migration_file_name %>.rb
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
 
@@ -7,16 +7,16 @@ module SeedBuilder
7
7
 
8
8
  attr_writer :seeds_path
9
9
  def seeds_path
10
- @seeds_path ||= Rails.root.join(seeds_relative_path)
10
+ @seeds_path ||= "db/seeds"
11
11
  end
12
12
 
13
- def seeds_path_glob
14
- "#{seeds_path}/*.rb"
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
- attr_writer :seeds_relative_path
18
- def seeds_relative_path
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
@@ -2,7 +2,7 @@ require "seed_builder/config"
2
2
  require "seed_builder/loader"
3
3
 
4
4
  module SeedBuilder
5
- VERSION = "1.0.1".freeze
5
+ VERSION = "1.1.0".freeze
6
6
 
7
7
  module_function
8
8
 
@@ -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(:params) { ["create_users"] }
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
- seed_files = Dir[rails_root.join("db/seeds/*_create_users.rb")]
26
- expect(seed_files).not_to be_empty
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.seeds_relative_path).to eq "db/seeds"
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 seeds_path" do
27
- expect(config.seeds_path).to eq Rails.root.join("db/seeds")
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: seed_builder
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrei Makarov