rosa-build/spec/controllers/platforms/tokens_controller_spec.rb

128 lines
3.3 KiB
Ruby
Raw Normal View History

2013-06-26 09:04:40 +01:00
require 'spec_helper'
def create_key_pair(repository, user)
2014-01-21 04:51:49 +00:00
@key_pair = FactoryGirl.create(:key_pair, repository: repository, user: user)
2013-06-26 09:04:40 +01:00
end
shared_examples_for 'token of platform for owner' do
[:index, :new].each do |action|
it "should be able to perform #{action} action" do
2014-01-21 04:51:49 +00:00
get action, platform_id: @platform
2013-06-26 09:04:40 +01:00
response.should render_template(action)
end
end
it 'should not be able to perform show action' do
2014-01-21 04:51:49 +00:00
get :show, platform_id: @platform, id: @platform_token
2013-06-26 09:04:40 +01:00
response.should render_template(:show)
end
it 'should be able to perform create action' do
post :create, @create_params
response.should redirect_to(platform_tokens_path(@platform))
end
it 'should create key pair into db on create action' do
lambda { post :create, @create_params }.should change{Token.count}.by(1)
end
end
shared_examples_for 'token of platform for simple user or guest' do
[:index, :new].each do |action|
it "should not be able to perform #{ action } action" do
2014-01-21 04:51:49 +00:00
get action, platform_id: @platform
2013-06-26 09:04:40 +01:00
response.should redirect_to(redirected_url)
end
end
it 'should not be able to perform show action' do
2014-01-21 04:51:49 +00:00
get :show, platform_id: @platform, id: @platform_token
2013-06-26 09:04:40 +01:00
response.should redirect_to(redirected_url)
end
it 'should not be able to perform show action' do
post :create, @create_params
response.should redirect_to(redirected_url)
end
it 'should not change objects count on create success' do
lambda { post :create, @create_params }.should change{ Token.count }.by(0)
end
end
describe Platforms::TokensController do
before do
stub_symlink_methods
@platform = FactoryGirl.create(:platform)
@user = FactoryGirl.create(:user)
2014-01-21 04:51:49 +00:00
@platform_token = FactoryGirl.create(:platform_token, subject: @platform)
2013-06-26 09:04:40 +01:00
@create_params = {
2014-01-21 04:51:49 +00:00
platform_id: @platform,
tokens: {
description: 'description'
2013-06-26 09:04:40 +01:00
}
}
end
it_should_behave_like 'token of platform for simple user or guest' do
let(:redirected_url) { new_user_session_path }
end
context 'for global admin' do
before(:each) do
@admin = FactoryGirl.create(:admin)
@user = FactoryGirl.create(:user)
set_session_for(@admin)
end
it_should_behave_like 'token of platform for owner'
end
context 'for owner user' do
before(:each) do
@user = FactoryGirl.create(:user)
set_session_for(@user)
2014-01-21 04:51:49 +00:00
2013-06-26 09:04:40 +01:00
@platform.owner = @user
@platform.save
end
it_should_behave_like 'token of platform for owner'
end
context 'for admin user' do
before(:each) do
@user = FactoryGirl.create(:user)
set_session_for(@user)
create_relation(@platform, @user, 'admin')
2013-06-26 09:04:40 +01:00
end
it_should_behave_like 'token of platform for owner'
end
context 'for reader user' do
before do
@user = FactoryGirl.create(:user)
set_session_for(@user)
create_relation(@platform, @user, 'reader')
2013-06-26 09:04:40 +01:00
end
it_should_behave_like 'token of platform for simple user or guest' do
let(:redirected_url) { forbidden_url }
end
end
context 'for simple user' do
before do
@user = FactoryGirl.create(:user)
set_session_for(@user)
end
it_should_behave_like 'token of platform for simple user or guest' do
let(:redirected_url) { forbidden_url }
end
end
end