2012-01-30 20:39:34 +00:00
|
|
|
# -*- encoding : utf-8 -*-
|
2011-12-19 15:30:14 +00:00
|
|
|
require 'spec_helper'
|
2011-12-30 14:21:08 +00:00
|
|
|
require "cancan/matchers"
|
|
|
|
|
2012-01-17 08:17:12 +00:00
|
|
|
def set_commentable_data
|
2011-12-30 14:21:08 +00:00
|
|
|
@ability = Ability.new(@user)
|
|
|
|
|
2012-03-29 21:34:22 +01:00
|
|
|
@project = FactoryGirl.create(:project)
|
2012-04-13 20:44:04 +01:00
|
|
|
@issue = FactoryGirl.create(:issue, :project_id => @project.id, :user => @user)
|
2011-12-30 14:21:08 +00:00
|
|
|
|
2012-03-29 21:34:22 +01:00
|
|
|
@comment = FactoryGirl.create(:comment, :commentable => @issue, :user => @user, :project => @project)
|
|
|
|
@stranger_comment = FactoryGirl.create(:comment, :commentable => @issue, :user => @stranger, :project => @project)
|
2011-12-30 14:21:08 +00:00
|
|
|
|
|
|
|
any_instance_of(Project, :versions => ['v1.0', 'v2.0'])
|
|
|
|
end
|
2011-12-19 15:30:14 +00:00
|
|
|
|
|
|
|
describe Comment do
|
2012-02-20 23:13:05 +00:00
|
|
|
before { stub_rsync_methods }
|
2011-12-30 14:21:08 +00:00
|
|
|
context 'for global admin user' do
|
|
|
|
before(:each) do
|
2012-03-29 21:34:22 +01:00
|
|
|
@user = FactoryGirl.create(:admin)
|
|
|
|
@stranger = FactoryGirl.create(:user)
|
2011-12-30 14:21:08 +00:00
|
|
|
|
2012-01-17 08:17:12 +00:00
|
|
|
set_commentable_data
|
2011-12-30 14:21:08 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should create comment' do
|
2012-03-22 10:12:33 +00:00
|
|
|
@ability.should be_able_to(:create, @comment)
|
2011-12-30 14:21:08 +00:00
|
|
|
end
|
|
|
|
|
2012-01-11 07:12:23 +00:00
|
|
|
pending "sends an e-mail" do
|
|
|
|
ActionMailer::Base.deliveries.last.to.include?(@stranger.email).should == true
|
|
|
|
end
|
|
|
|
|
2011-12-30 14:21:08 +00:00
|
|
|
it 'should update comment' do
|
|
|
|
@ability.should be_able_to(:update, @comment)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should update stranger comment' do
|
|
|
|
@ability.should be_able_to(:update, @stranger_comment)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should destroy own comment' do
|
2012-01-11 07:12:23 +00:00
|
|
|
@ability.should be_able_to(:destroy, @comment)
|
2011-12-30 14:21:08 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should destroy stranger comment' do
|
|
|
|
@ability.should be_able_to(:destroy, @stranger_comment)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'for project admin user' do
|
|
|
|
before(:each) do
|
2012-03-29 21:34:22 +01:00
|
|
|
@user = FactoryGirl.create(:user)
|
|
|
|
@stranger = FactoryGirl.create(:user)
|
2011-12-30 14:21:08 +00:00
|
|
|
|
2012-01-17 08:17:12 +00:00
|
|
|
set_commentable_data
|
2011-12-30 14:21:08 +00:00
|
|
|
|
|
|
|
@project.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'admin')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should create comment' do
|
2012-03-22 10:12:33 +00:00
|
|
|
@comment.user = @user
|
|
|
|
@ability.should be_able_to(:create, @comment)
|
2011-12-30 14:21:08 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should update comment' do
|
|
|
|
@ability.should be_able_to(:update, @comment)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should update stranger comment' do
|
|
|
|
@ability.should be_able_to(:update, @stranger_comment)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not destroy comment' do
|
|
|
|
@ability.should_not be_able_to(:destroy, @comment)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'for project owner user' do
|
|
|
|
before(:each) do
|
2012-03-29 21:34:22 +01:00
|
|
|
@user = FactoryGirl.create(:user)
|
|
|
|
@stranger = FactoryGirl.create(:user)
|
2011-12-30 14:21:08 +00:00
|
|
|
|
2012-01-17 08:17:12 +00:00
|
|
|
set_commentable_data
|
2011-12-30 14:21:08 +00:00
|
|
|
|
|
|
|
@project.update_attribute(:owner, @user)
|
|
|
|
@project.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'admin')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should create comment' do
|
2012-03-22 10:12:33 +00:00
|
|
|
@ability.should be_able_to(:create, @comment)
|
2011-12-30 14:21:08 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should update comment' do
|
|
|
|
@ability.should be_able_to(:update, @comment)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should update stranger comment' do
|
|
|
|
@ability.should be_able_to(:update, @stranger_comment)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not destroy comment' do
|
|
|
|
@ability.should_not be_able_to(:destroy, @comment)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'for simple user' do
|
|
|
|
before(:each) do
|
2012-03-29 21:34:22 +01:00
|
|
|
@user = FactoryGirl.create(:user)
|
|
|
|
@stranger = FactoryGirl.create(:user)
|
2011-12-30 14:21:08 +00:00
|
|
|
|
2012-01-17 08:17:12 +00:00
|
|
|
set_commentable_data
|
2011-12-30 14:21:08 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should create comment' do
|
2012-03-22 10:12:33 +00:00
|
|
|
@ability.should be_able_to(:create, @comment)
|
2011-12-30 14:21:08 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should update comment' do
|
|
|
|
@ability.should be_able_to(:update, @comment)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not update stranger comment' do
|
|
|
|
@ability.should_not be_able_to(:update, @stranger_comment)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not destroy comment' do
|
|
|
|
@ability.should_not be_able_to(:destroy, @comment)
|
|
|
|
end
|
2012-03-27 17:42:12 +01:00
|
|
|
|
|
|
|
context 'with mass assignment' do
|
|
|
|
it 'should not be able to update commentable' do
|
|
|
|
@comment.update_attributes({:commentable_type => 'Grit::Commit', :commentable_id => 0})
|
|
|
|
@comment.reload.commentable_id.should eql @issue.id
|
|
|
|
@comment.reload.commentable_type.should eql @issue.class.name
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not be able to update owner' do
|
|
|
|
@comment.should_not allow_mass_assignment_of :user_id
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not be able to update project' do
|
|
|
|
@comment.should_not allow_mass_assignment_of :project_id
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-12-30 14:21:08 +00:00
|
|
|
end
|
2011-12-19 15:30:14 +00:00
|
|
|
end
|