File tree 2 files changed +21
-1
lines changed 2 files changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -71,7 +71,16 @@ def index
71
71
end
72
72
73
73
def show
74
- page = Page . find ( params [ :id ] )
74
+ begin
75
+ page = Page . find ( params [ :id ] )
76
+ rescue ActiveRecord ::RecordNotFound
77
+ merge = MergedPage . find ( params [ :id ] )
78
+ redirect_to (
79
+ api_v0_page_url ( merge . target_uuid ) ,
80
+ status : :permanent_redirect
81
+ ) and return
82
+ end
83
+
75
84
data = page . as_json ( include : [ :maintainers , :tags ] )
76
85
if should_allow_versions
77
86
data [ 'versions' ] = page . versions . where ( different : true ) . as_json
Original file line number Diff line number Diff line change @@ -744,4 +744,15 @@ def get_all_pages(url)
744
744
body = JSON . parse ( @response . body )
745
745
assert ( body [ 'data' ] . all? { |page | page [ 'status' ] >= 400 && page [ 'status' ] < 500 } )
746
746
end
747
+
748
+ test 'redirects to new page if requested page was merged away' do
749
+ page1 = Page . create ( title : 'First Page' , url : 'https://example.gov/' )
750
+ page2 = Page . create ( title : 'Second Page' , url : 'https://example.gov/subpage' )
751
+ page1 . merge ( page2 )
752
+
753
+ sign_in users ( :alice )
754
+ get ( api_v0_page_url ( page2 ) )
755
+ assert_response ( :permanent_redirect )
756
+ assert_redirected_to ( api_v0_page_url ( page1 . uuid ) )
757
+ end
747
758
end
You can’t perform that action at this time.
0 commit comments