Fix some issues with ci models specs

This commit is contained in:
Dmitriy Zaporozhets 2015-09-10 15:47:15 +02:00
parent 381180bc27
commit 10b3c85e2c
9 changed files with 55 additions and 55 deletions

View file

@ -12,10 +12,10 @@
module Ci
class WebHook < ActiveRecord::Base
extend Ci::Model
include HTTParty
belongs_to :project, class_name: 'Ci::WebHook'
belongs_to :project, class_name: 'Ci::Project'
# HTTParty timeout
default_timeout 10

View file

@ -1,6 +1,6 @@
FactoryGirl.define do
factory :ci_web_hook, class: Ci::WebHook do
sequence(:url) { Faker::Internet.uri('http') }
project
sequence(:url) { FFaker::Internet.uri('http') }
project factory: :ci_project
end
end

View file

@ -28,7 +28,7 @@
require 'spec_helper'
describe Project do
subject { FactoryGirl.build :project }
subject { FactoryGirl.build :ci_project }
it { should have_many(:commits) }
@ -38,36 +38,36 @@ describe Project do
describe 'before_validation' 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 == ""
end
it 'should not set an random toke if one provided' do
project = FactoryGirl.create :project
project = FactoryGirl.create :ci_project
project.token.should == "iPWx6WM4lhHNedGfBpPJNP"
end
end
describe "ordered_by_last_commit_date" do
it "returns ordered projects" do
newest_project = FactoryGirl.create :project
oldest_project = FactoryGirl.create :project
project_without_commits = FactoryGirl.create :project
newest_project = FactoryGirl.create :ci_project
oldest_project = FactoryGirl.create :ci_project
project_without_commits = FactoryGirl.create :ci_project
FactoryGirl.create :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: 1.hour.ago, project: newest_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]
end
end
context :valid_project do
let(:project) { FactoryGirl.create :project }
let(:project) { FactoryGirl.create :ci_project }
context :project_with_commit_and_builds do
before do
commit = FactoryGirl.create(:commit, project: project)
FactoryGirl.create(:build, commit: commit)
commit = FactoryGirl.create(:ci_commit, project: project)
FactoryGirl.create(:ci_build, commit: commit)
end
it { project.status.should == 'pending' }
@ -78,45 +78,45 @@ describe Project do
describe '#email_notification?' 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
end
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
end
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
end
end
describe '#broken_or_success?' do
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(:success?).and_return(true)
project.broken_or_success?.should == true
}
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(:success?).and_return(false)
project.broken_or_success?.should == true
}
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(:success?).and_return(true)
project.broken_or_success?.should == true
}
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(:success?).and_return(false)
project.broken_or_success?.should == false
@ -127,7 +127,7 @@ describe Project do
let(:project_dump) { YAML.load File.read(Rails.root.join('spec/support/gitlab_stubs/raw_project.yml')) }
let(:parsed_project) { Project.parse(project_dump) }
it { parsed_project.should be_valid }
it { parsed_project.should be_kind_of(Project) }
it { parsed_project.name.should eq("GitLab / api.gitlab.org") }
@ -140,7 +140,7 @@ describe Project do
end
describe :repo_url_with_auth do
let(:project) { FactoryGirl.create :project }
let(:project) { FactoryGirl.create :ci_project }
subject { project.repo_url_with_auth }
it { should be_a(String) }
@ -152,7 +152,7 @@ describe Project do
end
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('bar').should be_empty }
@ -160,25 +160,25 @@ describe Project do
describe :any_runners do
it "there are no runners available" do
project = FactoryGirl.create(:project)
project = FactoryGirl.create(:ci_project)
project.any_runners?.should be_false
end
it "there is a specific runner" do
project = FactoryGirl.create(:project)
project.runners << FactoryGirl.create(:specific_runner)
project = FactoryGirl.create(:ci_project)
project.runners << FactoryGirl.create(:ci_specific_runner)
project.any_runners?.should be_true
end
it "there is a shared runner" do
project = FactoryGirl.create(:project, shared_runners_enabled: true)
FactoryGirl.create(:shared_runner)
project = FactoryGirl.create(:ci_project, shared_runners_enabled: true)
FactoryGirl.create(:ci_shared_runner)
project.any_runners?.should be_true
end
it "there is a shared runner, but they are prohibited to use" do
project = FactoryGirl.create(:project)
FactoryGirl.create(:shared_runner)
project = FactoryGirl.create(:ci_project)
FactoryGirl.create(:ci_shared_runner)
project.any_runners?.should be_false
end
end

View file

@ -27,7 +27,7 @@ describe Ci::Runner do
end
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
end
@ -38,8 +38,8 @@ describe Ci::Runner do
end
describe :assign_to do
let!(:project) { FactoryGirl.create :project }
let!(:shared_runner) { FactoryGirl.create(:shared_runner) }
let!(:project) { FactoryGirl.create :ci_project }
let!(:shared_runner) { FactoryGirl.create(:ci_shared_runner) }
before { shared_runner.assign_to(project) }
@ -50,9 +50,9 @@ describe Ci::Runner do
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)
runner = FactoryGirl.create(:ci_specific_runner)
project = FactoryGirl.create(:ci_project)
project1 = FactoryGirl.create(:ci_project)
project.runners << runner
project1.runners << runner
@ -60,8 +60,8 @@ describe Ci::Runner do
end
it "returns true" do
runner = FactoryGirl.create(:specific_runner)
project = FactoryGirl.create(:project)
runner = FactoryGirl.create(:ci_specific_runner)
project = FactoryGirl.create(:ci_project)
project.runners << runner
runner.belongs_to_one_project?.should be_true

View file

@ -29,9 +29,9 @@ describe Ci::Service do
end
describe "Testable" do
let (:project) { FactoryGirl.create :project }
let (:commit) { FactoryGirl.create :commit, project: project }
let (:build) { FactoryGirl.create :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
@service.stub(

View file

@ -1,16 +1,16 @@
require 'spec_helper'
describe Ci::Trigger do
let(:project) { FactoryGirl.create :project }
let(:project) { FactoryGirl.create :ci_project }
describe 'before_validation' 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
end
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'
end
end

View file

@ -6,8 +6,8 @@ describe Ci::User do
let (:user) { User.new({}) }
before do
FactoryGirl.create :project, gitlab_id: 1
FactoryGirl.create :project, gitlab_id: 2
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})
User.any_instance.stub(:gitlab_projects).and_return([gitlab_project, gitlab_project1])
@ -28,17 +28,17 @@ describe Ci::User do
describe "authorized_runners" do
it "returns authorized runners" do
project = FactoryGirl.create :project, gitlab_id: 1
project1 = FactoryGirl.create :project, gitlab_id: 2
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})
User.any_instance.stub(:gitlab_projects).and_return([gitlab_project, gitlab_project1])
User.any_instance.stub(:can_manage_project?).and_return(true)
user = User.new({})
runner = FactoryGirl.create :specific_runner
runner1 = FactoryGirl.create :specific_runner
runner2 = FactoryGirl.create :specific_runner
runner = FactoryGirl.create :ci_specific_runner
runner1 = FactoryGirl.create :ci_specific_runner
runner2 = FactoryGirl.create :ci_specific_runner
project.runners << runner
project1.runners << runner1

View file

@ -34,7 +34,7 @@ describe Ci::WebHook do
describe "execute" do
before(:each) do
@web_hook = FactoryGirl.create(:web_hook)
@web_hook = FactoryGirl.create(:ci_web_hook)
@project = @web_hook.project
@data = { before: 'oldrev', after: 'newrev', ref: 'ref'}

View file

@ -5,7 +5,7 @@ RSpec.configure do |config|
config.before(:each) do
FileUtils.mkdir_p(builds_path)
Ci::Settings.gitlab_ci['builds_path'] = builds_path
Settings.gitlab_ci['builds_path'] = builds_path
end
config.after(:suite) do