Skip to content

Commit 4b491a8

Browse files
better code for checking if bundle exec is needed
1 parent 9d36b30 commit 4b491a8

2 files changed

Lines changed: 25 additions & 42 deletions

File tree

spec/support/acceptance/helpers/step_helpers.rb

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,7 @@ def create_rails_application
9292
end
9393

9494
def rails_new_command
95-
if ruby_gt_4_0?
96-
"rails new #{fs.project_directory} --database=#{database.adapter_name} --skip-bundle --skip-javascript --no-rc --skip-bootsnap"
97-
else
98-
"bundle exec rails new #{fs.project_directory} --database=#{database.adapter_name} --skip-bundle --skip-javascript --no-rc --skip-bootsnap"
99-
end
95+
"#{additional_command} rails new #{fs.project_directory} --database=#{database.adapter_name} --skip-bundle --skip-javascript --no-rc --skip-bootsnap"
10096
end
10197

10298
def configure_routes
@@ -130,5 +126,11 @@ def run_rspec_tests(*paths)
130126
def run_rspec_suite
131127
run_rake_tasks('spec', env: { SPEC_OPTS: '-fd' })
132128
end
129+
130+
def additional_command
131+
unless ruby_gt_4_0?
132+
'bundle exec'
133+
end
134+
end
133135
end
134136
end

spec/support/unit/rails_application.rb

Lines changed: 18 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,7 @@ def rails_new
9393
end
9494

9595
def rails_new_command
96-
if ruby_gt_4_0?
97-
"rails new #{fs.project_directory} --database=#{database.adapter_name} --skip-bundle --skip-javascript --no-rc --skip-bootsnap"
98-
else
99-
"bundle exec rails new #{fs.project_directory} --database=#{database.adapter_name} --skip-bundle --skip-javascript --no-rc --skip-bootsnap"
100-
end
96+
"#{additional_command} rails new #{fs.project_directory} --database=#{database.adapter_name} --skip-bundle --skip-javascript --no-rc --skip-bootsnap"
10197
end
10298

10399
def fix_available_locales_warning
@@ -150,21 +146,13 @@ class DevelopmentRecord < ActiveRecord::Base
150146

151147
def add_action_text_migration
152148
fs.within_project do
153-
if ruby_gt_4_0?
154-
run_command! 'rake action_text:install:migrations'
155-
else
156-
run_command! 'bundle exec rake action_text:install:migrations'
157-
end
149+
run_command! "#{additional_command} rake action_text:install:migrations"
158150
end
159151
end
160152

161153
def add_active_storage_migration
162154
fs.within_project do
163-
if ruby_gt_4_0?
164-
run_command! 'rake active_storage:install:migrations'
165-
else
166-
run_command! 'bundle exec rake active_storage:install:migrations'
167-
end
155+
run_command! "#{additional_command} rake active_storage:install:migrations"
168156
end
169157
end
170158

@@ -182,28 +170,15 @@ def load_environment
182170
end
183171

184172
def run_migrations
185-
if ruby_gt_4_0?
186-
fs.within_project do
187-
run_command! 'rake db:drop:all'
188-
run_command! 'rake db:create RAILS_ENV=test'
189-
run_command! 'rake db:create RAILS_ENV=development'
190-
run_command! 'rake db:create RAILS_ENV=production'
191-
end
192-
193-
fs.within_project do
194-
run_command! 'rake db:migrate'
195-
end
196-
else
197-
fs.within_project do
198-
run_command! 'bundle exec rake db:drop:all'
199-
run_command! 'bundle exec rake db:create RAILS_ENV=test'
200-
run_command! 'bundle exec rake db:create RAILS_ENV=development'
201-
run_command! 'bundle exec rake db:create RAILS_ENV=production'
202-
end
203-
204-
fs.within_project do
205-
run_command! 'bundle exec rake db:migrate'
206-
end
173+
fs.within_project do
174+
run_command! "#{additional_command} rake db:drop:all"
175+
run_command! "#{additional_command} rake db:create RAILS_ENV=test"
176+
run_command! "#{additional_command} rake db:create RAILS_ENV=development"
177+
run_command! "#{additional_command} rake db:create RAILS_ENV=production"
178+
end
179+
180+
fs.within_project do
181+
run_command! "#{additional_command} rake db:migrate"
207182
end
208183
end
209184

@@ -225,5 +200,11 @@ def run_command!(*args)
225200
def rails_version
226201
bundle.version_of('rails')
227202
end
203+
204+
def additional_command
205+
unless ruby_gt_4_0?
206+
'bundle exec'
207+
end
208+
end
228209
end
229210
end

0 commit comments

Comments
 (0)