X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/5be5155e03b9e7989d2c8d3d244511c0b9b13eb7..6b633e9d4a49df1f9308ef392203437cb7742558:/test/controllers/diary_entries_controller_test.rb diff --git a/test/controllers/diary_entries_controller_test.rb b/test/controllers/diary_entries_controller_test.rb index 2003f9a08..6365d46e5 100644 --- a/test/controllers/diary_entries_controller_test.rb +++ b/test/controllers/diary_entries_controller_test.rb @@ -563,12 +563,37 @@ class DiaryEntriesControllerTest < ActionDispatch::IntegrationTest # Try and get the index get diary_entries_path assert_response :success - assert_select "div.diary_post", :count => 20 + assert_select "article.diary_post", :count => 20 + assert_select "li.page-item a.page-link", :text => "Older Entries", :count => 1 + assert_select "li.page-item.disabled span.page-link", :text => "Newer Entries", :count => 1 # Try and get the second page - get diary_entries_path(:page => 2) + get css_select("li.page-item a.page-link").first["href"] assert_response :success - assert_select "div.diary_post", :count => 20 + assert_select "article.diary_post", :count => 20 + assert_select "li.page-item a.page-link", :text => "Older Entries", :count => 1 + assert_select "li.page-item a.page-link", :text => "Newer Entries", :count => 1 + + # Try and get the third page + get css_select("li.page-item a.page-link").first["href"] + assert_response :success + assert_select "article.diary_post", :count => 10 + assert_select "li.page-item.disabled span.page-link", :text => "Older Entries", :count => 1 + assert_select "li.page-item a.page-link", :text => "Newer Entries", :count => 1 + + # Go back to the second page + get css_select("li.page-item a.page-link").last["href"] + assert_response :success + assert_select "article.diary_post", :count => 20 + assert_select "li.page-item a.page-link", :text => "Older Entries", :count => 1 + assert_select "li.page-item a.page-link", :text => "Newer Entries", :count => 1 + + # Go back to the first page + get css_select("li.page-item a.page-link").last["href"] + assert_response :success + assert_select "article.diary_post", :count => 20 + assert_select "li.page-item a.page-link", :text => "Older Entries", :count => 1 + assert_select "li.page-item.disabled span.page-link", :text => "Newer Entries", :count => 1 end def test_rss @@ -669,20 +694,37 @@ class DiaryEntriesControllerTest < ActionDispatch::IntegrationTest assert_response :success assert_template :show + # Try a non-integer ID + assert_raise ActionController::RoutingError do + get "/user/#{CGI.escape(user.display_name)}/diary/#{diary_entry.id})" + end + # Try a deleted entry diary_entry_deleted = create(:diary_entry, :user => user, :visible => false) get diary_entry_path(:display_name => user.display_name, :id => diary_entry_deleted) assert_response :not_found # Try an entry by a suspended user - diary_entry_suspended = create(:diary_entry, :user => suspended_user) - get diary_entry_path(:display_name => suspended_user.display_name, :id => diary_entry_suspended) + diary_entry_suspended_user = create(:diary_entry, :user => suspended_user) + get diary_entry_path(:display_name => suspended_user.display_name, :id => diary_entry_suspended_user) assert_response :not_found # Try an entry by a deleted user - diary_entry_deleted = create(:diary_entry, :user => deleted_user) - get diary_entry_path(:display_name => deleted_user.display_name, :id => diary_entry_deleted) + diary_entry_deleted_user = create(:diary_entry, :user => deleted_user) + get diary_entry_path(:display_name => deleted_user.display_name, :id => diary_entry_deleted_user) assert_response :not_found + + # Now try as a moderator + session_for(create(:moderator_user)) + get diary_entry_path(:display_name => user.display_name, :id => diary_entry_deleted) + assert_response :success + assert_template :show + + # Finally try as an administrator + session_for(create(:administrator_user)) + get diary_entry_path(:display_name => user.display_name, :id => diary_entry_deleted) + assert_response :success + assert_template :show end def test_show_hidden_comments @@ -759,8 +801,11 @@ class DiaryEntriesControllerTest < ActionDispatch::IntegrationTest session_for(create(:moderator_user)) post unhide_diary_entry_path(:display_name => user.display_name, :id => diary_entry) assert_response :redirect - assert_redirected_to :controller => :errors, :action => :forbidden - assert_not DiaryEntry.find(diary_entry.id).visible + assert_redirected_to :action => :index, :display_name => user.display_name + assert DiaryEntry.find(diary_entry.id).visible + + # Reset + diary_entry.reload.update(:visible => true) # Finally try as an administrator session_for(create(:administrator_user)) @@ -826,8 +871,11 @@ class DiaryEntriesControllerTest < ActionDispatch::IntegrationTest session_for(create(:moderator_user)) post unhide_diary_comment_path(:display_name => user.display_name, :id => diary_entry, :comment => diary_comment) assert_response :redirect - assert_redirected_to :controller => :errors, :action => :forbidden - assert_not DiaryComment.find(diary_comment.id).visible + assert_redirected_to :action => :show, :display_name => user.display_name, :id => diary_entry.id + assert DiaryComment.find(diary_comment.id).visible + + # Reset + diary_comment.reload.update(:visible => true) # Finally try as an administrator session_for(create(:administrator_user)) @@ -949,7 +997,7 @@ class DiaryEntriesControllerTest < ActionDispatch::IntegrationTest assert_response :success assert_template "index" assert_no_missing_translations - assert_select "div.diary_post", entries.count + assert_select "article.diary_post", entries.count entries.each do |entry| assert_select "a[href=?]", "/user/#{ERB::Util.u(entry.user.display_name)}/diary/#{entry.id}"