#465 update comment specs

This commit is contained in:
Alexander Machehin 2015-04-13 15:15:55 +05:00
parent 09afec1ad6
commit dd58b4a0a5
2 changed files with 135 additions and 235 deletions

View File

@ -1,196 +1,133 @@
# require 'spec_helper' require 'spec_helper'
# require "cancan/matchers"
# def set_commentable_data
# def set_commentable_data @project = FactoryGirl.create(:project)
# @ability = Ability.new(@user) @issue = FactoryGirl.create(:issue, project_id: @project.id, user: @user)
#
# @project = FactoryGirl.create(:project) @comment = FactoryGirl.create(:comment, commentable: @issue, user: @user, project: @project)
# @issue = FactoryGirl.create(:issue, project_id: @project.id, user: @user) @stranger_comment = FactoryGirl.create(:comment, commentable: @issue, user: @stranger, project: @project)
#
# @comment = FactoryGirl.create(:comment, commentable: @issue, user: @user, project: @project) allow_any_instance_of(Project).to receive(:versions).and_return(%w(v1.0 v2.0))
# @stranger_comment = FactoryGirl.create(:comment, commentable: @issue, user: @stranger, project: @project) end
#
# allow_any_instance_of(Project).to receive(:versions).and_return(%w(v1.0 v2.0)) def create_comment_in_issue issue, body
# end FactoryGirl.create(:comment, user: issue.user, commentable: issue, project: issue.project, body: body)
# end
# def create_comment_in_issue issue, body
# FactoryGirl.create(:comment, user: issue.user, commentable: issue, project: issue.project, body: body) describe Comment do
# end before { stub_symlink_methods }
#
# describe Comment do context 'for simple user' do
# before { stub_symlink_methods } before(:each) do
# context 'for global admin user' do @user = FactoryGirl.create(:user)
# before(:each) do @stranger = FactoryGirl.create(:user)
# @user = FactoryGirl.create(:admin) set_commentable_data
# @stranger = FactoryGirl.create(:user) end
#
# set_commentable_data context 'with mass assignment' do
# end it 'should not be able to update commentable' do
# @comment.update_attributes({commentable_type: 'Grit::Commit', commentable_id: 0})
# it_should_behave_like 'user with create comment ability (for model)' expect(@comment.reload.commentable).to eq(@issue)
# 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 'automatic issue linking' do
# end before(:each) do
# @same_name_project = FactoryGirl.create(:project, name: @project.name)
# context 'for project admin user' do @issue_in_same_name_project = FactoryGirl.create(:issue, project: @same_name_project, user: @same_name_project.owner)
# before(:each) do @another_project = FactoryGirl.create(:project, owner: @user)
# @user = FactoryGirl.create(:user) @other_user_project = FactoryGirl.create(:project)
# @stranger = FactoryGirl.create(:user) @issue = FactoryGirl.create(:issue, project: @project, user: @user)
# @second_issue = FactoryGirl.create(:issue, project: @project, user: @user)
# set_commentable_data @issue_in_another_project = FactoryGirl.create(:issue, project: @another_project, user: @user)
# create_relation(@project, @user, 'admin') @issue_in_other_user_project = FactoryGirl.create(:issue, project: @other_user_project, user: @other_user_project.owner)
# end end
#
# it_should_behave_like 'user with create comment ability (for model)' it 'should create automatic comment' do
# it_should_behave_like 'user with update own comment ability (for model)' create_comment_in_issue(@issue, "test link to ##{@issue.serial_id}; [##{@second_issue.serial_id}]")
# it_should_behave_like 'user with update stranger comment ability (for model)' expect(
# it_should_behave_like 'user with destroy comment ability (for model)' Comment.where(automatic: true, commentable_type: 'Issue',
# it_should_behave_like 'user with destroy stranger comment ability (for model)' commentable_id: @second_issue.id,
# created_from_issue_id: @issue.id).count
# pending "sends an e-mail" do ).to eq(1)
# ActionMailer::Base.deliveries.last.to.include?(@stranger.email).should == true end
# end
# end it 'should not create automatic comment to the same issue' do
# create_comment_in_issue(@issue, "test link to ##{@issue.serial_id}; [##{@second_issue.serial_id}]")
# context 'for project owner user' do expect(
# before(:each) do Comment.where(automatic: true,
# @user = FactoryGirl.create(:user) created_from_issue_id: @issue.id).count
# @stranger = FactoryGirl.create(:user) ).to eq(1)
# end
# set_commentable_data
# it 'should create automatic comment in the another project issue' do
# @project.owner = @user body = "[#{@another_project.name_with_owner}##{@issue_in_another_project.serial_id}]"
# @project.save create_comment_in_issue(@issue, body)
# create_relation(@project, @user, 'admin') expect(
# end Comment.where(automatic: true, commentable_type: 'Issue',
# commentable_id: @issue_in_another_project.id,
# it_should_behave_like 'user with create comment ability (for model)' created_from_issue_id: @issue.id).count
# it_should_behave_like 'user with update own comment ability (for model)' ).to eq(1)
# 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)' it 'should create automatic comment in the same name project issue' do
# end body = "[#{@same_name_project.owner.uname}##{@issue_in_same_name_project.serial_id}]"
# create_comment_in_issue(@issue, body)
# context 'for simple user' do expect(
# before(:each) do Comment.where(automatic: true, commentable_type: 'Issue',
# @user = FactoryGirl.create(:user) commentable_id: @issue_in_same_name_project.id,
# @stranger = FactoryGirl.create(:user) created_from_issue_id: @issue.id).count
# ).to eq(1)
# set_commentable_data end
# end
# it 'should not create duplicate automatic comment' do
# it_should_behave_like 'user with create comment ability (for model)' create_comment_in_issue(@issue, "test link to [##{@second_issue.serial_id}]")
# it_should_behave_like 'user with update own comment ability (for model)' create_comment_in_issue(@issue, "test duplicate link to [##{@second_issue.serial_id}]")
# it_should_behave_like 'user without update stranger comment ability (for model)' expect(
# it_should_behave_like 'user with destroy comment ability (for model)' Comment.where(automatic: true, commentable_type: 'Issue',
# it_should_behave_like 'user without destroy stranger comment ability (for model)' commentable_id: @second_issue.id,
# created_from_issue_id: @issue.id).count
# context 'with mass assignment' do ).to eq(1)
# it 'should not be able to update commentable' do end
# @comment.update_attributes({commentable_type: 'Grit::Commit', commentable_id: 0})
# @comment.reload.commentable_id.should eql @issue.id it 'should not create duplicate automatic comment from one' do
# @comment.reload.commentable_type.should eql @issue.class.name create_comment_in_issue(@issue, "test link to [##{@second_issue.serial_id}]; ##{@second_issue.serial_id}")
# end expect(
# Comment.where(automatic: true, commentable_type: 'Issue',
# it 'should not be able to update owner' do commentable_id: @second_issue.id,
# @comment.should_not allow_mass_assignment_of :user_id created_from_issue_id: @issue.id).count
# end ).to eq(1)
# end
# it 'should not be able to update project' do
# @comment.should_not allow_mass_assignment_of :project_id it 'should create two automatic comment' do
# end body = "test ##{@second_issue.serial_id}" +
# end " && [#{@another_project.name_with_owner}##{@issue_in_another_project.serial_id}]"
# create_comment_in_issue(@issue, body)
# context 'automatic issue linking' do expect(Comment.where(automatic: true,
# before(:each) do created_from_issue_id: @issue.id).count).to eq(2)
# @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 create automatic comment by issue title' do
# @other_user_project = FactoryGirl.create(:project) issue = FactoryGirl.create(:issue, project: @project, user: @user,
# @issue = FactoryGirl.create(:issue, project: @project, user: @user) title: "link to ##{@issue.serial_id}")
# @second_issue = FactoryGirl.create(:issue, project: @project, user: @user) expect(Comment.where(automatic: true,
# @issue_in_another_project = FactoryGirl.create(:issue, project: @another_project, user: @user) created_from_issue_id: issue.id).count).to eq(1)
# @issue_in_other_user_project = FactoryGirl.create(:issue, project: @other_user_project, user: @other_user_project.owner) end
# end
# it 'should create automatic comment from issue body' do
# it 'should create automatic comment' do issue = FactoryGirl.create(:issue, project: @project, user: @user,
# create_comment_in_issue(@issue, "test link to ##{@issue.serial_id}; [##{@second_issue.serial_id}]") body: "link to ##{@issue.serial_id}")
# Comment.where(automatic: true, commentable_type: 'Issue', expect(Comment.where(automatic: true,
# commentable_id: @second_issue.id, created_from_issue_id: issue.id).count).to eq(1)
# created_from_issue_id: @issue.id).count.should == 1 end
# end
# it 'should create only one automatic comment from issue title and body' do
# it 'should not create automatic comment to the same issue' do issue = FactoryGirl.create(:issue, project: @project, user: @user,
# create_comment_in_issue(@issue, "test link to ##{@issue.serial_id}; [##{@second_issue.serial_id}]") title: "link to ##{@issue.serial_id} in title",
# Comment.where(automatic: true, :body => "link to ##{@issue.serial_id} in body")
# created_from_issue_id: @issue.id).count.should == 1 expect(Comment.where(automatic: true,
# end created_from_issue_id: issue.id).count).to eq(1)
# end
# it 'should create automatic comment in the another project issue' do end
# body = "[#{@another_project.name_with_owner}##{@issue_in_another_project.serial_id}]" end
# create_comment_in_issue(@issue, body) end
# Comment.where(automatic: true, commentable_type: 'Issue',
# commentable_id: @issue_in_another_project.id,
# created_from_issue_id: @issue.id).count.should == 1
# end
#
# it 'should create automatic comment in the same name project issue' do
# body = "[#{@same_name_project.owner.uname}##{@issue_in_same_name_project.serial_id}]"
# create_comment_in_issue(@issue, body)
# Comment.where(automatic: true, commentable_type: 'Issue',
# commentable_id: @issue_in_same_name_project.id,
# created_from_issue_id: @issue.id).count.should == 1
# end
#
# it 'should not create duplicate automatic comment' do
# create_comment_in_issue(@issue, "test link to [##{@second_issue.serial_id}]")
# create_comment_in_issue(@issue, "test duplicate link to [##{@second_issue.serial_id}]")
# Comment.where(automatic: true, commentable_type: 'Issue',
# commentable_id: @second_issue.id,
# created_from_issue_id: @issue.id).count.should == 1
# end
#
# it 'should not create duplicate automatic comment from one' do
# create_comment_in_issue(@issue, "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_issue_id: @issue.id).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_issue(@issue, body)
# Comment.where(automatic: true,
# created_from_issue_id: @issue.id).count.should == 2
# end
#
# it 'should create automatic comment by issue title' do
# issue = FactoryGirl.create(:issue, project: @project, user: @user,
# title: "link to ##{@issue.serial_id}")
# expect(Comment.where(automatic: true,
# created_from_issue_id: issue.id).count).to eq 1
# end
#
# it 'should create automatic comment from issue body' do
# issue = FactoryGirl.create(:issue, project: @project, user: @user,
# body: "link to ##{@issue.serial_id}")
# Comment.where(automatic: true,
# created_from_issue_id: issue.id).count.should == 1
# end
#
# it 'should create only one automatic comment from issue title and body' do
# issue = FactoryGirl.create(:issue, project: @project, user: @user,
# title: "link to ##{@issue.serial_id} in title",
# :body => "link to ##{@issue.serial_id} in body")
# Comment.where(automatic: true,
# created_from_issue_id: issue.id).count.should == 1
# end
#
#
#
# end
# end
# end

