#465 update commit comment specs

This commit is contained in:
Alexander Machehin 2015-04-13 15:26:51 +05:00
parent dd58b4a0a5
commit aa81ec6d53
1 changed files with 300 additions and 325 deletions

View File

@ -1,325 +1,300 @@
# require 'spec_helper' require 'spec_helper'
# require "cancan/matchers"
# def create_comment user
# def create_comment user FactoryGirl.create(:comment, user: user, commentable: @commit, project: @project)
# FactoryGirl.create(:comment, user: user, commentable: @commit, project: @project) end
# end
# def create_comment_in_commit commit, project, body
# def create_comment_in_commit commit, project, body FactoryGirl.create(:comment, user: @user, commentable: commit, project: project, body: body)
# FactoryGirl.create(:comment, user: @user, commentable: commit, project: project, body: body) end
# end
# def set_comments_data_for_commit
# def set_comments_data_for_commit @project = FactoryGirl.create(:project_with_commit, owner: @user)
# @ability = Ability.new(@user) @commit = @project.repo.commits.first
#
# @project = FactoryGirl.create(:project_with_commit, owner: @user) @comment = create_comment(@user)
# @commit = @project.repo.commits.first @stranger_comment = create_comment(@stranger)
#
# @comment = create_comment(@user) @subscribe_params = {project_id: @project.id, subscribeable_id: @commit.id.hex, subscribeable_type: @commit.class.name}
# @stranger_comment = create_comment(@stranger) Subscribe.destroy_all
#
# @subscribe_params = {project_id: @project.id, subscribeable_id: @commit.id.hex, subscribeable_type: @commit.class.name} allow_any_instance_of(Project).to receive(:versions).and_return(%w(v1.0 v2.0))
# Subscribe.destroy_all end
#
# allow_any_instance_of(Project).to receive(:versions).and_return(%w(v1.0 v2.0)) def should_send_email(args={})
# end user_mailer = double(:user_mailer)
# expect(UserMailer).to receive(:new_comment_notification).with(kind_of(Comment), args[:receiver].id).and_return(user_mailer)
# def should_send_email(args={}) expect(user_mailer).to receive(:deliver)
# user_mailer = double(:user_mailer)
# expect(UserMailer).to receive(:new_comment_notification).with(kind_of(Comment), args[:receiver].id).and_return(user_mailer) create_comment args[:commentor]
# expect(user_mailer).to receive(:deliver) end
#
# create_comment args[:commentor] def should_not_send_email(args={})
# end expect(UserMailer).to_not receive(:new_comment_notification)
# create_comment args[:commentor]
# def should_not_send_email(args={}) end
# expect(UserMailer).to_not receive(:new_comment_notification)
# create_comment args[:commentor] describe Comment do
# end before { stub_symlink_methods }
#
# describe Comment do context 'for project admin user' do
# before { stub_symlink_methods } before do
# context 'for global admin user' do @user = FactoryGirl.create(:user)
# before(:each) do @stranger = FactoryGirl.create(:user)
# @user = FactoryGirl.create(:admin)
# @stranger = FactoryGirl.create(:user) set_comments_data_for_commit
# @admin = FactoryGirl.create(:user)
# set_comments_data_for_commit create_relation(@project, @admin, 'admin')
# end end
#
# it_should_behave_like 'user with create comment ability (for model)' it 'should send an e-mail by default settings' do
# it_should_behave_like 'user with update own comment ability (for model)' should_send_email(commentor: @stranger, receiver: @user)
# it_should_behave_like 'user with update stranger comment ability (for model)' end
# it_should_behave_like 'user with destroy comment ability (for model)'
# it_should_behave_like 'user with destroy stranger comment ability (for model)' context 'for disabled notify setting new_comment_commit_repo_owner' do
# end it 'should send an e-mail' do
# @user.notifier.update_column :new_comment_commit_repo_owner, false
# context 'for project admin user' do should_send_email(commentor: @stranger, receiver: @user)
# before do end
# @user = FactoryGirl.create(:user) end
# @stranger = FactoryGirl.create(:user)
# context 'for disabled notify setting new_comment_commit_owner' do
# set_comments_data_for_commit it 'should send an e-mail' do
# @admin = FactoryGirl.create(:user) @user.notifier.update_column :new_comment_commit_owner, false
# @ability = Ability.new(@admin) should_send_email(commentor: @stranger, receiver: @user)
# create_relation(@project, @admin, 'admin') end
# end end
#
# it_should_behave_like 'user with create comment ability (for model)' context 'for disabled notify setting new_comment_commit_commentor' do
# it_should_behave_like 'user with update own comment ability (for model)' it 'should send an e-mail' do
# it_should_behave_like 'user with update stranger comment ability (for model)' @user.notifier.update_column :new_comment_commit_commentor, false
# it_should_behave_like 'user with destroy comment ability (for model)' should_send_email(commentor: @stranger, receiver: @user)
# it_should_behave_like 'user with destroy stranger comment ability (for model)' end
# end
# it 'should send an e-mail by default settings' do
# should_send_email(commentor: @stranger, receiver: @user) context 'for disabled all notify setting expect global' do
# end it 'should not send an e-mail' do
# @user.notifier.update_column :new_comment_commit_repo_owner, false
# context 'for disabled notify setting new_comment_commit_repo_owner' do @user.notifier.update_column :new_comment_commit_owner, false
# it 'should send an e-mail' do @user.notifier.update_column :new_comment_commit_commentor, false
# @user.notifier.update_column :new_comment_commit_repo_owner, false should_not_send_email(commentor: @stranger)
# should_send_email(commentor: @stranger, receiver: @user) end
# end end
# end
# context 'for unsubscribe commit' do
# context 'for disabled notify setting new_comment_commit_owner' do it 'should not send an e-mail' do
# it 'should send an e-mail' do Subscribe.unsubscribe_from_commit @subscribe_params.merge(user_id: @user.id)
# @user.notifier.update_column :new_comment_commit_owner, false should_not_send_email(commentor: @stranger)
# should_send_email(commentor: @stranger, receiver: @user) end
# end end
# end
# context 'for disabled global notify setting' do
# context 'for disabled notify setting new_comment_commit_commentor' do it 'should not send an e-mail' do
# it 'should send an e-mail' do @user.notifier.update_column :can_notify, false
# @user.notifier.update_column :new_comment_commit_commentor, false should_not_send_email(commentor: @stranger)
# should_send_email(commentor: @stranger, receiver: @user) end
# end end
# end end
#
# context 'for disabled all notify setting expect global' do context 'for project owner user' do
# it 'should not send an e-mail' do before(:each) do
# @user.notifier.update_column :new_comment_commit_repo_owner, false @user = FactoryGirl.create(:user)
# @user.notifier.update_column :new_comment_commit_owner, false @stranger = FactoryGirl.create(:user)
# @user.notifier.update_column :new_comment_commit_commentor, false set_comments_data_for_commit
# should_not_send_email(commentor: @stranger)
# end @project.owner = @user
# end @project.save
# end
# context 'for unsubscribe commit' do
# it 'should not send an e-mail' do context 'for default enabled settings' do
# Subscribe.unsubscribe_from_commit @subscribe_params.merge(user_id: @user.id) it 'should send an e-mail by default settings' do
# should_not_send_email(commentor: @stranger) should_send_email(commentor: @stranger, receiver: @project.owner)
# end end
# end end
#
# context 'for disabled global notify setting' do context 'for disabled notify setting new_comment_commit_repo_owner' do
# it 'should not send an e-mail' do it 'should not send an e-mail' do
# @user.notifier.update_column :can_notify, false @user.notifier.update_column :new_comment_commit_repo_owner, false
# should_not_send_email(commentor: @stranger) Comment.destroy_all
# end should_not_send_email(commentor: @stranger)
# end end
# end end
#
# context 'for project owner user' do context 'for disabled notify setting new_comment_commit_owner' do
# before(:each) do it 'should send an e-mail' do
# @user = FactoryGirl.create(:user) @user.notifier.update_column :new_comment_commit_owner, false
# @stranger = FactoryGirl.create(:user) should_send_email(commentor: @stranger, receiver: @user)
# set_comments_data_for_commit end
# end
# @project.owner = @user
# @project.save context 'for disabled notify setting new_comment_commit_commentor' do
# end it 'should send an e-mail' do
# @user.notifier.update_column :new_comment_commit_commentor, false
# it_should_behave_like 'user with create comment ability (for model)' should_send_email(commentor: @stranger, receiver: @user)
# it_should_behave_like 'user with update own comment ability (for model)' end
# it_should_behave_like 'user with update stranger comment ability (for model)' end
# it_should_behave_like 'user with destroy comment ability (for model)'
# it_should_behave_like 'user with destroy stranger comment ability (for model)' context 'for disabled all notify setting expect global' do
# it 'should not send an e-mail' do
# context 'for default enabled settings' do @user.notifier.update_column :new_comment_commit_repo_owner, false
# it 'should send an e-mail by default settings' do @user.notifier.update_column :new_comment_commit_owner, false
# should_send_email(commentor: @stranger, receiver: @project.owner) @user.notifier.update_column :new_comment_commit_commentor, false
# end should_not_send_email(commentor: @stranger)
# end end
# end
# context 'for disabled notify setting new_comment_commit_repo_owner' do
# it 'should not send an e-mail' do context 'for unsubscribe project' do
# @user.notifier.update_column :new_comment_commit_repo_owner, false it 'should not send an e-mail' do
# Comment.destroy_all Subscribe.unsubscribe_from_commit @subscribe_params.merge(user_id: @user.id)
# should_not_send_email(commentor: @stranger) should_not_send_email(commentor: @stranger)
# end end
# end end
#
# context 'for disabled notify setting new_comment_commit_owner' do context 'for disabled global notify setting' do
# it 'should send an e-mail' do it 'should not send an e-mail' do
# @user.notifier.update_column :new_comment_commit_owner, false @user.notifier.update_column :can_notify, false
# should_send_email(commentor: @stranger, receiver: @user) should_not_send_email(commentor: @stranger)
# end end
# end end
#
# context 'for disabled notify setting new_comment_commit_commentor' do context 'for own commit' do
# it 'should send an e-mail' do it 'should send a one e-mail' do
# @user.notifier.update_column :new_comment_commit_commentor, false @project.owner.update_column :email, 'code@tpope.net'
# should_send_email(commentor: @stranger, receiver: @user) should_send_email(commentor: @stranger, receiver: @project.owner)
# end end
# end end
# end
# context 'for disabled all notify setting expect global' do
# it 'should not send an e-mail' do context 'for simple user' do
# @user.notifier.update_column :new_comment_commit_repo_owner, false before(:each) do
# @user.notifier.update_column :new_comment_commit_owner, false @user = FactoryGirl.create(:user)
# @user.notifier.update_column :new_comment_commit_commentor, false @simple = FactoryGirl.create(:user)
# should_not_send_email(commentor: @stranger) @stranger = FactoryGirl.create(:user)
# end set_comments_data_for_commit
# end @comment = create_comment(@simple)
# Subscribe.unsubscribe_from_commit @subscribe_params.merge(user_id: [@stranger.id, @project.owner.id])
# context 'for unsubscribe project' do end
# it 'should not send an e-mail' do
# Subscribe.unsubscribe_from_commit @subscribe_params.merge(user_id: @user.id) context 'for default enabled settings' do
# should_not_send_email(commentor: @stranger) it 'should send an e-mail' do
# end should_send_email(commentor: @stranger, receiver: @simple)
# end end
#
# context 'for disabled global notify setting' do it 'should send an e-mail for comments after his comment' do
# it 'should not send an e-mail' do comment = create_comment(@simple)
# @user.notifier.update_column :can_notify, false should_send_email(commentor: @stranger, receiver: @simple)
# should_not_send_email(commentor: @stranger) end
# end
# end it 'should send an e-mail when subscribed to project' do
# Subscribe.subscribe_to_commit @subscribe_params.merge(user_id: @simple.id)
# context 'for own commit' do should_send_email(commentor: @project.owner, receiver: @simple)
# it 'should send a one e-mail' do end
# @project.owner.update_column :email, 'code@tpope.net'
# should_send_email(commentor: @stranger, receiver: @project.owner) it 'should not send an e-mail for own comment' do
# end should_not_send_email(commentor: @simple)
# end end
# end end
#
# context 'for simple user' do context 'for committer' do
# before(:each) do it 'should send an e-mail' do
# @user = FactoryGirl.create(:user) @simple.update_column :email, 'test@test.test'
# @simple = FactoryGirl.create(:user) should_send_email commentor: @stranger, receiver: @simple
# @stranger = FactoryGirl.create(:user) end
# set_comments_data_for_commit
# @comment = create_comment(@simple) it 'should send a one e-mail when subscribed to commit' do
# @ability = Ability.new(@simple) Subscribe.subscribe_to_commit @subscribe_params.merge(user_id: @simple.id)
# Subscribe.unsubscribe_from_commit @subscribe_params.merge(user_id: [@stranger.id, @project.owner.id]) @simple.update_column :email, 'test@test.test'
# end should_send_email(commentor: @stranger, receiver: @simple)
# end
# it_should_behave_like 'user with create comment ability (for model)'
# it_should_behave_like 'user with update own comment ability (for model)' it 'should not send an e-mail for own comment' do
# it_should_behave_like 'user without update stranger comment ability (for model)' @simple.update_column :email, 'test@test.test'
# it_should_behave_like 'user with destroy comment ability (for model)' should_not_send_email(commentor: @simple)
# it_should_behave_like 'user without destroy stranger comment ability (for model)' end
#
# context 'for default enabled settings' do it 'should not send an e-mail if global notify off' do
# it 'should send an e-mail' do @project.owner.notifier.update_column :can_notify, false
# should_send_email(commentor: @stranger, receiver: @simple) @simple.update_column :email, 'test@test.test'
# end @simple.notifier.update_column :can_notify, false
# should_not_send_email(commentor: @user)
# it 'should send an e-mail for comments after his comment' do end
# comment = create_comment(@simple)
# should_send_email(commentor: @stranger, receiver: @simple) it 'should not send an e-mail if notify for my commits off' do
# end Comment.destroy_all
# @simple.notifier.update_column :new_comment_commit_owner, false
# it 'should send an e-mail when subscribed to project' do @simple.update_column :email, 'test@test.test'
# Subscribe.subscribe_to_commit @subscribe_params.merge(user_id: @simple.id) should_not_send_email(commentor: @user)
# should_send_email(commentor: @project.owner, receiver: @simple) end
# end end
#
# it 'should not send an e-mail for own comment' do context 'automatic issue linking' do
# should_not_send_email(commentor: @simple) before(:each) do
# end @same_name_project = FactoryGirl.create(:project, name: @project.name)
# end @issue_in_same_name_project = FactoryGirl.create(:issue, project: @same_name_project, user: @same_name_project.owner)
# @another_project = FactoryGirl.create(:project, owner: @user)
# context 'for committer' do @other_user_project = FactoryGirl.create(:project)
# it 'should send an e-mail' do @issue = FactoryGirl.create(:issue, project: @project, user: @user)
# @simple.update_column :email, 'test@test.test' @second_issue = FactoryGirl.create(:issue, project: @project, user: @user)
# should_send_email commentor: @stranger, receiver: @simple @issue_in_another_project = FactoryGirl.create(:issue, project: @another_project, user: @user)
# end @issue_in_other_user_project = FactoryGirl.create(:issue, project: @other_user_project, user: @other_user_project.owner)
# end
# it 'should send a one e-mail when subscribed to commit' do
# Subscribe.subscribe_to_commit @subscribe_params.merge(user_id: @simple.id) it 'should create automatic comment' do
# @simple.update_column :email, 'test@test.test' create_comment_in_commit(@commit, @project, "test link to ##{@issue.serial_id}; [##{@second_issue.serial_id}]")
# should_send_email(commentor: @stranger, receiver: @simple) expect(
# end Comment.where(automatic: true, commentable_type: 'Issue',
# commentable_id: @second_issue.id,
# it 'should not send an e-mail for own comment' do created_from_commit_hash: @commit.id.hex).count
# @simple.update_column :email, 'test@test.test' ).to eq(1)
# should_not_send_email(commentor: @simple) end
# end
# it 'should create automatic comment in the another project issue' do
# it 'should not send an e-mail if global notify off' do body = "[#{@another_project.name_with_owner}##{@issue_in_another_project.serial_id}]"
# @project.owner.notifier.update_column :can_notify, false create_comment_in_commit(@commit, @project, body)
# @simple.update_column :email, 'test@test.test' expect(
# @simple.notifier.update_column :can_notify, false Comment.where(automatic: true, commentable_type: 'Issue',
# should_not_send_email(commentor: @user) commentable_id: @issue_in_another_project.id,
# end created_from_commit_hash: @commit.id.hex).count
# ).to eq(1)
# it 'should not send an e-mail if notify for my commits off' do end
# Comment.destroy_all
# @simple.notifier.update_column :new_comment_commit_owner, false it 'should create automatic comment in the same name project issue' do
# @simple.update_column :email, 'test@test.test' body = "[#{@same_name_project.owner.uname}##{@issue_in_same_name_project.serial_id}]"
# should_not_send_email(commentor: @user) create_comment_in_commit(@commit, @project, body)
# end expect(
# end Comment.where(automatic: true, commentable_type: 'Issue',
# commentable_id: @issue_in_same_name_project.id,
# context 'automatic issue linking' do created_from_commit_hash: @commit.id.hex).count
# before(:each) do ).to eq(1)
# @same_name_project = FactoryGirl.create(:project, name: @project.name) end
# @issue_in_same_name_project = FactoryGirl.create(:issue, project: @same_name_project, user: @same_name_project.owner)
# @another_project = FactoryGirl.create(:project, owner: @user) it 'should not create duplicate automatic comment' do
# @other_user_project = FactoryGirl.create(:project) create_comment_in_commit(@commit, @project, "test link to [##{@second_issue.serial_id}]")
# @issue = FactoryGirl.create(:issue, project: @project, user: @user) create_comment_in_commit(@commit, @project, "test duplicate link to [##{@second_issue.serial_id}]")
# @second_issue = FactoryGirl.create(:issue, project: @project, user: @user) expect(
# @issue_in_another_project = FactoryGirl.create(:issue, project: @another_project, user: @user) Comment.where(automatic: true, commentable_type: 'Issue',
# @issue_in_other_user_project = FactoryGirl.create(:issue, project: @other_user_project, user: @other_user_project.owner) commentable_id: @second_issue.id,
# end created_from_commit_hash: @commit.id.hex).count
# ).to eq(1)
# it 'should create automatic comment' do end
# create_comment_in_commit(@commit, @project, "test link to ##{@issue.serial_id}; [##{@second_issue.serial_id}]")
# Comment.where(automatic: true, commentable_type: 'Issue', it 'should not create duplicate automatic comment from one' do
# commentable_id: @second_issue.id, create_comment_in_commit(@commit, @project, "test link to [##{@second_issue.serial_id}]; ##{@second_issue.serial_id}")
# created_from_commit_hash: @commit.id.hex).count.should == 1 expect(
# end Comment.where(automatic: true, commentable_type: 'Issue',
# commentable_id: @second_issue.id,
# it 'should create automatic comment in the another project issue' do created_from_commit_hash: @commit.id.hex).count
# body = "[#{@another_project.name_with_owner}##{@issue_in_another_project.serial_id}]" ).to eq(1)
# create_comment_in_commit(@commit, @project, body) end
# Comment.where(automatic: true, commentable_type: 'Issue', it 'should create two automatic comment' do
# commentable_id: @issue_in_another_project.id, body = "test ##{@second_issue.serial_id}" +
# created_from_commit_hash: @commit.id.hex).count.should == 1 " && [#{@another_project.name_with_owner}##{@issue_in_another_project.serial_id}]"
# end create_comment_in_commit(@commit, @project, body)
# expect(
# it 'should create automatic comment in the same name project issue' do Comment.where(automatic: true,
# body = "[#{@same_name_project.owner.uname}##{@issue_in_same_name_project.serial_id}]" created_from_commit_hash: @commit.id.hex).count
# create_comment_in_commit(@commit, @project, body) ).to eq(2)
# Comment.where(automatic: true, commentable_type: 'Issue', end
# commentable_id: @issue_in_same_name_project.id, end
# created_from_commit_hash: @commit.id.hex).count.should == 1 end
# end end
#
# it 'should not create duplicate automatic comment' do
# create_comment_in_commit(@commit, @project, "test link to [##{@second_issue.serial_id}]")
# create_comment_in_commit(@commit, @project, "test duplicate link to [##{@second_issue.serial_id}]")
# Comment.where(automatic: true, commentable_type: 'Issue',
# commentable_id: @second_issue.id,
# created_from_commit_hash: @commit.id.hex).count.should == 1
# end
#
# it 'should not create duplicate automatic comment from one' do
# create_comment_in_commit(@commit, @project, "test link to [##{@second_issue.serial_id}]; ##{@second_issue.serial_id}")
# Comment.where(automatic: true, commentable_type: 'Issue',
# commentable_id: @second_issue.id,
# created_from_commit_hash: @commit.id.hex).count.should == 1
# end
# it 'should create two automatic comment' do
# body = "test ##{@second_issue.serial_id}" +
# " && [#{@another_project.name_with_owner}##{@issue_in_another_project.serial_id}]"
# create_comment_in_commit(@commit, @project, body)
# Comment.where(automatic: true,
# created_from_commit_hash: @commit.id.hex).count.should == 2
# end
# end
# end
# end