]> git.openstreetmap.org Git - rails.git/blobdiff - test/controllers/diary_entries_controller_test.rb
Drop user tokens table
[rails.git] / test / controllers / diary_entries_controller_test.rb
index c9464ffeddd0bc36eec82d4480b696aac71ddef2..e7d812b3e7fa8fabae7d9fe8151834eb601caeb3 100644 (file)
@@ -98,10 +98,18 @@ class DiaryEntriesControllerTest < ActionDispatch::IntegrationTest
       { :path => "/user/username/diary/1/unhidecomment/2", :method => :post },
       { :controller => "diary_entries", :action => "unhidecomment", :display_name => "username", :id => "1", :comment => "2" }
     )
+    assert_routing(
+      { :path => "/user/username/diary/1/subscribe", :method => :get },
+      { :controller => "diary_entries", :action => "subscribe", :display_name => "username", :id => "1" }
+    )
     assert_routing(
       { :path => "/user/username/diary/1/subscribe", :method => :post },
       { :controller => "diary_entries", :action => "subscribe", :display_name => "username", :id => "1" }
     )
+    assert_routing(
+      { :path => "/user/username/diary/1/unsubscribe", :method => :get },
+      { :controller => "diary_entries", :action => "unsubscribe", :display_name => "username", :id => "1" }
+    )
     assert_routing(
       { :path => "/user/username/diary/1/unsubscribe", :method => :post },
       { :controller => "diary_entries", :action => "unsubscribe", :display_name => "username", :id => "1" }
@@ -135,7 +143,7 @@ class DiaryEntriesControllerTest < ActionDispatch::IntegrationTest
         assert_select "input[name=commit][type=submit][value=Publish]", :count => 1
         assert_select "input[name=commit][type=submit][value=Edit]", :count => 1
         assert_select "input[name=commit][type=submit][value=Preview]", :count => 1
-        assert_select "input", :count => 7
+        assert_select "input", :count => 6
       end
     end
   end
@@ -164,7 +172,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 +197,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 +224,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
@@ -294,7 +302,7 @@ class DiaryEntriesControllerTest < ActionDispatch::IntegrationTest
         assert_select "input[name=commit][type=submit][value=Update]", :count => 1
         assert_select "input[name=commit][type=submit][value=Edit]", :count => 1
         assert_select "input[name=commit][type=submit][value=Preview]", :count => 1
-        assert_select "input", :count => 8
+        assert_select "input", :count => 7
       end
     end
 
@@ -563,35 +571,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
@@ -677,7 +685,7 @@ class DiaryEntriesControllerTest < ActionDispatch::IntegrationTest
     get diary_rss_path
     assert_select "rss>channel>item", :count => 2
 
-    with_diary_feed_delay(6) do
+    with_settings(:diary_feed_delay => 6) do
       get diary_rss_path
       assert_select "rss>channel>item", :count => 1
     end
@@ -695,9 +703,9 @@ class DiaryEntriesControllerTest < ActionDispatch::IntegrationTest
     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
+    get "/user/#{CGI.escape(user.display_name)}/diary/#{diary_entry.id})"
+    assert_response :not_found
+    assert_template "rescues/routing_error"
 
     # Try a deleted entry
     diary_entry_deleted = create(:diary_entry, :user => user, :visible => false)
@@ -916,6 +924,25 @@ class DiaryEntriesControllerTest < ActionDispatch::IntegrationTest
     assert_response :not_found
   end
 
+  def test_subscribe_page
+    user = create(:user)
+    other_user = create(:user)
+    diary_entry = create(:diary_entry, :user => user)
+    path = diary_entry_subscribe_path(:id => diary_entry, :display_name => user.display_name)
+
+    get path
+    assert_response :redirect
+    assert_redirected_to login_path(:referer => path)
+
+    session_for(other_user)
+    get path
+    assert_response :success
+    assert_dom ".content-body" do
+      assert_dom "a[href='#{diary_entry_path(:id => diary_entry, :display_name => user.display_name)}']", :text => diary_entry.title
+      assert_dom "a[href='#{user_path(user)}']", :text => user.display_name
+    end
+  end
+
   def test_subscribe_success
     user = create(:user)
     other_user = create(:user)
@@ -953,6 +980,25 @@ class DiaryEntriesControllerTest < ActionDispatch::IntegrationTest
     end
   end
 
+  def test_unsubscribe_page
+    user = create(:user)
+    other_user = create(:user)
+    diary_entry = create(:diary_entry, :user => user)
+    path = diary_entry_unsubscribe_path(:id => diary_entry, :display_name => user.display_name)
+
+    get path
+    assert_response :redirect
+    assert_redirected_to login_path(:referer => path)
+
+    session_for(other_user)
+    get path
+    assert_response :success
+    assert_dom ".content-body" do
+      assert_dom "a[href='#{diary_entry_path(:id => diary_entry, :display_name => user.display_name)}']", :text => diary_entry.title
+      assert_dom "a[href='#{user_path(user)}']", :text => user.display_name
+    end
+  end
+
   def test_unsubscribe_success
     user = create(:user)
     other_user = create(:user)
@@ -997,19 +1043,10 @@ 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}"
     end
   end
-
-  def with_diary_feed_delay(value)
-    diary_feed_delay = Settings.diary_feed_delay
-    Settings.diary_feed_delay = value
-
-    yield
-
-    Settings.diary_feed_delay = diary_feed_delay
-  end
 end