From 84a899c2d42da2ffd4a454878009cb7144953688 Mon Sep 17 00:00:00 2001 From: Admir23 Date: Mon, 16 Oct 2017 22:07:55 +0200 Subject: [PATCH 1/4] error_pages --- Gemfile.lock | 2 +- app/assets/javascripts/errors.js | 2 + app/assets/stylesheets/application.scss | 32 +++++++++ app/controllers/errors_controller.rb | 15 +++++ app/helpers/errors_helper.rb | 2 + .../errors/internal_server_error.html.erb | 12 ++++ app/views/errors/not_found.html.erb | 12 ++++ .../errors/unprocessable_entity.html.erb | 12 ++++ config/application.rb | 3 + config/routes.rb | 5 ++ public/404.html | 67 ------------------- public/422.html | 67 ------------------- public/500.html | 66 ------------------ spec/controllers/errors_controller_spec.rb | 26 +++++++ spec/helpers/errors_helper_spec.rb | 15 +++++ .../internal_server_error.html.erb_spec.rb | 5 ++ spec/views/errors/not_found.html.erb_spec.rb | 5 ++ .../unprocessable_entity.html.erb_spec.rb | 5 ++ 18 files changed, 152 insertions(+), 201 deletions(-) create mode 100644 app/assets/javascripts/errors.js create mode 100644 app/controllers/errors_controller.rb create mode 100644 app/helpers/errors_helper.rb create mode 100644 app/views/errors/internal_server_error.html.erb create mode 100644 app/views/errors/not_found.html.erb create mode 100644 app/views/errors/unprocessable_entity.html.erb delete mode 100644 public/404.html delete mode 100644 public/422.html delete mode 100644 public/500.html create mode 100644 spec/controllers/errors_controller_spec.rb create mode 100644 spec/helpers/errors_helper_spec.rb create mode 100644 spec/views/errors/internal_server_error.html.erb_spec.rb create mode 100644 spec/views/errors/not_found.html.erb_spec.rb create mode 100644 spec/views/errors/unprocessable_entity.html.erb_spec.rb diff --git a/Gemfile.lock b/Gemfile.lock index e13a405..2e4c911 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -308,4 +308,4 @@ RUBY VERSION ruby 2.4.1p111 BUNDLED WITH - 1.15.4 + 1.16.0.pre.3 diff --git a/app/assets/javascripts/errors.js b/app/assets/javascripts/errors.js new file mode 100644 index 0000000..dee720f --- /dev/null +++ b/app/assets/javascripts/errors.js @@ -0,0 +1,2 @@ +// Place all the behaviors and hooks related to the matching controller here. +// All this logic will automatically be available in application.js. diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index b1b2209..86f17e5 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -7,3 +7,35 @@ /* local */ @import "variables"; @import "playtime"; + + +// Error pages css +.error { + margin: 0 auto; + text-align: center; +} + +.error-code { + bottom: 60%; + color: #2d353c; + font-size: 96px; + line-height: 100px; +} + +.error-desc { + font-size: 12px; + color: #647788; +} + +.m-b-10 { + margin-bottom: 10px!important; +} + +.m-b-20 { + margin-bottom: 20px!important; +} + +.m-t-20 { + margin-top: 20px!important; +} + diff --git a/app/controllers/errors_controller.rb b/app/controllers/errors_controller.rb new file mode 100644 index 0000000..d5695b8 --- /dev/null +++ b/app/controllers/errors_controller.rb @@ -0,0 +1,15 @@ +class ErrorsController < ApplicationController + before_action :skip_authorization + + def not_found + render(:status => 404) + end + + def internal_server_error + render(:status => 500) + end + + def unprocessable_entity + render(:status => 422) + end +end diff --git a/app/helpers/errors_helper.rb b/app/helpers/errors_helper.rb new file mode 100644 index 0000000..8e3b415 --- /dev/null +++ b/app/helpers/errors_helper.rb @@ -0,0 +1,2 @@ +module ErrorsHelper +end diff --git a/app/views/errors/internal_server_error.html.erb b/app/views/errors/internal_server_error.html.erb new file mode 100644 index 0000000..7802b34 --- /dev/null +++ b/app/views/errors/internal_server_error.html.erb @@ -0,0 +1,12 @@ +
+
+

