[refs #54] Add comments, subscribes models specs. Finish subscribes controller specs. Some ability.rb fixes
This commit is contained in:
parent
402133aff6
commit
3f72082e0e
|
@ -13,6 +13,8 @@ class Ability
|
||||||
|
|
||||||
if user.admin?
|
if user.admin?
|
||||||
can :manage, :all
|
can :manage, :all
|
||||||
|
cannot :destroy, Subscribe
|
||||||
|
cannot :create, Subscribe
|
||||||
else
|
else
|
||||||
# Shared rights between guests and registered users
|
# Shared rights between guests and registered users
|
||||||
can :forbidden, Platform
|
can :forbidden, Platform
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
shared_examples_for 'user with create subscribe rights' do
|
shared_examples_for 'can subscribe' do
|
||||||
it 'should be able to perform create action' do
|
it 'should be able to perform create action' do
|
||||||
post :create, @create_params
|
post :create, @create_params
|
||||||
response.should redirect_to(project_issue_path(@project, @issue))
|
response.should redirect_to(project_issue_path(@project, @issue))
|
||||||
|
@ -11,14 +11,42 @@ shared_examples_for 'user with create subscribe rights' do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
shared_examples_for 'user without destroy subscribe rights' do
|
shared_examples_for 'can not subscribe' do
|
||||||
|
it 'should not be able to perform create action' do
|
||||||
|
post :create, @create_params
|
||||||
|
response.should redirect_to(forbidden_path)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should not create subscribe object into db' do
|
||||||
|
lambda{ post :create, @create_params }.should change{ Subscribe.count }.by(0)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
shared_examples_for 'can unsubscribe' do
|
||||||
|
it 'should be able to perform destroy action' do
|
||||||
|
#set_objects_to_destroy
|
||||||
|
delete :destroy, @destroy_params
|
||||||
|
|
||||||
|
response.should redirect_to([@project, @issue])
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should reduce subscribes count' do
|
||||||
|
#set_objects_to_destroy
|
||||||
|
lambda{ delete :destroy, @destroy_params }.should change{ Subscribe.count }.by(-1)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
shared_examples_for 'can not unsubscribe' do
|
||||||
it 'should not be able to perform destroy action' do
|
it 'should not be able to perform destroy action' do
|
||||||
delete :destroy, :id => @subscribe.id, :issue_id => @issue.id, :project_id => @project.id
|
#set_objects_to_destroy
|
||||||
|
delete :destroy, @destroy_params
|
||||||
|
|
||||||
response.should redirect_to(forbidden_path)
|
response.should redirect_to(forbidden_path)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should not reduce subscribes count' do
|
it 'should not reduce subscribes count' do
|
||||||
lambda{ delete :destroy, :id => @subscribe.id, :issue_id => @issue.id, :project_id => @project.id }.should change{ Subscribe.count }.by(0)
|
#set_objects_to_destroy
|
||||||
|
lambda{ delete :destroy, @destroy_params }.should change{ Subscribe.count }.by(0)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -28,7 +56,9 @@ describe SubscribesController do
|
||||||
|
|
||||||
@project = Factory(:project)
|
@project = Factory(:project)
|
||||||
@issue = Factory(:issue, :project_id => @project.id)
|
@issue = Factory(:issue, :project_id => @project.id)
|
||||||
@subscribe = Factory(:subscribe, :subscribeable => @issue, :user => @user)
|
|
||||||
|
@create_params = {:issue_id => @issue.serial_id, :project_id => @project.id}
|
||||||
|
@destroy_params = {:issue_id => @issue.serial_id, :project_id => @project.id}
|
||||||
|
|
||||||
any_instance_of(Project, :versions => ['v1.0', 'v2.0'])
|
any_instance_of(Project, :versions => ['v1.0', 'v2.0'])
|
||||||
|
|
||||||
|
@ -40,30 +70,46 @@ describe SubscribesController do
|
||||||
@user = Factory(:admin)
|
@user = Factory(:admin)
|
||||||
set_session_for(@user)
|
set_session_for(@user)
|
||||||
@project.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'admin')
|
@project.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'admin')
|
||||||
|
@destroy_params = @destroy_params.merge({:id => @user.id})
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should be able to perform create action' do
|
context 'subscribed' do
|
||||||
post :create, :project_id => @project.id, :issue_id => @issue.id
|
before(:each) do
|
||||||
response.should redirect_to(project_issue_path(@project, @issue))
|
ss = @issue.subscribes.build(:user => @user)
|
||||||
|
ss.save!
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should create issue object into db' do
|
it_should_behave_like 'can unsubscribe'
|
||||||
lambda{ post :create, :project_id => @project.id, :issue_id => @issue.id }.should change{ Subscribe.count }.by(1)
|
it_should_behave_like 'can not subscribe'
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should be able to perform destroy action' do
|
context 'not subscribed' do
|
||||||
delete :destroy, :id => @subscribe.id, :issue_id => @issue.id, :project_id => @project.id
|
it_should_behave_like 'can subscribe'
|
||||||
response.should redirect_to(forbidden_path)
|
#it_should_behave_like 'can not unsubscribe'
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should reduce subscribes count' do
|
context 'for simple user' do
|
||||||
lambda{ delete :destroy, :id => @subscribe.id, :issue_id => @issue.id, :project_id => @project.id }.should change{ Issue.count }.by(-1)
|
before(:each) do
|
||||||
|
@user = Factory(:user)
|
||||||
|
set_session_for(@user)
|
||||||
|
@destroy_params = @destroy_params.merge({:id => @user.id})
|
||||||
end
|
end
|
||||||
|
|
||||||
#it_should_behave_like 'user with create subscribe rights'
|
context 'subscribed' do
|
||||||
#it_should_behave_like 'user with update stranger subscribe rights'
|
before(:each) do
|
||||||
#it_should_behave_like 'user with update own subscribe rights'
|
ss = @issue.subscribes.build(:user => @user)
|
||||||
#it_should_behave_like 'user without destroy subscribe rights'
|
ss.save!
|
||||||
|
end
|
||||||
|
|
||||||
|
it_should_behave_like 'can unsubscribe'
|
||||||
|
it_should_behave_like 'can not subscribe'
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'not subscribed' do
|
||||||
|
it_should_behave_like 'can subscribe'
|
||||||
|
#it_should_behave_like 'can not unsubscribe'
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,5 +1,125 @@
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
require "cancan/matchers"
|
||||||
|
|
||||||
|
def set_testable_data
|
||||||
|
@ability = Ability.new(@user)
|
||||||
|
|
||||||
|
@project = Factory(:project)
|
||||||
|
@issue = Factory(:issue, :project_id => @project.id)
|
||||||
|
|
||||||
|
@comment = Factory(:comment, :commentable => @issue, :user => @user)
|
||||||
|
@stranger_comment = Factory(:comment, :commentable => @issue, :user => @stranger)
|
||||||
|
|
||||||
|
any_instance_of(Project, :versions => ['v1.0', 'v2.0'])
|
||||||
|
end
|
||||||
|
|
||||||
describe Comment do
|
describe Comment do
|
||||||
pending "add some examples to (or delete) #{__FILE__}"
|
context 'for global admin user' do
|
||||||
|
before(:each) do
|
||||||
|
@user = Factory(:admin)
|
||||||
|
@stranger = Factory(:user)
|
||||||
|
|
||||||
|
set_testable_data
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should create comment' do
|
||||||
|
@ability.should be_able_to(:create, Comment.new(:commentable => @issue, :user => @user))
|
||||||
|
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 destroy own comment' do
|
||||||
|
@ability.should be_able_to(:destroy, @comment)
|
||||||
|
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
|
||||||
|
@user = Factory(:user)
|
||||||
|
@stranger = Factory(:user)
|
||||||
|
|
||||||
|
set_testable_data
|
||||||
|
|
||||||
|
@project.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'admin')
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should create comment' do
|
||||||
|
@ability.should be_able_to(:create, Comment.new(:commentable => @issue, :user => @user))
|
||||||
|
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
|
||||||
|
@user = Factory(:user)
|
||||||
|
@stranger = Factory(:user)
|
||||||
|
|
||||||
|
set_testable_data
|
||||||
|
|
||||||
|
@project.update_attribute(:owner, @user)
|
||||||
|
@project.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'admin')
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should create comment' do
|
||||||
|
@ability.should be_able_to(:create, Comment.new(:commentable => @issue, :user => @user))
|
||||||
|
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
|
||||||
|
@user = Factory(:user)
|
||||||
|
@stranger = Factory(:user)
|
||||||
|
|
||||||
|
set_testable_data
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should create comment' do
|
||||||
|
@ability.should be_able_to(:create, Comment.new(:commentable => @issue, :user => @user))
|
||||||
|
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
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,5 +1,77 @@
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
require "cancan/matchers"
|
||||||
|
|
||||||
|
def set_testable_data
|
||||||
|
@ability = Ability.new(@user)
|
||||||
|
|
||||||
|
@project = Factory(:project)
|
||||||
|
@issue = Factory(:issue, :project_id => @project.id)
|
||||||
|
|
||||||
|
any_instance_of(Project, :versions => ['v1.0', 'v2.0'])
|
||||||
|
end
|
||||||
|
|
||||||
describe Subscribe do
|
describe Subscribe do
|
||||||
pending "add some examples to (or delete) #{__FILE__}"
|
context 'for global admin user' do
|
||||||
|
before(:each) do
|
||||||
|
@user = Factory(:admin)
|
||||||
|
@stranger = Factory(:user)
|
||||||
|
|
||||||
|
set_testable_data
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should create subscribe' do
|
||||||
|
@ability.should be_able_to(:create, Subscribe.new(:subscribeable => @issue, :user => @user))
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'destroy' do
|
||||||
|
before(:each) do
|
||||||
|
@subscribe = Factory(:subscribe, :subscribeable => @issue, :user => @user)
|
||||||
|
@stranger_subscribe = Factory(:subscribe, :subscribeable => @issue, :user => @stranger)
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'own subscribe' do
|
||||||
|
it 'should destroy subscribe' do
|
||||||
|
@ability.should be_able_to(:destroy, @subscribe)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'stranger subscribe' do
|
||||||
|
it 'should not destroy subscribe' do
|
||||||
|
@ability.should_not be_able_to(:destroy, @stranger_subscribe)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'for simple user' do
|
||||||
|
before(:each) do
|
||||||
|
@user = Factory(:user)
|
||||||
|
@stranger = Factory(:user)
|
||||||
|
|
||||||
|
set_testable_data
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should create subscribe' do
|
||||||
|
@ability.should be_able_to(:create, Subscribe.new(:subscribeable => @issue, :user => @user))
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'destroy' do
|
||||||
|
before(:each) do
|
||||||
|
@subscribe = Factory(:subscribe, :subscribeable => @issue, :user => @user)
|
||||||
|
@stranger_subscribe = Factory(:subscribe, :subscribeable => @issue, :user => @stranger)
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'own subscribe' do
|
||||||
|
it 'should destroy subscribe' do
|
||||||
|
@ability.should be_able_to(:destroy, @subscribe)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'stranger subscribe' do
|
||||||
|
it 'should not destroy subscribe' do
|
||||||
|
@ability.should_not be_able_to(:destroy, @stranger_subscribe)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue