diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2014-11-04 19:50:38 +0200 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2014-11-04 19:50:38 +0200 |
commit | f4281edaf28205bb3af27f28d39b894a227c4e3e (patch) | |
tree | b7b341b2171b0c9062ddc48cd17d80cad71d5e21 | |
parent | c21288c06bc4e7ed22c301f118aa1c14cda85c9d (diff) | |
download | gitlab-ci-f4281edaf28205bb3af27f28d39b894a227c4e3e.tar.gz |
Refactor specs and add email tests
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
-rw-r--r-- | Gemfile | 1 | ||||
-rw-r--r-- | Gemfile.lock | 4 | ||||
-rw-r--r-- | app/controllers/builds_controller.rb | 4 | ||||
-rw-r--r-- | app/views/notify/build_fail_email.html.haml | 4 | ||||
-rw-r--r-- | app/views/notify/build_fail_email.text.erb | 4 | ||||
-rw-r--r-- | app/views/notify/build_success_email.html.haml | 4 | ||||
-rw-r--r-- | app/views/notify/build_success_email.text.erb | 4 | ||||
-rw-r--r-- | spec/mailers/notify_spec.rb | 36 | ||||
-rw-r--r-- | spec/requests/api/builds_spec.rb | 79 | ||||
-rw-r--r-- | spec/requests/api/projects_spec.rb (renamed from spec/requests/projects_spec.rb) | 0 | ||||
-rw-r--r-- | spec/requests/api/runners_spec.rb (renamed from spec/requests/runners_spec.rb) | 0 | ||||
-rw-r--r-- | spec/requests/builds_spec.rb | 81 | ||||
-rw-r--r-- | spec/requests/commits_spec.rb | 17 |
13 files changed, 156 insertions, 82 deletions
@@ -99,4 +99,5 @@ end group :test do gem 'webmock' + gem 'email_spec' end diff --git a/Gemfile.lock b/Gemfile.lock index eedf52e..fb05eb7 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -74,6 +74,9 @@ GEM diff-lcs (1.2.5) docile (1.1.1) dotenv (0.9.0) + email_spec (1.5.0) + launchy (~> 2.1) + mail (~> 2.2) equalizer (0.0.9) erubis (2.7.0) execjs (2.0.2) @@ -313,6 +316,7 @@ DEPENDENCIES capybara coffee-rails (~> 4.0.0) coveralls + email_spec factory_girl_rails ffaker font-awesome-rails (~> 3.2) diff --git a/app/controllers/builds_controller.rb b/app/controllers/builds_controller.rb index 011b4a5..243aaae 100644 --- a/app/controllers/builds_controller.rb +++ b/app/controllers/builds_controller.rb @@ -2,7 +2,7 @@ class BuildsController < ApplicationController before_filter :authenticate_user!, except: [:status] before_filter :project before_filter :authorize_access_project!, except: [:status] - before_filter :build, except: [:status, :show] + before_filter :build, except: [:show] def show if params[:id] =~ /\A\d+\Z/ @@ -38,8 +38,6 @@ class BuildsController < ApplicationController end def status - @build = build_by_sha - render json: @build.to_json(only: [:status, :id, :sha, :coverage]) end diff --git a/app/views/notify/build_fail_email.html.haml b/app/views/notify/build_fail_email.html.haml index 71e36e3..7573e17 100644 --- a/app/views/notify/build_fail_email.html.haml +++ b/app/views/notify/build_fail_email.html.haml @@ -6,9 +6,9 @@ %p Status: #{@build.status} %p - Commit: #{@build.short_sha} + Commit: #{@build.commit.short_sha} %p - Author: #{@build.git_author_name} + Author: #{@build.commit.git_author_name} %p Url: #{link_to @build.short_sha, project_build_url(@build.project, @build)} diff --git a/app/views/notify/build_fail_email.text.erb b/app/views/notify/build_fail_email.text.erb index e93e9d4..ef2233c 100644 --- a/app/views/notify/build_fail_email.text.erb +++ b/app/views/notify/build_fail_email.text.erb @@ -1,7 +1,7 @@ Build failed for <%= @project.name %> Status: <%= @build.status %> -Commit: <%= @build.short_sha %> -Author: <%= @build.git_author_name %> +Commit: <%= @build.commit.short_sha %> +Author: <%= @build.commit.git_author_name %> Url: <%= project_build_url(@build.project, @build) %> diff --git a/app/views/notify/build_success_email.html.haml b/app/views/notify/build_success_email.html.haml index 9549408..10ceba4 100644 --- a/app/views/notify/build_success_email.html.haml +++ b/app/views/notify/build_success_email.html.haml @@ -6,9 +6,9 @@ %p Status: #{@build.status} %p - Commit: #{@build.short_sha} + Commit: #{@build.commit.short_sha} %p - Author: #{@build.git_author_name} + Author: #{@build.commit.git_author_name} %p Url: #{link_to @build.short_sha, project_build_url(@build.project, @build)} diff --git a/app/views/notify/build_success_email.text.erb b/app/views/notify/build_success_email.text.erb index 5ebe71a..5470a5b 100644 --- a/app/views/notify/build_success_email.text.erb +++ b/app/views/notify/build_success_email.text.erb @@ -1,7 +1,7 @@ Build successful for <%= @project.name %> Status: <%= @build.status %> -Commit: <%= @build.short_sha %> -Author: <%= @build.git_author_name %> +Commit: <%= @build.commit.short_sha %> +Author: <%= @build.commit.git_author_name %> Url: <%= project_build_url(@build.project, @build) %> diff --git a/spec/mailers/notify_spec.rb b/spec/mailers/notify_spec.rb new file mode 100644 index 0000000..81aaa27 --- /dev/null +++ b/spec/mailers/notify_spec.rb @@ -0,0 +1,36 @@ +require 'spec_helper' + +describe Notify do + include EmailSpec::Helpers + include EmailSpec::Matchers + + before do + @project = FactoryGirl.create :project + @commit = FactoryGirl.create :commit, project: @project + @build = FactoryGirl.create :build, commit: @commit + end + + describe 'build success' do + subject { Notify.build_success_email(@build.id, 'wow@example.com') } + + it 'has the correct subject' do + should have_subject /Build success for/ + end + + it 'contains name of project' do + should have_body_text /Build successful/ + end + end + + describe 'build fail' do + subject { Notify.build_fail_email(@build.id, 'wow@example.com') } + + it 'has the correct subject' do + should have_subject /Build failed for/ + end + + it 'contains name of project' do + should have_body_text /Build failed/ + end + end +end diff --git a/spec/requests/api/builds_spec.rb b/spec/requests/api/builds_spec.rb new file mode 100644 index 0000000..0fe2313 --- /dev/null +++ b/spec/requests/api/builds_spec.rb @@ -0,0 +1,79 @@ +require 'spec_helper' + +describe API::API do + include ApiHelpers + + let(:runner) { FactoryGirl.create(:runner) } + let(:project) { FactoryGirl.create(:project) } + + describe "Builds API for runners" do + before do + FactoryGirl.create :runner_project, project_id: project.id, runner_id: runner.id + end + + describe "POST /builds/register" do + it "should start a build" do + commit = FactoryGirl.create(:commit, project: project) + build = FactoryGirl.create(:build, commit: commit, status: 'pending' ) + + post api("/builds/register"), token: runner.token + + response.status.should == 201 + json_response['sha'].should == build.sha + end + + it "should return 404 error if no pending build found" do + post api("/builds/register"), token: runner.token + + response.status.should == 404 + end + end + + describe "PUT /builds/:id" do + let(:commit) { FactoryGirl.create(:commit, project: project)} + let(:build) { FactoryGirl.create(:build, commit: commit, runner_id: runner.id) } + + it "should update a running build" do + build.run! + put api("/builds/#{build.id}"), token: runner.token + response.status.should == 200 + end + end + end + + describe "POST /builds" do + let(:data) { + { + "before" => "95790bf891e76fee5e1747ab589903a6a1f80f22", + "after" => "da1560886d4f094c3e6c9ef40349f7d38b5d27d7", + "ref" => "refs/heads/master", + "commits" => [ + { + "id" => "b6568db1bc1dcd7f8b4d5a946b0b91f9dacd7327", + "message" => "Update Catalan translation to e38cb41.", + "timestamp" => "2011-12-12T14:27:31+02:00", + "url" => "http://localhost/diaspora/commits/b6568db1bc1dcd7f8b4d5a946b0b91f9dacd7327", + "author" => { + "name" => "Jordi Mallach", + "email" => "jordi@softcatala.org", + } + } + ] + } + } + + it "should create a build" do + post api("/builds"), project_id: project.id, data: data, project_token: project.token + + response.status.should == 201 + json_response['sha'].should == "da1560886d4f094c3e6c9ef40349f7d38b5d27d7" + end + + it "should return 400 error if no data passed" do + post api("/builds"), project_id: project.id, project_token: project.token + + response.status.should == 400 + json_response['message'].should == "400 (Bad request) \"data\" not given" + end + end +end diff --git a/spec/requests/projects_spec.rb b/spec/requests/api/projects_spec.rb index bb2f1cb..bb2f1cb 100644 --- a/spec/requests/projects_spec.rb +++ b/spec/requests/api/projects_spec.rb diff --git a/spec/requests/runners_spec.rb b/spec/requests/api/runners_spec.rb index bf0b658..bf0b658 100644 --- a/spec/requests/runners_spec.rb +++ b/spec/requests/api/runners_spec.rb diff --git a/spec/requests/builds_spec.rb b/spec/requests/builds_spec.rb index 0fe2313..73d540e 100644 --- a/spec/requests/builds_spec.rb +++ b/spec/requests/builds_spec.rb @@ -1,79 +1,18 @@ require 'spec_helper' -describe API::API do - include ApiHelpers - - let(:runner) { FactoryGirl.create(:runner) } - let(:project) { FactoryGirl.create(:project) } - - describe "Builds API for runners" do - before do - FactoryGirl.create :runner_project, project_id: project.id, runner_id: runner.id - end - - describe "POST /builds/register" do - it "should start a build" do - commit = FactoryGirl.create(:commit, project: project) - build = FactoryGirl.create(:build, commit: commit, status: 'pending' ) - - post api("/builds/register"), token: runner.token - - response.status.should == 201 - json_response['sha'].should == build.sha - end - - it "should return 404 error if no pending build found" do - post api("/builds/register"), token: runner.token - - response.status.should == 404 - end - end - - describe "PUT /builds/:id" do - let(:commit) { FactoryGirl.create(:commit, project: project)} - let(:build) { FactoryGirl.create(:build, commit: commit, runner_id: runner.id) } - - it "should update a running build" do - build.run! - put api("/builds/#{build.id}"), token: runner.token - response.status.should == 200 - end - end +describe "Builds" do + before do + @project = FactoryGirl.create :project + @commit = FactoryGirl.create :commit, project: @project + @build = FactoryGirl.create :build, commit: @commit end - describe "POST /builds" do - let(:data) { - { - "before" => "95790bf891e76fee5e1747ab589903a6a1f80f22", - "after" => "da1560886d4f094c3e6c9ef40349f7d38b5d27d7", - "ref" => "refs/heads/master", - "commits" => [ - { - "id" => "b6568db1bc1dcd7f8b4d5a946b0b91f9dacd7327", - "message" => "Update Catalan translation to e38cb41.", - "timestamp" => "2011-12-12T14:27:31+02:00", - "url" => "http://localhost/diaspora/commits/b6568db1bc1dcd7f8b4d5a946b0b91f9dacd7327", - "author" => { - "name" => "Jordi Mallach", - "email" => "jordi@softcatala.org", - } - } - ] - } - } - - it "should create a build" do - post api("/builds"), project_id: project.id, data: data, project_token: project.token - - response.status.should == 201 - json_response['sha'].should == "da1560886d4f094c3e6c9ef40349f7d38b5d27d7" + describe "GET /:project/builds/:id/status.json" do + before do + get status_project_build_path(@project, @build), format: :json end - it "should return 400 error if no data passed" do - post api("/builds"), project_id: project.id, project_token: project.token - - response.status.should == 400 - json_response['message'].should == "400 (Bad request) \"data\" not given" - end + it { response.status.should == 200 } + it { response.body.should include(@build.sha) } end end diff --git a/spec/requests/commits_spec.rb b/spec/requests/commits_spec.rb new file mode 100644 index 0000000..5c894ea --- /dev/null +++ b/spec/requests/commits_spec.rb @@ -0,0 +1,17 @@ +require 'spec_helper' + +describe "Commits" do + before do + @project = FactoryGirl.create :project + @commit = FactoryGirl.create :commit, project: @project + end + + describe "GET /:project/commits/:id/status.json" do + before do + get status_project_commit_path(@project, @commit), format: :json + end + + it { response.status.should == 200 } + it { response.body.should include(@commit.sha) } + end +end |