forked from zendesk/samson
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
simplify project create/delete mailer logic
- test logic - remove from default test setup since it is only a weird edge-case - dry-up duplicated logic
- Loading branch information
Showing
7 changed files
with
42 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,6 @@ DATADOG_APPLICATION_KEY=dappkey | |
JENKINS_URL=http://www.test-url.com | ||
JENKINS_USERNAME=[email protected] | ||
JENKINS_API_KEY=japikey | ||
PROJECT_CREATED_NOTIFY_ADDRESS=[email protected] | ||
RUBY_MIME_TYPES_LAZY_LOAD=true | ||
AUTH_GITHUB=1 | ||
GITHUB_CLIENT_ID=github-id | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
# frozen_string_literal: true | ||
require_relative '../test_helper' | ||
|
||
SingleCov.covered! uncovered: 2 | ||
SingleCov.covered! | ||
|
||
describe ProjectsController do | ||
def fields_disabled? | ||
|
@@ -268,14 +268,18 @@ def fields_disabled? | |
|
||
assert_redirected_to projects_path | ||
request.flash[:notice].wont_be_nil | ||
|
||
refute ActionMailer::Base.deliveries.last | ||
end | ||
end | ||
|
||
it "sends deletion notification" do | ||
delete :destroy, params: {id: project.to_param} | ||
mail = ActionMailer::Base.deliveries.last | ||
mail.subject.include?("Samson Project Deleted") | ||
mail.subject.include?(project.name) | ||
with_env PROJECT_DELETED_NOTIFY_ADDRESS: '[email protected]' do | ||
delete :destroy, params: {id: project.to_param} | ||
mail = ActionMailer::Base.deliveries.last | ||
mail.subject.include?("Samson Project Deleted") | ||
mail.subject.include?(project.name) | ||
end | ||
end | ||
|
||
it "does not fail when validations fail" do | ||
|
@@ -303,41 +307,36 @@ def fields_disabled? | |
end | ||
|
||
describe "#create" do | ||
before do | ||
post :create, params: params | ||
end | ||
|
||
describe "with valid parameters" do | ||
let(:params) do | ||
{ | ||
project: { | ||
name: "Hello", | ||
repository_url: "git://foo.com/bar" | ||
} | ||
let(:params) do | ||
{ | ||
project: { | ||
name: "Hello", | ||
repository_url: "git://foo.com/bar" | ||
} | ||
end | ||
let(:project) { Project.where(name: "Hello").first } | ||
|
||
it "redirects to the new project's page" do | ||
assert_redirected_to project_path(project) | ||
end | ||
} | ||
end | ||
|
||
it "creates a new project" do | ||
project.wont_be_nil | ||
project.stages.must_be_empty | ||
end | ||
it "redirects to the new project's page" do | ||
post :create, params: params | ||
project = Project.last | ||
assert_redirected_to project_path(project) | ||
refute ActionMailer::Base.deliveries.last | ||
end | ||
|
||
it "notifies about creation" do | ||
it "notifies about creation" do | ||
with_env PROJECT_CREATED_NOTIFY_ADDRESS: '[email protected]' do | ||
post :create, params: params | ||
mail = ActionMailer::Base.deliveries.last | ||
mail.subject.include?("Samson Project Created") | ||
mail.subject.include?(project.name) | ||
end | ||
end | ||
|
||
describe "with invalid parameters" do | ||
let(:params) { {project: {name: ""}} } | ||
before { params[:project][:name] = '' } | ||
|
||
it "renders new template" do | ||
post :create, params: params | ||
assert_template :new | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ class ProjectMailerTest < ActionMailer::TestCase | |
|
||
describe "#created_email" do | ||
it "contains user and project name" do | ||
ProjectMailer.created_email(user, project).deliver_now | ||
ProjectMailer.created_email('[email protected]', user, project).deliver_now | ||
mail_sent = ActionMailer::Base.deliveries.last | ||
assert mail_sent.subject.include?('Foo') | ||
assert mail_sent.body.include?('Admin') | ||
|
@@ -19,7 +19,7 @@ class ProjectMailerTest < ActionMailer::TestCase | |
|
||
describe "#deleted_email" do | ||
it "contains user and project name" do | ||
ProjectMailer.deleted_email(user, project).deliver_now | ||
ProjectMailer.deleted_email('[email protected]', user, project).deliver_now | ||
mail_sent = ActionMailer::Base.deliveries.last | ||
assert mail_sent.subject.include?('Foo') | ||
assert mail_sent.body.include?('Admin') | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters