X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/6499b2603dbffce61d9427a06f0be13d59007b01..425b79b5cc79273b2c74e65b224d44458f7863dc:/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 2b4230db7..0f071914e 100644 --- a/test/controllers/diary_entries_controller_test.rb +++ b/test/controllers/diary_entries_controller_test.rb @@ -4,6 +4,7 @@ class DiaryEntriesControllerTest < ActionController::TestCase include ActionView::Helpers::NumberHelper def setup + super # Create the default language for diary entries create(:language, :code => "en") # Stub nominatim response for diary entry locations @@ -528,8 +529,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 @@ -733,9 +734,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 @@ -749,6 +750,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 }, @@ -787,9 +799,9 @@ class DiaryEntriesControllerTest < ActionController::TestCase 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 } @@ -804,10 +816,21 @@ 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 @@ -850,7 +873,7 @@ class DiaryEntriesControllerTest < ActionController::TestCase get :comments, :params => { :display_name => user.display_name } assert_response :success assert_template :comments - assert_select "table.messages" do + assert_select "table.table-striped" do assert_select "tr", :count => 1 # header, no comments end @@ -860,7 +883,7 @@ class DiaryEntriesControllerTest < ActionController::TestCase get :comments, :params => { :display_name => other_user.display_name } assert_response :success assert_template :comments - assert_select "table.messages" do + assert_select "table.table-striped" do assert_select "tr", :count => 2 # header and one comment end