Commit 623e17f3 authored by Laurent Arnoud's avatar Laurent Arnoud

Fix rendering error message when list.key is not available

When a key is not found ActiveResource::ResourceNotFound is raised as a
result a 404 is rendered because of `rescue_from` in the
application_controller.
With this patch we are returning nil so we can show the error defined on
_list_menu to the browser.
parent d10dc9da
......@@ -17,6 +17,8 @@ class List < Base
def key
@key ||= Key.find(fingerprint, params: { list_id: self.id })
rescue ActiveResource::ResourceNotFound
nil
end
def headers_to_meta
......
require "rails_helper"
feature "User views a list" do
scenario "when the key is found but no admins present" do
email = "subscription1@example.org"
account = create(:account, email: email)
subscription1 = create(:subscription, email: email)
list = create(:list, email: email, subscriptions: [subscription1])
stub_request(
:get,
"https://localhost:4443/keys/59C71FB38AEE22E091C78259D06350440F759BD3.json?list_id=#{list.id}"
).to_return(status: 200, body: File.read(File.join(fixture_path, "key.json")))
sign_in(account)
visit(list_subscriptions_path(list))
expect(page).to have_content('This list is not functional!')
expect(page).to have_content("It needs at least one list-admin!")
WebMock.reset!
end
scenario "when the key is not found it show the error message" do
email = "subscription1@example.org"
account = create(:account, email: email)
subscription1 = create(:subscription, email: email, admin: true)
list = create(:list, email: email, subscriptions: [subscription1])
stub_request(
:get,
"https://localhost:4443/keys/59C71FB38AEE22E091C78259D06350440F759BD3.json?list_id=#{list.id}"
).to_return(status: 404, body: "[]")
sign_in(account)
visit(list_subscriptions_path(list))
expect(page).to have_content('This list is not functional!')
expect(page).to have_content("No list-key present for #{list.email}")
WebMock.reset!
end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment