Skip to content
Snippets Groups Projects
Commit 4c53cc0e authored by Valery Sizov's avatar Valery Sizov
Browse files

rubocop satisfy

parent 95037c9c
No related branches found
No related tags found
No related merge requests found
Showing
with 132 additions and 132 deletions
module Ci
class Admin::RunnersController < Ci::Admin::ApplicationController
before_filter :runner, except: :index
before_action :runner, except: :index
 
def index
@runners = Ci::Runner.order('id DESC')
Loading
Loading
module Ci
class BuildsController < Ci::ApplicationController
before_filter :authenticate_user!, except: [:status, :show]
before_filter :authenticate_public_page!, only: :show
before_filter :project
before_filter :authorize_access_project!, except: [:status, :show]
before_filter :authorize_manage_project!, except: [:status, :show, :retry, :cancel]
before_filter :authorize_manage_builds!, only: [:retry, :cancel]
before_filter :build, except: [:show]
before_action :authenticate_user!, except: [:status, :show]
before_action :authenticate_public_page!, only: :show
before_action :project
before_action :authorize_access_project!, except: [:status, :show]
before_action :authorize_manage_project!, except: [:status, :show, :retry, :cancel]
before_action :authorize_manage_builds!, only: [:retry, :cancel]
before_action :build, except: [:show]
layout 'ci/project'
 
def show
Loading
Loading
module Ci
class ChartsController < Ci::ApplicationController
before_filter :authenticate_user!
before_filter :project
before_filter :authorize_access_project!
before_filter :authorize_manage_project!
before_action :authenticate_user!
before_action :project
before_action :authorize_access_project!
before_action :authorize_manage_project!
 
layout 'ci/project'
 
Loading
Loading
module Ci
class CommitsController < Ci::ApplicationController
before_filter :authenticate_user!, except: [:status, :show]
before_filter :authenticate_public_page!, only: :show
before_filter :project
before_filter :authorize_access_project!, except: [:status, :show, :cancel]
before_filter :authorize_manage_builds!, only: [:cancel]
before_filter :commit, only: :show
before_action :authenticate_user!, except: [:status, :show]
before_action :authenticate_public_page!, only: :show
before_action :project
before_action :authorize_access_project!, except: [:status, :show, :cancel]
before_action :authorize_manage_builds!, only: [:cancel]
before_action :commit, only: :show
layout 'ci/project'
 
def show
Loading
Loading
Loading
Loading
@@ -2,9 +2,9 @@ module Ci
class EventsController < Ci::ApplicationController
EVENTS_PER_PAGE = 50
 
before_filter :authenticate_user!
before_filter :project
before_filter :authorize_manage_project!
before_action :authenticate_user!
before_action :project
before_action :authorize_manage_project!
 
layout 'ci/project'
 
Loading
Loading
module Ci
class LintsController < Ci::ApplicationController
before_filter :authenticate_user!
before_action :authenticate_user!
 
def show
end
Loading
Loading
Loading
Loading
@@ -2,13 +2,13 @@ module Ci
class ProjectsController < Ci::ApplicationController
PROJECTS_BATCH = 100
 
before_filter :authenticate_user!, except: [:build, :badge, :index, :show]
before_filter :authenticate_public_page!, only: :show
before_filter :project, only: [:build, :integration, :show, :badge, :edit, :update, :destroy, :toggle_shared_runners, :dumped_yaml]
before_filter :authorize_access_project!, except: [:build, :gitlab, :badge, :index, :show, :new, :create]
before_filter :authorize_manage_project!, only: [:edit, :integration, :update, :destroy, :toggle_shared_runners, :dumped_yaml]
before_filter :authenticate_token!, only: [:build]
before_filter :no_cache, only: [:badge]
before_action :authenticate_user!, except: [:build, :badge, :index, :show]
before_action :authenticate_public_page!, only: :show
before_action :project, only: [:build, :integration, :show, :badge, :edit, :update, :destroy, :toggle_shared_runners, :dumped_yaml]
before_action :authorize_access_project!, except: [:build, :gitlab, :badge, :index, :show, :new, :create]
before_action :authorize_manage_project!, only: [:edit, :integration, :update, :destroy, :toggle_shared_runners, :dumped_yaml]
before_action :authenticate_token!, only: [:build]
before_action :no_cache, only: [:badge]
protect_from_forgery except: :build
 
layout 'ci/project', except: [:index, :gitlab]
Loading
Loading
module Ci
class RunnerProjectsController < Ci::ApplicationController
before_filter :authenticate_user!
before_filter :project
before_filter :authorize_manage_project!
before_action :authenticate_user!
before_action :project
before_action :authorize_manage_project!
 
layout 'ci/project'
 
Loading
Loading
module Ci
class RunnersController < Ci::ApplicationController
before_filter :authenticate_user!
before_filter :project
before_filter :set_runner, only: [:edit, :update, :destroy, :pause, :resume, :show]
before_filter :authorize_access_project!
before_filter :authorize_manage_project!
before_action :authenticate_user!
before_action :project
before_action :set_runner, only: [:edit, :update, :destroy, :pause, :resume, :show]
before_action :authorize_access_project!
before_action :authorize_manage_project!
 
layout 'ci/project'
 
Loading
Loading
module Ci
class ServicesController < Ci::ApplicationController
before_filter :authenticate_user!
before_filter :project
before_filter :authorize_access_project!
before_filter :authorize_manage_project!
before_filter :service, only: [:edit, :update, :test]
before_action :authenticate_user!
before_action :project
before_action :authorize_access_project!
before_action :authorize_manage_project!
before_action :service, only: [:edit, :update, :test]
 
respond_to :html
 
Loading
Loading
module Ci
class TriggersController < Ci::ApplicationController
before_filter :authenticate_user!
before_filter :project
before_filter :authorize_access_project!
before_filter :authorize_manage_project!
before_action :authenticate_user!
before_action :project
before_action :authorize_access_project!
before_action :authorize_manage_project!
 
layout 'ci/project'
 
Loading
Loading
module Ci
class VariablesController < Ci::ApplicationController
before_filter :authenticate_user!
before_filter :project
before_filter :authorize_access_project!
before_filter :authorize_manage_project!
before_action :authenticate_user!
before_action :project
before_action :authorize_access_project!
before_action :authorize_manage_project!
 
layout 'ci/project'
 
Loading
Loading
module Ci
class WebHooksController < Ci::ApplicationController
before_filter :authenticate_user!
before_filter :project
before_filter :authorize_access_project!
before_filter :authorize_manage_project!
before_action :authenticate_user!
before_action :project
before_action :authorize_access_project!
before_action :authorize_manage_project!
 
layout 'ci/project'
 
Loading
Loading
Loading
Loading
@@ -13,13 +13,13 @@ module Ci
 
def dump
success = case config["adapter"]
when /^mysql/ then
$progress.print "Dumping MySQL database #{config['database']} ... "
system('mysqldump', *mysql_args, config['database'], out: db_file_name)
when "postgresql" then
$progress.print "Dumping PostgreSQL database #{config['database']} ... "
pg_env
system('pg_dump', config['database'], out: db_file_name)
when /^mysql/ then
$progress.print "Dumping MySQL database #{config['database']} ... "
system('mysqldump', *mysql_args, config['database'], out: db_file_name)
when "postgresql" then
$progress.print "Dumping PostgreSQL database #{config['database']} ... "
pg_env
system('pg_dump', config['database'], out: db_file_name)
end
report_success(success)
abort 'Backup failed' unless success
Loading
Loading
@@ -27,17 +27,17 @@ module Ci
 
