Skip to content

Commit

Permalink
Fix not found pages
Browse files Browse the repository at this point in the history
  • Loading branch information
noracato committed Nov 21, 2024
1 parent 369ff79 commit 7f28fad
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 32 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%= render(partial: "saved_scenarios/block_right_sub_options", locals: { saved_scenario: saved_scenario }) %>
3 changes: 3 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
en:
undo: Undo

errors:
sorry: Oops! We're sorry

time:
formats:
short: "%-d %b %H:%M"
Expand Down
5 changes: 2 additions & 3 deletions public/404.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!DOCTYPE html>
<html>
<head>
<title>The page you were looking for doesn't exist (404)</title>
<title>ETM - Oops! We cannot find this page! </title>
<meta name="viewport" content="width=device-width,initial-scale=1">
<style>
.rails-default-error-page {
Expand Down Expand Up @@ -54,14 +54,13 @@
</style>
</head>

<body class="rails-default-error-page">
<body class="error-page">
<!-- This file lives in public/404.html -->
<div class="dialog">
<div>
<h1>The page you were looking for doesn't exist.</h1>
<p>You may have mistyped the address or the page may have moved.</p>
</div>
<p>If you are the application owner check the logs for more information.</p>
</div>
</body>
</html>
53 changes: 27 additions & 26 deletions spec/controllers/saved_scenario_users_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
let(:client) { Faraday.new(url: 'http://et.engine') }

# Non logged-in users should always receive 404 not-found responses
# when attempting to perform an action on SavedScenarioUsers.
# when attempting to perform an action on SavedScenarioUsers. Because
# of the current setup, some of these 404's are rendered as 302 redirects
describe 'a non-logged in visitor' do
let(:user) { FactoryBot.create(:user) }
let!(:scenario_owner) do
Expand All @@ -36,29 +37,29 @@
it 'cannot view the list of users for a saved scenario' do
get(:index, params: { saved_scenario_id: saved_scenario.id })

expect(response).to have_http_status(404)
expect(response).to have_http_status(302)
end

it 'cannot add a new user to a scenario' do
post(:create, format: :js, params: {
post(:create, format: :turbo_stream, params: {
saved_scenario_id: saved_scenario.id,
user_email: '[email protected]',
role_id: User::Roles.index_of(:scenario_owner)
})

expect(response).to have_http_status(404)
expect(response).to have_http_status(302)
end

it 'cannot update an existing scenario user' do
put(:update, format: :js, params: {
put(:update, format: :turbo_stream, params: {
saved_scenario_id: saved_scenario.id,
id: scenario_owner.id,
saved_scenario_user: {
role_id: User::Roles.index_of(:scenario_viewer)
}
})

expect(response).to have_http_status(404)
expect(response).to have_http_status(302)
end

it 'cannot remove an existing scenario user' do
Expand All @@ -67,7 +68,7 @@
id: scenario_owner.id
})

expect(response).to have_http_status(404)
expect(response).to have_http_status(302)
end
end

Expand Down Expand Up @@ -113,7 +114,7 @@
end

it 'is redirected when attempting to add a new user to a scenario' do
post(:create, format: :js, params: {
post(:create, format: :turbo_stream, params: {
saved_scenario_id: saved_scenario.id,
saved_scenario_user: {
user_email: '[email protected]',
Expand All @@ -125,7 +126,7 @@
end

it 'is redirected when attempting to update an existing scenario user' do
put(:update, format: :js, params: {
put(:update, format: :turbo_stream, params: {
saved_scenario_id: saved_scenario.id,
id: scenario_owner.id,
saved_scenario_user: {
Expand Down Expand Up @@ -158,7 +159,7 @@
end

it 'is redirected when attempting to add a new user to a scenario' do
post(:create, format: :js, params: {
post(:create, format: :turbo_stream, params: {
saved_scenario_id: saved_scenario.id,
saved_scenario_user: {
user_email: '[email protected]',
Expand All @@ -170,7 +171,7 @@
end

it 'is redirected when attempting to update an existing scenario user' do
put(:update, format: :js, params: {
put(:update, format: :turbo_stream, params: {
saved_scenario_id: saved_scenario.id,
id: scenario_owner.id,
saved_scenario_user: {
Expand Down Expand Up @@ -215,7 +216,7 @@
end

it 'can add a new user to a scenario' do
post(:create, format: :js, params: {
post(:create, format: :turbo_stream, params: {
saved_scenario_id: saved_scenario.id,
saved_scenario_user: {
user_email: '[email protected]',
Expand All @@ -240,7 +241,7 @@

it 'can update the role' do
# Promote viewer to owner!
put(:update, format: :js, params: {
put(:update, format: :turbo_stream, params: {
saved_scenario_id: saved_scenario.id,
id: scenario_viewer.id,
saved_scenario_user: {
Expand All @@ -256,7 +257,7 @@
end

it 'can remove the user' do
delete(:destroy, format: :js, params: {
delete(:destroy, format: :turbo_stream, params: {
saved_scenario_id: saved_scenario.id,
id: scenario_viewer.id
})
Expand All @@ -268,7 +269,7 @@
end

it "cannot change its own role if it's the last owner" do
put(:update, format: :js, params: {
put(:update, format: :turbo_stream, params: {
saved_scenario_id: saved_scenario.id,
id: scenario_owner.id,
saved_scenario_user: {
Expand Down Expand Up @@ -297,14 +298,14 @@
sign_in admin
end

it 'can not view the list of users for a saved scenario' do
it 'can view the list of users for a saved scenario' do
get(:index, params: { saved_scenario_id: saved_scenario.id })

expect(response).to have_http_status(404)
expect(response).to have_http_status(200)
end

it 'can not add a new user to a scenario' do
post(:create, format: :js, params: {
it 'can add a new user to a scenario' do
post(:create, format: :turbo_stream, params: {
saved_scenario_id: saved_scenario.id,
saved_scenario_user: {
user_email: '[email protected]',
Expand All @@ -314,7 +315,7 @@

expect(
saved_scenario.saved_scenario_users.where(user_email: '[email protected]').count
).to be(0)
).to be(1)
end

context 'when updating or removing an existing scenario user' do
Expand All @@ -327,9 +328,9 @@
)
end

it 'can not update the role' do
it 'can update the role' do
# Promote to owner!
put(:update, format: :js, params: {
put(:update, format: :turbo_stream, params: {
saved_scenario_id: saved_scenario.id,
id: scenario_viewer.id,
saved_scenario_user: {
Expand All @@ -340,19 +341,19 @@
expect(
saved_scenario.saved_scenario_users.find_by(user_email: '[email protected]')&.role_id
).to eq(
User::Roles.index_of(:scenario_viewer)
User::Roles.index_of(:scenario_owner)
)
end

it 'can not remove the user' do
delete(:destroy, format: :js, params: {
it 'can remove the user' do
delete(:destroy, format: :turbo_stream, params: {
saved_scenario_id: saved_scenario.id,
id: scenario_viewer.id
})

expect(
saved_scenario.saved_scenario_users.where(user_email: '[email protected]').count
).to be(1)
).to be(0)
end
end
end
Expand Down
6 changes: 3 additions & 3 deletions spec/services/create_saved_scenario_user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
end

it 'returns the scenario error messages' do
expect(result.errors).to eq(['Invalid email'])
expect(result.errors).to eq([ :user_email ])
end
end

Expand Down Expand Up @@ -96,9 +96,9 @@
end
end

context 'when the API response contains a found linked user' do
context 'when there is a found linked user' do
let(:existing_user) {create(:user)}
let(:api_result) { ServiceResult.success([{ 'role_id' => 1, 'user_id' => existing_user.id }]) }
let(:new_viewer_user_params) { { role_id: 1, user_email: existing_user.email } }

it 'returns a ServiceResult' do
expect(result).to be_a(ServiceResult)
Expand Down

0 comments on commit 7f28fad

Please sign in to comment.