Skip to content

Commit

Permalink
Remove rescue_from :render_404 from frontend
Browse files Browse the repository at this point in the history
Rails knows how to render a 404, so this is unnecessary and can hide
errors.

Doing this is also necessary in order to test without full rails
installation directory (specifically with a public/404.html).
  • Loading branch information
jhawthorn committed Oct 26, 2017
1 parent f9eb6c6 commit 11658e4
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 16 deletions.
7 changes: 0 additions & 7 deletions core/lib/spree/core/controller_helpers/common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,6 @@ def accurate_title
current_store.seo_title
end

def render_404(_exception = nil)
respond_to do |type|
type.html { render status: :not_found, file: "#{::Rails.root}/public/404", formats: [:html], layout: nil }
type.all { render status: :not_found, nothing: true }
end
end

private

def set_user_language
Expand Down
1 change: 0 additions & 1 deletion frontend/app/controllers/spree/orders_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
module Spree
class OrdersController < Spree::StoreController
before_action :check_authorization
rescue_from ActiveRecord::RecordNotFound, with: :render_404
helper 'spree/products', 'spree/orders'

respond_to :html
Expand Down
1 change: 0 additions & 1 deletion frontend/app/controllers/spree/products_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ class ProductsController < Spree::StoreController
before_action :load_product, only: :show
before_action :load_taxon, only: :index

rescue_from ActiveRecord::RecordNotFound, with: :render_404
helper 'spree/taxons'

respond_to :html
Expand Down
1 change: 0 additions & 1 deletion frontend/app/controllers/spree/taxons_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
module Spree
class TaxonsController < Spree::StoreController
rescue_from ActiveRecord::RecordNotFound, with: :render_404
helper 'spree/products'

respond_to :html
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module Spree
let(:user) { create(:user) }
let(:guest_user) { create(:user) }
let(:order) { Spree::Order.create }
let(:variant) { create(:variant) }

it 'should understand order routes with token' do
expect(spree.token_order_path('R123456', 'ABCDEF')).to eq('/orders/R123456/token/ABCDEF')
Expand All @@ -25,11 +26,11 @@ module Spree
context '#populate' do
it 'should check if user is authorized for :edit' do
expect(controller).to receive(:authorize!).with(:edit, order, token)
post :populate, params: { token: token }
post :populate, params: { variant_id: variant.id, token: token }
end
it "should check against the specified order" do
expect(controller).to receive(:authorize!).with(:edit, specified_order, token)
post :populate, params: { id: specified_order.number, token: token }
post :populate, params: { id: specified_order.number, variant_id: variant.id, token: token }
end
end

Expand Down Expand Up @@ -95,8 +96,9 @@ module Spree

context 'when no token present' do
it 'should respond with 404' do
get :show, params: { id: 'R123' }
expect(response.code).to eq('404')
expect {
get :show, params: { id: 'R123' }
}.to raise_error(ActiveRecord::RecordNotFound)
end
end
end
Expand Down
5 changes: 3 additions & 2 deletions frontend/spec/controllers/spree/products_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
end

it "cannot view non-active products" do
get :show, params: { id: product.to_param }
expect(response.status).to eq(404)
expect {
get :show, params: { id: product.to_param }
}.to raise_error(ActiveRecord::RecordNotFound)
end

it "should provide the current user to the searcher class" do
Expand Down

0 comments on commit 11658e4

Please sign in to comment.