def restore
success = case config["adapter"]
when /^mysql/ then
$progress.print "Restoring MySQL database #{config['database']} ... "
system('mysql', *mysql_args, config['database'], in: db_file_name)
when "postgresql" then
$progress.print "Restoring PostgreSQL database #{config['database']} ... "
# Drop all tables because PostgreSQL DB dumps do not contain DROP TABLE
# statements like MySQL.
drop_all_tables
drop_all_postgres_sequences
pg_env
system('psql', config['database'], '-f', db_file_name)
when /^mysql/ then
$progress.print "Restoring MySQL database #{config['database']} ... "
system('mysql', *mysql_args, config['database'], in: db_file_name)
when "postgresql" then
$progress.print "Restoring PostgreSQL database #{config['database']} ... "
# Drop all tables because PostgreSQL DB dumps do not contain DROP TABLE
# statements like MySQL.
drop_all_tables
drop_all_postgres_sequences
pg_env
system('psql', config['database'], '-f', db_file_name)
end
report_success(success)
abort 'Restore failed' unless success
Loading
Loading
Loading
Loading
@@ -8,12 +8,12 @@ describe Ci::ProjectsController do
describe "POST #build" do
it 'should respond 200 if params is ok' do
post :build, id: @project.id,
ref: 'master',
before: '2aa371379db71ac89ae20843fcff3b3477cf1a1d',
after: '1c8a9df454ef68c22c2a33cca8232bb50849e5c5',
token: @project.token,
ref: 'master',
before: '2aa371379db71ac89ae20843fcff3b3477cf1a1d',
after: '1c8a9df454ef68c22c2a33cca8232bb50849e5c5',
token: @project.token,
ci_yaml_file: gitlab_ci_yaml,
commits: [ { message: "Message" } ]
commits: [ { message: "Message" } ]
 
 
expect(response).to be_success
Loading
Loading
@@ -22,10 +22,10 @@ describe Ci::ProjectsController do
 
it 'should respond 400 if push about removed branch' do
post :build, id: @project.id,
ref: 'master',
before: '2aa371379db71ac89ae20843fcff3b3477cf1a1d',
after: '0000000000000000000000000000000000000000',
token: @project.token,
ref: 'master',
before: '2aa371379db71ac89ae20843fcff3b3477cf1a1d',
after: '0000000000000000000000000000000000000000',
token: @project.token,
ci_yaml_file: gitlab_ci_yaml
 
expect(response).not_to be_success
Loading
Loading
Loading
Loading
@@ -60,14 +60,14 @@ FactoryGirl.define do
 
factory :ci_commit_with_one_job do
after(:create) do |commit, evaluator|
commit.push_data[:ci_yaml_file] = YAML.dump({rspec: { script: "ls" }})
commit.push_data[:ci_yaml_file] = YAML.dump({ rspec: { script: "ls" } })
commit.save
end
end
 
factory :ci_commit_with_two_jobs do
after(:create) do |commit, evaluator|
commit.push_data[:ci_yaml_file] = YAML.dump({rspec: { script: "ls" }, spinach: { script: "ls" }})
commit.push_data[:ci_yaml_file] = YAML.dump({ rspec: { script: "ls" }, spinach: { script: "ls" } })
commit.save
end
end
Loading
Loading
Loading
Loading
@@ -131,7 +131,7 @@ describe Ci::GitlabCiYamlProcessor do
image: "ruby:2.1",
services: ["mysql"],
before_script: ["pwd"],
rspec: {image: "ruby:2.5", services: ["postgresql"], script: "rspec"}
rspec: { image: "ruby:2.5", services: ["postgresql"], script: "rspec" }
})
 
config_processor = GitlabCiYamlProcessor.new(config)
Loading
Loading
@@ -176,133 +176,133 @@ describe Ci::GitlabCiYamlProcessor do
end
 
it "returns errors if tags parameter is invalid" do
config = YAML.dump({rspec: {script: "test", tags: "mysql"}})
config = YAML.dump({ rspec: { script: "test", tags: "mysql" } })
expect do
GitlabCiYamlProcessor.new(config)
end.to raise_error(GitlabCiYamlProcessor::ValidationError, "rspec job: tags parameter should be an array of strings")
end
 
it "returns errors if before_script parameter is invalid" do
config = YAML.dump({before_script: "bundle update", rspec: {script: "test"}})
config = YAML.dump({ before_script: "bundle update", rspec: { script: "test" } })
expect do
GitlabCiYamlProcessor.new(config)
end.to raise_error(GitlabCiYamlProcessor::ValidationError, "before_script should be an array of strings")
end
 
it "returns errors if image parameter is invalid" do
config = YAML.dump({image: ["test"], rspec: {script: "test"}})
config = YAML.dump({ image: ["test"], rspec: { script: "test" } })
expect do
GitlabCiYamlProcessor.new(config)
end.to raise_error(GitlabCiYamlProcessor::ValidationError, "image should be a string")
end
 
it "returns errors if job image parameter is invalid" do
config = YAML.dump({rspec: {script: "test", image: ["test"]}})
config = YAML.dump({rspec: { script: "test", image: ["test"] } })
expect do
GitlabCiYamlProcessor.new(config)
end.to raise_error(GitlabCiYamlProcessor::ValidationError, "rspec job: image should be a string")
end
 
it "returns errors if services parameter is not an array" do
config = YAML.dump({services: "test", rspec: {script: "test"}})
config = YAML.dump({ services: "test", rspec: { script: "test" } })
expect do
GitlabCiYamlProcessor.new(config)
end.to raise_error(GitlabCiYamlProcessor::ValidationError, "services should be an array of strings")
end
 
it "returns errors if services parameter is not an array of strings" do
config = YAML.dump({services: [10, "test"], rspec: {script: "test"}})
config = YAML.dump({ services: [10, "test"], rspec: { script: "test" } })
expect do
GitlabCiYamlProcessor.new(config)
end.to raise_error(GitlabCiYamlProcessor::ValidationError, "services should be an array of strings")
end
 
it "returns errors if job services parameter is not an array" do
config = YAML.dump({rspec: {script: "test", services: "test"}})
config = YAML.dump({ rspec: { script: "test", services: "test" } })
expect do
GitlabCiYamlProcessor.new(config)
end.to raise_error(GitlabCiYamlProcessor::ValidationError, "rspec job: services should be an array of strings")
end
 
it "returns errors if job services parameter is not an array of strings" do
config = YAML.dump({rspec: {script: "test", services: [10, "test"]}})
config = YAML.dump({ rspec: { script: "test", services: [10, "test"] } })
expect do
GitlabCiYamlProcessor.new(config)
end.to raise_error(GitlabCiYamlProcessor::ValidationError, "rspec job: services should be an array of strings")
end
 
it "returns errors if there are unknown parameters" do
config = YAML.dump({extra: "bundle update"})
config = YAML.dump({ extra: "bundle update" })
expect do
GitlabCiYamlProcessor.new(config)
end.to raise_error(GitlabCiYamlProcessor::ValidationError, "Unknown parameter: extra")
end
 
it "returns errors if there are unknown parameters that are hashes, but doesn't have a script" do
config = YAML.dump({extra: {services: "test"}})
config = YAML.dump({ extra: {services: "test" } })
expect do
GitlabCiYamlProcessor.new(config)
end.to raise_error(GitlabCiYamlProcessor::ValidationError, "Unknown parameter: extra")
end
 
it "returns errors if there is no any jobs defined" do
config = YAML.dump({before_script: ["bundle update"]})
config = YAML.dump({ before_script: ["bundle update"] })
expect do
GitlabCiYamlProcessor.new(config)
end.to raise_error(GitlabCiYamlProcessor::ValidationError, "Please define at least one job")
end
 
it "returns errors if job allow_failure parameter is not an boolean" do
config = YAML.dump({rspec: {script: "test", allow_failure: "string"}})
config = YAML.dump({ rspec: { script: "test", allow_failure: "string" } })
expect do
GitlabCiYamlProcessor.new(config)
end.to raise_error(GitlabCiYamlProcessor::ValidationError, "rspec job: allow_failure parameter should be an boolean")
end
 
