diff options
author | Valery Sizov <vsv2711@gmail.com> | 2015-06-01 14:33:04 +0300 |
---|---|---|
committer | Valery Sizov <vsv2711@gmail.com> | 2015-06-03 16:36:54 +0300 |
commit | 550bcc8aaab26f94ef6b288c28159be21d11f269 (patch) | |
tree | 3958de94cc933bfedbefcf144c37fb9d811169f5 /spec/models | |
parent | 227ffbc87c0d989c9213e4a4e4b87df0c8d01720 (diff) | |
download | gitlab-ci-550bcc8aaab26f94ef6b288c28159be21d11f269.tar.gz |
fix specs
Diffstat (limited to 'spec/models')
-rw-r--r-- | spec/models/commit_spec.rb | 4 | ||||
-rw-r--r-- | spec/models/project_services/hip_chat_message_spec.rb | 98 | ||||
-rw-r--r-- | spec/models/project_services/slack_message_spec.rb | 122 | ||||
-rw-r--r-- | spec/models/project_spec.rb | 19 |
4 files changed, 127 insertions, 116 deletions
diff --git a/spec/models/commit_spec.rb b/spec/models/commit_spec.rb index c4056e3..1658ae6 100644 --- a/spec/models/commit_spec.rb +++ b/spec/models/commit_spec.rb @@ -132,8 +132,8 @@ describe Commit do describe "create_deploy_builds" do it "creates deploy build" do - FactoryGirl.create :job, job_type: :deploy, project: project - project.reload + config_processor = GitlabCiYamlProcessor.new(gitlab_ci_yaml) + commit.stub(:config_processor).and_return(config_processor) commit.create_deploy_builds commit.builds.reload diff --git a/spec/models/project_services/hip_chat_message_spec.rb b/spec/models/project_services/hip_chat_message_spec.rb index 6096b5c..d4bfb31 100644 --- a/spec/models/project_services/hip_chat_message_spec.rb +++ b/spec/models/project_services/hip_chat_message_spec.rb @@ -4,62 +4,76 @@ describe HipChatMessage do subject { HipChatMessage.new(build) } let(:project) { FactoryGirl.create(:project) } - let(:commit) { FactoryGirl.create(:commit, project: project) } - let(:job) { FactoryGirl.create(:job, project: project) } - let(:build) { FactoryGirl.create(:build, commit: commit, job: job, status: 'success') } - context 'when build succeeds' do - - before { build.save } - - it 'returns a successful message' do - expect( subject.status_color ).to eq 'green' - expect( subject.notify? ).to be_false - expect( subject.to_s ).to match(/Build '[^']+' #\d+/) - expect( subject.to_s ).to match(/Successful in \d+ second\(s\)\./) + context "One build" do + let(:commit) do + commit = FactoryGirl.create(:commit, project: project) + commit.push_data[:ci_yaml_file] = YAML.dump({jobs: ["ls"]}) + commit.save + commit end - end - context 'when build fails' do + let(:build) do + commit.create_builds + commit.builds.first + end - before do - build.status = 'failed' - build.save + context 'when build succeeds' do + it 'returns a successful message' do + build.update(status: "success") + + expect( subject.status_color ).to eq 'green' + expect( subject.notify? ).to be_false + expect( subject.to_s ).to match(/Build '[^']+' #\d+/) + expect( subject.to_s ).to match(/Successful in \d+ second\(s\)\./) + end end - it 'returns a failure message' do - expect( subject.status_color ).to eq 'red' - expect( subject.notify? ).to be_true - expect( subject.to_s ).to match(/Build '[^']+' #\d+/) - expect( subject.to_s ).to match(/Failed in \d+ second\(s\)\./) + context 'when build fails' do + it 'returns a failure message' do + build.update(status: "failed") + + expect( subject.status_color ).to eq 'red' + expect( subject.notify? ).to be_true + expect( subject.to_s ).to match(/Build '[^']+' #\d+/) + expect( subject.to_s ).to match(/Failed in \d+ second\(s\)\./) + end end end - context 'when all matrix builds succeed' do - let(:job2) { FactoryGirl.create(:job, project: project, name: 'Another Job') } - let(:build2) { FactoryGirl.create(:build, id: 10, commit: commit, job: job2, status: 'success') } - - before { build.save; build2.save } + context "Several builds" do + let(:commit) {commit = FactoryGirl.create(:commit, project: project)} - it 'returns a successful message' do - expect( subject.status_color ).to eq 'green' - expect( subject.notify? ).to be_false - expect( subject.to_s ).to match(/Commit #\d+/) - expect( subject.to_s ).to match(/Successful in \d+ second\(s\)\./) + let(:build) do + commit.builds.first end - end - context 'when at least one matrix build fails' do - let(:job2) { FactoryGirl.create(:job, project: project, name: 'Another Job') } - let(:build2) { FactoryGirl.create(:build, id: 10, commit: commit, job: job2, status: 'failed') } + context 'when all matrix builds succeed' do + it 'returns a successful message' do + commit.create_builds + commit.builds.update_all(status: "success") + commit.reload - before { build.save; build2.save } + expect( subject.status_color ).to eq 'green' + expect( subject.notify? ).to be_false + expect( subject.to_s ).to match(/Commit #\d+/) + expect( subject.to_s ).to match(/Successful in \d+ second\(s\)\./) + end + end - it 'returns a failure message' do - expect( subject.status_color ).to eq 'red' - expect( subject.notify? ).to be_true - expect( subject.to_s ).to match(/Commit #\d+/) - expect( subject.to_s ).to match(/Failed in \d+ second\(s\)\./) + context 'when at least one matrix build fails' do + it 'returns a failure message' do + commit.create_builds + first_build = commit.builds.first + second_build = commit.builds.last + first_build.update(status: "success") + second_build.update(status: "failed") + + expect( subject.status_color ).to eq 'red' + expect( subject.notify? ).to be_true + expect( subject.to_s ).to match(/Commit #\d+/) + expect( subject.to_s ).to match(/Failed in \d+ second\(s\)\./) + end end end end diff --git a/spec/models/project_services/slack_message_spec.rb b/spec/models/project_services/slack_message_spec.rb index 83a6352..03c0cd3 100644 --- a/spec/models/project_services/slack_message_spec.rb +++ b/spec/models/project_services/slack_message_spec.rb @@ -4,76 +4,90 @@ describe SlackMessage do subject { SlackMessage.new(commit) } let(:project) { FactoryGirl.create :project } - let(:commit) { FactoryGirl.create :commit, project: project } - let(:job) { FactoryGirl.create :job, project: project } - let(:build) { FactoryGirl.create :build, commit: commit, job: job, status: 'success' } - context 'when build succeeded' do - let(:color) { 'good' } - - before { build } + context "One build" do + let(:commit) do + commit = FactoryGirl.create(:commit, project: project) + commit.push_data[:ci_yaml_file] = YAML.dump({jobs: ["ls"]}) + commit.save + commit + end - it 'returns a message with succeeded build' do - subject.color.should == color - subject.fallback.should include('Build') - subject.fallback.should include("\##{build.id}") - subject.fallback.should include('succeeded') - subject.attachments.first[:fields].should be_empty + let(:build) do + commit.create_builds + commit.builds.first end - end - context 'when build failed' do - let(:color) { 'danger' } + context 'when build succeeded' do + let(:color) { 'good' } - before do - build.status = 'failed' - build.save - end + it 'returns a message with succeeded build' do + build.update(status: "success") - it 'returns a message with failed build' do - subject.color.should == color - subject.fallback.should include('Build') - subject.fallback.should include("\##{build.id}") - subject.fallback.should include('failed') - subject.attachments.first[:fields].should be_empty + subject.color.should == color + subject.fallback.should include('Build') + subject.fallback.should include("\##{build.id}") + subject.fallback.should include('succeeded') + subject.attachments.first[:fields].should be_empty + end end - end - context 'when all matrix builds succeeded' do - let(:job2) { FactoryGirl.create :job, project: project } - let(:build2) { FactoryGirl.create :build, commit: commit, job: job2, status: 'success' } - let(:color) { 'good' } + context 'when build failed' do + let(:color) { 'danger' } - before { build; build2 } + it 'returns a message with failed build' do + build.update(status: "failed") - it 'returns a message with success' do - subject.color.should == color - subject.fallback.should include('Commit') - subject.fallback.should include("\##{commit.id}") - subject.fallback.should include('succeeded') - subject.attachments.first[:fields].should be_empty + subject.color.should == color + subject.fallback.should include('Build') + subject.fallback.should include("\##{build.id}") + subject.fallback.should include('failed') + subject.attachments.first[:fields].should be_empty + end end end - context 'when one of matrix builds failed' do - let(:job2) { FactoryGirl.create :job, project: project, name: 'Test JOB' } - let(:build2) { FactoryGirl.create :build, id: 10, commit: commit, job: job2, status: 'success' } - let(:color) { 'danger' } + context "Several builds" do + let(:commit) {commit = FactoryGirl.create(:commit, project: project)} - before do - build - build2.status = 'failed' - build2.save + let(:build) do + commit.builds.first end - it 'returns a message with information about failed build' do - subject.color.should == color - subject.fallback.should include('Commit') - subject.fallback.should include("\##{commit.id}") - subject.fallback.should include('failed') - subject.attachments.first[:fields].size.should == 1 - subject.attachments.first[:fields].first[:title].should == build2.name - subject.attachments.first[:fields].first[:value].should include("\##{build2.id}") + context 'when all matrix builds succeeded' do + let(:color) { 'good' } + + it 'returns a message with success' do + commit.create_builds + commit.builds.update_all(status: "success") + commit.reload + + subject.color.should == color + subject.fallback.should include('Commit') + subject.fallback.should include("\##{commit.id}") + subject.fallback.should include('succeeded') + subject.attachments.first[:fields].should be_empty + end + end + + context 'when one of matrix builds failed' do + let(:color) { 'danger' } + + it 'returns a message with information about failed build' do + commit.create_builds + first_build = commit.builds.first + second_build = commit.builds.last + first_build.update(status: "success") + second_build.update(status: "failed") + + subject.color.should == color + subject.fallback.should include('Commit') + subject.fallback.should include("\##{commit.id}") + subject.fallback.should include('failed') + subject.attachments.first[:fields].size.should == 1 + subject.attachments.first[:fields].first[:title].should == second_build.name + subject.attachments.first[:fields].first[:value].should include("\##{second_build.id}") + end end end end diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index 4bcd130..44a6f51 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -126,8 +126,7 @@ describe Project do let(:project_dump) { File.read(Rails.root.join('spec/support/gitlab_stubs/raw_project.yml')) } let(:parsed_project) { Project.parse(project_dump) } - #before { parsed_project.build_default_job } - + it { parsed_project.should be_valid } it { parsed_project.should be_kind_of(Project) } it { parsed_project.name.should eq("GitLab / api.gitlab.org") } @@ -152,22 +151,6 @@ describe Project do it { should include(project.gitlab_url[7..-1]) } end - describe "#skip_ref?" do - let(:project) { FactoryGirl.create(:project, skip_refs: "master, develop, feature/*") } - - it 'returns true when item is not in list' do - expect(project.skip_ref?('someotherstring')).to eq false - end - - it 'accepts string values' do - expect(project.skip_ref?('master')).to eq true - end - - it 'accepts glob pattern syntax' do - expect(project.skip_ref?('feature/some_feature')).to eq true - end - end - describe :search do let!(:project) { FactoryGirl.create(:project, name: "foo") } |