2012-01-30 20:39:34 +00:00
|
|
|
# -*- encoding : utf-8 -*-
|
2011-12-19 15:30:14 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2011-12-29 11:16:54 +00:00
|
|
|
shared_examples_for 'user with create comment rights' do
|
|
|
|
it 'should be able to perform create action' do
|
|
|
|
post :create, @create_params
|
|
|
|
response.should redirect_to(project_issue_path(@project, @issue))
|
|
|
|
end
|
|
|
|
|
2011-12-29 17:03:53 +00:00
|
|
|
it 'should create subscribe object into db' do
|
2011-12-29 11:16:54 +00:00
|
|
|
lambda{ post :create, @create_params }.should change{ Comment.count }.by(1)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples_for 'user with update own comment rights' do
|
|
|
|
it 'should be able to perform update action' do
|
|
|
|
put :update, {:id => @own_comment.id}.merge(@update_params)
|
|
|
|
response.should redirect_to([@project, @issue])
|
|
|
|
end
|
|
|
|
|
2011-12-29 17:03:53 +00:00
|
|
|
it 'should update subscribe body' do
|
2011-12-29 11:16:54 +00:00
|
|
|
put :update, {:id => @own_comment.id}.merge(@update_params)
|
|
|
|
@own_comment.reload.body.should == 'updated'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples_for 'user with update stranger comment rights' do
|
|
|
|
it 'should be able to perform update action' do
|
|
|
|
put :update, {:id => @comment.id}.merge(@update_params)
|
|
|
|
response.should redirect_to([@project, @issue])
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should update issue title' do
|
|
|
|
put :update, {:id => @comment.id}.merge(@update_params)
|
|
|
|
@comment.reload.body.should == 'updated'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples_for 'user without update stranger comment rights' do
|
|
|
|
it 'should not be able to perform update action' do
|
|
|
|
put :update, {:id => @comment.id}.merge(@update_params)
|
|
|
|
response.should redirect_to(forbidden_path)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not update issue title' do
|
|
|
|
put :update, {:id => @comment.id}.merge(@update_params)
|
|
|
|
@comment.reload.body.should_not == 'updated'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples_for 'user without destroy comment rights' do
|
|
|
|
it 'should not be able to perform destroy action' do
|
2012-01-17 09:52:46 +00:00
|
|
|
delete :destroy, :id => @comment.id, :issue_id => @issue.serial_id, :project_id => @project.id
|
2011-12-29 11:16:54 +00:00
|
|
|
response.should redirect_to(forbidden_path)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not reduce comments count' do
|
2012-01-17 09:52:46 +00:00
|
|
|
lambda{ delete :destroy, :id => @comment.id, :issue_id => @issue.serial_id, :project_id => @project.id }.should change{ Issue.count }.by(0)
|
2011-12-29 11:16:54 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
#shared_examples_for 'user with destroy rights' do
|
|
|
|
# it 'should be able to perform destroy action' do
|
|
|
|
# delete :destroy, :id => @comment.id, :issue_id => @issue.id, :project_id => @project.id
|
|
|
|
# response.should redirect_to([@project, @issue])
|
|
|
|
# end
|
|
|
|
#
|
|
|
|
# it 'should reduce comments count' do
|
|
|
|
# lambda{ delete :destroy, :id => @comment.id, :issue_id => @issue.id, :project_id => @project.id }.should change{ Comment.count }.by(-1)
|
|
|
|
# end
|
|
|
|
#end
|
|
|
|
|
2011-12-19 15:30:14 +00:00
|
|
|
describe CommentsController do
|
2011-12-29 11:16:54 +00:00
|
|
|
before(:each) do
|
|
|
|
stub_rsync_methods
|
|
|
|
|
2012-03-29 21:34:22 +01:00
|
|
|
@project = FactoryGirl.create(:project)
|
|
|
|
@issue = FactoryGirl.create(:issue, :project_id => @project.id, :creator => FactoryGirl.create(:user))
|
|
|
|
@comment = FactoryGirl.create(:comment, :commentable => @issue, :project_id => @project.id)
|
2011-12-29 11:16:54 +00:00
|
|
|
|
2012-01-16 21:07:48 +00:00
|
|
|
@create_params = {:comment => {:body => 'I am a comment!'}, :project_id => @project.id, :issue_id => @issue.serial_id}
|
|
|
|
@update_params = {:comment => {:body => 'updated'}, :project_id => @project.id, :issue_id => @issue.serial_id}
|
2011-12-29 11:16:54 +00:00
|
|
|
|
|
|
|
any_instance_of(Project, :versions => ['v1.0', 'v2.0'])
|
|
|
|
|
2012-03-29 21:34:22 +01:00
|
|
|
@user = FactoryGirl.create(:user)
|
2012-03-27 16:09:04 +01:00
|
|
|
set_session_for(@user)
|
2012-03-29 21:34:22 +01:00
|
|
|
@own_comment = FactoryGirl.create(:comment, :commentable => @issue, :user => @user, :project_id => @project.id)
|
2011-12-29 11:16:54 +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
|
|
|
|
|
|
|
|
it_should_behave_like 'user with create comment rights'
|
|
|
|
it_should_behave_like 'user with update stranger comment rights'
|
|
|
|
it_should_behave_like 'user with update own comment rights'
|
|
|
|
it_should_behave_like 'user without destroy comment rights'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'for project owner user' do
|
|
|
|
before(:each) do
|
|
|
|
@project.update_attribute(:owner, @user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it_should_behave_like 'user with create comment rights'
|
|
|
|
it_should_behave_like 'user with update stranger comment rights'
|
|
|
|
it_should_behave_like 'user with update own comment rights'
|
|
|
|
it_should_behave_like 'user without destroy comment rights'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'for project reader user' do
|
|
|
|
before(:each) do
|
|
|
|
@project.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'reader')
|
|
|
|
end
|
|
|
|
|
|
|
|
it_should_behave_like 'user with create comment rights'
|
|
|
|
it_should_behave_like 'user without update stranger comment rights'
|
|
|
|
it_should_behave_like 'user with update own comment rights'
|
|
|
|
it_should_behave_like 'user without destroy comment rights'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'for project writer user' do
|
|
|
|
before(:each) do
|
|
|
|
@project.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'writer')
|
|
|
|
end
|
2011-12-19 15:30:14 +00:00
|
|
|
|
2011-12-29 11:16:54 +00:00
|
|
|
it_should_behave_like 'user with create comment rights'
|
|
|
|
it_should_behave_like 'user without update stranger comment rights'
|
|
|
|
it_should_behave_like 'user with update own comment rights'
|
|
|
|
it_should_behave_like 'user without destroy comment rights'
|
|
|
|
end
|
2011-12-19 15:30:14 +00:00
|
|
|
end
|