2012-01-30 20:39:34 +00:00
|
|
|
# -*- encoding : utf-8 -*-
|
2012-01-13 16:00:28 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2012-03-27 16:09:04 +01:00
|
|
|
def create_comment user
|
2012-04-04 22:43:06 +01:00
|
|
|
FactoryGirl.create(:comment, :user => user, :commentable => @commit, :project => @project)
|
2012-03-27 16:09:04 +01:00
|
|
|
end
|
|
|
|
|
2012-01-16 13:43:23 +00:00
|
|
|
shared_examples_for 'user with create comment rights for commits' do
|
2012-01-13 16:00:28 +00:00
|
|
|
it 'should be able to perform create action' do
|
|
|
|
post :create, @create_params
|
|
|
|
response.should redirect_to(commit_path(@project, @commit.id))
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should create subscribe object into db' do
|
|
|
|
lambda{ post :create, @create_params }.should change{ Comment.count }.by(1)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-01-16 13:43:23 +00:00
|
|
|
shared_examples_for 'user with update own comment rights for commits' do
|
2012-01-13 16:00:28 +00:00
|
|
|
it 'should be able to perform update action' do
|
|
|
|
put :update, {:id => @own_comment.id}.merge(@update_params)
|
|
|
|
response.should redirect_to(commit_path(@project, @commit.id))
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should update subscribe body' do
|
|
|
|
put :update, {:id => @own_comment.id}.merge(@update_params)
|
|
|
|
@own_comment.reload.body.should == 'updated'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-01-16 13:43:23 +00:00
|
|
|
shared_examples_for 'user with update stranger comment rights for commits' do
|
2012-01-13 16:00:28 +00:00
|
|
|
it 'should be able to perform update action' do
|
2012-03-27 16:09:04 +01:00
|
|
|
put :update, {:id => @stranger_comment.id}.merge(@update_params)
|
2012-01-13 16:00:28 +00:00
|
|
|
response.should redirect_to(commit_path(@project, @commit.id))
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should update comment title' do
|
2012-03-27 16:09:04 +01:00
|
|
|
put :update, {:id => @stranger_comment.id}.merge(@update_params)
|
|
|
|
@stranger_comment.reload.body.should == 'updated'
|
2012-01-13 16:00:28 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-01-16 13:43:23 +00:00
|
|
|
shared_examples_for 'user without update stranger comment rights for commits' do
|
2012-01-13 16:00:28 +00:00
|
|
|
it 'should not be able to perform update action' do
|
2012-03-27 16:09:04 +01:00
|
|
|
put :update, {:id => @stranger_comment.id}.merge(@update_params)
|
2012-01-13 16:00:28 +00:00
|
|
|
response.should redirect_to(forbidden_path)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not update comment title' do
|
2012-03-27 16:09:04 +01:00
|
|
|
put :update, {:id => @stranger_comment.id}.merge(@update_params)
|
|
|
|
@stranger_comment.reload.body.should_not == 'updated'
|
2012-01-13 16:00:28 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-01-16 13:43:23 +00:00
|
|
|
shared_examples_for 'user without destroy comment rights for commits' do
|
2012-01-13 16:00:28 +00:00
|
|
|
it 'should not be able to perform destroy action' do
|
2012-03-27 16:09:04 +01:00
|
|
|
delete :destroy, :id => @stranger_comment.id, :commit_id => @commit.id, :project_id => @project.id
|
2012-01-13 16:00:28 +00:00
|
|
|
response.should redirect_to(forbidden_path)
|
|
|
|
end
|
2012-01-14 12:16:42 +00:00
|
|
|
|
|
|
|
it 'should not reduce comments count' do
|
2012-03-27 16:09:04 +01:00
|
|
|
lambda{ delete :destroy, :id => @stranger_comment.id, :commit_id => @commit.id, :project_id => @project.id }.should change{ Comment.count }.by(0)
|
2012-01-14 12:16:42 +00:00
|
|
|
end
|
2012-01-13 16:00:28 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
#shared_examples_for 'user with destroy rights' do
|
|
|
|
# it 'should be able to perform destroy action' do
|
2012-03-27 16:09:04 +01:00
|
|
|
# delete :destroy, :id => @stranger_comment.id, :project_id => @project.id
|
|
|
|
# response.should redirect_to(commit_path(@project, @commit.id))
|
2012-01-13 16:00:28 +00:00
|
|
|
# end
|
|
|
|
#
|
|
|
|
# it 'should reduce comments count' do
|
2012-03-27 16:09:04 +01:00
|
|
|
# lambda{ delete :destroy, :id => @stranger_comment.id, :issue_id => @issue.serial_id, :project_id => @project.id }.should change{ Comment.count }.by(-1)
|
2012-01-13 16:00:28 +00:00
|
|
|
# end
|
|
|
|
#end
|
|
|
|
|
|
|
|
describe CommentsController do
|
|
|
|
before(:each) do
|
|
|
|
stub_rsync_methods
|
2012-03-29 21:34:22 +01:00
|
|
|
@project = FactoryGirl.create(:project)
|
2012-01-13 16:00:28 +00:00
|
|
|
%x(cp -Rf #{Rails.root}/spec/tests.git/* #{@project.git_repository.path}) # maybe FIXME ?
|
|
|
|
@commit = @project.git_repository.commits.first
|
|
|
|
|
|
|
|
@create_params = {:comment => {:body => 'I am a comment!'}, :project_id => @project.id, :commit_id => @commit.id}
|
|
|
|
@update_params = {:comment => {:body => 'updated'}, :project_id => @project.id, :commit_id => @commit.id}
|
|
|
|
|
|
|
|
any_instance_of(Project, :versions => ['v1.0', 'v2.0'])
|
2012-03-29 21:34:22 +01:00
|
|
|
@stranger_comment = create_comment FactoryGirl.create(:user)
|
|
|
|
@user = FactoryGirl.create(:user)
|
2012-03-27 16:09:04 +01:00
|
|
|
@own_comment = create_comment @user
|
|
|
|
set_session_for(@user)
|
2012-01-13 16:00:28 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'for project admin user' do
|
|
|
|
before(:each) do
|
|
|
|
@project.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'admin')
|
|
|
|
end
|
|
|
|
|
2012-01-16 13:43:23 +00:00
|
|
|
it_should_behave_like 'user with create comment rights for commits'
|
|
|
|
it_should_behave_like 'user with update stranger comment rights for commits'
|
|
|
|
it_should_behave_like 'user with update own comment rights for commits'
|
|
|
|
it_should_behave_like 'user without destroy comment rights for commits'
|
2012-03-27 16:09:04 +01:00
|
|
|
#it_should_behave_like 'user with destroy rights'
|
2012-01-13 16:00:28 +00:00
|
|
|
end
|
|
|
|
|
2012-01-14 12:16:42 +00:00
|
|
|
context 'for project owner user' do
|
|
|
|
before(:each) do
|
2012-03-27 16:09:04 +01:00
|
|
|
@user.destroy
|
2012-01-14 12:16:42 +00:00
|
|
|
@user = @project.owner
|
|
|
|
set_session_for(@user)
|
2012-03-27 16:09:04 +01:00
|
|
|
@own_comment = create_comment @user
|
2012-01-14 12:16:42 +00:00
|
|
|
end
|
|
|
|
|
2012-01-16 13:43:23 +00:00
|
|
|
it_should_behave_like 'user with create comment rights for commits'
|
|
|
|
it_should_behave_like 'user with update stranger comment rights for commits'
|
|
|
|
it_should_behave_like 'user with update own comment rights for commits'
|
|
|
|
it_should_behave_like 'user without destroy comment rights for commits'
|
2012-01-14 12:16:42 +00:00
|
|
|
end
|
2012-01-13 16:00:28 +00:00
|
|
|
|
|
|
|
context 'for project reader user' do
|
|
|
|
before(:each) do
|
|
|
|
@project.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'reader')
|
|
|
|
end
|
|
|
|
|
2012-01-16 13:43:23 +00:00
|
|
|
it_should_behave_like 'user with create comment rights for commits'
|
|
|
|
it_should_behave_like 'user without update stranger comment rights for commits'
|
|
|
|
it_should_behave_like 'user with update own comment rights for commits'
|
|
|
|
it_should_behave_like 'user without destroy comment rights for commits'
|
2012-01-13 16:00:28 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'for project writer user' do
|
|
|
|
before(:each) do
|
|
|
|
@project.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'writer')
|
|
|
|
end
|
|
|
|
|
2012-01-16 13:43:23 +00:00
|
|
|
it_should_behave_like 'user with create comment rights for commits'
|
|
|
|
it_should_behave_like 'user without update stranger comment rights for commits'
|
|
|
|
it_should_behave_like 'user with update own comment rights for commits'
|
|
|
|
it_should_behave_like 'user without destroy comment rights for commits'
|
2012-01-13 16:00:28 +00:00
|
|
|
end
|
2012-01-16 13:43:23 +00:00
|
|
|
end
|