Commit e2cbb36b authored by Valery Sizov's avatar Valery Sizov

fix specs. Stage 5

parent 16ba41a1
......@@ -998,6 +998,7 @@ AllCops:
- 'tmp/**/*'
- 'bin/**/*'
- 'lib/backup/**/*'
- 'lib/ci/backup/**/*'
- 'lib/tasks/**/*'
- 'lib/email_validator.rb'
- 'lib/gitlab/upgrader.rb'
......
module Ci
module Admin
class ApplicationController < Ci::ApplicationController
before_filter :authenticate_user!
before_filter :authenticate_admin!
before_action :authenticate_user!
before_action :authenticate_admin!
layout "ci/admin"
end
......
......@@ -11,16 +11,13 @@ module Ci
expose :builds
end
class BuildOptions < Grape::Entity
expose :image
expose :services
end
class Build < Grape::Entity
expose :id, :commands, :ref, :sha, :project_id, :repo_url,
:before_sha, :allow_git_fetch, :project_name
expose :options, using: BuildOptions
expose :options do |model|
model.options
end
expose :timeout do |model|
model.timeout
......
......@@ -7,26 +7,29 @@ describe Ci::ProjectsController do
describe "POST #build" do
it 'should respond 200 if params is ok' do
post :build, id: @project.id,
post :build, {
id: @project.id,
ref: 'master',
before: '2aa371379db71ac89ae20843fcff3b3477cf1a1d',
after: '1c8a9df454ef68c22c2a33cca8232bb50849e5c5',
token: @project.token,
ci_yaml_file: gitlab_ci_yaml,
commits: [ { message: "Message" } ]
}
expect(response).to be_success
expect(response.code).to eq('201')
end
it 'should respond 400 if push about removed branch' do
post :build, id: @project.id,
post :build, {
id: @project.id,
ref: 'master',
before: '2aa371379db71ac89ae20843fcff3b3477cf1a1d',
after: '0000000000000000000000000000000000000000',
token: @project.token,
ci_yaml_file: gitlab_ci_yaml
}
expect(response).not_to be_success
expect(response.code).to eq('400')
......@@ -49,7 +52,7 @@ describe Ci::ProjectsController do
let(:project_dump) { YAML.load File.read(Rails.root.join('spec/support/gitlab_stubs/raw_project.yml')) }
let(:gitlab_url) { GitlabCi.config.gitlab_server.url }
let (:user_data) do
let(:user_data) do
data = JSON.parse File.read(Rails.root.join('spec/support/gitlab_stubs/user.json'))
data.merge("url" => gitlab_url)
end
......@@ -85,7 +88,7 @@ describe Ci::ProjectsController do
describe "GET /gitlab" do
let(:gitlab_url) { GitlabCi.config.gitlab_server.url }
let (:user_data) do
let(:user_data) do
data = JSON.parse File.read(Rails.root.join('spec/support/gitlab_stubs/user.json'))
data.merge("url" => gitlab_url)
end
......
......@@ -13,8 +13,8 @@ describe "Runners" do
# all projects should be authorized for user
allow_any_instance_of(Network).to receive(:projects).and_return([
OpenStruct.new({id: @project.gitlab_id}),
OpenStruct.new({id: @project2.gitlab_id})
OpenStruct.new({ id: @project.gitlab_id }),
OpenStruct.new({ id: @project2.gitlab_id })
])
@shared_runner = FactoryGirl.create :shared_runner
......
......@@ -3,12 +3,12 @@ require 'spec_helper'
describe Ci::GitlabCiYamlProcessor do
describe "#builds_for_ref" do
let (:type) { 'test' }
let(:type) { 'test' }
it "returns builds if no branch specified" do
config = YAML.dump({
before_script: ["pwd"],
rspec: {script: "rspec"}
rspec: { script: "rspec" }
})
config_processor = GitlabCiYamlProcessor.new(config)
......@@ -29,7 +29,7 @@ describe Ci::GitlabCiYamlProcessor do
it "does not return builds if only has another branch" do
config = YAML.dump({
before_script: ["pwd"],
rspec: {script: "rspec", only: ["deploy"]}
rspec: { script: "rspec", only: ["deploy"] }
})
config_processor = GitlabCiYamlProcessor.new(config)
......@@ -40,7 +40,7 @@ describe Ci::GitlabCiYamlProcessor do
it "does not return builds if only has regexp with another branch" do
config = YAML.dump({
before_script: ["pwd"],
rspec: {script: "rspec", only: ["/^deploy$/"]}
rspec: { script: "rspec", only: ["/^deploy$/"] }
})
config_processor = GitlabCiYamlProcessor.new(config)
......@@ -51,7 +51,7 @@ describe Ci::GitlabCiYamlProcessor do
it "returns builds if only has specified this branch" do
config = YAML.dump({
before_script: ["pwd"],
rspec: {script: "rspec", only: ["master"]}
rspec: { script: "rspec", only: ["master"] }
})
config_processor = GitlabCiYamlProcessor.new(config)
......@@ -62,7 +62,7 @@ describe Ci::GitlabCiYamlProcessor do
it "does not build tags" do
config = YAML.dump({
before_script: ["pwd"],
rspec: {script: "rspec", except: ["tags"]}
rspec: { script: "rspec", except: ["tags"] }
})
config_processor = GitlabCiYamlProcessor.new(config)
......@@ -73,7 +73,7 @@ describe Ci::GitlabCiYamlProcessor do
it "returns builds if only has a list of branches including specified" do
config = YAML.dump({
before_script: ["pwd"],
rspec: {script: "rspec", type: type, only: ["master", "deploy"]}
rspec: { script: "rspec", type: type, only: ["master", "deploy"] }
})
config_processor = GitlabCiYamlProcessor.new(config)
......@@ -85,10 +85,10 @@ describe Ci::GitlabCiYamlProcessor do
config = YAML.dump({
before_script: ["pwd"],
build: {script: "build", type: "build", only: ["master", "deploy"]},
rspec: {script: "rspec", type: type, only: ["master", "deploy"]},
staging: {script: "deploy", type: "deploy", only: ["master", "deploy"]},
production: {script: "deploy", type: "deploy", only: ["master", "deploy"]},
build: { script: "build", type: "build", only: ["master", "deploy"] },
rspec: { script: "rspec", type: type, only: ["master", "deploy"] },
staging: { script: "deploy", type: "deploy", only: ["master", "deploy"] },
production: { script: "deploy", type: "deploy", only: ["master", "deploy"] },
})
config_processor = GitlabCiYamlProcessor.new(config)
......@@ -105,7 +105,7 @@ describe Ci::GitlabCiYamlProcessor do
image: "ruby:2.1",
services: ["mysql"],
before_script: ["pwd"],
rspec: {script: "rspec"}
rspec: { script: "rspec" }
})
config_processor = GitlabCiYamlProcessor.new(config)
......@@ -162,7 +162,7 @@ describe Ci::GitlabCiYamlProcessor do
config = YAML.dump({
variables: variables,
before_script: ["pwd"],
rspec: {script: "rspec"}
rspec: { script: "rspec" }
})
config_processor = GitlabCiYamlProcessor.new(config)
......@@ -197,7 +197,7 @@ describe Ci::GitlabCiYamlProcessor do
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")
......@@ -239,7 +239,7 @@ describe Ci::GitlabCiYamlProcessor do
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")
......@@ -267,7 +267,7 @@ describe Ci::GitlabCiYamlProcessor do
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")
......
......@@ -56,7 +56,7 @@ describe Ci::Build do
end
let(:create_from_build) { Ci::Build.create_from build }
it ('there should be a pending task') do
it 'there should be a pending task' do
expect(Ci::Build.pending.count(:all)).to eq 0
create_from_build
expect(Ci::Build.pending.count(:all)).to be > 0
......
......@@ -72,4 +72,3 @@ describe Ci::HipChatService do
end
end
end
......@@ -29,9 +29,9 @@ describe Ci::Service do
end
describe "Testable" do
let (:project) { FactoryGirl.create :ci_project }
let (:commit) { FactoryGirl.create :ci_commit, project: project }
let (:build) { FactoryGirl.create :ci_build, commit: commit }
let(:project) { FactoryGirl.create :ci_project }
let(:commit) { FactoryGirl.create :ci_commit, project: project }
let(:build) { FactoryGirl.create :ci_build, commit: commit }
before do
allow(@service).to receive_messages(
......
......@@ -36,7 +36,7 @@ describe Ci::WebHook do
before(:each) do
@web_hook = FactoryGirl.create(:ci_web_hook)
@project = @web_hook.project
@data = { before: 'oldrev', after: 'newrev', ref: 'ref'}
@data = { before: 'oldrev', after: 'newrev', ref: 'ref' }
WebMock.stub_request(:post, @web_hook.url)
end
......@@ -56,9 +56,7 @@ describe Ci::WebHook do
it "catches exceptions" do
expect(WebHook).to receive(:post).and_raise("Some HTTP Post error")
expect {
@web_hook.execute(@data)
}.to raise_error
expect{ @web_hook.execute(@data) }.to raise_error
end
end
end
......@@ -11,7 +11,7 @@ describe Ci::API::API do
let(:shared_project) { FactoryGirl.create(:ci_project, name: "SharedProject") }
before do
FactoryGirl.create :runner_project, project_id: project.id, runner_id: runner.id
FactoryGirl.create :ci_runner_project, project_id: project.id, runner_id: runner.id
end
describe "POST /builds/register" do
......@@ -20,7 +20,7 @@ describe Ci::API::API do
commit.create_builds
build = commit.builds.first
post api("/builds/register"), token: runner.token, info: { platform: :darwin }
post ci_api("/builds/register"), token: runner.token, info: { platform: :darwin }
expect(response.status).to eq(201)
expect(json_response['sha']).to eq(build.sha)
......@@ -28,7 +28,7 @@ describe Ci::API::API do
end
it "should return 404 error if no pending build found" do
post api("/builds/register"), token: runner.token
post ci_api("/builds/register"), token: runner.token
expect(response.status).to eq(404)
end
......@@ -37,7 +37,7 @@ describe Ci::API::API do
commit = FactoryGirl.create(:ci_commit, project: shared_project)
FactoryGirl.create(:ci_build, commit: commit, status: 'pending' )
post api("/builds/register"), token: runner.token
post ci_api("/builds/register"), token: runner.token
expect(response.status).to eq(404)
end
......@@ -46,7 +46,7 @@ describe Ci::API::API do
commit = FactoryGirl.create(:ci_commit, project: project)
FactoryGirl.create(:ci_build, commit: commit, status: 'pending' )
post api("/builds/register"), token: shared_runner.token
post ci_api("/builds/register"), token: shared_runner.token
expect(response.status).to eq(404)
end
......@@ -55,7 +55,7 @@ describe Ci::API::API do
commit = FactoryGirl.create(:ci_commit, project: project)
commit.create_builds
post api("/builds/register"), token: runner.token, info: { platform: :darwin }
post ci_api("/builds/register"), token: runner.token, info: { platform: :darwin }
expect(response.status).to eq(201)
expect(json_response["options"]).to eq({ "image" => "ruby:2.1", "services" => ["postgres"] })
......@@ -64,9 +64,9 @@ describe Ci::API::API do
it "returns variables" do
commit = FactoryGirl.create(:ci_commit, project: project)
commit.create_builds
project.variables << Variable.new(key: "SECRET_KEY", value: "secret_value")
project.variables << Ci::Variable.new(key: "SECRET_KEY", value: "secret_value")
post api("/builds/register"), token: runner.token, info: { platform: :darwin }
post ci_api("/builds/register"), token: runner.token, info: { platform: :darwin }
expect(response.status).to eq(201)
expect(json_response["variables"]).to eq([
......@@ -81,9 +81,9 @@ describe Ci::API::API do
trigger_request = FactoryGirl.create(:ci_trigger_request_with_variables, commit: commit, trigger: trigger)
commit.create_builds(trigger_request)
project.variables << Variable.new(key: "SECRET_KEY", value: "secret_value")
project.variables << Ci::Variable.new(key: "SECRET_KEY", value: "secret_value")
post api("/builds/register"), token: runner.token, info: { platform: :darwin }
post ci_api("/builds/register"), token: runner.token, info: { platform: :darwin }
expect(response.status).to eq(201)
expect(json_response["variables"]).to eq([
......@@ -100,14 +100,14 @@ describe Ci::API::API do
it "should update a running build" do
build.run!
put api("/builds/#{build.id}"), token: runner.token
put ci_api("/builds/#{build.id}"), token: runner.token
expect(response.status).to eq(200)
end
it 'Should not override trace information when no trace is given' do
build.run!
build.update!(trace: 'hello_world')
put api("/builds/#{build.id}"), token: runner.token
put ci_api("/builds/#{build.id}"), token: runner.token
expect(build.reload.trace).to eq 'hello_world'
end
end
......
......@@ -62,7 +62,7 @@ describe Ci::API::API do
let!(:project) { FactoryGirl.create(:ci_project) }
context "Valid Webhook URL" do
let!(:webhook) { {web_hook: "http://example.com/sth/1/ala_ma_kota" } }
let!(:webhook) { { web_hook: "http://example.com/sth/1/ala_ma_kota" } }
before do
options.merge!(webhook)
......
......@@ -8,11 +8,11 @@ describe Ci::API::API do
let!(:project) { FactoryGirl.create(:ci_project) }
let!(:project2) { FactoryGirl.create(:ci_project) }
let!(:trigger) { FactoryGirl.create(:ci_trigger, project: project, token: trigger_token) }
let(:options) {
let(:options) do
{
token: trigger_token
}
}
end
context 'Handles errors' do
it 'should return bad request if token is missing' do
......
require 'spec_helper'
describe Ci::EventService do
let (:project) { FactoryGirl.create :project, name: "GitLab / gitlab-shell" }
let (:user) { double(username: "root", id: 1) }
let(:project) { FactoryGirl.create :project, name: "GitLab / gitlab-shell" }
let(:user) { double(username: "root", id: 1) }
before do
Event.destroy_all
......
require 'spec_helper'
describe Ci::WebHookService do
let (:project) { FactoryGirl.create :project }
let (:commit) { FactoryGirl.create :commit, project: project }
let (:build) { FactoryGirl.create :build, commit: commit }
let (:hook) { FactoryGirl.create :web_hook, project: project }
let(:project) { FactoryGirl.create :project }
let(:commit) { FactoryGirl.create :commit, project: project }
let(:build) { FactoryGirl.create :build, commit: commit }
let(:hook) { FactoryGirl.create :web_hook, project: project }
describe :execute do
it "should execute successfully" do
......
......@@ -24,20 +24,20 @@ module StubGitlabCalls
stub_request(:post, "#{gitlab_url}api/v3/session.json").
with(body: "{\"email\":\"test@test.com\",\"password\":\"123456\"}",
headers: {'Content-Type'=>'application/json'}).
to_return(status: 201, body: f, headers: {'Content-Type'=>'application/json'})
headers: { 'Content-Type'=>'application/json' }).
to_return(status: 201, body: f, headers: { 'Content-Type'=>'application/json' })
end
def stub_user
f = File.read(Rails.root.join('spec/support/gitlab_stubs/user.json'))
stub_request(:get, "#{gitlab_url}api/v3/user?private_token=Wvjy2Krpb7y8xi93owUz").
with(headers: {'Content-Type'=>'application/json'}).
to_return(status: 200, body: f, headers: {'Content-Type'=>'application/json'})
with(headers: { 'Content-Type'=>'application/json' }).
to_return(status: 200, body: f, headers: { 'Content-Type'=>'application/json' })
stub_request(:get, "#{gitlab_url}api/v3/user?access_token=some_token").
with(headers: {'Content-Type'=>'application/json'}).
to_return(status: 200, body: f, headers: {'Content-Type'=>'application/json'})
with(headers: { 'Content-Type'=>'application/json' }).
to_return(status: 200, body: f, headers: { 'Content-Type'=>'application/json' })
end
def stub_project_8
......@@ -54,19 +54,19 @@ module StubGitlabCalls
f = File.read(Rails.root.join('spec/support/gitlab_stubs/projects.json'))
stub_request(:get, "#{gitlab_url}api/v3/projects.json?archived=false&ci_enabled_first=true&private_token=Wvjy2Krpb7y8xi93owUz").
with(headers: {'Content-Type'=>'application/json'}).
to_return(status: 200, body: f, headers: {'Content-Type'=>'application/json'})
with(headers: { 'Content-Type'=>'application/json' }).
to_return(status: 200, body: f, headers: { 'Content-Type'=>'application/json' })
end
def stub_projects_owned
stub_request(:get, "#{gitlab_url}api/v3/projects/owned.json?archived=false&ci_enabled_first=true&private_token=Wvjy2Krpb7y8xi93owUz").
with(headers: {'Content-Type'=>'application/json'}).
with(headers: { 'Content-Type'=>'application/json' }).
to_return(status: 200, body: "", headers: {})
end
def stub_ci_enable
stub_request(:put, "#{gitlab_url}api/v3/projects/2/services/gitlab-ci.json?private_token=Wvjy2Krpb7y8xi93owUz").
with(headers: {'Content-Type'=>'application/json'}).
with(headers: { 'Content-Type'=>'application/json' }).
to_return(status: 200, body: "", headers: {})
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