rosa-build/spec/models/subscribe_spec.rb

79 lines
2.2 KiB
Ruby
Raw Normal View History

require 'spec_helper'
require "cancan/matchers"
def set_testable_data
@ability = Ability.new(@user)
@project = FactoryGirl.create(:project)
2014-01-21 04:51:49 +00:00
@issue = FactoryGirl.create(:issue, project_id: @project.id)
2015-02-19 01:28:02 +00:00
allow_any_instance_of(Project).to receive(:versions).and_return(%w(v1.0 v2.0))
end
describe Subscribe do
before { stub_symlink_methods }
context 'for global admin user' do
before(:each) do
@user = FactoryGirl.create(:admin)
@stranger = FactoryGirl.create(:user)
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))
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)
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 = FactoryGirl.create(:user)
@stranger = FactoryGirl.create(:user)
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))
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)
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