-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2386 from alphagov/browser-extension
Add route for browser extension to get routed to publisher
- Loading branch information
Showing
3 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
class ContentItemController < ApplicationController | ||
def by_content_id | ||
artefact = | ||
Artefact.find_by(content_id: params[:content_id]) | ||
|
||
if artefact | ||
redirect_to edition_path(artefact.latest_edition) | ||
else | ||
redirect_to_root_path_with_error | ||
end | ||
rescue StandardError | ||
redirect_to_root_path_with_error | ||
end | ||
|
||
private | ||
|
||
def redirect_to_root_path_with_error | ||
flash[:danger] = "The requested content was not found" | ||
redirect_to root_path | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
require "test_helper" | ||
|
||
class ContentItemControllerTest < ActionController::TestCase | ||
def setup | ||
login_as_stub_user | ||
@edition = FactoryBot.create(:edition) | ||
end | ||
|
||
should "redirect to content by content_id" do | ||
get :by_content_id, params: { content_id: @edition.content_id } | ||
|
||
assert_redirected_to edition_path(@edition.artefact.latest_edition) | ||
end | ||
|
||
should "redirect to root with error message if content_id is not found" do | ||
get :by_content_id, params: { content_id: "#{@edition.artefact.content_id}wrong-id" } | ||
|
||
assert_redirected_to root_path | ||
assert_equal "The requested content was not found", flash[:danger] | ||
end | ||
|
||
should "redirect to root with error message if any error" do | ||
Artefact.any_instance.stubs(:find_by).raises(StandardError) | ||
|
||
get :by_content_id, params: { content_id: "#{@edition.artefact.content_id}wrong-id" } | ||
|
||
assert_equal "The requested content was not found", flash[:danger] | ||
assert_redirected_to root_path | ||
end | ||
end |