]> git.openstreetmap.org Git - rails.git/blobdiff - test/controllers/diary_entries_controller_test.rb
Replace page numbers with ID based selection for diary indexes
[rails.git] / test / controllers / diary_entries_controller_test.rb
index b1e9b72f2ba5dc48cef62358286a12421acc9485..2bc6516bc3a1d14f64cae8d82ea2e9b16778f575 100644 (file)
@@ -325,7 +325,6 @@ class DiaryEntriesControllerTest < ActionDispatch::IntegrationTest
       assert_select "p", :text => /#{new_body}/, :count => 1
       assert_select "abbr[class='geo'][title='#{number_with_precision(new_latitude, :precision => 4)}; #{number_with_precision(new_longitude, :precision => 4)}']", :count => 1
       # As we're not logged in, check that you cannot edit
-      # print @response.body
       assert_select "a[href='/user/#{ERB::Util.u(entry.user.display_name)}/diary/#{entry.id}/edit']", :text => "Edit this entry", :count => 1
     end
 
@@ -565,11 +564,36 @@ class DiaryEntriesControllerTest < ActionDispatch::IntegrationTest
     get diary_entries_path
     assert_response :success
     assert_select "div.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 "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 "div.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 "div.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 "div.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
@@ -670,6 +694,11 @@ 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)