2011-12-19 15:30:14 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2012-08-15 14:52:32 +01:00
|
|
|
shared_context "comments controller" do
|
|
|
|
before(:each) do
|
|
|
|
stub_symlink_methods
|
|
|
|
|
|
|
|
@project = FactoryGirl.create(:project)
|
2014-01-21 04:51:49 +00:00
|
|
|
@issue = FactoryGirl.create(:issue, project_id: @project.id)
|
|
|
|
@comment = FactoryGirl.create(:comment, commentable: @issue, project_id: @project.id)
|
2012-08-15 14:52:32 +01:00
|
|
|
|
|
|
|
@user = FactoryGirl.create(:user)
|
2014-01-21 04:51:49 +00:00
|
|
|
@own_comment = FactoryGirl.create(:comment, commentable: @issue, user: @user, project_id: @project.id)
|
2012-09-27 09:50:45 +01:00
|
|
|
|
2012-09-06 11:53:03 +01:00
|
|
|
set_session_for(@user)
|
2012-08-15 14:52:32 +01:00
|
|
|
|
2014-03-19 07:19:03 +00:00
|
|
|
@path = { name_with_owner: @project.name_with_owner, issue_id: @issue.serial_id }
|
2012-12-13 18:19:24 +00:00
|
|
|
@return_path = project_issue_path(@project, @issue)
|
2014-03-19 07:11:16 +00:00
|
|
|
@create_params = { comment: { body: 'I am a comment!' }}.merge(@path)
|
|
|
|
@update_params = { comment: { body: 'updated' }}.merge(@path)
|
2012-08-15 14:52:32 +01:00
|
|
|
end
|
2012-09-06 11:53:03 +01:00
|
|
|
|
2012-08-15 14:52:32 +01:00
|
|
|
end
|
|
|
|
|
2012-05-02 10:18:07 +01:00
|
|
|
describe Projects::CommentsController do
|
2012-08-15 14:52:32 +01:00
|
|
|
include_context "comments controller"
|
2011-12-29 11:16:54 +00:00
|
|
|
|
2012-09-06 11:53:03 +01:00
|
|
|
context 'for global admin user' do
|
|
|
|
before(:each) do
|
|
|
|
@user.role = "admin"
|
|
|
|
@user.save
|
|
|
|
end
|
|
|
|
|
2012-12-13 18:19:24 +00:00
|
|
|
it_should_behave_like 'user with create comment ability'
|
|
|
|
it_should_behave_like 'user with update stranger comment ability'
|
|
|
|
it_should_behave_like 'user with update own comment ability'
|
|
|
|
it_should_behave_like 'user with destroy comment ability'
|
2012-09-06 11:53:03 +01:00
|
|
|
end
|
|
|
|
|
2011-12-29 11:16:54 +00:00
|
|
|
context 'for project admin user' do
|
|
|
|
before(:each) do
|
2014-03-18 09:31:01 +00:00
|
|
|
create_relation(@project, @user, 'admin')
|
2011-12-29 11:16:54 +00:00
|
|
|
end
|
|
|
|
|
2012-12-13 18:19:24 +00:00
|
|
|
it_should_behave_like 'user with create comment ability'
|
|
|
|
it_should_behave_like 'user with update stranger comment ability'
|
|
|
|
it_should_behave_like 'user with update own comment ability'
|
|
|
|
it_should_behave_like 'user with destroy comment ability'
|
2011-12-29 11:16:54 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'for project owner user' do
|
|
|
|
before(:each) do
|
2012-09-06 11:53:03 +01:00
|
|
|
set_session_for(@project.owner) # owner should be user
|
2011-12-29 11:16:54 +00:00
|
|
|
end
|
|
|
|
|
2012-12-13 18:19:24 +00:00
|
|
|
it_should_behave_like 'user with create comment ability'
|
|
|
|
it_should_behave_like 'user with update stranger comment ability'
|
|
|
|
it_should_behave_like 'user with update own comment ability'
|
|
|
|
it_should_behave_like 'user with destroy comment ability'
|
2011-12-29 11:16:54 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'for project reader user' do
|
|
|
|
before(:each) do
|
2014-03-18 09:31:01 +00:00
|
|
|
create_relation(@project, @user, 'reader')
|
2011-12-29 11:16:54 +00:00
|
|
|
end
|
|
|
|
|
2012-12-13 18:19:24 +00:00
|
|
|
it_should_behave_like 'user with create comment ability'
|
|
|
|
it_should_behave_like 'user without update stranger comment ability'
|
|
|
|
it_should_behave_like 'user with update own comment ability'
|
|
|
|
it_should_behave_like 'user without destroy comment ability'
|
2011-12-29 11:16:54 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'for project writer user' do
|
|
|
|
before(:each) do
|
2014-03-18 09:31:01 +00:00
|
|
|
create_relation(@project, @user, 'writer')
|
2011-12-29 11:16:54 +00:00
|
|
|
end
|
2011-12-19 15:30:14 +00:00
|
|
|
|
2012-12-13 18:19:24 +00:00
|
|
|
it_should_behave_like 'user with create comment ability'
|
|
|
|
it_should_behave_like 'user without update stranger comment ability'
|
|
|
|
it_should_behave_like 'user with update own comment ability'
|
|
|
|
it_should_behave_like 'user without destroy comment ability'
|
2011-12-29 11:16:54 +00:00
|
|
|
end
|
2011-12-19 15:30:14 +00:00
|
|
|
end
|