class Katapult::Generators::ClearanceGenerator
Constants
- MENU_BAR
Public Instance Methods
add_authentication_paths()
click to toggle source
# File lib/generators/katapult/clearance/clearance_generator.rb, line 109 def add_authentication_paths inject_into_file 'features/support/paths.rb', <<-CONTENT, after: 'case page_name' # Authentication when 'the sign-in form' sign_in_path when 'the reset password page' new_password_path when 'the new password page for the user above' edit_user_password_path(User.last!) CONTENT end
add_current_user_to_layout()
click to toggle source
# File lib/generators/katapult/clearance/clearance_generator.rb, line 78 def add_current_user_to_layout template 'app/views/layouts/_current_user.html.haml' inject_into_file MENU_BAR, <<-CONTENT, after: /^\s+#navbar.*\n/ = render 'layouts/current_user' if signed_in? CONTENT end
add_sign_in_background_to_all_features()
click to toggle source
# File lib/generators/katapult/clearance/clearance_generator.rb, line 89 def add_sign_in_background_to_all_features Dir['features/*.feature'].each do |file| inject_into_file file, <<-CONTENT, after: /^Feature: .*$/ Background: Given there is a user And I sign in as the user above CONTENT end end
add_user_factory()
click to toggle source
# File lib/generators/katapult/clearance/clearance_generator.rb, line 124 def add_user_factory factories_file = 'spec/factories/factories.rb' # Remove empty factory gsub_file factories_file, "\n factory :user\n", '' # In a second `transform` run, this might already be present unless file_contains? factories_file, 'factory :user' inject_into_file factories_file, <<-'CONTENT', before: /end\n\z/ factory :user do sequence(:email) { |i| "user-#{ i }@example.com" } password 'password' end CONTENT end end
create_authentication_feature()
click to toggle source
# File lib/generators/katapult/clearance/clearance_generator.rb, line 101 def create_authentication_feature template 'features/authentication.feature' end
create_authentication_steps()
click to toggle source
# File lib/generators/katapult/clearance/clearance_generator.rb, line 105 def create_authentication_steps template 'features/step_definitions/authentication_steps.rb' end
create_clearance_views()
click to toggle source
# File lib/generators/katapult/clearance/clearance_generator.rb, line 41 def create_clearance_views directory 'app/views/clearance_mailer' directory 'app/views/passwords' directory 'app/views/sessions' end
create_initializer()
click to toggle source
# File lib/generators/katapult/clearance/clearance_generator.rb, line 55 def create_initializer template 'config/initializers/clearance.rb', force: true end
create_routes()
click to toggle source
# File lib/generators/katapult/clearance/clearance_generator.rb, line 63 def create_routes route <<-ROUTES resources :users do resource :password, controller: 'passwords', only: %i[edit update] end # Clearance get '/login', to: 'clearance/sessions#new', as: 'sign_in' resource :session, controller: 'clearance/sessions', only: [:create] resources :passwords, controller: 'passwords', only: [:create, :new] delete '/logout', to: 'clearance/sessions#destroy', as: 'sign_out' ROUTES end
create_translations()
click to toggle source
# File lib/generators/katapult/clearance/clearance_generator.rb, line 59 def create_translations template 'config/locales/clearance.en.yml' end
install_backdoor()
click to toggle source
# File lib/generators/katapult/clearance/clearance_generator.rb, line 47 def install_backdoor # This creepy indentation leads to correct formatting in the file application <<-CONTENT, env: 'test' # Enable quick-signin in tests: `visit homepage(as: User.last!)` config.middleware.use Clearance::BackDoor CONTENT end
install_clearance()
click to toggle source
# File lib/generators/katapult/clearance/clearance_generator.rb, line 20 def install_clearance insert_into_file 'Gemfile', <<-GEM, before: "gem 'katapult'" gem 'clearance' GEM run 'bundle install --quiet' generate 'clearance:install' end
migrate()
click to toggle source
# File lib/generators/katapult/clearance/clearance_generator.rb, line 16 def migrate rake 'db:migrate' # Clearance must see the users table in the db end
overwrite_clearance_controllers()
click to toggle source
# File lib/generators/katapult/clearance/clearance_generator.rb, line 37 def overwrite_clearance_controllers template 'app/controllers/passwords_controller.rb' end
require_login()
click to toggle source
# File lib/generators/katapult/clearance/clearance_generator.rb, line 29 def require_login file = 'app/controllers/application_controller.rb' insert_into_file file, <<-CONTENT, after: "Clearance::Controller\n" before_action :require_login CONTENT end
Private Instance Methods
user()
click to toggle source
# File lib/generators/katapult/clearance/clearance_generator.rb, line 144 def user @element.user end