-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[101] Create method and message to record not found access (#102)
- Loading branch information
Showing
5 changed files
with
78 additions
and
87 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,18 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'active_record' | ||
|
||
class ApplicationController < ActionController::Base | ||
rescue_from ActiveRecord::RecordNotFound, with: :invalid_page | ||
|
||
def user_has_profile | ||
return unless user_signed_in? | ||
|
||
redirect_to new_profile_path if current_user.profile.blank? | ||
end | ||
|
||
def invalid_page | ||
logger.error "Attempt to access invalid page: #{request.url}" | ||
redirect_to root_url, notice: I18n.t('errors.messages.invalid_page') | ||
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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -3,66 +3,80 @@ | |
require 'rails_helper' | ||
|
||
describe 'Visitor visit homepage' do | ||
it 'and view title and menu content' do | ||
visit root_path | ||
expect(page).to have_content('All Jobs') | ||
expect(page).to have_link('All Jobs', href: root_path) | ||
expect(page).to have_content(I18n.t('go_to_login')) | ||
within('nav') do | ||
expect(page).to have_link('Login User', href: new_user_session_path) | ||
expect(page).to have_link('Login Headhunter', href: new_headhunter_session_path) | ||
expect(page).not_to have_link(Profile.model_name.human, href: new_profile_path) | ||
expect(page).not_to have_link('Logout User', href: destroy_user_session_path) | ||
expect(page).not_to have_link('Logout Headhunter', href: destroy_headhunter_session_path) | ||
expect(page).not_to have_link(I18n.t('openings'), href: jobs_path) | ||
expect(page).not_to have_link(I18n.t('new_opening'), href: new_job_path) | ||
expect(page).not_to have_link(I18n.t('profiles'), href: profiles_path) | ||
expect(page).not_to have_link(I18n.t('stars'), href: stars_path) | ||
expect(page).not_to have_link(I18n.t('applies'), href: applies_path) | ||
context 'when view title and menu content' do | ||
it 'only see login options' do | ||
visit root_path | ||
expect(page).to have_content('All Jobs') | ||
expect(page).to have_link('All Jobs', href: root_path) | ||
expect(page).to have_content(I18n.t('go_to_login')) | ||
within('nav') do | ||
expect(page).to have_link('Login User', href: new_user_session_path) | ||
expect(page).to have_link('Login Headhunter', href: new_headhunter_session_path) | ||
expect(page).not_to have_link(Profile.model_name.human, href: new_profile_path) | ||
expect(page).not_to have_link('Logout User', href: destroy_user_session_path) | ||
expect(page).not_to have_link('Logout Headhunter', href: destroy_headhunter_session_path) | ||
expect(page).not_to have_link(I18n.t('openings'), href: jobs_path) | ||
expect(page).not_to have_link(I18n.t('new_opening'), href: new_job_path) | ||
expect(page).not_to have_link(I18n.t('profiles'), href: profiles_path) | ||
expect(page).not_to have_link(I18n.t('stars'), href: stars_path) | ||
expect(page).not_to have_link(I18n.t('applies'), href: applies_path) | ||
end | ||
end | ||
end | ||
|
||
it 'after User login and view title and menu content' do | ||
user = User.create!(email: '[email protected]', password: 'test123') | ||
login_as(user, scope: :user) | ||
visit root_path | ||
context 'when login as user and view title and menu content' do | ||
it 'see only user menu' do | ||
user = User.create!(email: '[email protected]', password: 'test123') | ||
login_as(user, scope: :user) | ||
visit root_path | ||
|
||
expect(page).to have_content(I18n.t('choose_option')) | ||
expect(page).to have_link('All Jobs', href: root_path) | ||
within('nav') do | ||
expect(page).to have_content("#{I18n.t('you_are')} [email protected]") | ||
expect(page).to have_link(Profile.model_name.human, href: new_profile_path) | ||
expect(page).to have_link(I18n.t('openings'), href: jobs_path) | ||
expect(page).to have_link('Logout User', href: destroy_user_session_path) | ||
expect(page).to have_link(I18n.t('applies'), href: applies_path) | ||
expect(page).not_to have_link('Logout Headhunter', href: destroy_headhunter_session_path) | ||
expect(page).not_to have_link(I18n.t('new_opening'), href: new_job_path) | ||
expect(page).not_to have_link(I18n.t('profiles'), href: profiles_path) | ||
expect(page).not_to have_link(I18n.t('stars'), href: stars_path) | ||
expect(page).not_to have_link('Login User', href: new_user_session_path) | ||
expect(page).not_to have_link('Login Headhunter', href: new_headhunter_session_path) | ||
expect(page).to have_content(I18n.t('choose_option')) | ||
expect(page).to have_link('All Jobs', href: root_path) | ||
within('nav') do | ||
expect(page).to have_content("#{I18n.t('you_are')} [email protected]") | ||
expect(page).to have_link(Profile.model_name.human, href: new_profile_path) | ||
expect(page).to have_link(I18n.t('openings'), href: jobs_path) | ||
expect(page).to have_link('Logout User', href: destroy_user_session_path) | ||
expect(page).to have_link(I18n.t('applies'), href: applies_path) | ||
expect(page).not_to have_link('Logout Headhunter', href: destroy_headhunter_session_path) | ||
expect(page).not_to have_link(I18n.t('new_opening'), href: new_job_path) | ||
expect(page).not_to have_link(I18n.t('profiles'), href: profiles_path) | ||
expect(page).not_to have_link(I18n.t('stars'), href: stars_path) | ||
expect(page).not_to have_link('Login User', href: new_user_session_path) | ||
expect(page).not_to have_link('Login Headhunter', href: new_headhunter_session_path) | ||
end | ||
end | ||
end | ||
|
||
it 'after Headhunter login and view title and menu content' do | ||
headhunter = Headhunter.create!(email: '[email protected]', password: 'test123') | ||
login_as(headhunter, scope: :headhunter) | ||
visit root_path | ||
context 'when login as headhunter and view title and menu content' do | ||
it 'see only the headhunter menu' do | ||
headhunter = Headhunter.create!(email: '[email protected]', password: 'test123') | ||
login_as(headhunter, scope: :headhunter) | ||
visit root_path | ||
|
||
expect(page).to have_content(I18n.t('choose_option')) | ||
expect(page).to have_link('All Jobs', href: root_path) | ||
within('nav') do | ||
expect(page).to have_content("#{I18n.t('you_are')} [email protected]") | ||
expect(page).to have_link('Logout Headhunter', href: destroy_headhunter_session_path) | ||
expect(page).to have_link(I18n.t('new_opening'), href: new_job_path) | ||
expect(page).to have_link(I18n.t('profiles'), href: profiles_path) | ||
expect(page).to have_link(I18n.t('stars'), href: stars_path) | ||
expect(page).to have_link(I18n.t('openings'), href: jobs_path) | ||
expect(page).not_to have_link(I18n.t('applies'), href: applies_path) | ||
expect(page).not_to have_link(Profile.model_name.human, href: new_profile_path) | ||
expect(page).not_to have_link('Logout User', href: destroy_user_session_path) | ||
expect(page).not_to have_link('Login User', href: new_user_session_path) | ||
expect(page).not_to have_link('Login Headhunter', href: new_headhunter_session_path) | ||
expect(page).to have_content(I18n.t('choose_option')) | ||
expect(page).to have_link('All Jobs', href: root_path) | ||
within('nav') do | ||
expect(page).to have_content("#{I18n.t('you_are')} [email protected]") | ||
expect(page).to have_link('Logout Headhunter', href: destroy_headhunter_session_path) | ||
expect(page).to have_link(I18n.t('new_opening'), href: new_job_path) | ||
expect(page).to have_link(I18n.t('profiles'), href: profiles_path) | ||
expect(page).to have_link(I18n.t('stars'), href: stars_path) | ||
expect(page).to have_link(I18n.t('openings'), href: jobs_path) | ||
expect(page).not_to have_link(I18n.t('applies'), href: applies_path) | ||
expect(page).not_to have_link(Profile.model_name.human, href: new_profile_path) | ||
expect(page).not_to have_link('Logout User', href: destroy_user_session_path) | ||
expect(page).not_to have_link('Login User', href: new_user_session_path) | ||
expect(page).not_to have_link('Login Headhunter', href: new_headhunter_session_path) | ||
end | ||
end | ||
end | ||
|
||
context 'when try to access a not found record' do | ||
it 'redirect to home page and return invalid page message' do | ||
visit profile_path(9_999_999_999) | ||
expect(current_path).to eq(root_path) | ||
expect(page).to have_content(I18n.t('errors.messages.invalid_page')) | ||
end | ||
end | ||
end |