debian-mirror-gitlab/spec/models/ci/runner_spec.rb

136 lines
3.6 KiB
Ruby
Raw Normal View History

2015-09-25 12:07:36 +05:30
# == Schema Information
#
2015-11-26 14:37:03 +05:30
# Table name: ci_runners
2015-09-25 12:07:36 +05:30
#
# id :integer not null, primary key
# token :string(255)
# created_at :datetime
# updated_at :datetime
# description :string(255)
# contacted_at :datetime
# active :boolean default(TRUE), not null
# is_shared :boolean default(FALSE)
# name :string(255)
# version :string(255)
# revision :string(255)
# platform :string(255)
# architecture :string(255)
#
require 'spec_helper'
2015-12-23 02:04:40 +05:30
describe Ci::Runner, models: true do
2015-09-25 12:07:36 +05:30
describe '#display_name' do
it 'should return the description if it has a value' do
runner = FactoryGirl.build(:ci_runner, description: 'Linux/Ruby-1.9.3-p448')
expect(runner.display_name).to eq 'Linux/Ruby-1.9.3-p448'
end
it 'should return the token if it does not have a description' do
runner = FactoryGirl.create(:ci_runner)
expect(runner.display_name).to eq runner.description
end
it 'should return the token if the description is an empty string' do
2015-10-24 18:46:33 +05:30
runner = FactoryGirl.build(:ci_runner, description: '', token: 'token')
2015-09-25 12:07:36 +05:30
expect(runner.display_name).to eq runner.token
end
end
describe :assign_to do
2015-12-23 02:04:40 +05:30
let!(:project) { FactoryGirl.create :empty_project }
2016-04-02 18:10:28 +05:30
let!(:shared_runner) { FactoryGirl.create(:ci_runner, :shared) }
2015-09-25 12:07:36 +05:30
before { shared_runner.assign_to(project) }
it { expect(shared_runner).to be_specific }
it { expect(shared_runner.projects).to eq([project]) }
it { expect(shared_runner.only_for?(project)).to be_truthy }
end
2015-10-24 18:46:33 +05:30
describe :online do
subject { Ci::Runner.online }
before do
2016-04-02 18:10:28 +05:30
@runner1 = FactoryGirl.create(:ci_runner, :shared, contacted_at: 1.year.ago)
@runner2 = FactoryGirl.create(:ci_runner, :shared, contacted_at: 1.second.ago)
2015-10-24 18:46:33 +05:30
end
it { is_expected.to eq([@runner2])}
end
describe :online? do
2016-04-02 18:10:28 +05:30
let(:runner) { FactoryGirl.create(:ci_runner, :shared) }
2015-10-24 18:46:33 +05:30
subject { runner.online? }
context 'never contacted' do
before { runner.contacted_at = nil }
it { is_expected.to be_falsey }
end
context 'contacted long time ago time' do
before { runner.contacted_at = 1.year.ago }
it { is_expected.to be_falsey }
end
context 'contacted 1s ago' do
before { runner.contacted_at = 1.second.ago }
it { is_expected.to be_truthy }
end
end
describe :status do
2016-04-02 18:10:28 +05:30
let(:runner) { FactoryGirl.create(:ci_runner, :shared, contacted_at: 1.second.ago) }
2015-10-24 18:46:33 +05:30
subject { runner.status }
context 'never connected' do
before { runner.contacted_at = nil }
it { is_expected.to eq(:not_connected) }
end
context 'contacted 1s ago' do
before { runner.contacted_at = 1.second.ago }
it { is_expected.to eq(:online) }
end
context 'contacted long time ago' do
before { runner.contacted_at = 1.year.ago }
it { is_expected.to eq(:offline) }
end
context 'inactive' do
before { runner.active = false }
it { is_expected.to eq(:paused) }
end
end
2015-09-25 12:07:36 +05:30
describe "belongs_to_one_project?" do
it "returns false if there are two projects runner assigned to" do
2016-04-02 18:10:28 +05:30
runner = FactoryGirl.create(:ci_runner)
2015-12-23 02:04:40 +05:30
project = FactoryGirl.create(:empty_project)
project1 = FactoryGirl.create(:empty_project)
2015-09-25 12:07:36 +05:30
project.runners << runner
project1.runners << runner
expect(runner.belongs_to_one_project?).to be_falsey
end
it "returns true" do
2016-04-02 18:10:28 +05:30
runner = FactoryGirl.create(:ci_runner)
2015-12-23 02:04:40 +05:30
project = FactoryGirl.create(:empty_project)
2015-09-25 12:07:36 +05:30
project.runners << runner
expect(runner.belongs_to_one_project?).to be_truthy
end
end
end