Commit 54108b6c authored by Gabriel Mazetto's avatar Gabriel Mazetto

Added specs for Geo Key synchronization and fixed mistakes

parent 9ba1c009
......@@ -8,7 +8,7 @@ module Geo
end
def execute
GeoKeyRefreshWorker.perform_async(project['id'], project['clone_url'])
GeoKeyRefreshWorker.perform_async(@id, @action)
end
end
end
......@@ -19,6 +19,8 @@ class GeoKeyRefreshWorker
# ActiveRecord::RecordNotFound when not found (so job will retry)
key = Key.find(key_id)
key.remove_from_shell
else
fail "Invalid action: #{action}"
end
end
......
......@@ -8,14 +8,33 @@ describe API::API, api: true do
describe 'POST /geo/refresh_projects' do
before(:each) { allow_any_instance_of(::Geo::ScheduleRepoUpdateService).to receive(:execute) }
it 'should retrieve the license information if admin is logged in' do
it 'starts refresh process if admin and correct params' do
post api('/geo/refresh_projects', admin), projects: ['1', '2', '3']
expect(response.status).to eq 201
end
it 'should deny access if not admin' do
it 'denies access if not admin' do
post api('/geo/refresh_projects', user)
expect(response.status).to eq 403
end
end
describe 'POST /geo/refresh_key' do
before(:each) { allow_any_instance_of(::Geo::ScheduleKeyChangeService).to receive(:execute) }
it 'enqueues on disk key creation if admin and correct params' do
post api('/geo/refresh_key', admin), key_change: { id: 1, action: 'create' }
expect(response.status).to eq 201
end
it 'enqueues on disk key removal if admin and correct params' do
post api('/geo/refresh_key', admin), key_change: { id: 1, action: 'delete' }
expect(response.status).to eq 201
end
it 'denies access if not admin' do
post api('/geo/refresh_key', user)
expect(response.status).to eq 403
end
end
end
require 'spec_helper'
describe Geo::ScheduleKeyChangeService, service: true do
subject(:key_create) { Geo::ScheduleKeyChangeService.new({ 'id' => 1, 'action' => 'create' }) }
subject(:key_delete) { Geo::ScheduleKeyChangeService.new({ 'id' => 1, 'action' => 'delete' }) }
before(:each) { allow_any_instance_of(GeoKeyRefreshWorker).to receive(:perform) }
context 'key creation' do
it 'executes action' do
expect(key_create.execute).to be_truthy
end
end
context 'key removal' do
it 'executes action' do
expect(key_delete.execute).to be_truthy
end
end
end
require 'spec_helper'
describe GeoKeyRefreshWorker do
subject(:key_create) { described_class.new.perform(key.id, 'create') }
subject(:key_delete) { described_class.new.perform(key.id, 'delete') }
let(:key) { FactoryGirl.create(:key) }
context 'key creation' do
it 'adds key to shell' do
expect(Key).to receive(:find).with(key.id) { key }
expect(key).to receive(:add_to_shell)
expect { key_create }.not_to raise_error
end
end
context 'key removal' do
it 'removes key from the shell' do
expect(Key).to receive(:find).with(key.id) { key }
expect(key).to receive(:remove_from_shell)
expect { key_delete }.not_to raise_error
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment