Commit 10b3c85e authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Fix some issues with ci models specs

parent 381180bc
...@@ -15,7 +15,7 @@ module Ci ...@@ -15,7 +15,7 @@ module Ci
include HTTParty include HTTParty
belongs_to :project, class_name: 'Ci::WebHook' belongs_to :project, class_name: 'Ci::Project'
# HTTParty timeout # HTTParty timeout
default_timeout 10 default_timeout 10
......
FactoryGirl.define do FactoryGirl.define do
factory :ci_web_hook, class: Ci::WebHook do factory :ci_web_hook, class: Ci::WebHook do
sequence(:url) { Faker::Internet.uri('http') } sequence(:url) { FFaker::Internet.uri('http') }
project project factory: :ci_project
end end
end end
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
require 'spec_helper' require 'spec_helper'
describe Project do describe Project do
subject { FactoryGirl.build :project } subject { FactoryGirl.build :ci_project }
it { should have_many(:commits) } it { should have_many(:commits) }
...@@ -38,36 +38,36 @@ describe Project do ...@@ -38,36 +38,36 @@ describe Project do
describe 'before_validation' do describe 'before_validation' do
it 'should set an random token if none provided' do it 'should set an random token if none provided' do
project = FactoryGirl.create :project_without_token project = FactoryGirl.create :ci_project_without_token
project.token.should_not == "" project.token.should_not == ""
end end
it 'should not set an random toke if one provided' do it 'should not set an random toke if one provided' do
project = FactoryGirl.create :project project = FactoryGirl.create :ci_project
project.token.should == "iPWx6WM4lhHNedGfBpPJNP" project.token.should == "iPWx6WM4lhHNedGfBpPJNP"
end end
end end
describe "ordered_by_last_commit_date" do describe "ordered_by_last_commit_date" do
it "returns ordered projects" do it "returns ordered projects" do
newest_project = FactoryGirl.create :project newest_project = FactoryGirl.create :ci_project
oldest_project = FactoryGirl.create :project oldest_project = FactoryGirl.create :ci_project
project_without_commits = FactoryGirl.create :project project_without_commits = FactoryGirl.create :ci_project
FactoryGirl.create :commit, committed_at: 1.hour.ago, project: newest_project FactoryGirl.create :ci_commit, committed_at: 1.hour.ago, project: newest_project
FactoryGirl.create :commit, committed_at: 2.hour.ago, project: oldest_project FactoryGirl.create :ci_commit, committed_at: 2.hour.ago, project: oldest_project
Project.ordered_by_last_commit_date.should == [newest_project, oldest_project, project_without_commits] Project.ordered_by_last_commit_date.should == [newest_project, oldest_project, project_without_commits]
end end
end end
context :valid_project do context :valid_project do
let(:project) { FactoryGirl.create :project } let(:project) { FactoryGirl.create :ci_project }
context :project_with_commit_and_builds do context :project_with_commit_and_builds do
before do before do
commit = FactoryGirl.create(:commit, project: project) commit = FactoryGirl.create(:ci_commit, project: project)
FactoryGirl.create(:build, commit: commit) FactoryGirl.create(:ci_build, commit: commit)
end end
it { project.status.should == 'pending' } it { project.status.should == 'pending' }
...@@ -78,45 +78,45 @@ describe Project do ...@@ -78,45 +78,45 @@ describe Project do
describe '#email_notification?' do describe '#email_notification?' do
it do it do
project = FactoryGirl.create :project, email_add_pusher: true project = FactoryGirl.create :ci_project, email_add_pusher: true
project.email_notification?.should == true project.email_notification?.should == true
end end
it do it do
project = FactoryGirl.create :project, email_add_pusher: false, email_recipients: 'test tesft' project = FactoryGirl.create :ci_project, email_add_pusher: false, email_recipients: 'test tesft'
project.email_notification?.should == true project.email_notification?.should == true
end end
it do it do
project = FactoryGirl.create :project, email_add_pusher: false, email_recipients: '' project = FactoryGirl.create :ci_project, email_add_pusher: false, email_recipients: ''
project.email_notification?.should == false project.email_notification?.should == false
end end
end end
describe '#broken_or_success?' do describe '#broken_or_success?' do
it { it {
project = FactoryGirl.create :project, email_add_pusher: true project = FactoryGirl.create :ci_project, email_add_pusher: true
project.stub(:broken?).and_return(true) project.stub(:broken?).and_return(true)
project.stub(:success?).and_return(true) project.stub(:success?).and_return(true)
project.broken_or_success?.should == true project.broken_or_success?.should == true
} }
it { it {
project = FactoryGirl.create :project, email_add_pusher: true project = FactoryGirl.create :ci_project, email_add_pusher: true
project.stub(:broken?).and_return(true) project.stub(:broken?).and_return(true)
project.stub(:success?).and_return(false) project.stub(:success?).and_return(false)
project.broken_or_success?.should == true project.broken_or_success?.should == true
} }
it { it {
project = FactoryGirl.create :project, email_add_pusher: true project = FactoryGirl.create :ci_project, email_add_pusher: true
project.stub(:broken?).and_return(false) project.stub(:broken?).and_return(false)
project.stub(:success?).and_return(true) project.stub(:success?).and_return(true)
project.broken_or_success?.should == true project.broken_or_success?.should == true
} }
it { it {
project = FactoryGirl.create :project, email_add_pusher: true project = FactoryGirl.create :ci_project, email_add_pusher: true
project.stub(:broken?).and_return(false) project.stub(:broken?).and_return(false)
project.stub(:success?).and_return(false) project.stub(:success?).and_return(false)
project.broken_or_success?.should == false project.broken_or_success?.should == false
...@@ -140,7 +140,7 @@ describe Project do ...@@ -140,7 +140,7 @@ describe Project do
end end
describe :repo_url_with_auth do describe :repo_url_with_auth do
let(:project) { FactoryGirl.create :project } let(:project) { FactoryGirl.create :ci_project }
subject { project.repo_url_with_auth } subject { project.repo_url_with_auth }
it { should be_a(String) } it { should be_a(String) }
...@@ -152,7 +152,7 @@ describe Project do ...@@ -152,7 +152,7 @@ describe Project do
end end
describe :search do describe :search do
let!(:project) { FactoryGirl.create(:project, name: "foo") } let!(:project) { FactoryGirl.create(:ci_project, name: "foo") }
it { Project.search('fo').should include(project) } it { Project.search('fo').should include(project) }
it { Project.search('bar').should be_empty } it { Project.search('bar').should be_empty }
...@@ -160,25 +160,25 @@ describe Project do ...@@ -160,25 +160,25 @@ describe Project do
describe :any_runners do describe :any_runners do
it "there are no runners available" do it "there are no runners available" do
project = FactoryGirl.create(:project) project = FactoryGirl.create(:ci_project)
project.any_runners?.should be_false project.any_runners?.should be_false
end end
it "there is a specific runner" do it "there is a specific runner" do
project = FactoryGirl.create(:project) project = FactoryGirl.create(:ci_project)
project.runners << FactoryGirl.create(:specific_runner) project.runners << FactoryGirl.create(:ci_specific_runner)
project.any_runners?.should be_true project.any_runners?.should be_true
end end
it "there is a shared runner" do it "there is a shared runner" do
project = FactoryGirl.create(:project, shared_runners_enabled: true) project = FactoryGirl.create(:ci_project, shared_runners_enabled: true)
FactoryGirl.create(:shared_runner) FactoryGirl.create(:ci_shared_runner)
project.any_runners?.should be_true project.any_runners?.should be_true
end end
it "there is a shared runner, but they are prohibited to use" do it "there is a shared runner, but they are prohibited to use" do
project = FactoryGirl.create(:project) project = FactoryGirl.create(:ci_project)
FactoryGirl.create(:shared_runner) FactoryGirl.create(:ci_shared_runner)
project.any_runners?.should be_false project.any_runners?.should be_false
end end
end end
......
...@@ -27,7 +27,7 @@ describe Ci::Runner do ...@@ -27,7 +27,7 @@ describe Ci::Runner do
end end
it 'should return the token if it does not have a description' do it 'should return the token if it does not have a description' do
runner = FactoryGirl.create(:runner) runner = FactoryGirl.create(:ci_runner)
expect(runner.display_name).to eq runner.description expect(runner.display_name).to eq runner.description
end end
...@@ -38,8 +38,8 @@ describe Ci::Runner do ...@@ -38,8 +38,8 @@ describe Ci::Runner do
end end
describe :assign_to do describe :assign_to do
let!(:project) { FactoryGirl.create :project } let!(:project) { FactoryGirl.create :ci_project }
let!(:shared_runner) { FactoryGirl.create(:shared_runner) } let!(:shared_runner) { FactoryGirl.create(:ci_shared_runner) }
before { shared_runner.assign_to(project) } before { shared_runner.assign_to(project) }
...@@ -50,9 +50,9 @@ describe Ci::Runner do ...@@ -50,9 +50,9 @@ describe Ci::Runner do
describe "belongs_to_one_project?" do describe "belongs_to_one_project?" do
it "returns false if there are two projects runner assigned to" do it "returns false if there are two projects runner assigned to" do
runner = FactoryGirl.create(:specific_runner) runner = FactoryGirl.create(:ci_specific_runner)
project = FactoryGirl.create(:project) project = FactoryGirl.create(:ci_project)
project1 = FactoryGirl.create(:project) project1 = FactoryGirl.create(:ci_project)
project.runners << runner project.runners << runner
project1.runners << runner project1.runners << runner
...@@ -60,8 +60,8 @@ describe Ci::Runner do ...@@ -60,8 +60,8 @@ describe Ci::Runner do
end end
it "returns true" do it "returns true" do
runner = FactoryGirl.create(:specific_runner) runner = FactoryGirl.create(:ci_specific_runner)
project = FactoryGirl.create(:project) project = FactoryGirl.create(:ci_project)
project.runners << runner project.runners << runner
runner.belongs_to_one_project?.should be_true runner.belongs_to_one_project?.should be_true
......
...@@ -29,9 +29,9 @@ describe Ci::Service do ...@@ -29,9 +29,9 @@ describe Ci::Service do
end end
describe "Testable" do describe "Testable" do
let (:project) { FactoryGirl.create :project } let (:project) { FactoryGirl.create :ci_project }
let (:commit) { FactoryGirl.create :commit, project: project } let (:commit) { FactoryGirl.create :ci_commit, project: project }
let (:build) { FactoryGirl.create :build, commit: commit } let (:build) { FactoryGirl.create :ci_build, commit: commit }
before do before do
@service.stub( @service.stub(
......
require 'spec_helper' require 'spec_helper'
describe Ci::Trigger do describe Ci::Trigger do
let(:project) { FactoryGirl.create :project } let(:project) { FactoryGirl.create :ci_project }
describe 'before_validation' do describe 'before_validation' do
it 'should set an random token if none provided' do it 'should set an random token if none provided' do
trigger = FactoryGirl.create :trigger_without_token, project: project trigger = FactoryGirl.create :ci_trigger_without_token, project: project
trigger.token.should_not be_nil trigger.token.should_not be_nil
end end
it 'should not set an random token if one provided' do it 'should not set an random token if one provided' do
trigger = FactoryGirl.create :trigger, project: project trigger = FactoryGirl.create :ci_trigger, project: project
trigger.token.should == 'token' trigger.token.should == 'token'
end end
end end
......
...@@ -6,8 +6,8 @@ describe Ci::User do ...@@ -6,8 +6,8 @@ describe Ci::User do
let (:user) { User.new({}) } let (:user) { User.new({}) }
before do before do
FactoryGirl.create :project, gitlab_id: 1 FactoryGirl.create :ci_project, gitlab_id: 1
FactoryGirl.create :project, gitlab_id: 2 FactoryGirl.create :ci_project, gitlab_id: 2
gitlab_project = OpenStruct.new({id: 1}) gitlab_project = OpenStruct.new({id: 1})
gitlab_project1 = OpenStruct.new({id: 2}) gitlab_project1 = OpenStruct.new({id: 2})
User.any_instance.stub(:gitlab_projects).and_return([gitlab_project, gitlab_project1]) User.any_instance.stub(:gitlab_projects).and_return([gitlab_project, gitlab_project1])
...@@ -28,17 +28,17 @@ describe Ci::User do ...@@ -28,17 +28,17 @@ describe Ci::User do
describe "authorized_runners" do describe "authorized_runners" do
it "returns authorized runners" do it "returns authorized runners" do
project = FactoryGirl.create :project, gitlab_id: 1 project = FactoryGirl.create :ci_project, gitlab_id: 1
project1 = FactoryGirl.create :project, gitlab_id: 2 project1 = FactoryGirl.create :ci_project, gitlab_id: 2
gitlab_project = OpenStruct.new({id: 1}) gitlab_project = OpenStruct.new({id: 1})
gitlab_project1 = OpenStruct.new({id: 2}) gitlab_project1 = OpenStruct.new({id: 2})
User.any_instance.stub(:gitlab_projects).and_return([gitlab_project, gitlab_project1]) User.any_instance.stub(:gitlab_projects).and_return([gitlab_project, gitlab_project1])
User.any_instance.stub(:can_manage_project?).and_return(true) User.any_instance.stub(:can_manage_project?).and_return(true)
user = User.new({}) user = User.new({})
runner = FactoryGirl.create :specific_runner runner = FactoryGirl.create :ci_specific_runner
runner1 = FactoryGirl.create :specific_runner runner1 = FactoryGirl.create :ci_specific_runner
runner2 = FactoryGirl.create :specific_runner runner2 = FactoryGirl.create :ci_specific_runner
project.runners << runner project.runners << runner
project1.runners << runner1 project1.runners << runner1
......
...@@ -34,7 +34,7 @@ describe Ci::WebHook do ...@@ -34,7 +34,7 @@ describe Ci::WebHook do
describe "execute" do describe "execute" do
before(:each) do before(:each) do
@web_hook = FactoryGirl.create(:web_hook) @web_hook = FactoryGirl.create(:ci_web_hook)
@project = @web_hook.project @project = @web_hook.project
@data = { before: 'oldrev', after: 'newrev', ref: 'ref'} @data = { before: 'oldrev', after: 'newrev', ref: 'ref'}
......
...@@ -5,7 +5,7 @@ RSpec.configure do |config| ...@@ -5,7 +5,7 @@ RSpec.configure do |config|
config.before(:each) do config.before(:each) do
FileUtils.mkdir_p(builds_path) FileUtils.mkdir_p(builds_path)
Ci::Settings.gitlab_ci['builds_path'] = builds_path Settings.gitlab_ci['builds_path'] = builds_path
end end
config.after(:suite) do config.after(:suite) do
......
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