it "returns errors if job stage is not a string" do
config = YAML.dump({rspec: {script: "test", type: 1, allow_failure: "string"}})
config = YAML.dump({ rspec: { script: "test", type: 1, allow_failure: "string" } })
expect do
GitlabCiYamlProcessor.new(config)
end.to raise_error(GitlabCiYamlProcessor::ValidationError, "rspec job: stage parameter should be build, test, deploy")
end
 
it "returns errors if job stage is not a pre-defined stage" do
config = YAML.dump({rspec: {script: "test", type: "acceptance", allow_failure: "string"}})
config = YAML.dump({rspec: { script: "test", type: "acceptance", allow_failure: "string" } })
expect do
GitlabCiYamlProcessor.new(config)
end.to raise_error(GitlabCiYamlProcessor::ValidationError, "rspec job: stage parameter should be build, test, deploy")
end
 
it "returns errors if job stage is not a defined stage" do
config = YAML.dump({types: ["build", "test"], rspec: {script: "test", type: "acceptance", allow_failure: "string"}})
config = YAML.dump({ types: ["build", "test"], rspec: { script: "test", type: "acceptance", allow_failure: "string" } })
expect do
GitlabCiYamlProcessor.new(config)
end.to raise_error(GitlabCiYamlProcessor::ValidationError, "rspec job: stage parameter should be build, test")
end
 
it "returns errors if stages is not an array" do
config = YAML.dump({types: "test", rspec: {script: "test"}})
config = YAML.dump({ types: "test", rspec: { script: "test" } })
expect do
GitlabCiYamlProcessor.new(config)
end.to raise_error(GitlabCiYamlProcessor::ValidationError, "stages should be an array of strings")
end
 
it "returns errors if stages is not an array of strings" do
config = YAML.dump({types: [true, "test"], rspec: {script: "test"}})
config = YAML.dump({ types: [true, "test"], rspec: { script: "test" } })
expect do
GitlabCiYamlProcessor.new(config)
end.to raise_error(GitlabCiYamlProcessor::ValidationError, "stages should be an array of strings")
end
 
it "returns errors if variables is not a map" do
config = YAML.dump({variables: "test", rspec: {script: "test"}})
config = YAML.dump({ variables: "test", rspec: { script: "test" } })
expect do
GitlabCiYamlProcessor.new(config)
end.to raise_error(GitlabCiYamlProcessor::ValidationError, "variables should be a map of key-valued strings")
end
 
it "returns errors if variables is not a map of key-valued strings" do
config = YAML.dump({variables: {test: false}, rspec: {script: "test"}})
config = YAML.dump({ variables: { test: false }, rspec: { script: "test" } })
expect do
GitlabCiYamlProcessor.new(config)
end.to raise_error(GitlabCiYamlProcessor::ValidationError, "variables should be a map of key-valued strings")
Loading
Loading
Loading
Loading
@@ -211,14 +211,14 @@ describe Ci::Build do
end
 
