diff --git a/lib/generators/authentication/authentication_generator.rb b/lib/generators/authentication/authentication_generator.rb index ad0b807e..090d9c98 100644 --- a/lib/generators/authentication/authentication_generator.rb +++ b/lib/generators/authentication/authentication_generator.rb @@ -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? @@ -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 diff --git a/lib/generators/test_unit/authentication/authentication_generator.rb b/lib/generators/test_unit/authentication/authentication_generator.rb new file mode 100644 index 00000000..19ef046b --- /dev/null +++ b/lib/generators/test_unit/authentication/authentication_generator.rb @@ -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 \ No newline at end of file diff --git a/lib/generators/authentication/templates/test_unit/controllers/api/identity/email_verifications_controller_test.rb.tt b/lib/generators/test_unit/authentication/templates/test/controllers/api/identity/email_verifications_controller_test.rb.tt similarity index 100% rename from lib/generators/authentication/templates/test_unit/controllers/api/identity/email_verifications_controller_test.rb.tt rename to lib/generators/test_unit/authentication/templates/test/controllers/api/identity/email_verifications_controller_test.rb.tt diff --git a/lib/generators/authentication/templates/test_unit/controllers/api/identity/emails_controller_test.rb.tt b/lib/generators/test_unit/authentication/templates/test/controllers/api/identity/emails_controller_test.rb.tt similarity index 100% rename from lib/generators/authentication/templates/test_unit/controllers/api/identity/emails_controller_test.rb.tt rename to lib/generators/test_unit/authentication/templates/test/controllers/api/identity/emails_controller_test.rb.tt diff --git a/lib/generators/authentication/templates/test_unit/controllers/api/identity/password_resets_controller_test.rb.tt b/lib/generators/test_unit/authentication/templates/test/controllers/api/identity/password_resets_controller_test.rb.tt similarity index 100% rename from lib/generators/authentication/templates/test_unit/controllers/api/identity/password_resets_controller_test.rb.tt rename to lib/generators/test_unit/authentication/templates/test/controllers/api/identity/password_resets_controller_test.rb.tt diff --git a/lib/generators/authentication/templates/test_unit/controllers/api/passwords_controller_test.rb.tt b/lib/generators/test_unit/authentication/templates/test/controllers/api/passwords_controller_test.rb.tt similarity index 100% rename from lib/generators/authentication/templates/test_unit/controllers/api/passwords_controller_test.rb.tt rename to lib/generators/test_unit/authentication/templates/test/controllers/api/passwords_controller_test.rb.tt diff --git a/lib/generators/authentication/templates/test_unit/controllers/api/registrations_controller_test.rb.tt b/lib/generators/test_unit/authentication/templates/test/controllers/api/registrations_controller_test.rb.tt similarity index 100% rename from lib/generators/authentication/templates/test_unit/controllers/api/registrations_controller_test.rb.tt rename to lib/generators/test_unit/authentication/templates/test/controllers/api/registrations_controller_test.rb.tt diff --git a/lib/generators/authentication/templates/test_unit/controllers/api/sessions_controller_test.rb.tt b/lib/generators/test_unit/authentication/templates/test/controllers/api/sessions_controller_test.rb.tt similarity index 100% rename from lib/generators/authentication/templates/test_unit/controllers/api/sessions_controller_test.rb.tt rename to lib/generators/test_unit/authentication/templates/test/controllers/api/sessions_controller_test.rb.tt diff --git a/lib/generators/authentication/templates/test_unit/controllers/html/identity/email_verifications_controller_test.rb.tt b/lib/generators/test_unit/authentication/templates/test/controllers/html/identity/email_verifications_controller_test.rb.tt similarity index 100% rename from lib/generators/authentication/templates/test_unit/controllers/html/identity/email_verifications_controller_test.rb.tt rename to lib/generators/test_unit/authentication/templates/test/controllers/html/identity/email_verifications_controller_test.rb.tt diff --git a/lib/generators/authentication/templates/test_unit/controllers/html/identity/emails_controller_test.rb.tt b/lib/generators/test_unit/authentication/templates/test/controllers/html/identity/emails_controller_test.rb.tt similarity index 100% rename from lib/generators/authentication/templates/test_unit/controllers/html/identity/emails_controller_test.rb.tt rename to lib/generators/test_unit/authentication/templates/test/controllers/html/identity/emails_controller_test.rb.tt diff --git a/lib/generators/authentication/templates/test_unit/controllers/html/identity/password_resets_controller_test.rb.tt b/lib/generators/test_unit/authentication/templates/test/controllers/html/identity/password_resets_controller_test.rb.tt similarity index 100% rename from lib/generators/authentication/templates/test_unit/controllers/html/identity/password_resets_controller_test.rb.tt rename to lib/generators/test_unit/authentication/templates/test/controllers/html/identity/password_resets_controller_test.rb.tt diff --git a/lib/generators/authentication/templates/test_unit/controllers/html/passwords_controller_test.rb.tt b/lib/generators/test_unit/authentication/templates/test/controllers/html/passwords_controller_test.rb.tt similarity index 100% rename from lib/generators/authentication/templates/test_unit/controllers/html/passwords_controller_test.rb.tt rename to lib/generators/test_unit/authentication/templates/test/controllers/html/passwords_controller_test.rb.tt diff --git a/lib/generators/authentication/templates/test_unit/controllers/html/registrations_controller_test.rb.tt b/lib/generators/test_unit/authentication/templates/test/controllers/html/registrations_controller_test.rb.tt similarity index 100% rename from lib/generators/authentication/templates/test_unit/controllers/html/registrations_controller_test.rb.tt rename to lib/generators/test_unit/authentication/templates/test/controllers/html/registrations_controller_test.rb.tt diff --git a/lib/generators/authentication/templates/test_unit/controllers/html/sessions_controller_test.rb.tt b/lib/generators/test_unit/authentication/templates/test/controllers/html/sessions_controller_test.rb.tt similarity index 100% rename from lib/generators/authentication/templates/test_unit/controllers/html/sessions_controller_test.rb.tt rename to lib/generators/test_unit/authentication/templates/test/controllers/html/sessions_controller_test.rb.tt diff --git a/lib/generators/authentication/templates/test_unit/users.yml b/lib/generators/test_unit/authentication/templates/test/fixtures/users.yml.tt similarity index 69% rename from lib/generators/authentication/templates/test_unit/users.yml rename to lib/generators/test_unit/authentication/templates/test/fixtures/users.yml.tt index 4c5f5d7d..450e58fb 100644 --- a/lib/generators/authentication/templates/test_unit/users.yml +++ b/lib/generators/test_unit/authentication/templates/test/fixtures/users.yml.tt @@ -2,5 +2,5 @@ lazaro_nixon: email: lazaronixon@hotmail.com - password_digest: <%= BCrypt::Password.create("Secret1*3*5*") %> + password_digest: <%%= BCrypt::Password.create("Secret1*3*5*") %> verified: true diff --git a/lib/generators/authentication/templates/test_unit/mailers/user_mailer_test.rb.tt b/lib/generators/test_unit/authentication/templates/test/mailers/user_mailer_test.rb.tt similarity index 100% rename from lib/generators/authentication/templates/test_unit/mailers/user_mailer_test.rb.tt rename to lib/generators/test_unit/authentication/templates/test/mailers/user_mailer_test.rb.tt diff --git a/lib/generators/authentication/templates/test_unit/test_helper.rb.tt b/lib/generators/test_unit/authentication/templates/test/test_helper.rb.tt similarity index 100% rename from lib/generators/authentication/templates/test_unit/test_helper.rb.tt rename to lib/generators/test_unit/authentication/templates/test/test_helper.rb.tt