X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/b7893df84ed0de89bff772cd9bf94caf8fcfc383..783b5e3729228908d7404ae7404af1023501a906:/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 bd9f0ed71..8414e18a7 100644 --- a/test/controllers/diary_entries_controller_test.rb +++ b/test/controllers/diary_entries_controller_test.rb @@ -85,10 +85,18 @@ class DiaryEntriesControllerTest < ActionController::TestCase { :path => "/user/username/diary/1/hide", :method => :post }, { :controller => "diary_entries", :action => "hide", :display_name => "username", :id => "1" } ) + assert_routing( + { :path => "/user/username/diary/1/unhide", :method => :post }, + { :controller => "diary_entries", :action => "unhide", :display_name => "username", :id => "1" } + ) assert_routing( { :path => "/user/username/diary/1/hidecomment/2", :method => :post }, { :controller => "diary_entries", :action => "hidecomment", :display_name => "username", :id => "1", :comment => "2" } ) + assert_routing( + { :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 => :post }, { :controller => "diary_entries", :action => "subscribe", :display_name => "username", :id => "1" } @@ -279,9 +287,9 @@ class DiaryEntriesControllerTest < ActionController::TestCase :params => { :display_name => entry.user.display_name, :id => entry.id }, :session => { :user => entry.user } assert_response :success - assert_select "title", :text => /Edit diary entry/, :count => 1 + assert_select "title", :text => /Edit Diary Entry/, :count => 1 assert_select "div.content-heading", :count => 1 do - assert_select "h1", :text => /Edit diary entry/, :count => 1 + assert_select "h1", :text => /Edit Diary Entry/, :count => 1 end assert_select "div#content", :count => 1 do assert_select "form[action='/user/#{ERB::Util.u(entry.user.display_name)}/diary/#{entry.id}'][method=post]", :count => 1 do @@ -290,7 +298,7 @@ class DiaryEntriesControllerTest < ActionController::TestCase assert_select "select#diary_entry_language_code", :count => 1 assert_select "input#latitude[name='diary_entry[latitude]']", :count => 1 assert_select "input#longitude[name='diary_entry[longitude]']", :count => 1 - assert_select "input[name=commit][type=submit][value=Save]", :count => 1 + 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 @@ -520,8 +528,8 @@ class DiaryEntriesControllerTest < ActionController::TestCase def test_index_friends user = create(:user) other_user = create(:user) - friend = create(:friend, :befriender => user) - diary_entry = create(:diary_entry, :user => friend.befriendee) + friendship = create(:friendship, :befriender => user) + diary_entry = create(:diary_entry, :user => friendship.befriendee) _other_entry = create(:diary_entry, :user => other_user) # Try a list of diary entries for your friends when not logged in @@ -664,6 +672,18 @@ class DiaryEntriesControllerTest < ActionController::TestCase assert_match "<script>", response.body end + def test_feed_delay + create(:diary_entry, :created_at => 7.hours.ago) + create(:diary_entry, :created_at => 5.hours.ago) + get :rss, :params => { :format => :rss } + assert_select "rss>channel>item", :count => 2 + + with_diary_feed_delay(6) do + get :rss, :params => { :format => :rss } + assert_select "rss>channel>item", :count => 1 + end + end + def test_show user = create(:user) suspended_user = create(:user, :suspended) @@ -713,9 +733,9 @@ class DiaryEntriesControllerTest < ActionController::TestCase def test_hide user = create(:user) + diary_entry = create(:diary_entry, :user => user) # Try without logging in - diary_entry = create(:diary_entry, :user => user) post :hide, :params => { :display_name => user.display_name, :id => diary_entry.id } assert_response :forbidden @@ -729,6 +749,17 @@ class DiaryEntriesControllerTest < ActionController::TestCase assert_redirected_to :controller => :errors, :action => :forbidden assert_equal true, DiaryEntry.find(diary_entry.id).visible + # Now try as a moderator + post :hide, + :params => { :display_name => user.display_name, :id => diary_entry.id }, + :session => { :user => create(:moderator_user) } + assert_response :redirect + assert_redirected_to :action => :index, :display_name => user.display_name + assert_equal false, DiaryEntry.find(diary_entry.id).visible + + # Reset + diary_entry.reload.update(:visible => true) + # Finally try as an administrator post :hide, :params => { :display_name => user.display_name, :id => diary_entry.id }, @@ -738,11 +769,38 @@ class DiaryEntriesControllerTest < ActionController::TestCase assert_equal false, DiaryEntry.find(diary_entry.id).visible end + def test_unhide + user = create(:user) + + # Try without logging in + diary_entry = create(:diary_entry, :user => user, :visible => false) + post :unhide, + :params => { :display_name => user.display_name, :id => diary_entry.id } + assert_response :forbidden + assert_equal false, DiaryEntry.find(diary_entry.id).visible + + # Now try as a normal user + post :unhide, + :params => { :display_name => user.display_name, :id => diary_entry.id }, + :session => { :user => user } + assert_response :redirect + assert_redirected_to :controller => :errors, :action => :forbidden + assert_equal false, DiaryEntry.find(diary_entry.id).visible + + # Finally try as an administrator + post :unhide, + :params => { :display_name => user.display_name, :id => diary_entry.id }, + :session => { :user => create(:administrator_user) } + assert_response :redirect + assert_redirected_to :action => :index, :display_name => user.display_name + assert_equal true, DiaryEntry.find(diary_entry.id).visible + end + def test_hidecomment user = create(:user) - administrator_user = create(:administrator_user) diary_entry = create(:diary_entry, :user => user) diary_comment = create(:diary_comment, :diary_entry => diary_entry) + # Try without logging in post :hidecomment, :params => { :display_name => user.display_name, :id => diary_entry.id, :comment => diary_comment.id } @@ -757,15 +815,54 @@ class DiaryEntriesControllerTest < ActionController::TestCase assert_redirected_to :controller => :errors, :action => :forbidden assert_equal true, DiaryComment.find(diary_comment.id).visible + # Try as a moderator + post :hidecomment, + :params => { :display_name => user.display_name, :id => diary_entry.id, :comment => diary_comment.id }, + :session => { :user => create(:moderator_user) } + assert_response :redirect + assert_redirected_to :action => :show, :display_name => user.display_name, :id => diary_entry.id + assert_equal false, DiaryComment.find(diary_comment.id).visible + + # Reset + diary_comment.reload.update(:visible => true) + # Finally try as an administrator post :hidecomment, :params => { :display_name => user.display_name, :id => diary_entry.id, :comment => diary_comment.id }, - :session => { :user => administrator_user } + :session => { :user => create(:administrator_user) } assert_response :redirect assert_redirected_to :action => :show, :display_name => user.display_name, :id => diary_entry.id assert_equal false, DiaryComment.find(diary_comment.id).visible end + def test_unhidecomment + user = create(:user) + administrator_user = create(:administrator_user) + diary_entry = create(:diary_entry, :user => user) + diary_comment = create(:diary_comment, :diary_entry => diary_entry, :visible => false) + # Try without logging in + post :unhidecomment, + :params => { :display_name => user.display_name, :id => diary_entry.id, :comment => diary_comment.id } + assert_response :forbidden + assert_equal false, DiaryComment.find(diary_comment.id).visible + + # Now try as a normal user + post :unhidecomment, + :params => { :display_name => user.display_name, :id => diary_entry.id, :comment => diary_comment.id }, + :session => { :user => user } + assert_response :redirect + assert_redirected_to :controller => :errors, :action => :forbidden + assert_equal false, DiaryComment.find(diary_comment.id).visible + + # Finally try as an administrator + post :unhidecomment, + :params => { :display_name => user.display_name, :id => diary_entry.id, :comment => diary_comment.id }, + :session => { :user => administrator_user } + assert_response :redirect + assert_redirected_to :action => :show, :display_name => user.display_name, :id => diary_entry.id + assert_equal true, DiaryComment.find(diary_comment.id).visible + end + def test_comments user = create(:user) other_user = create(:user) @@ -897,4 +994,13 @@ class DiaryEntriesControllerTest < ActionController::TestCase 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