Skip to content

Commit

Permalink
Featured Issue #55: Added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Lando-L committed Jan 4, 2017
1 parent fce6ad4 commit b615725
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
2 changes: 2 additions & 0 deletions app/controllers/emails_controller.rb
@@ -1,6 +1,8 @@
class EmailsController < ApplicationController
def send_email
debug(email_params)
@email = Email.new(email_params)
debug(@email)
Mailer.send_generic_email(@email.hide_recipients, @email.recipients, @email.reply_to, @email.subject, @email.content)
redirect_to :events, notice: t('.sending_successful')
end
Expand Down
6 changes: 5 additions & 1 deletion app/models/email.rb
Expand Up @@ -10,10 +10,14 @@ class Email
attribute :subject, :type => String
attribute :content, :type => String

validates_presence_of :hide_recipients, :recipients, :reply_to, :subject, :content
validates_presence_of :recipients, :reply_to, :subject, :content
validates_inclusion_of :hide_recipients, in: [true, false]

def initialize(attributes = {})
attributes.each do |name, value|
if name == 'content'
value.gsub!(/\n/, '<br/>')
end
send("#{name}=", value)
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/factories/emails.rb
Expand Up @@ -6,4 +6,4 @@
subject "Email-Subject"
content "Email-Content"
end
end
end
19 changes: 19 additions & 0 deletions spec/models/email_spec.rb
@@ -0,0 +1,19 @@
require 'rails_helper'

describe Email do
let(:valid_email) {FactoryGirl.build(:email) }
let(:invalid_email) { FactoryGirl.build(:email, subject: nil) }
let(:mulitline_email) { FactoryGirl.build(:email, content: "Email-content \n Email-Content") }

it 'is buildd by factory' do
expect(valid_email).to be_valid
end

it 'should not be valid without content' do
expect(invalid_email).to_not be_valid
end

it 'should convert ruby line breaks to html <br>' do
expect(mulitline_email).to_not include('\n')
end
end

0 comments on commit b615725

Please sign in to comment.