2012-01-30 20:39:34 +00:00
|
|
|
# -*- encoding : utf-8 -*-
|
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)
|
|
|
|
|
|
|
|
@project = Factory(:project)
|
|
|
|
@issue = Factory(:issue, :project_id => @project.id)
|
|
|
|
|
|
|
|
any_instance_of(Project, :versions => ['v1.0', 'v2.0'])
|
|
|
|
end
|
2011-12-26 15:48:57 +00:00
|
|
|
|
|
|
|
describe Subscribe do
|
2012-02-20 23:13:05 +00:00
|
|
|
before { stub_rsync_methods }
|
2011-12-30 14:21:08 +00:00
|
|
|
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
|
2011-12-26 15:48:57 +00:00
|
|
|
end
|