Commit 9a9417ee authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Fix more tests

parent dc2e38e5
......@@ -55,7 +55,7 @@ describe Ci::ProjectsController do
end
let(:user) do
Ci::User.new(user_data)
create(:user)
end
it "creates project" do
......@@ -73,7 +73,7 @@ describe Ci::ProjectsController do
it "shows error" do
allow(controller).to receive(:reset_cache) { true }
allow(controller).to receive(:current_user) { user }
allow_any_instance_of(Ci::User).to receive(:can_manage_project?).and_return(false)
allow_any_instance_of(User).to receive(:can_manage_project?).and_return(false)
post :create, { project: JSON.dump(project_dump.to_h) }.with_indifferent_access
......@@ -91,7 +91,7 @@ describe Ci::ProjectsController do
end
let(:user) do
Ci::User.new(user_data)
create(:user)
end
it "searches projects" do
......
require 'spec_helper'
describe Ci::HipChatMessage do
subject { HipChatMessage.new(build) }
subject { Ci::HipChatMessage.new(build) }
let(:project) { FactoryGirl.create(:project) }
let(:project) { FactoryGirl.create(:ci_project) }
context "One build" do
let(:commit) { FactoryGirl.create(:commit_with_one_job, project: project) }
let(:commit) { FactoryGirl.create(:ci_commit_with_one_job, project: project) }
let(:build) do
commit.create_builds
......@@ -37,7 +37,7 @@ describe Ci::HipChatMessage do
end
context "Several builds" do
let(:commit) { FactoryGirl.create(:commit_with_two_jobs, project: project) }
let(:commit) { FactoryGirl.create(:ci_commit_with_two_jobs, project: project) }
let(:build) do
commit.builds.first
......
......@@ -32,10 +32,10 @@ describe Ci::HipChatService do
describe "Execute" do
let(:service) { HipChatService.new }
let(:project) { FactoryGirl.create :project }
let(:commit) { FactoryGirl.create :commit, project: project }
let(:build) { FactoryGirl.create :build, commit: commit, status: 'failed' }
let(:service) { Ci::HipChatService.new }
let(:project) { FactoryGirl.create :ci_project }
let(:commit) { FactoryGirl.create :ci_commit, project: project }
let(:build) { FactoryGirl.create :ci_build, commit: commit, status: 'failed' }
let(:api_url) { 'https://api.hipchat.com/v2/room/123/notification?auth_token=a1b2c3d4e5f6' }
before do
......
......@@ -3,10 +3,10 @@ require 'spec_helper'
describe Ci::SlackMessage do
subject { SlackMessage.new(commit) }
let(:project) { FactoryGirl.create :project }
let(:project) { FactoryGirl.create :ci_project }
context "One build" do
let(:commit) { FactoryGirl.create(:commit_with_one_job, project: project) }
let(:commit) { FactoryGirl.create(:ci_commit_with_one_job, project: project) }
let(:build) do
commit.create_builds
......
......@@ -31,9 +31,9 @@ describe Ci::SlackService do
describe "Execute" do
let(:slack) { SlackService.new }
let(:project) { FactoryGirl.create :project }
let(:commit) { FactoryGirl.create :commit, project: project }
let(:build) { FactoryGirl.create :build, commit: commit, status: 'failed' }
let(:project) { FactoryGirl.create :ci_project }
let(:commit) { FactoryGirl.create :ci_commit, project: project }
let(:build) { FactoryGirl.create :ci_build, commit: commit, status: 'failed' }
let(:webhook_url) { 'https://hooks.slack.com/services/SVRWFV0VVAR97N/B02R25XN3/ZBqu7xMupaEEICInN685' }
let(:notify_only_broken_builds) { false }
......
require 'spec_helper'
describe Ci::User do
describe "authorized_projects" do
let (:user) { User.new({}) }
before do
FactoryGirl.create :ci_project, gitlab_id: 1
FactoryGirl.create :ci_project, gitlab_id: 2
gitlab_project = OpenStruct.new({id: 1})
gitlab_project1 = OpenStruct.new({id: 2})
allow_any_instance_of(User).to receive(:gitlab_projects).and_return([gitlab_project, gitlab_project1])
end
it "returns projects" do
allow_any_instance_of(User).to receive(:can_manage_project?).and_return(true)
expect(user.authorized_projects.count).to eq(2)
end
it "empty list if user miss manage permission" do
allow_any_instance_of(User).to receive(:can_manage_project?).and_return(false)
expect(user.authorized_projects.count).to eq(0)
end
end
describe "authorized_runners" do
it "returns authorized runners" do
project = FactoryGirl.create :ci_project, gitlab_id: 1
project1 = FactoryGirl.create :ci_project, gitlab_id: 2
gitlab_project = OpenStruct.new({id: 1})
gitlab_project1 = OpenStruct.new({id: 2})
allow_any_instance_of(User).to receive(:gitlab_projects).and_return([gitlab_project, gitlab_project1])
allow_any_instance_of(User).to receive(:can_manage_project?).and_return(true)
user = User.new({})
runner = FactoryGirl.create :ci_specific_runner
runner1 = FactoryGirl.create :ci_specific_runner
runner2 = FactoryGirl.create :ci_specific_runner
project.runners << runner
project1.runners << runner1
expect(user.authorized_runners).to include(runner, runner1)
expect(user.authorized_runners).not_to include(runner2)
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