Move hash merge in before block and add test for missing name

This commit is contained in:
Aditya Prakash 2016-03-29 23:10:19 +05:30
parent 459a281230
commit 4129955835

View file

@ -2,7 +2,7 @@ require 'spec_helper'
describe EmailSettings do
let(:conference) { create(:conference, short_title: 'goto', start_date: Date.new(2014, 05, 01), end_date: Date.new(2014, 05, 06)) }
let(:user) { create(:user, email: 'john@doe.com', name: 'John Doe') }
let(:user) { create(:user, username: 'johnd', email: 'john@doe.com', name: 'John Doe') }
let(:event_user) { create(:submitter, user: user) }
let(:event) { create(:event, program: conference.program, title: 'Talk about talks', event_users: [event_user]) }
let(:expected_hash) do
@ -27,8 +27,22 @@ describe EmailSettings do
end
describe '#get_values' do
it 'returns correct key-value pairs' do
expect(conference.email_settings.get_values(conference, user)).to eq expected_hash
context 'user has name' do
it 'returns correct key-value pairs' do
expect(conference.email_settings.get_values(conference, user)).to eq expected_hash
end
end
context 'user does not have name' do
before do
user.update_attributes(name: nil)
username_hash = { 'name' => 'johnd' }
expected_hash.merge!(username_hash)
end
it 'returns correct key-value pairs with username as name' do
expect(conference.email_settings.get_values(conference, user)).to eq expected_hash
end
end
context 'conference has cfp' do
@ -36,21 +50,23 @@ describe EmailSettings do
conference.program.update_attributes(cfp: create(:cfp,
start_date: Date.new(2014, 04, 29),
end_date: Date.new(2014, 05, 06)))
cfp_dates_hash = { 'cfp_start_date' => Date.new(2014, 04, 29), 'cfp_end_date' => Date.new(2014, 05, 06) }
expected_hash.merge!(cfp_dates_hash)
end
it 'returns hash with cfp start and end date' do
cfp_dates_hash = { 'cfp_start_date' => Date.new(2014, 04, 29), 'cfp_end_date' => Date.new(2014, 05, 06) }
expected_hash.merge!(cfp_dates_hash)
expect(conference.email_settings.get_values(conference, user)).to eq expected_hash
end
end
context 'conference has venue' do
before { conference.update_attributes(venue: create(:venue)) }
it 'returns hash with venue and venue_address' do
before do
conference.update_attributes(venue: create(:venue))
venue_hash = { 'venue' => 'Suse Office', 'venue_address' => 'Maxfeldstrasse 5, Nuremberg, Germany' }
expected_hash.merge!(venue_hash)
end
it 'returns hash with venue and venue_address' do
expect(conference.email_settings.get_values(conference, user)).to eq expected_hash
end
end
@ -60,19 +76,22 @@ describe EmailSettings do
conference.update_attributes(registration_period: create(:registration_period,
start_date: Date.new(2014, 05, 03),
end_date: Date.new(2014, 05, 05)))
registration_period_hash = { 'registration_start_date' => Date.new(2014, 05, 03), 'registration_end_date' => Date.new(2014, 05, 05) }
expected_hash.merge!(registration_period_hash)
end
it 'returns hash with registration_start_date and registration_end_date' do
registration_period_hash = { 'registration_start_date' => Date.new(2014, 05, 03), 'registration_end_date' => Date.new(2014, 05, 05) }
expected_hash.merge!(registration_period_hash)
expect(conference.email_settings.get_values(conference, user)).to eq expected_hash
end
end
context 'conference has event' do
it 'returns hash with eventtitle and proposalslink' do
before do
event_hash = { 'eventtitle' => 'Talk about talks', 'proposalslink' => 'http://localhost:3000/conference/goto/program/proposal' }
expected_hash.merge!(event_hash)
end
it 'returns hash with eventtitle and proposalslink' do
expect(conference.email_settings.get_values(conference, user, event)).to eq expected_hash
end
end