We couldn't find the page..

+
+ Sorry, but the page you are looking for was either not found or does not exist.
+ Try refreshing the page or click the button below to go back to the Homepage. +
+ + <%= link_to 'Go back to Homepage', root_path , class:"login-detail-panel-button btn" %> +
+
+
\ No newline at end of file diff --git a/app/views/errors/not_found.html.erb b/app/views/errors/not_found.html.erb new file mode 100644 index 0000000..7802b34 --- /dev/null +++ b/app/views/errors/not_found.html.erb @@ -0,0 +1,12 @@ +
+
+

We couldn't find the page..

+
+ Sorry, but the page you are looking for was either not found or does not exist.
+ Try refreshing the page or click the button below to go back to the Homepage. +
+ + <%= link_to 'Go back to Homepage', root_path , class:"login-detail-panel-button btn" %> +
+
+
\ No newline at end of file diff --git a/app/views/errors/unprocessable_entity.html.erb b/app/views/errors/unprocessable_entity.html.erb new file mode 100644 index 0000000..7802b34 --- /dev/null +++ b/app/views/errors/unprocessable_entity.html.erb @@ -0,0 +1,12 @@ +
+
+

We couldn't find the page..

+
+ Sorry, but the page you are looking for was either not found or does not exist.
+ Try refreshing the page or click the button below to go back to the Homepage. +
+ + <%= link_to 'Go back to Homepage', root_path , class:"login-detail-panel-button btn" %> +
+
+
\ No newline at end of file diff --git a/config/application.rb b/config/application.rb index feff585..aeb432c 100644 --- a/config/application.rb +++ b/config/application.rb @@ -13,6 +13,9 @@ class Application < Rails::Application # Initialize configuration defaults for originally generated Rails version. config.load_defaults 5.1 + # Serve error pages from the app + config.exceptions_app = self.routes + # Settings in config/environments/* take precedence over those specified here. # Application configuration should go into files in config/initializers # -- all .rb files in that directory are automatically loaded. diff --git a/config/routes.rb b/config/routes.rb index d0f0ce9..2de626c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,9 @@ Rails.application.routes.draw do + # Error Pages + get '/404', :to => 'errors#not_found' + get '/500', :to => 'errors#internal_server_error' + get '/422', :to => 'errors#unprocessable_entity' + # Pledges resources :pledges, except: [:new] do patch :claim diff --git a/public/404.html b/public/404.html deleted file mode 100644 index 2be3af2..0000000 --- a/public/404.html +++ /dev/null @@ -1,67 +0,0 @@ - - - - The page you were looking for doesn't exist (404) - - - - - - -
-
-

The page you were looking for doesn't exist.

-

You may have mistyped the address or the page may have moved.

-
-

If you are the application owner check the logs for more information.

-
- - diff --git a/public/422.html b/public/422.html deleted file mode 100644 index c08eac0..0000000 --- a/public/422.html +++ /dev/null @@ -1,67 +0,0 @@ - - - - The change you wanted was rejected (422) - - - - - - -
-
-

The change you wanted was rejected.

-

Maybe you tried to change something you didn't have access to.

-
-

If you are the application owner check the logs for more information.

-
- - diff --git a/public/500.html b/public/500.html deleted file mode 100644 index 78a030a..0000000 --- a/public/500.html +++ /dev/null @@ -1,66 +0,0 @@ - - - - We're sorry, but something went wrong (500) - - - - - - -
-
-

We're sorry, but something went wrong.

-
-

If you are the application owner check the logs for more information.

-
- - diff --git a/spec/controllers/errors_controller_spec.rb b/spec/controllers/errors_controller_spec.rb new file mode 100644 index 0000000..f390cf1 --- /dev/null +++ b/spec/controllers/errors_controller_spec.rb @@ -0,0 +1,26 @@ +require 'rails_helper' + +RSpec.describe ErrorsController, type: :controller do + + describe "GET #not_found" do + it "returns http success" do + get :not_found + expect(response).to have_http_status(:success) + end + end + + describe "GET #internal_server_error" do + it "returns http success" do + get :internal_server_error + expect(response).to have_http_status(:success) + end + end + + describe "GET #unprocessable_entity" do + it "returns http success" do + get :unprocessable_entity + expect(response).to have_http_status(:success) + end + end + +end diff --git a/spec/helpers/errors_helper_spec.rb b/spec/helpers/errors_helper_spec.rb new file mode 100644 index 0000000..e359203 --- /dev/null +++ b/spec/helpers/errors_helper_spec.rb @@ -0,0 +1,15 @@ +require 'rails_helper' + +# Specs in this file have access to a helper object that includes +# the ErrorsHelper. For example: +# +# describe ErrorsHelper do +# describe "string concat" do +# it "concats two strings with spaces" do +# expect(helper.concat_strings("this","that")).to eq("this that") +# end +# end +# end +RSpec.describe ErrorsHelper, type: :helper do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/views/errors/internal_server_error.html.erb_spec.rb b/spec/views/errors/internal_server_error.html.erb_spec.rb new file mode 100644 index 0000000..2ae6ed2 --- /dev/null +++ b/spec/views/errors/internal_server_error.html.erb_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe "errors/internal_server_error.html.erb", type: :view do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/views/errors/not_found.html.erb_spec.rb b/spec/views/errors/not_found.html.erb_spec.rb new file mode 100644 index 0000000..4e0eed4 --- /dev/null +++ b/spec/views/errors/not_found.html.erb_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe "errors/not_found.html.erb", type: :view do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/views/errors/unprocessable_entity.html.erb_spec.rb b/spec/views/errors/unprocessable_entity.html.erb_spec.rb new file mode 100644 index 0000000..43c906d --- /dev/null +++ b/spec/views/errors/unprocessable_entity.html.erb_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe "errors/unprocessable_entity.html.erb", type: :view do + pending "add some examples to (or delete) #{__FILE__}" +end From 073c5692a58e6d6b9db4a54c79f08eb4817d5633 Mon Sep 17 00:00:00 2001 From: nico24687 Date: Tue, 27 Mar 2018 19:43:54 -0600 Subject: [PATCH 2/4] updated expected status codes in error specs --- app/assets/stylesheets/application.scss | 2 +- app/controllers/errors_controller.rb | 1 + .../errors/internal_server_error.html.erb | 7 ++++--- app/views/errors/not_found.html.erb | 2 +- app/views/errors/unprocessable_entity.html.erb | 7 +++---- app/views/layouts/error.html.erb | 18 ++++++++++++++++++ spec/controllers/errors_controller_spec.rb | 6 +++--- 7 files changed, 31 insertions(+), 12 deletions(-) create mode 100644 app/views/layouts/error.html.erb diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index 86f17e5..39b9123 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -11,7 +11,7 @@ // Error pages css .error { - margin: 0 auto; + margin: 150px auto; text-align: center; } diff --git a/app/controllers/errors_controller.rb b/app/controllers/errors_controller.rb index d5695b8..42af3e2 100644 --- a/app/controllers/errors_controller.rb +++ b/app/controllers/errors_controller.rb @@ -1,5 +1,6 @@ class ErrorsController < ApplicationController before_action :skip_authorization + layout "error" def not_found render(:status => 404) diff --git a/app/views/errors/internal_server_error.html.erb b/app/views/errors/internal_server_error.html.erb index 7802b34..d0ccc0d 100644 --- a/app/views/errors/internal_server_error.html.erb +++ b/app/views/errors/internal_server_error.html.erb @@ -1,9 +1,10 @@
-

