]> git.openstreetmap.org Git - rails.git/blobdiff - test/controllers/diary_entries_controller_test.rb
Prefer find_by() instead of where().first
[rails.git] / test / controllers / diary_entries_controller_test.rb
index c9464ffeddd0bc36eec82d4480b696aac71ddef2..0c1e655512f23c003898bfc040b0206e8d9b21ff 100644 (file)
@@ -164,7 +164,7 @@ class DiaryEntriesControllerTest < ActionDispatch::IntegrationTest
     assert_response :success
     assert_template :new
 
-    assert_nil UserPreference.where(:user_id => user.id, :k => "diary.default_language").first
+    assert_nil UserPreference.find_by(:user => user, :k => "diary.default_language")
   end
 
   def test_create
@@ -189,7 +189,7 @@ class DiaryEntriesControllerTest < ActionDispatch::IntegrationTest
     # checks if user was subscribed
     assert_equal 1, entry.subscribers.length
 
-    assert_equal "en", UserPreference.where(:user_id => user.id, :k => "diary.default_language").first.v
+    assert_equal "en", UserPreference.find_by(:user => user, :k => "diary.default_language").v
   end
 
   def test_create_german
@@ -216,7 +216,7 @@ class DiaryEntriesControllerTest < ActionDispatch::IntegrationTest
     # checks if user was subscribed
     assert_equal 1, entry.subscribers.length
 
-    assert_equal "de", UserPreference.where(:user_id => user.id, :k => "diary.default_language").first.v
+    assert_equal "de", UserPreference.find_by(:user => user, :k => "diary.default_language").v
   end
 
   def test_new_spammy
@@ -563,35 +563,35 @@ 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 css_select("li.page-item a.page-link").first["href"]
+    get css_select("li.page-item .page-link").last["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"]
+    get css_select("li.page-item .page-link").last["href"]
     assert_response :success
-    assert_select "div.diary_post", :count => 10
+    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"]
+    get css_select("li.page-item .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
 
     # Go back to the first page
-    get css_select("li.page-item a.page-link").last["href"]
+    get css_select("li.page-item .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.disabled span.page-link", :text => "Newer Entries", :count => 1
   end
@@ -997,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}"