seed_builder 1.2.1 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/_trunk_check.yml +1 -1
- data/.github/workflows/test.yml +77 -21
- data/.gitignore +1 -0
- data/.standard.yml +22 -0
- data/Appraisals +15 -0
- data/CHANGELOG.md +12 -0
- data/Gemfile.lock +58 -3
- data/README.md +82 -2
- data/bin/appraisals +99 -0
- data/bin/seed +36 -0
- data/lib/seed_builder/config.rb +6 -4
- data/lib/seed_builder/loader.rb +134 -26
- data/lib/seed_builder/railtie.rb +15 -0
- data/lib/seed_builder.rb +22 -1
- data/lib/tasks/seed.rake +22 -0
- data/seed_builder.gemspec +7 -4
- data/sig/seed_builder/config.rbs +22 -0
- data/sig/seed_builder/loader.rbs +8 -0
- data/sig/seed_builder/railtie.rbs +5 -0
- data/sig/seed_builder.rbs +7 -0
- data/spec/seed_builder/config_spec.rb +15 -0
- data/spec/seed_builder/loader_spec.rb +281 -17
- data/spec/seed_builder/railtie_spec.rb +118 -0
- data/spec/spec_helper.rb +3 -0
- metadata +68 -12
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
require "spec_helper"
|
|
2
|
+
|
|
3
|
+
# Define Rails::Railtie stub for testing
|
|
4
|
+
unless defined?(Rails::Railtie)
|
|
5
|
+
module Rails
|
|
6
|
+
class Railtie
|
|
7
|
+
def self.config
|
|
8
|
+
@config ||= Class.new do
|
|
9
|
+
def to_prepare(&block)
|
|
10
|
+
@to_prepare_blocks ||= []
|
|
11
|
+
if block_given?
|
|
12
|
+
@to_prepare_blocks << block
|
|
13
|
+
end
|
|
14
|
+
self
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def call_to_prepare
|
|
18
|
+
(@to_prepare_blocks || []).each(&:call)
|
|
19
|
+
end
|
|
20
|
+
end.new
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# Load the Railtie manually since it's conditionally required
|
|
27
|
+
require_relative "../../lib/seed_builder/railtie"
|
|
28
|
+
|
|
29
|
+
class SeedBuilderUser < ActiveRecord::Base; end
|
|
30
|
+
class SeedUser < SeedBuilderUser; end
|
|
31
|
+
|
|
32
|
+
describe SeedBuilder::Railtie do
|
|
33
|
+
let(:app_class) do
|
|
34
|
+
Class.new do
|
|
35
|
+
def initialize
|
|
36
|
+
@prepared = false
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def load_seed
|
|
40
|
+
# Default implementation - should be patched by Railtie
|
|
41
|
+
raise "Original load_seed called"
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def prepare!
|
|
45
|
+
@prepared = true
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def prepared?
|
|
49
|
+
@prepared
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
let(:rails_application) { app_class.new }
|
|
55
|
+
let(:logger) { Logger.new($stdout) }
|
|
56
|
+
let(:seeds_path) { File.expand_path("../../fixtures/seeds", __FILE__) }
|
|
57
|
+
let(:default_seeds_path) { File.expand_path("../../fixtures/seeds.rb", __FILE__) }
|
|
58
|
+
|
|
59
|
+
before do
|
|
60
|
+
# Set up Rails.application mock
|
|
61
|
+
# In Rails, Rails.application.class_eval works because Rails.application is an instance
|
|
62
|
+
# and class_eval is called on it, which modifies the class.
|
|
63
|
+
# We need to stub this properly.
|
|
64
|
+
allow(Rails).to receive(:application).and_return(rails_application)
|
|
65
|
+
allow(Rails).to receive(:root).and_return(rails_root)
|
|
66
|
+
allow(Rails).to receive(:env).and_return(rails_env)
|
|
67
|
+
allow(Rails).to receive(:logger).and_return(logger)
|
|
68
|
+
allow(Rails).to receive(:logger=)
|
|
69
|
+
|
|
70
|
+
SeedBuilder.configure do |config|
|
|
71
|
+
config.seeds_full_path = seeds_path
|
|
72
|
+
config.default_seeds_full_path = default_seeds_path
|
|
73
|
+
config.load_default_seeds = true
|
|
74
|
+
config.load_seeds = true
|
|
75
|
+
config.use_seed_loader = true
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
# Clear any existing data
|
|
79
|
+
SeedUser.delete_all
|
|
80
|
+
SeedBuilderUser.delete_all
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
describe "Rails.application.load_seed integration" do
|
|
84
|
+
context "when use_seed_loader is enabled" do
|
|
85
|
+
before do
|
|
86
|
+
# Ensure rails_application is created before calling to_prepare
|
|
87
|
+
# so that Rails.application returns the correct instance
|
|
88
|
+
rails_application
|
|
89
|
+
# Simulate Rails initialization by running the Railtie's to_prepare blocks
|
|
90
|
+
SeedBuilder::Railtie.config.call_to_prepare
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
it "patches Rails.application.load_seed to use SeedBuilder loader" do
|
|
94
|
+
expect { rails_application.load_seed }.not_to raise_error
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
it "loads seeds using SeedBuilder loader" do
|
|
98
|
+
rails_application.load_seed
|
|
99
|
+
expect(SeedUser.count).to eq 1
|
|
100
|
+
expect(SeedBuilderUser.count).to eq 1
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
context "when use_seed_loader is disabled" do
|
|
105
|
+
before do
|
|
106
|
+
SeedBuilder.configure do |config|
|
|
107
|
+
config.use_seed_loader = false
|
|
108
|
+
end
|
|
109
|
+
# Simulate Rails initialization by running the Railtie's to_prepare blocks
|
|
110
|
+
SeedBuilder::Railtie.config.call_to_prepare
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
it "does not patch Rails.application.load_seed" do
|
|
114
|
+
expect { rails_application.load_seed }.to raise_error("Original load_seed called")
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
end
|
data/spec/spec_helper.rb
CHANGED
|
@@ -7,6 +7,9 @@ end
|
|
|
7
7
|
require "simplecov-cobertura"
|
|
8
8
|
SimpleCov.formatter = SimpleCov::Formatter::CoberturaFormatter
|
|
9
9
|
|
|
10
|
+
# Fix for Rails 6.1 compatibility: require Logger before ActiveRecord
|
|
11
|
+
# to avoid "uninitialized constant ActiveSupport::LoggerThreadSafeLevel::Logger" error
|
|
12
|
+
require "logger"
|
|
10
13
|
require "active_record"
|
|
11
14
|
|
|
12
15
|
require "seed_builder"
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: seed_builder
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Andrei Makarov
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2025-11-04 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rails
|
|
@@ -16,40 +16,40 @@ dependencies:
|
|
|
16
16
|
requirements:
|
|
17
17
|
- - ">="
|
|
18
18
|
- !ruby/object:Gem::Version
|
|
19
|
-
version: '6'
|
|
19
|
+
version: '6.1'
|
|
20
20
|
- - "<"
|
|
21
21
|
- !ruby/object:Gem::Version
|
|
22
|
-
version: '8.
|
|
22
|
+
version: '8.2'
|
|
23
23
|
type: :runtime
|
|
24
24
|
prerelease: false
|
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
|
26
26
|
requirements:
|
|
27
27
|
- - ">="
|
|
28
28
|
- !ruby/object:Gem::Version
|
|
29
|
-
version: '6'
|
|
29
|
+
version: '6.1'
|
|
30
30
|
- - "<"
|
|
31
31
|
- !ruby/object:Gem::Version
|
|
32
|
-
version: '8.
|
|
32
|
+
version: '8.2'
|
|
33
33
|
- !ruby/object:Gem::Dependency
|
|
34
34
|
name: activerecord
|
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
|
36
36
|
requirements:
|
|
37
37
|
- - ">="
|
|
38
38
|
- !ruby/object:Gem::Version
|
|
39
|
-
version: '6'
|
|
39
|
+
version: '6.1'
|
|
40
40
|
- - "<"
|
|
41
41
|
- !ruby/object:Gem::Version
|
|
42
|
-
version: '8.
|
|
42
|
+
version: '8.2'
|
|
43
43
|
type: :runtime
|
|
44
44
|
prerelease: false
|
|
45
45
|
version_requirements: !ruby/object:Gem::Requirement
|
|
46
46
|
requirements:
|
|
47
47
|
- - ">="
|
|
48
48
|
- !ruby/object:Gem::Version
|
|
49
|
-
version: '6'
|
|
49
|
+
version: '6.1'
|
|
50
50
|
- - "<"
|
|
51
51
|
- !ruby/object:Gem::Version
|
|
52
|
-
version: '8.
|
|
52
|
+
version: '8.2'
|
|
53
53
|
- !ruby/object:Gem::Dependency
|
|
54
54
|
name: bundler
|
|
55
55
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -134,11 +134,55 @@ dependencies:
|
|
|
134
134
|
- - "~>"
|
|
135
135
|
- !ruby/object:Gem::Version
|
|
136
136
|
version: '2.4'
|
|
137
|
+
- !ruby/object:Gem::Dependency
|
|
138
|
+
name: standard
|
|
139
|
+
requirement: !ruby/object:Gem::Requirement
|
|
140
|
+
requirements:
|
|
141
|
+
- - "~>"
|
|
142
|
+
- !ruby/object:Gem::Version
|
|
143
|
+
version: '1.0'
|
|
144
|
+
type: :development
|
|
145
|
+
prerelease: false
|
|
146
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
147
|
+
requirements:
|
|
148
|
+
- - "~>"
|
|
149
|
+
- !ruby/object:Gem::Version
|
|
150
|
+
version: '1.0'
|
|
151
|
+
- !ruby/object:Gem::Dependency
|
|
152
|
+
name: rbs
|
|
153
|
+
requirement: !ruby/object:Gem::Requirement
|
|
154
|
+
requirements:
|
|
155
|
+
- - "~>"
|
|
156
|
+
- !ruby/object:Gem::Version
|
|
157
|
+
version: '3.0'
|
|
158
|
+
type: :development
|
|
159
|
+
prerelease: false
|
|
160
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
161
|
+
requirements:
|
|
162
|
+
- - "~>"
|
|
163
|
+
- !ruby/object:Gem::Version
|
|
164
|
+
version: '3.0'
|
|
165
|
+
- !ruby/object:Gem::Dependency
|
|
166
|
+
name: appraisal
|
|
167
|
+
requirement: !ruby/object:Gem::Requirement
|
|
168
|
+
requirements:
|
|
169
|
+
- - "~>"
|
|
170
|
+
- !ruby/object:Gem::Version
|
|
171
|
+
version: '2.4'
|
|
172
|
+
type: :development
|
|
173
|
+
prerelease: false
|
|
174
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
175
|
+
requirements:
|
|
176
|
+
- - "~>"
|
|
177
|
+
- !ruby/object:Gem::Version
|
|
178
|
+
version: '2.4'
|
|
137
179
|
description: Extension for ActiveRecord to organize seeds in a directory and generate
|
|
138
180
|
them as migrations
|
|
139
181
|
email:
|
|
140
|
-
-
|
|
141
|
-
executables:
|
|
182
|
+
- contact@kiskolabs.com
|
|
183
|
+
executables:
|
|
184
|
+
- appraisals
|
|
185
|
+
- seed
|
|
142
186
|
extensions: []
|
|
143
187
|
extra_rdoc_files: []
|
|
144
188
|
files:
|
|
@@ -148,6 +192,7 @@ files:
|
|
|
148
192
|
- ".github/workflows/test.yml"
|
|
149
193
|
- ".gitignore"
|
|
150
194
|
- ".ruby-version"
|
|
195
|
+
- ".standard.yml"
|
|
151
196
|
- ".trunk/.gitignore"
|
|
152
197
|
- ".trunk/configs/.markdownlint.yaml"
|
|
153
198
|
- ".trunk/configs/.shellcheckrc"
|
|
@@ -155,24 +200,34 @@ files:
|
|
|
155
200
|
- ".trunk/trunk.yaml"
|
|
156
201
|
- ".vscode/extensions.json"
|
|
157
202
|
- ".vscode/settings.json"
|
|
203
|
+
- Appraisals
|
|
158
204
|
- CHANGELOG.md
|
|
159
205
|
- Gemfile
|
|
160
206
|
- Gemfile.lock
|
|
161
207
|
- LICENSE.md
|
|
162
208
|
- README.md
|
|
209
|
+
- bin/appraisals
|
|
210
|
+
- bin/seed
|
|
163
211
|
- lib/generators/seed_generator.rb
|
|
164
212
|
- lib/generators/templates/seed.rb.tt
|
|
165
213
|
- lib/rails_config.rb
|
|
166
214
|
- lib/seed_builder.rb
|
|
167
215
|
- lib/seed_builder/config.rb
|
|
168
216
|
- lib/seed_builder/loader.rb
|
|
217
|
+
- lib/seed_builder/railtie.rb
|
|
218
|
+
- lib/tasks/seed.rake
|
|
169
219
|
- seed_builder.gemspec
|
|
220
|
+
- sig/seed_builder.rbs
|
|
221
|
+
- sig/seed_builder/config.rbs
|
|
222
|
+
- sig/seed_builder/loader.rbs
|
|
223
|
+
- sig/seed_builder/railtie.rbs
|
|
170
224
|
- spec/fixtures/schema.rb
|
|
171
225
|
- spec/fixtures/seeds.rb
|
|
172
226
|
- spec/fixtures/seeds/20241206200111_create_users.rb
|
|
173
227
|
- spec/generator_spec.rb
|
|
174
228
|
- spec/seed_builder/config_spec.rb
|
|
175
229
|
- spec/seed_builder/loader_spec.rb
|
|
230
|
+
- spec/seed_builder/railtie_spec.rb
|
|
176
231
|
- spec/seed_builder_spec.rb
|
|
177
232
|
- spec/spec_helper.rb
|
|
178
233
|
- spec/support/junit_formatter.rb
|
|
@@ -213,6 +268,7 @@ test_files:
|
|
|
213
268
|
- spec/generator_spec.rb
|
|
214
269
|
- spec/seed_builder/config_spec.rb
|
|
215
270
|
- spec/seed_builder/loader_spec.rb
|
|
271
|
+
- spec/seed_builder/railtie_spec.rb
|
|
216
272
|
- spec/seed_builder_spec.rb
|
|
217
273
|
- spec/spec_helper.rb
|
|
218
274
|
- spec/support/junit_formatter.rb
|