summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorValery Sizov <vsv2711@gmail.com>2015-04-16 18:27:22 +0300
committerValery Sizov <vsv2711@gmail.com>2015-04-21 19:28:18 +0300
commit21138800fe9d366c25b98065f584271b32df4c36 (patch)
tree7fab646956ab0703fc2264875d7e0de990e2388e
parent6f78038a119af4d63ddf4a7b9df6de229ac6a9dc (diff)
downloadgitlab-ci-21138800fe9d366c25b98065f584271b32df4c36.tar.gz
runner page: specs
-rw-r--r--app/models/runner.rb4
-rw-r--r--app/views/runners/_runner.html.haml7
-rw-r--r--app/views/runners/_shared_runners.html.haml2
-rw-r--r--app/views/runners/_specific_runners.html.haml4
-rw-r--r--spec/factories/runners.rb12
-rw-r--r--spec/features/runners_spec.rb66
-rw-r--r--spec/helpers/runners_helper_spec.rb18
-rw-r--r--spec/models/runner_spec.rb26
-rw-r--r--spec/models/user_spec.rb34
9 files changed, 160 insertions, 13 deletions
diff --git a/app/models/runner.rb b/app/models/runner.rb
index bfd5a54..3747218 100644
--- a/app/models/runner.rb
+++ b/app/models/runner.rb
@@ -53,6 +53,10 @@ class Runner < ActiveRecord::Base
is_shared
end
+ def belongs_to_one_project?
+ runner_projects.count == 1
+ end
+
def specific?
!shared?
end
diff --git a/app/views/runners/_runner.html.haml b/app/views/runners/_runner.html.haml
index 9ac847d..4cb2879 100644
--- a/app/views/runners/_runner.html.haml
+++ b/app/views/runners/_runner.html.haml
@@ -10,8 +10,11 @@
.pull-right
- if @runners.include?(runner)
- - runner_project = @project.runner_projects.find_by(runner_id: runner)
- = link_to 'Disable for this project', [@project, runner_project], data: { confirm: "Are you sure?" }, method: :delete, class: 'btn btn-danger btn-small'
+ - if runner.belongs_to_one_project?
+ = link_to 'Remove runner', [@project, runner], data: { confirm: "Are you sure?" }, method: :delete, class: 'btn btn-danger btn-small'
+ - else
+ - runner_project = @project.runner_projects.find_by(runner_id: runner)
+ = link_to 'Disable for this project', [@project, runner_project], data: { confirm: "Are you sure?" }, method: :delete, class: 'btn btn-danger btn-small'
- elsif runner.specific?
= form_for [@project, @project.runner_projects.new] do |f|
= f.hidden_field :runner_id, value: runner.id
diff --git a/app/views/runners/_shared_runners.html.haml b/app/views/runners/_shared_runners.html.haml
index 7cd365f..ae803e2 100644
--- a/app/views/runners/_shared_runners.html.haml
+++ b/app/views/runners/_shared_runners.html.haml
@@ -16,7 +16,7 @@
Please use specific runners or ask administrator to create one
- else
%h4.underlined-title Available shared runners - #{@shared_runners_count}
- %ul.bordered-list
+ %ul.bordered-list.available-shared-runners
= render @shared_runners.first(10)
- if @shared_runners_count > 10
.light
diff --git a/app/views/runners/_specific_runners.html.haml b/app/views/runners/_specific_runners.html.haml
index 2e47b1b..be8525e 100644
--- a/app/views/runners/_specific_runners.html.haml
+++ b/app/views/runners/_specific_runners.html.haml
@@ -19,11 +19,11 @@
- if @runners.any?
%h4.underlined-title Runners activated for this project
- %ul.bordered-list
+ %ul.bordered-list.activated-specific-runners
= render @runners
- if @specific_runners.any?
%h4.underlined-title Available specific runners
- %ul.bordered-list
+ %ul.bordered-list.available-specific-runners
= render @specific_runners
= paginate @specific_runners
diff --git a/spec/factories/runners.rb b/spec/factories/runners.rb
index 5fe32a6..32af2ce 100644
--- a/spec/factories/runners.rb
+++ b/spec/factories/runners.rb
@@ -16,6 +16,16 @@
FactoryGirl.define do
factory :runner do
- token "MyString"
+ sequence :description do |n|
+ "My runner#{n}"
+ end
+
+ factory :shared_runner do
+ is_shared true
+ end
+
+ factory :specific_runner do
+ is_shared false
+ end
end
end
diff --git a/spec/features/runners_spec.rb b/spec/features/runners_spec.rb
index 888b202..36b7fab 100644
--- a/spec/features/runners_spec.rb
+++ b/spec/features/runners_spec.rb
@@ -3,15 +3,73 @@ require 'spec_helper'
describe "Runners" do
before do
login_as :user
- @project = FactoryGirl.create :project
end
- describe "GET /projects/:id/runners" do
+ describe "specific runners" do
before do
+ @project = FactoryGirl.create :project
+ @project2 = FactoryGirl.create :project
+ stub_js_gitlab_calls
+
+ @shared_runner = FactoryGirl.create :shared_runner
+ @specific_runner = FactoryGirl.create :specific_runner
+ @specific_runner2 = FactoryGirl.create :specific_runner
+ @project.runners << @specific_runner
+ @project2.runners << @specific_runner2
+ end
+
+ it "places runners in right places" do
+ visit project_runners_path(@project)
+ page.find(".available-specific-runners").should have_content(@specific_runner2.display_name)
+ page.find(".activated-specific-runners").should have_content(@specific_runner.display_name)
+ page.find(".available-shared-runners").should have_content(@shared_runner.display_name)
+ end
+
+ it "enables specific runner for project" do
+ visit project_runners_path(@project)
+
+ within ".available-specific-runners" do
+ click_on "Enable for this project"
+ end
+
+ page.find(".activated-specific-runners").should have_content(@specific_runner2.display_name)
+ end
+
+ it "disables specific runner for project" do
+ @project2.runners << @specific_runner
+
visit project_runners_path(@project)
+
+ within ".activated-specific-runners" do
+ click_on "Disable for this project"
+ end
+
+ page.find(".available-specific-runners").should have_content(@specific_runner.display_name)
end
- it { page.should have_content @project.name }
- it { page.should have_content 'How to setup a new project specific runner' }
+ it "removes specific runner for project if this is last project for that runners" do
+ visit project_runners_path(@project)
+
+ within ".activated-specific-runners" do
+ click_on "Remove runner"
+ end
+
+ Runner.exists?(id: @specific_runner).should be_false
+ end
+ end
+
+ describe "shared runners" do
+ before do
+ @project = FactoryGirl.create :project
+ stub_js_gitlab_calls
+ end
+
+ it "enables shared runners" do
+ visit project_runners_path(@project)
+
+ click_on "Enable shared runners"
+
+ @project.reload.shared_runners_enabled.should be_true
+ end
end
end
diff --git a/spec/helpers/runners_helper_spec.rb b/spec/helpers/runners_helper_spec.rb
new file mode 100644
index 0000000..02d497b
--- /dev/null
+++ b/spec/helpers/runners_helper_spec.rb
@@ -0,0 +1,18 @@
+require 'spec_helper'
+
+describe RunnersHelper do
+ it "returns - not contacted yet" do
+ runner = FactoryGirl.build :runner
+ runner_status_icon(runner).should include("not connected yet")
+ end
+
+ it "returns offline text" do
+ runner = FactoryGirl.build(:runner, contacted_at: 1.day.ago, active: true)
+ runner_status_icon(runner).should include("Runner is offline")
+ end
+
+ it "returns online text" do
+ runner = FactoryGirl.build(:runner, contacted_at: 1.hour.ago, active: true)
+ runner_status_icon(runner).should include("Runner is online")
+ end
+end
diff --git a/spec/models/runner_spec.rb b/spec/models/runner_spec.rb
index 5440e9e..6b90367 100644
--- a/spec/models/runner_spec.rb
+++ b/spec/models/runner_spec.rb
@@ -22,8 +22,8 @@ describe Runner do
end
it 'should return the token if it does not have a description' do
- runner = FactoryGirl.build(:runner)
- expect(runner.display_name).to eq runner.token
+ runner = FactoryGirl.create(:runner)
+ expect(runner.display_name).to eq runner.description
end
it 'should return the token if the description is an empty string' do
@@ -34,7 +34,7 @@ describe Runner do
describe :assign_to do
let!(:project) { FactoryGirl.create :project }
- let!(:shared_runner) { FactoryGirl.create(:runner, is_shared: true) }
+ let!(:shared_runner) { FactoryGirl.create(:shared_runner) }
before { shared_runner.assign_to(project) }
@@ -42,4 +42,24 @@ describe Runner do
it { shared_runner.projects.should == [project] }
it { shared_runner.only_for?(project).should be_true }
end
+
+ describe "belongs_to_one_project?" do
+ it "returns false if there are two projects runner assigned to" do
+ runner = FactoryGirl.create(:specific_runner)
+ project = FactoryGirl.create(:project)
+ project1 = FactoryGirl.create(:project)
+ project.runners << runner
+ project1.runners << runner
+
+ runner.belongs_to_one_project?.should be_false
+ end
+
+ it "returns true" do
+ runner = FactoryGirl.create(:specific_runner)
+ project = FactoryGirl.create(:project)
+ project.runners << runner
+
+ runner.belongs_to_one_project?.should be_true
+ end
+ end
end
diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb
index 44b260b..4a1e393 100644
--- a/spec/models/user_spec.rb
+++ b/spec/models/user_spec.rb
@@ -51,4 +51,38 @@ describe User do
@user.has_developer_access?(1).should be_true
end
end
+
+ describe "authorized_projects" do
+ it "returns projects" do
+ project = FactoryGirl.create :project, gitlab_id: 1
+ project1 = FactoryGirl.create :project, gitlab_id: 2
+ gitlab_project = OpenStruct.new({id: 1})
+ gitlab_project1 = OpenStruct.new({id: 2})
+ User.any_instance.stub(:gitlab_projects).and_return([gitlab_project, gitlab_project1])
+ user = User.new({})
+
+ user.authorized_projects.count.should == 2
+ end
+ end
+
+ describe "authorized_runners" do
+ it "returns authorized runners" do
+ project = FactoryGirl.create :project, gitlab_id: 1
+ project1 = FactoryGirl.create :project, gitlab_id: 2
+ gitlab_project = OpenStruct.new({id: 1})
+ gitlab_project1 = OpenStruct.new({id: 2})
+ User.any_instance.stub(:gitlab_projects).and_return([gitlab_project, gitlab_project1])
+ user = User.new({})
+
+ runner = FactoryGirl.create :specific_runner
+ runner1 = FactoryGirl.create :specific_runner
+ runner2 = FactoryGirl.create :specific_runner
+
+ project.runners << runner
+ project1.runners << runner1
+
+ user.authorized_runners.should include(runner, runner1)
+ user.authorized_runners.should_not include(runner2)
+ end
+ end
end