Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate tests via hook_for :test_framework #132

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 1 addition & 9 deletions lib/generators/authentication/authentication_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,6 @@ def create_models
template "models/user.rb", "app/models/user.rb"
end

def create_fixture_file
copy_file "test_unit/users.yml", "test/fixtures/users.yml"
end

def create_controllers
template "controllers/#{format}/authentications/events_controller.rb", "app/controllers/authentications/events_controller.rb" if options.trackable?

Expand Down Expand Up @@ -206,11 +202,7 @@ def add_routes
route 'get "sign_in", to: "sessions#new"' unless options.api?
end

def create_test_files
directory "test_unit/controllers/#{format}", "test/controllers"
directory "test_unit/mailers/", "test/mailers"
template "test_unit/test_helper.rb", "test/test_helper.rb", force: true
end
hook_for :test_framework

private
def format
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
require "rails/generators/test_unit"

module TestUnit # :nodoc:
class AuthenticationGenerator < Rails::Generators::Base # :nodoc:
source_root File.expand_path("templates", __dir__)

class_option :api, type: :boolean, desc: "Generates API authentication"

def create_fixture_file
template "test/fixtures/users.yml"
end

def create_test_files
directory "test/controllers/#{format}", "test/controllers"
directory "test/mailers/", "test/mailers"
template "test/test_helper.rb", "test/test_helper.rb", force: true
end

private

def format
options.api? ? "api" : "html"
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

lazaro_nixon:
email: [email protected]
password_digest: <%= BCrypt::Password.create("Secret1*3*5*") %>
password_digest: <%%= BCrypt::Password.create("Secret1*3*5*") %>
verified: true