-
-
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 #122 from Zero-Config-Rails/update-vcr-generator
Update vcr and devise generator with minor improvements
- Loading branch information
Showing
6 changed files
with
47 additions
and
28 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
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 |
---|---|---|
|
@@ -7,21 +7,28 @@ class InstallGenerator < Rails::Generators::Base | |
|
||
DEFAULT_DEVISE_MODEL_NAME = "User" | ||
|
||
class_option :model_name, type: :string, aliases: "-m", | ||
desc: "Tell us the user model name which will be used for authentication. Defaults to #{DEFAULT_DEVISE_MODEL_NAME}" | ||
class_option :skip_devise_view, type: :boolean, aliases: "-sv", | ||
class_option :model_name, | ||
type: :string, | ||
aliases: "-m", | ||
desc: | ||
"Tell us the user model name which will be used for authentication. Defaults to #{DEFAULT_DEVISE_MODEL_NAME}" | ||
class_option :skip_devise_view, | ||
type: :boolean, | ||
aliases: "-sv", | ||
desc: "Skip generating devise views" | ||
class_option :skip_devise_model, type: :boolean, aliases: "-sm", | ||
class_option :skip_devise_model, | ||
type: :boolean, | ||
aliases: "-sm", | ||
desc: "Skip generating devise model" | ||
class_option :run_db_migrate, type: :boolean, aliases: "-rdm", | ||
class_option :run_db_migrate, | ||
type: :boolean, | ||
aliases: "-rdm", | ||
desc: "Run migrations after generating user table", | ||
default: false | ||
|
||
def add_devise_gem | ||
say "Adding devise gem", :green | ||
Bundler.with_unbundled_env do | ||
run "bundle add devise" | ||
end | ||
Bundler.with_unbundled_env { run "bundle add devise" } | ||
end | ||
|
||
def generating_devise_defaults | ||
|
@@ -33,10 +40,12 @@ def generating_devise_defaults | |
|
||
def add_devise_action_mailer_development_config | ||
say "Adding devise Action Mailer development configuration", :green | ||
insert_into_file "config/environments/development.rb", <<~RUBY, after: /Rails.application.configure do/ | ||
insert_into_file "config/environments/development.rb", | ||
<<~RUBY, | ||
\n | ||
\tconfig.action_mailer.default_url_options = { host: 'localhost', port: 3000 } | ||
RUBY | ||
after: /Rails.application.configure do/ | ||
end | ||
|
||
def add_devise_user_model | ||
|
@@ -49,18 +58,27 @@ def add_devise_user_model | |
run "DISABLE_SPRING=1 bundle exec rails generate devise #{model_name}" | ||
end | ||
|
||
# comment out user fixture because it fails the test due to email not being unique | ||
# make the email unique | ||
if File.exist?("test/fixtures/users.yml") | ||
comment_lines "test/fixtures/users.yml", /one: {}/ | ||
comment_lines "test/fixtures/users.yml", /two: {}/ | ||
email_content = <<~FIXTURE | ||
one: | ||
email: [email protected] | ||
FIXTURE | ||
|
||
gsub_file "test/fixtures/users.yml", | ||
/one: {}/, | ||
optimize_indentation(email_content, 0) | ||
end | ||
end | ||
|
||
def add_devise_authentication_filter_to_application_controller | ||
insert_into_file "app/controllers/application_controller.rb", <<~RUBY, after: /class ApplicationController < ActionController::Base/ | ||
insert_into_file "app/controllers/application_controller.rb", | ||
<<~RUBY, | ||
\n | ||
\tbefore_action :authenticate_user! | ||
RUBY | ||
after: | ||
/class ApplicationController < ActionController::Base/ | ||
end | ||
|
||
def add_devise_views | ||
|
@@ -77,9 +95,7 @@ def add_devise_views | |
def run_db_migrate | ||
return unless options[:run_db_migrate] | ||
|
||
Bundler.with_unbundled_env do | ||
rails_command "db:migrate" | ||
end | ||
Bundler.with_unbundled_env { rails_command "db:migrate" } | ||
end | ||
end | ||
end | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
require "vcr" | ||
|
||
VCR.configure do |c| | ||
c.cassette_library_dir = "spec/cassettes" | ||
c.cassette_library_dir = "spec/vcr_cassettes" | ||
c.hook_into <%= @stubbing_libraries %> | ||
c.configure_rspec_metadata! | ||
c.ignore_localhost = true | ||
c.allow_http_connections_when_no_cassette = true | ||
end |
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