File tree 6 files changed +127
-0
lines changed
test/generators/suspenders
6 files changed +127
-0
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ Unreleased
10
10
* Introduce ` suspenders:lint ` generator
11
11
* Introduce ` suspenders:rake ` generator
12
12
* Introduce ` suspenders:views ` generator
13
+ * Introduce ` suspenders:setup ` generator
13
14
14
15
20230113.0 (January, 13, 2023)
15
16
Original file line number Diff line number Diff line change @@ -134,6 +134,14 @@ document [lang][].
134
134
[ title ] : https://github.com/calebhearth/title
135
135
[ lang ] : https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/lang
136
136
137
+ ### Setup
138
+
139
+ A holistic setup script.
140
+
141
+ ``` sh
142
+ bin/setup
143
+ ```
144
+
137
145
## Contributing
138
146
139
147
See the [ CONTRIBUTING] document.
Original file line number Diff line number Diff line change
1
+ module Suspenders
2
+ module Generators
3
+ class SetupGenerator < Rails ::Generators ::Base
4
+ source_root File . expand_path ( "../../templates/setup" , __FILE__ )
5
+ desc <<~TEXT
6
+ A holistic setup script.
7
+
8
+ ```sh
9
+ bin/setup
10
+ ```
11
+ TEXT
12
+
13
+ def replace_bin_setup
14
+ copy_file "bin_setup.rb" , "bin/setup" , force : true
15
+ end
16
+ end
17
+ end
18
+ end
Original file line number Diff line number Diff line change
1
+ #!/usr/bin/env ruby
2
+ require "fileutils"
3
+ require "bundler"
4
+
5
+ # path to your application root.
6
+ APP_ROOT = File . expand_path ( ".." , __dir__ )
7
+
8
+ def system! ( *args )
9
+ system ( *args , exception : true )
10
+ end
11
+
12
+ def using_node?
13
+ File . exist? "package.json"
14
+ end
15
+
16
+ FileUtils . chdir APP_ROOT do
17
+ puts "== Installing dependencies =="
18
+ system! "gem install bundler --conservative"
19
+ system ( "bundle check" ) || system! ( "bundle install" )
20
+ system ( "yarn install --check-files" ) if using_node?
21
+
22
+ puts "\n == Preparing database and adding development seed data =="
23
+ if File . exist? "lib/tasks/dev.rake"
24
+ system! "bin/rails dev:prime"
25
+ else
26
+ system! "bin/rails db:prepare"
27
+ end
28
+
29
+ if Bundler . rubygems . find_name ( "sprockets" )
30
+ puts "\n == Generating assets =="
31
+ system! "bin/rails assets:clobber assets:precompile"
32
+ end
33
+
34
+ # https://github.com/rails/rails/pull/47719/files
35
+ puts "\n == Setup test environment =="
36
+ system! "bin/rails test:prepare"
37
+
38
+ puts "\n == Removing old logs and tempfiles =="
39
+ system! "bin/rails log:clear tmp:clear"
40
+
41
+ puts "\n == Restarting application server =="
42
+ system! "bin/rails restart"
43
+ end
Original file line number Diff line number Diff line change
1
+ if Rails . env . development? || Rails . env . test?
2
+ require "factory_bot" if Bundler . rubygems . find_name ( "factory_bot_rails" ) . any?
3
+
4
+ namespace :dev do
5
+ desc "Sample data for local development environment"
6
+ task prime : "db:setup" do
7
+ include FactoryBot ::Syntax ::Methods if Bundler . rubygems . find_name ( "factory_bot_rails" ) . any?
8
+
9
+ # create(:user, email: "[email protected] ", password: "password")
10
+ end
11
+ end
12
+ end
Original file line number Diff line number Diff line change
1
+ require "test_helper"
2
+ require "generators/suspenders/setup_generator"
3
+
4
+ module Suspenders
5
+ module Generators
6
+ class SetupGeneratorTest < Rails ::Generators ::TestCase
7
+ include Suspenders ::TestHelpers
8
+
9
+ tests Suspenders ::Generators ::SetupGenerator
10
+ destination Rails . root
11
+ setup :prepare_destination
12
+ teardown :restore_destination
13
+
14
+ test "modifies bin/setup" do
15
+ expected = bin_setup
16
+
17
+ run_generator
18
+
19
+ assert_file app_root ( "bin/setup" ) do |file |
20
+ assert_equal expected , file
21
+ end
22
+ end
23
+
24
+ test "has a custom description" do
25
+ assert_no_match ( /Description:/ , generator_class . desc )
26
+ end
27
+
28
+ private
29
+
30
+ def prepare_destination
31
+ backup_file "bin/setup"
32
+ end
33
+
34
+ def restore_destination
35
+ remove_file_if_exists "Brewfile"
36
+ restore_file "bin/setup"
37
+ remove_dir_if_exists "lib/tasks"
38
+ end
39
+
40
+ def bin_setup
41
+ File . read ( "./lib/generators/templates/setup/bin_setup.rb" )
42
+ end
43
+ end
44
+ end
45
+ end
You can’t perform that action at this time.
0 commit comments