We couldn't find the page..

+

Oops, something went wrong

- Sorry, but the page you are looking for was either not found or does not exist.
- Try refreshing the page or click the button below to go back to the Homepage. + The server is unavailable for the moment. We're doing everything we can to correct the problem. +
+ Please try again later.
<%= link_to 'Go back to Homepage', root_path , class:"login-detail-panel-button btn" %> diff --git a/app/views/errors/not_found.html.erb b/app/views/errors/not_found.html.erb index 7802b34..8a670ec 100644 --- a/app/views/errors/not_found.html.erb +++ b/app/views/errors/not_found.html.erb @@ -1,6 +1,6 @@
-

We couldn't find the page..

+

We couldn't find the page

Sorry, but the page you are looking for was either not found or does not exist.
Try refreshing the page or click the button below to go back to the Homepage. diff --git a/app/views/errors/unprocessable_entity.html.erb b/app/views/errors/unprocessable_entity.html.erb index 7802b34..8a2c9cd 100644 --- a/app/views/errors/unprocessable_entity.html.erb +++ b/app/views/errors/unprocessable_entity.html.erb @@ -1,9 +1,8 @@ -
+
-

We couldn't find the page..

+

The change you wanted was rejected

- Sorry, but the page you are looking for was either not found or does not exist.
- Try refreshing the page or click the button below to go back to the Homepage. + Maybe you tried to change something you didn't have access to.
<%= link_to 'Go back to Homepage', root_path , class:"login-detail-panel-button btn" %> diff --git a/app/views/layouts/error.html.erb b/app/views/layouts/error.html.erb new file mode 100644 index 0000000..fbd8f1c --- /dev/null +++ b/app/views/layouts/error.html.erb @@ -0,0 +1,18 @@ + + + + Playtime + <%= csrf_meta_tags %> + <%= favicon_link_tag 'favicon.png' %> + <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %> + <%= favicon_link_tag 'https://www.playtimeproject.org/wp-content/uploads/2013/03/Logo-no-words-e1363625449703.png'%> + + + + + <%= yield %> + + + diff --git a/spec/controllers/errors_controller_spec.rb b/spec/controllers/errors_controller_spec.rb index f390cf1..8aadf97 100644 --- a/spec/controllers/errors_controller_spec.rb +++ b/spec/controllers/errors_controller_spec.rb @@ -5,21 +5,21 @@ describe "GET #not_found" do it "returns http success" do get :not_found - expect(response).to have_http_status(:success) + expect(response).to have_http_status(:not_found) end end describe "GET #internal_server_error" do it "returns http success" do get :internal_server_error - expect(response).to have_http_status(:success) + expect(response).to have_http_status(:internal_server_error) end end describe "GET #unprocessable_entity" do it "returns http success" do get :unprocessable_entity - expect(response).to have_http_status(:success) + expect(response).to have_http_status(:unprocessable_entity) end end From 6e8858530f537256b2493c9c8628e5db4e8af12c Mon Sep 17 00:00:00 2001 From: nico24687 Date: Tue, 27 Mar 2018 19:45:50 -0600 Subject: [PATCH 3/4] Remove unused error specs --- app/helpers/errors_helper.rb | 2 -- spec/helpers/errors_helper_spec.rb | 15 --------------- .../errors/internal_server_error.html.erb_spec.rb | 5 ----- spec/views/errors/not_found.html.erb_spec.rb | 5 ----- .../errors/unprocessable_entity.html.erb_spec.rb | 5 ----- 5 files changed, 32 deletions(-) delete mode 100644 app/helpers/errors_helper.rb delete mode 100644 spec/helpers/errors_helper_spec.rb delete mode 100644 spec/views/errors/internal_server_error.html.erb_spec.rb delete mode 100644 spec/views/errors/not_found.html.erb_spec.rb delete mode 100644 spec/views/errors/unprocessable_entity.html.erb_spec.rb diff --git a/app/helpers/errors_helper.rb b/app/helpers/errors_helper.rb deleted file mode 100644 index 8e3b415..0000000 --- a/app/helpers/errors_helper.rb +++ /dev/null @@ -1,2 +0,0 @@ -module ErrorsHelper -end diff --git a/spec/helpers/errors_helper_spec.rb b/spec/helpers/errors_helper_spec.rb deleted file mode 100644 index e359203..0000000 --- a/spec/helpers/errors_helper_spec.rb +++ /dev/null @@ -1,15 +0,0 @@ -require 'rails_helper' - -# Specs in this file have access to a helper object that includes -# the ErrorsHelper. For example: -# -# describe ErrorsHelper do -# describe "string concat" do -# it "concats two strings with spaces" do -# expect(helper.concat_strings("this","that")).to eq("this that") -# end -# end -# end -RSpec.describe ErrorsHelper, type: :helper do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/views/errors/internal_server_error.html.erb_spec.rb b/spec/views/errors/internal_server_error.html.erb_spec.rb deleted file mode 100644 index 2ae6ed2..0000000 --- a/spec/views/errors/internal_server_error.html.erb_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe "errors/internal_server_error.html.erb", type: :view do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/views/errors/not_found.html.erb_spec.rb b/spec/views/errors/not_found.html.erb_spec.rb deleted file mode 100644 index 4e0eed4..0000000 --- a/spec/views/errors/not_found.html.erb_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe "errors/not_found.html.erb", type: :view do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/views/errors/unprocessable_entity.html.erb_spec.rb b/spec/views/errors/unprocessable_entity.html.erb_spec.rb deleted file mode 100644 index 43c906d..0000000 --- a/spec/views/errors/unprocessable_entity.html.erb_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe "errors/unprocessable_entity.html.erb", type: :view do - pending "add some examples to (or delete) #{__FILE__}" -end From e87bc63564bf7ec8d4d86fca936e4d5dbc8352a8 Mon Sep 17 00:00:00 2001 From: nico24687 Date: Tue, 27 Mar 2018 19:50:33 -0600 Subject: [PATCH 4/4] moved error styles into dedicated stylesheet --- app/assets/stylesheets/application.scss | 33 +------------------------ app/assets/stylesheets/error.scss | 29 ++++++++++++++++++++++ 2 files changed, 30 insertions(+), 32 deletions(-) create mode 100644 app/assets/stylesheets/error.scss diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index 39b9123..e46b2ee 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -7,35 +7,4 @@ /* local */ @import "variables"; @import "playtime"; - - -// Error pages css -.error { - margin: 150px auto; - text-align: center; -} - -.error-code { - bottom: 60%; - color: #2d353c; - font-size: 96px; - line-height: 100px; -} - -.error-desc { - font-size: 12px; - color: #647788; -} - -.m-b-10 { - margin-bottom: 10px!important; -} - -.m-b-20 { - margin-bottom: 20px!important; -} - -.m-t-20 { - margin-top: 20px!important; -} - +@import "error"; \ No newline at end of file diff --git a/app/assets/stylesheets/error.scss b/app/assets/stylesheets/error.scss new file mode 100644 index 0000000..5ed6e47 --- /dev/null +++ b/app/assets/stylesheets/error.scss @@ -0,0 +1,29 @@ +// Error pages css +.error { + margin: 150px auto; + text-align: center; +} + +.error-code { + bottom: 60%; + color: #2d353c; + font-size: 96px; + line-height: 100px; +} + +.error-desc { + font-size: 12px; + color: #647788; +} + +.m-b-10 { + margin-bottom: 10px!important; +} + +.m-b-20 { + margin-bottom: 20px!important; +} + +.m-t-20 { + margin-top: 20px!important; +} \ No newline at end of file