Skip to content

Commit

Permalink
404 when no invoice found
Browse files Browse the repository at this point in the history
it's mostly a problem for crawlers
at the app level it feels like there should be some better encapsulation of this crosscutting concern of not existing data

for now, treating each resource separately, but tests together
  • Loading branch information
andrzejkrzywda committed Aug 18, 2024
1 parent 6f21f6c commit b432b09
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 8 deletions.
4 changes: 4 additions & 0 deletions rails_application/app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@ def event_store
def command_bus
Rails.configuration.command_bus
end

def not_found
render file: "#{Rails.root}/public/404.html", layout: false, status: :not_found
end
end
1 change: 1 addition & 0 deletions rails_application/app/controllers/invoices_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
class InvoicesController < ApplicationController
def show
@invoice = Invoices::Invoice.find_by_order_uid(params[:id])
not_found unless @invoice
end

def create
Expand Down
3 changes: 0 additions & 3 deletions rails_application/app/controllers/orders_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,4 @@ def capture_payment_cmd(order_id)
Payments::CapturePayment.new(order_id: order_id)
end

def not_found
render file: "#{Rails.root}/public/404.html", layout: false, status: :not_found
end
end
5 changes: 0 additions & 5 deletions rails_application/test/integration/orders_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,6 @@ def test_expiring_orders
assert_select("td", "Expired")
end

def test_order_not_found
get "/orders/123"
assert_response :not_found
end

def test_cancel
shopify_id = register_customer("Shopify")

Expand Down
15 changes: 15 additions & 0 deletions rails_application/test/integration/routing_404_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
require "test_helper"

class MissingResourcesTest < InMemoryRESIntegrationTestCase


def test_order_not_found
get "/orders/123"
assert_response :not_found
end

def test_invoice_not_found
get "/invoices/123"
assert_response :not_found
end
end

0 comments on commit b432b09

Please sign in to comment.