9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/fixtures_from_factories/generate_set.rb', line 9
def call(generator_index_klass, output_path, time_cop_now:, faker_seed:, options: {})
raise "Do not run fixture generation in a production environment" if ::Rails.env.production?
::Faker::Config.random = Random.new(faker_seed)
::Faker::Config.locale = "en"
::Timecop.freeze(*time_cop_now)
if defined?(Devise)
::Devise::Encryptor.define_singleton_method(:digest) do |_klass, _password|
FixturesFromFactories.configuration.devise_password_hash
end
end
database_env_setup = "RAILS_ENV=#{ENV["RAILS_ENV"]}"
puts "Setup database for fixtures #{database_env_setup}"
system("#{database_env_setup} bin/rails db:environment:set RAILS_ENV=development")
system("#{database_env_setup} rake db:drop")
system("#{database_env_setup} rake db:create")
system("#{database_env_setup} rake db:migrate")
system("#{database_env_setup} rake db:seed")
if FixturesFromFactories.configuration.factory_bot_definition_file_paths
FactoryBot.definition_file_paths = FixturesFromFactories.configuration.factory_bot_definition_file_paths
end
FactoryBot.reload
FixtureGenerator.new(output_path).generate do
generator_index_klass.new(self, faker_seed, options).generate
end
system("#{database_env_setup} bin/rails db:environment:set RAILS_ENV=development")
::Timecop.return
end
|