-
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #107 from TruemarkDev/generator-for-rack-mini-prof…
…iler Generator for rack mini profiler
- Loading branch information
Showing
4 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
lib/generators/boring/rack_mini_profiler/install/install_generator.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# frozen_string_literal: true | ||
|
||
module Boring | ||
module RackMiniProfiler | ||
class InstallGenerator < Rails::Generators::Base | ||
desc 'Adds rack mini profiler to the application' | ||
|
||
def add_rack_mini_profiler_gem | ||
say 'Adding rack mini profiler gem', :green | ||
|
||
gem 'rack-mini-profiler', require: false | ||
|
||
Bundler.with_unbundled_env do | ||
run 'bundle install' | ||
end | ||
end | ||
|
||
def configure_rack_mini_profiler | ||
say 'Configuring rack mini profiler', :green | ||
|
||
Bundler.with_unbundled_env do | ||
run 'bundle exec rails g rack_mini_profiler:install' | ||
end | ||
end | ||
end | ||
end | ||
end |
31 changes: 31 additions & 0 deletions
31
test/generators/rack_mini_profiler_install_generator_test.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'test_helper' | ||
require 'generators/boring/rack_mini_profiler/install/install_generator' | ||
|
||
class RackMiniProfilerGeneratorTest < Rails::Generators::TestCase | ||
tests Boring::RackMiniProfiler::InstallGenerator | ||
setup :build_app | ||
teardown :teardown_app | ||
|
||
include GeneratorHelper | ||
|
||
def destination_root | ||
app_path | ||
end | ||
|
||
def test_should_configure_rack_mini_profiler_gem | ||
Dir.chdir(app_path) do | ||
quietly { run_generator } | ||
|
||
assert_file 'Gemfile' do |content| | ||
assert_match(/gem 'rack-mini-profiler', require: false/, content) | ||
end | ||
|
||
assert_file 'config/initializers/rack_mini_profiler.rb' do |content| | ||
assert_match(/if Rails\.env\.development\?/, content) | ||
assert_match(/Rack::MiniProfilerRails.initialize!\(Rails.application\)/, content) | ||
end | ||
end | ||
end | ||
end |