2012-01-30 20:39:34 +00:00
|
|
|
# -*- encoding : utf-8 -*-
|
2012-01-13 16:00:28 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2012-05-02 10:18:07 +01:00
|
|
|
describe Projects::CommentsController do
|
2012-01-13 16:00:28 +00:00
|
|
|
before(:each) do
|
2012-05-16 16:29:28 +01:00
|
|
|
stub_symlink_methods
|
2012-12-18 18:53:41 +00:00
|
|
|
@project = FactoryGirl.create(:project_with_commit)
|
2012-07-17 09:02:56 +01:00
|
|
|
@commit = @project.repo.commits.first
|
2012-01-13 16:00:28 +00:00
|
|
|
|
2012-04-23 21:55:42 +01:00
|
|
|
@create_params = {:comment => {:body => 'I am a comment!'}, :owner_name => @project.owner.uname, :project_name => @project.name, :commit_id => @commit.id}
|
|
|
|
@update_params = {:comment => {:body => 'updated'}, :owner_name => @project.owner.uname, :project_name => @project.name, :commit_id => @commit.id}
|
2012-01-13 16:00:28 +00:00
|
|
|
|
|
|
|
any_instance_of(Project, :versions => ['v1.0', 'v2.0'])
|
2012-12-13 18:19:24 +00:00
|
|
|
@comment = FactoryGirl.create(:comment, :commentable => @commit, :project => @project)
|
2012-03-29 21:34:22 +01:00
|
|
|
@user = FactoryGirl.create(:user)
|
2012-12-13 18:19:24 +00:00
|
|
|
@own_comment = FactoryGirl.create(:comment, :commentable => @commit, :user => @user, :project => @project)
|
2012-03-27 16:09:04 +01:00
|
|
|
set_session_for(@user)
|
2012-12-13 18:19:24 +00:00
|
|
|
@path = {:owner_name => @project.owner.uname, :project_name => @project.name, :commit_id => @commit.id}
|
|
|
|
@return_path = commit_path(@project, @commit.id)
|
2012-01-13 16:00:28 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'for project admin user' do
|
|
|
|
before(:each) do
|
2012-04-26 02:38:33 +01:00
|
|
|
@project.relations.create!(:actor_type => 'User', :actor_id => @user.id, :role => 'admin')
|
2012-01-13 16:00:28 +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'
|
|
|
|
#it_should_behave_like 'user with destroy ability'
|
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-12-13 18:19:24 +00:00
|
|
|
set_session_for(@project.owner)
|
2012-01-14 12:16:42 +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'
|
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
|
2012-04-26 02:38:33 +01:00
|
|
|
@project.relations.create!(:actor_type => 'User', :actor_id => @user.id, :role => 'reader')
|
2012-01-13 16:00:28 +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'
|
2012-01-13 16:00:28 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'for project writer user' do
|
|
|
|
before(:each) do
|
2012-04-26 02:38:33 +01:00
|
|
|
@project.relations.create!(:actor_type => 'User', :actor_id => @user.id, :role => 'writer')
|
2012-01-13 16:00:28 +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'
|
2012-01-13 16:00:28 +00:00
|
|
|
end
|
2012-01-16 13:43:23 +00:00
|
|
|
end
|