View File

@ -1,40 +1,3 @@
shared_examples_for 'user with create comment ability (for model)' do
it 'should create comment' do
@ability.should be_able_to(:create, @comment)
end
end
shared_examples_for 'user with update own comment ability (for model)' do
it 'should update comment' do
@ability.should be_able_to(:update, @comment)
end
end
shared_examples_for 'user with update stranger comment ability (for model)' do
it 'should update stranger comment' do
@ability.should be_able_to(:update, @stranger_comment)
end
end
shared_examples_for 'user with destroy comment ability (for model)' do
it 'should destroy own comment' do
@ability.should be_able_to(:destroy, @comment)
end
end
shared_examples_for 'user with destroy stranger comment ability (for model)' do
it 'should destroy stranger comment' do
@ability.should be_able_to(:destroy, @stranger_comment)
end
end
shared_examples_for 'user without update stranger comment ability (for model)' do
it 'should not update stranger comment' do
@ability.should_not be_able_to(:update, @stranger_comment)
end
end
shared_examples_for 'user without destroy stranger comment ability (for model)' do
it 'should not destroy stranger comment' do
@ability.should_not be_able_to(:destroy, @stranger_comment)
end
end
shared_examples_for 'user with create comment ability' do shared_examples_for 'user with create comment ability' do
it 'should be able to perform create action' do it 'should be able to perform create action' do
post :create, @create_params post :create, @create_params
@ -42,9 +5,9 @@ shared_examples_for 'user with create comment ability' do
end end
it 'should create comment in the database' do it 'should create comment in the database' do
expect do expect {
post :create, @create_params post :create, @create_params
end.to change(Comment, :count).by(1) }.to change(Comment, :count).by(1)
end end
end end
shared_examples_for 'user with update own comment ability' do shared_examples_for 'user with update own comment ability' do