describe :options do
let(:options) {
let(:options) do
{
:image => "ruby:2.1",
:services => [
image: "ruby:2.1",
services: [
"postgres"
]
}
}
end
 
subject { build.options }
it { is_expected.to eq(options) }
Loading
Loading
@@ -308,20 +308,20 @@ describe Ci::Build do
context 'returns variables' do
subject { build.variables }
 
let(:variables) {
let(:variables) do
[
{key: :DB_NAME, value: 'postgres', public: true}
{ key: :DB_NAME, value: 'postgres', public: true }
]
}
end
 
it { is_expected.to eq(variables) }
 
context 'and secure variables' do
let(:secure_variables) {
let(:secure_variables) do
[
{key: 'SECRET_KEY', value: 'secret_value', public: false}
{ key: 'SECRET_KEY', value: 'secret_value', public: false }
]
}
end
 
before do
build.project.variables << Ci::Variable.new(key: 'SECRET_KEY', value: 'secret_value')
Loading
Loading
@@ -332,11 +332,11 @@ describe Ci::Build do
context 'and trigger variables' do
let(:trigger) { FactoryGirl.create :ci_trigger, project: project }
let(:trigger_request) { FactoryGirl.create :ci_trigger_request_with_variables, commit: commit, trigger: trigger }
let(:trigger_variables) {
let(:trigger_variables) do
[
{key: :TRIGGER_KEY, value: 'TRIGGER_VALUE', public: false}
{ key: :TRIGGER_KEY, value: 'TRIGGER_VALUE', public: false }
]
}
end
 
before do
build.trigger_request = trigger_request
Loading
Loading
Loading
Loading
@@ -75,12 +75,12 @@ describe Ci::MailService do
end
 
describe 'successfull build and project has email_recipients' do
let(:project) {
let(:project) do
FactoryGirl.create(:ci_project,
email_add_pusher: true,
email_only_broken_builds: false,
email_recipients: "jeroen@example.com")
}
end
let(:commit) { FactoryGirl.create(:ci_commit, project: project) }
let(:build) { FactoryGirl.create(:ci_build, status: :success, commit: commit) }
 
Loading
Loading
@@ -103,12 +103,12 @@ describe Ci::MailService do
end
 
describe 'successful build and notify only broken builds' do
let(:project) {
let(:project) do
FactoryGirl.create(:ci_project,
email_add_pusher: true,
email_only_broken_builds: true,
email_recipients: "jeroen@example.com")
}
end
let(:commit) { FactoryGirl.create(:ci_commit, project: project) }
let(:build) { FactoryGirl.create(:ci_build, status: :success, commit: commit) }
 
Loading
Loading
@@ -131,12 +131,12 @@ describe Ci::MailService do
end
 
describe 'successful build and can test service' do
let(:project) {
let(:project) do
FactoryGirl.create(:ci_project,
email_add_pusher: true,
email_only_broken_builds: false,
email_recipients: "jeroen@example.com")
}
end
let(:commit) { FactoryGirl.create(:ci_commit, project: project) }
let(:build) { FactoryGirl.create(:ci_build, status: :success, commit: commit) }
 
Loading
Loading
@@ -153,12 +153,12 @@ describe Ci::MailService do
end
 
describe 'retried build should not receive email' do
let(:project) {
let(:project) do
FactoryGirl.create(:ci_project,
email_add_pusher: true,
email_only_broken_builds: true,
email_recipients: "jeroen@example.com")
}
end
let(:commit) { FactoryGirl.create(:ci_commit, project: project) }
let(:build) { FactoryGirl.create(:ci_build, status: :failed, commit: commit) }
 
Loading
Loading
Loading
Loading
@@ -94,33 +94,33 @@ describe Ci::Project do
end
 
describe '#broken_or_success?' do
it {
it do
project = FactoryGirl.create :ci_project, email_add_pusher: true
allow(project).to receive(:broken?).and_return(true)
allow(project).to receive(:success?).and_return(true)
expect(project.broken_or_success?).to eq(true)
}
end
 
it {
it do
project = FactoryGirl.create :ci_project, email_add_pusher: true
allow(project).to receive(:broken?).and_return(true)
allow(project).to receive(:success?).and_return(false)
expect(project.broken_or_success?).to eq(true)
}
end
 
it {
it do
project = FactoryGirl.create :ci_project, email_add_pusher: true
allow(project).to receive(:broken?).and_return(false)
allow(project).to receive(:success?).and_return(true)
expect(project.broken_or_success?).to eq(true)
}
end
 
it {
it do
project = FactoryGirl.create :ci_project, email_add_pusher: true
allow(project).to receive(:broken?).and_return(false)
allow(project).to receive(:success?).and_return(false)
expect(project.broken_or_success?).to eq(false)
}
end
end
 
describe 'Project.parse' do
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment