Skip to content

Commit

Permalink
Add welcome email when create organization. Add specs
Browse files Browse the repository at this point in the history
  • Loading branch information
taitus committed Dec 27, 2017
1 parent dcdfc6b commit dc5d4b4
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
1 change: 1 addition & 0 deletions app/controllers/admin/organizations_controller.rb
Expand Up @@ -22,6 +22,7 @@ def create
@organization = Organization.new(organization_params)
@organization.entity_type = 'lobby'
if @organization.save
UserMailer.welcome(@organization.user).deliver_now
redirect_to admin_organizations_path, notice: t('backend.successfully_created_record')
else
flash[:alert] = t('backend.review_errors')
Expand Down
2 changes: 2 additions & 0 deletions spec/features/admin/organizations_spec.rb
Expand Up @@ -231,6 +231,7 @@
end

scenario 'Visit new admin organization page and create organization with the minimum permitted fields' do
ActionMailer::Base.deliveries = []
category = create(:category)
visit new_admin_organization_path

Expand All @@ -244,6 +245,7 @@
click_button "Guardar"

expect(page).to have_content "Registro creado correctamente"
expect(ActionMailer::Base.deliveries.count).to eq(1)
end

scenario 'Should create organization with data fields' do
Expand Down
32 changes: 31 additions & 1 deletion spec/mailers/user_mailer_spec.rb
@@ -1,5 +1,35 @@
require "rails_helper"

RSpec.describe UserMailer, type: :mailer do
pending "add some examples to (or delete) #{__FILE__}"

describe "welcome" do

before do
@organization = create(:organization)
end

let!(:mail) { UserMailer.welcome(@organization.user) }

it "should send from example" do
expect(mail.from).to eq([ "from@example.com"])
end

it "should send to new user" do
expect(mail.to).to eq([@organization.user.email])
end

it "should contain welcome subject" do
expect(mail.subject).to eq I18n.t('mailers.welcome_organization.subject')
end

it "should contain welcome body" do
expect(mail.body).to have_content I18n.t('mailers.welcome_organization.welcome', name: @organization.user.name)
expect(mail.body).to have_content I18n.t('mailers.welcome_organization.text1')
expect(mail.body).to have_content I18n.t('mailers.welcome_organization.text2', email: @organization.user.email, password: @organization.user.password)
expect(mail.body).to have_content I18n.t('mailers.welcome_organization.thanks')

end

end

end

0 comments on commit dc5d4b4

Please sign in to comment.