Skip to content

Instantly share code, notes, and snippets.

@danmcclain
Created February 28, 2012 19:19
Show Gist options
  • Select an option

  • Save danmcclain/1934516 to your computer and use it in GitHub Desktop.

Select an option

Save danmcclain/1934516 to your computer and use it in GitHub Desktop.
require 'spec_helper'
describe EmailTemplate do
it { should have_valid(:category).when('Something') }
it { should_not have_valid(:category).when(nil,'') }
it { should have_valid(:content).when('Some content') }
it { should_not have_valid(:content).when(nil,'') }
it { should have_valid(:subject).when('Some subject') }
it { should_not have_valid(:subject).when(nil,'') }
describe 'active state before_save callback' do
let!(:email_template_1) { EmailTemplate.create(:content => 'Sample email template 1', :subject => 'Sample Subject', :category => 'Some category', :active => true) }
it 'ensure that there is only one active template in a category' do
email_template_2 = EmailTemplate.create(:content => 'Sample email template 2', :subject => 'Sample Subject',
:category => 'Another category', :active => true)
email_template_3 = EmailTemplate.create(:content => 'Sample email template 3', :subject => 'Sample Subject',
:category => 'Some category', :active => true)
email_template_1.reload
email_template_2.reload
email_template_1.active.should be_false
email_template_2.active.should be_true
end
it 'should not change the active state when an active template is updated' do
email_template_1.update_attributes :content => 'Some new content'
email_template_1.reload
email_template_1.active.should be_true
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment