132 lines
3.3 KiB
Ruby
132 lines
3.3 KiB
Ruby
require 'spec_helper'
|
|
|
|
def create_key_pair(repository, user)
|
|
@key_pair = FactoryGirl.create(:key_pair, repository: repository, user: user)
|
|
end
|
|
|
|
shared_examples_for 'token of platform for owner' do
|
|
[:index, :new].each do |action|
|
|
it "should be able to perform #{action} action" do
|
|
get action, platform_id: @platform
|
|
expect(response).to render_template(action)
|
|
end
|
|
end
|
|
|
|
it 'should not be able to perform show action' do
|
|
get :show, platform_id: @platform, id: @platform_token
|
|
expect(response).to render_template(:show)
|
|
end
|
|
|
|
it 'should be able to perform create action' do
|
|
post :create, @create_params
|
|
expect(response).to redirect_to(platform_tokens_path(@platform))
|
|
end
|
|
|
|
it 'should create key pair into db on create action' do
|
|
expect do
|
|
post :create, @create_params
|
|
end.to 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
|
|
get action, platform_id: @platform
|
|
expect(response).to redirect_to(redirected_url)
|
|
end
|
|
end
|
|
|
|
it 'should not be able to perform show action' do
|
|
get :show, platform_id: @platform, id: @platform_token
|
|
expect(response).to redirect_to(redirected_url)
|
|
end
|
|
|
|
it 'should not be able to perform show action' do
|
|
post :create, @create_params
|
|
expect(response).to redirect_to(redirected_url)
|
|
end
|
|
|
|
it 'should not change objects count on create success' do
|
|
expect do
|
|
post :create, @create_params
|
|
end.to_not change(Token, :count)
|
|
end
|
|
end
|
|
|
|
describe Platforms::TokensController, type: :controller do
|
|
before do
|
|
stub_symlink_methods
|
|
|
|
@platform = FactoryGirl.create(:platform)
|
|
@user = FactoryGirl.create(:user)
|
|
@platform_token = FactoryGirl.create(:platform_token, subject: @platform)
|
|
@create_params = {
|
|
platform_id: @platform,
|
|
tokens: {
|
|
description: 'description'
|
|
}
|
|
}
|
|
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)
|
|
|
|
@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')
|
|
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')
|
|
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
|