diff options
author | Gareth Rees <gareth@mysociety.org> | 2014-03-14 10:42:32 +0000 |
---|---|---|
committer | Gareth Rees <gareth@mysociety.org> | 2014-03-25 09:58:00 +0000 |
commit | 271adedcd705c7e6aa61e9706b5dc2832dea528f (patch) | |
tree | 9e32e9aee5c02574e3cd9da3cd79c5d31632208b /spec/controllers/admin_user_controller_spec.rb | |
parent | 8763a12fc51f72c9ccc195945fb191e35684aa23 (diff) |
Add specs for AdminUserController#modify_comment_visibility
Diffstat (limited to 'spec/controllers/admin_user_controller_spec.rb')
-rw-r--r-- | spec/controllers/admin_user_controller_spec.rb | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/spec/controllers/admin_user_controller_spec.rb b/spec/controllers/admin_user_controller_spec.rb index 99894a414..8b89506f9 100644 --- a/spec/controllers/admin_user_controller_spec.rb +++ b/spec/controllers/admin_user_controller_spec.rb @@ -44,3 +44,72 @@ describe AdminUserController, "when updating a user" do end end + +describe AdminUserController do + + describe :modify_comment_visibility do + + before(:each) do + @user = FactoryGirl.create(:user) + request.env["HTTP_REFERER"] = admin_user_show_path(@user) + end + + it 'redirects to the page the admin was previously on' do + comment = FactoryGirl.create(:visible_comment, :user => @user) + + post :modify_comment_visibility, { :id => @user.id, + :comment_ids => comment.id, + :hide_selected => 'hidden' } + + response.should redirect_to(admin_user_show_path(@user)) + end + + it 'sets the given comments visibility to hidden' do + comments = FactoryGirl.create_list(:visible_comment, 3, :user => @user) + comment_ids = comments.map(&:id) + + post :modify_comment_visibility, { :id => @user.id, + :comment_ids => comment_ids, + :hide_selected => 'hidden' } + + Comment.find(comment_ids).each { |comment| comment.should_not be_visible } + end + + it 'sets the given comments visibility to visible' do + comments = FactoryGirl.create_list(:hidden_comment, 3, :user => @user) + comment_ids = comments.map(&:id) + + post :modify_comment_visibility, { :id => @user.id, + :comment_ids => comment_ids, + :unhide_selected => 'visible' } + + Comment.find(comment_ids).each { |comment| comment.should be_visible } + end + + it 'only modifes the given list of comments' do + unaffected_comment = FactoryGirl.create(:hidden_comment, :user => @user) + affected_comment = FactoryGirl.create(:hidden_comment, :user => @user) + + post :modify_comment_visibility, { :id => @user.id, + :comment_ids => affected_comment.id, + :unhide_selected => 'visible' } + + Comment.find(unaffected_comment).should_not be_visible + Comment.find(affected_comment).should be_visible + end + + it 'preserves the visibility if a comment is already of the requested visibility' do + hidden_comment = FactoryGirl.create(:hidden_comment, :user => @user) + visible_comment = FactoryGirl.create(:visible_comment, :user => @user) + comment_ids = [hidden_comment.id, visible_comment.id] + + post :modify_comment_visibility, { :id => @user.id, + :comment_ids => comment_ids, + :unhide_selected => 'visible' } + + Comment.find(comment_ids).each { |c| c.should be_visible } + end + + end + +end |