BigW Consortium Gitlab

Commit 438e18d8 by Shinya Maeda

Refurbish spec/features/runners_spec.rb

parent 0f74ba96
......@@ -8,7 +8,7 @@
- if runner.locked?
= icon('lock', class: 'has-tooltip', title: 'Locked to current projects')
%small
%small.edit-runner
= link_to edit_project_runner_path(@project, runner) do
%i.fa.fa-edit.btn
- else
......
require 'spec_helper'
describe "Runners" do
let(:user) { create(:user) }
feature 'Runners' do
given(:user) { create(:user) }
before do
background do
sign_in(user)
end
describe "specific runners" do
before do
@project = FactoryGirl.create :project, shared_runners_enabled: false
@project.team << [user, :master]
context 'when a project has enabled shared_runners' do
given(:project) { create(:project) }
@project2 = FactoryGirl.create :project
@project2.team << [user, :master]
context 'when a specific runner is activated on the project' do
given(:specific_runner) { create(:ci_runner, :specific) }
@project3 = FactoryGirl.create :project
@project3.team << [user, :developer]
background do
project.add_master(user)
project.runners << specific_runner
end
@shared_runner = FactoryGirl.create :ci_runner, :shared
@specific_runner = FactoryGirl.create :ci_runner
@specific_runner2 = FactoryGirl.create :ci_runner
@specific_runner3 = FactoryGirl.create :ci_runner
@project.runners << @specific_runner
@project2.runners << @specific_runner2
@project3.runners << @specific_runner3
scenario 'user sees the specific runner' do
visit runners_path(project)
visit runners_path(@project)
end
within '.activated-specific-runners' do
expect(page).to have_content(specific_runner.display_name)
end
before do
expect(page).not_to have_content(@specific_runner3.display_name)
expect(page).not_to have_content(@specific_runner3.display_name)
end
click_on specific_runner.short_sha
it "places runners in right places" do
expect(page.find(".available-specific-runners")).to have_content(@specific_runner2.display_name)
expect(page.find(".activated-specific-runners")).to have_content(@specific_runner.display_name)
expect(page.find(".available-shared-runners")).to have_content(@shared_runner.display_name)
end
it "enables specific runner for project" do
within ".available-specific-runners" do
click_on "Enable for this project"
expect(page).to have_content(specific_runner.platform)
end
expect(page.find(".activated-specific-runners")).to have_content(@specific_runner2.display_name)
end
scenario 'user removes an activated specific runner' do
visit runners_path(project)
it "disables specific runner for project" do
@project2.runners << @specific_runner
visit runners_path(@project)
within '.activated-specific-runners' do
click_on 'Remove Runner'
end
within ".activated-specific-runners" do
click_on "Disable for this project"
expect(page).to have_no_css('.activated-specific-runners')
end
expect(page.find(".available-specific-runners")).to have_content(@specific_runner.display_name)
end
context 'when a runner has a tag' do
background do
specific_runner.update_attribute(:tag_list, ['tag'])
end
it "removes specific runner for project if this is last project for that runners" do
within ".activated-specific-runners" do
click_on "Remove Runner"
end
scenario 'user edits runner not to run untagged jobs' do
visit runners_path(project)
expect(Ci::Runner.exists?(id: @specific_runner)).to be_falsey
end
end
within '.activated-specific-runners' do
first('.edit-runner > a').click
end
describe "shared runners" do
before do
@project = FactoryGirl.create :project, shared_runners_enabled: false
@project.team << [user, :master]
visit runners_path(@project)
end
expect(page.find_field('runner[run_untagged]')).to be_checked
it "enables shared runners" do
click_on "Enable shared Runners"
expect(@project.reload.shared_runners_enabled).to be_truthy
end
end
uncheck 'runner_run_untagged'
click_button 'Save changes'
describe "shared runners description" do
let(:shared_runners_text) { 'custom **shared** runners description' }
let(:shared_runners_html) { 'custom shared runners description' }
expect(page).to have_content 'Can run untagged jobs No'
end
end
before do
stub_application_setting(shared_runners_text: shared_runners_text)
project = FactoryGirl.create :project, shared_runners_enabled: false
project.team << [user, :master]
visit runners_path(project)
end
context 'when a specific runner exists in another project' do
given(:another_project) { create(:project) }
given(:specific_runner2) { create(:ci_runner, :specific) }
it "sees shared runners description" do
expect(page.find(".shared-runners-description")).to have_content(shared_runners_html)
end
end
background do
another_project.add_master(user)
another_project.runners << specific_runner2
end
describe "show page" do
before do
@project = FactoryGirl.create :project
@project.team << [user, :master]
@specific_runner = FactoryGirl.create :ci_runner
@project.runners << @specific_runner
end
scenario 'user enables and disables a specific runner' do
visit runners_path(project)
it "shows runner information" do
visit runners_path(@project)
click_on @specific_runner.short_sha
expect(page).to have_content(@specific_runner.platform)
end
end
within '.available-specific-runners' do
click_on 'Enable for this project'
end
feature 'configuring runners ability to picking untagged jobs' do
given(:project) { create(:project) }
given(:runner) { create(:ci_runner) }
expect(page.find('.activated-specific-runners')).to have_content(specific_runner2.display_name)
background do
project.team << [user, :master]
project.runners << runner
end
within '.activated-specific-runners' do
click_on 'Disable for this project'
end
scenario 'user checks default configuration' do
visit project_runner_path(project, runner)
expect(page.find('.activated-specific-runners')).not_to have_content(specific_runner2.display_name)
end
end
context 'when a shared runner is activated on the project' do
given!(:shared_runner) { create(:ci_runner, :shared) }
expect(page).to have_content 'Can run untagged jobs Yes'
scenario 'user sees CI/CD setting page' do
visit runners_path(project)
expect(page.find('.available-shared-runners')).to have_content(shared_runner.display_name)
end
end
end
context 'when runner has tags' do
before do
runner.update_attribute(:tag_list, ['tag'])
context 'when application settings have shared_runners_text' do
given(:shared_runners_text) { 'custom **shared** runners description' }
given(:shared_runners_html) { 'custom shared runners description' }
background do
project.add_master(user)
stub_application_setting(shared_runners_text: shared_runners_text)
end
scenario 'user wants to prevent runner from running untagged job' do
scenario 'user sees shared runners description' do
visit runners_path(project)
page.within('.activated-specific-runners') do
first('small > a').click
end
uncheck 'runner_run_untagged'
click_button 'Save changes'
expect(page).to have_content 'Can run untagged jobs No'
expect(runner.reload.run_untagged?).to eq false
expect(page.find('.shared-runners-description')).to have_content(shared_runners_html)
end
end
end
context 'when a project has disabled shared_runners' do
given(:project) { create(:project, shared_runners_enabled: false) }
background do
project.add_master(user)
end
scenario 'user enables shared runners' do
visit runners_path(project)
click_on 'Enable shared Runners'
expect(page.find('.shared-runners-description')).to have_content('Disable shared Runners')
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