2012-01-30 20:39:34 +00:00
|
|
|
# -*- encoding : utf-8 -*-
|
2011-03-09 19:27:51 +00:00
|
|
|
require 'spec_helper'
|
2011-12-15 09:38:40 +00:00
|
|
|
|
|
|
|
shared_examples_for 'platform owner' do
|
|
|
|
it_should_behave_like 'platform index viewer'
|
|
|
|
|
|
|
|
it 'should not be able to destroy personal platform' do
|
|
|
|
delete :destroy, :id => @personal_platform.id
|
|
|
|
response.should redirect_to(forbidden_path)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should change objects count on destroy success' do
|
|
|
|
lambda { delete :destroy, :id => @platform.id }.should change{ Platform.count }.by(-1)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should be able to perform destroy action' do
|
|
|
|
delete :destroy, :id => @platform.id
|
|
|
|
response.should redirect_to(root_path)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples_for 'platform index viewer' do
|
|
|
|
it 'should be able to perform index action' do
|
|
|
|
get :index
|
|
|
|
response.should render_template(:index)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples_for 'user without create rights' do
|
|
|
|
it 'should not be able to create platform' do
|
|
|
|
post :create, @create_params
|
|
|
|
response.should redirect_to(forbidden_path)
|
|
|
|
end
|
|
|
|
end
|
2011-03-09 19:27:51 +00:00
|
|
|
|
|
|
|
describe PlatformsController do
|
2011-11-28 13:28:29 +00:00
|
|
|
before(:each) do
|
2011-12-12 07:51:39 +00:00
|
|
|
stub_rsync_methods
|
|
|
|
|
2011-11-28 13:28:29 +00:00
|
|
|
@platform = Factory(:platform)
|
|
|
|
@personal_platform = Factory(:platform, :platform_type => 'personal')
|
|
|
|
@user = Factory(:user)
|
|
|
|
@create_params = {:platform => {
|
|
|
|
:name => 'pl1',
|
2011-11-29 14:36:51 +00:00
|
|
|
:description => 'pl1',
|
2011-11-28 13:28:29 +00:00
|
|
|
:platform_type => 'main',
|
|
|
|
:distrib_type => APP_CONFIG['distr_types'].first
|
|
|
|
}}
|
|
|
|
end
|
2011-03-09 19:27:51 +00:00
|
|
|
|
2011-11-28 13:28:29 +00:00
|
|
|
context 'for guest' do
|
|
|
|
it "should not be able to perform easy_urpmi action" do
|
|
|
|
get :easy_urpmi
|
|
|
|
response.should redirect_to(forbidden_path)
|
|
|
|
end
|
|
|
|
|
|
|
|
[:index, :create].each do |action|
|
|
|
|
it "should not be able to perform #{ action } action" do
|
|
|
|
get action
|
|
|
|
response.should redirect_to(new_user_session_path)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
[:show, :new, :edit, :freeze, :unfreeze, :clone, :destroy].each do |action|
|
|
|
|
it "should not be able to perform #{ action } action" do
|
|
|
|
get action, :id => @platform
|
|
|
|
response.should redirect_to(new_user_session_path)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'for global admin' do
|
|
|
|
before(:each) do
|
|
|
|
@admin = Factory(:admin)
|
2011-12-11 16:00:50 +00:00
|
|
|
@user = Factory(:user)
|
2011-11-28 13:28:29 +00:00
|
|
|
set_session_for(@admin)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should be able to perform new action' do
|
|
|
|
get :new
|
|
|
|
response.should render_template(:new)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should be able to perform create action' do
|
|
|
|
post :create, @create_params
|
|
|
|
response.should redirect_to(platform_path(Platform.last))
|
|
|
|
end
|
|
|
|
|
2011-11-29 14:36:51 +00:00
|
|
|
it 'should change objects count on create success' do
|
|
|
|
lambda { post :create, @create_params }.should change{ Platform.count }.by(1)
|
2011-11-28 13:28:29 +00:00
|
|
|
end
|
|
|
|
|
2011-12-15 09:38:40 +00:00
|
|
|
it_should_behave_like 'platform owner'
|
2011-12-11 16:00:50 +00:00
|
|
|
|
|
|
|
|
2011-12-14 20:49:33 +00:00
|
|
|
it 'should create platform with mentioned owner if owner id present' do
|
2011-12-15 12:22:20 +00:00
|
|
|
post :create, @create_params.merge({:admin_id => @user.id, :admin_uname => @user.uname})
|
2011-12-14 20:49:33 +00:00
|
|
|
Platform.last.owner.id.should eql(@user.id)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should create platform with current user as owner if owner id not present' do
|
|
|
|
post :create, @create_params
|
|
|
|
Platform.last.owner.id.should eql(@admin.id)
|
2011-12-11 16:00:50 +00:00
|
|
|
end
|
|
|
|
|
2011-11-28 13:28:29 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'for owner user' do
|
|
|
|
before(:each) do
|
|
|
|
@user = Factory(:user)
|
|
|
|
set_session_for(@user)
|
|
|
|
@platform.update_attribute(:owner, @user)
|
2011-12-06 15:24:04 +00:00
|
|
|
@platform.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'admin')
|
2011-11-28 13:28:29 +00:00
|
|
|
end
|
|
|
|
|
2011-12-15 09:38:40 +00:00
|
|
|
it_should_behave_like 'user without create rights'
|
|
|
|
it_should_behave_like 'platform owner'
|
2011-11-28 13:28:29 +00:00
|
|
|
|
|
|
|
it 'should be able to perform new action' do
|
|
|
|
get :new
|
|
|
|
response.should redirect_to(forbidden_path)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should be able to perform create action' do
|
|
|
|
post :create, @create_params
|
|
|
|
response.should redirect_to(forbidden_path)
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'for reader user' do
|
|
|
|
before(:each) do
|
|
|
|
@user = Factory(:user)
|
|
|
|
set_session_for(@user)
|
2011-12-06 15:24:04 +00:00
|
|
|
@platform.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'reader')
|
2011-11-28 13:28:29 +00:00
|
|
|
end
|
|
|
|
|
2011-12-15 09:38:40 +00:00
|
|
|
it_should_behave_like 'platform index viewer'
|
|
|
|
it_should_behave_like 'user without create rights'
|
2011-11-28 13:28:29 +00:00
|
|
|
|
|
|
|
it 'should not be able to perform destroy action' do
|
|
|
|
delete :destroy, :id => @platform.id
|
|
|
|
response.should redirect_to(forbidden_path)
|
|
|
|
end
|
|
|
|
end
|
2011-03-09 19:27:51 +00:00
|
|
|
end
|