2011-12-26 15:48:57 +00:00
|
|
|
require 'spec_helper'
|
2011-12-30 14:21:08 +00:00
|
|
|
require "cancan/matchers"
|
|
|
|
|
|
|
|
def set_testable_data
|
|
|
|
@ability = Ability.new(@user)
|
|
|
|
|
2012-03-29 21:34:22 +01:00
|
|
|
@project = FactoryGirl.create(:project)
|
2014-01-21 04:51:49 +00:00
|
|
|
@issue = FactoryGirl.create(:issue, project_id: @project.id)
|
2011-12-30 14:21:08 +00:00
|
|
|
|
2014-01-21 04:51:49 +00:00
|
|
|
any_instance_of(Project, versions: ['v1.0', 'v2.0'])
|
2011-12-30 14:21:08 +00:00
|
|
|
end
|
2011-12-26 15:48:57 +00:00
|
|
|
|
|
|
|
describe Subscribe do
|
2012-05-16 16:29:28 +01:00
|
|
|
before { stub_symlink_methods }
|
2011-12-30 14:21:08 +00:00
|
|
|
context 'for global admin user' do
|
|
|
|
before(:each) do
|
2012-03-29 21:34:22 +01:00
|
|
|
@user = FactoryGirl.create(:admin)
|
|
|
|
@stranger = FactoryGirl.create(:user)
|
2011-12-30 14:21:08 +00:00
|
|
|
|
|
|
|
set_testable_data
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should create subscribe' do
|
2014-03-18 19:45:13 +00:00
|
|
|
@ability.should be_able_to(:create, FactoryGirl.build(:subscribe, subscribeable: @issue, user: @user))
|
2011-12-30 14:21:08 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'destroy' do
|
|
|
|
before(:each) do
|
2014-01-21 04:51:49 +00:00
|
|
|
@subscribe = FactoryGirl.create(:subscribe, subscribeable: @issue, user: @user)
|
|
|
|
@stranger_subscribe = FactoryGirl.create(:subscribe, subscribeable: @issue, user: @stranger)
|
2011-12-30 14:21:08 +00:00
|
|
|
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
|
2012-03-29 21:34:22 +01:00
|
|
|
@user = FactoryGirl.create(:user)
|
|
|
|
@stranger = FactoryGirl.create(:user)
|
2011-12-30 14:21:08 +00:00
|
|
|
|
|
|
|
set_testable_data
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should create subscribe' do
|
2014-03-18 19:45:13 +00:00
|
|
|
@ability.should be_able_to(:create, FactoryGirl.build(:subscribe, subscribeable: @issue, user: @user))
|
2011-12-30 14:21:08 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'destroy' do
|
|
|
|
before(:each) do
|
2014-01-21 04:51:49 +00:00
|
|
|
@subscribe = FactoryGirl.create(:subscribe, subscribeable: @issue, user: @user)
|
|
|
|
@stranger_subscribe = FactoryGirl.create(:subscribe, subscribeable: @issue, user: @stranger)
|
2011-12-30 14:21:08 +00:00
|
|
|
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
|
2011-12-26 15:48:57 +00:00
|
|
|
end
|