2015-10-11 05:41:23 -04:00
require " rails_helper "
2013-02-05 14:16:51 -05:00
describe InviteMailer do
2013-02-25 11:42:20 -05:00
2013-02-05 14:16:51 -05:00
describe " send_invite " do
2014-07-08 13:03:11 -04:00
context " invite to site " do
let ( :invite ) { Fabricate ( :invite ) }
2016-06-05 13:22:46 -04:00
context " default invite message " do
let ( :invite_mail ) { InviteMailer . send_invite ( invite ) }
2014-07-08 13:03:11 -04:00
2016-06-05 13:22:46 -04:00
it 'renders the invitee email' do
expect ( invite_mail . to ) . to eql ( [ invite . email ] )
end
2014-07-08 13:03:11 -04:00
2016-06-05 13:22:46 -04:00
it 'renders the subject' do
expect ( invite_mail . subject ) . to be_present
end
2014-07-10 01:27:40 -04:00
2016-06-05 13:22:46 -04:00
it 'renders site domain name in subject' do
expect ( invite_mail . subject ) . to match ( Discourse . current_hostname )
end
it 'renders the body' do
expect ( invite_mail . body ) . to be_present
end
2014-07-08 13:03:11 -04:00
2016-06-05 13:22:46 -04:00
it 'renders the inviter email' do
expect ( invite_mail . from ) . to eql ( [ SiteSetting . notification_email ] )
end
it 'renders invite link' do
expect ( invite_mail . body . encoded ) . to match ( " #{ Discourse . base_url } /invites/ #{ invite . invite_key } " )
end
2014-07-08 13:03:11 -04:00
end
2016-06-05 13:22:46 -04:00
context " custom invite message " do
context " custom message includes invite link " do
let ( :custom_invite_mail ) { InviteMailer . send_invite ( invite , " Hello, \n \n You've been invited you to join \n \n <a href= \" javascript:alert('HACK!') \" >Click me.</a> \n \n > **{site_title}** \n > \n > {site_description} \n \n If you're interested, click the link below: \n \n {invite_link} \n \n This invitation is from a trusted user, so you won't need to log in. " ) }
it 'renders the invitee email' do
expect ( custom_invite_mail . to ) . to eql ( [ invite . email ] )
end
it 'renders the subject' do
expect ( custom_invite_mail . subject ) . to be_present
end
it 'renders site domain name in subject' do
expect ( custom_invite_mail . subject ) . to match ( Discourse . current_hostname )
end
it 'renders the html' do
expect ( custom_invite_mail . html_part ) . to be_present
end
it 'renders custom_message' do
expect ( custom_invite_mail . html_part . to_s ) . to match ( " You've been invited you to join " )
end
it 'renders the inviter email' do
expect ( custom_invite_mail . from ) . to eql ( [ SiteSetting . notification_email ] )
end
it 'sanitizes HTML' do
expect ( custom_invite_mail . html_part . to_s ) . to_not match ( " HACK! " )
end
it 'renders invite link' do
expect ( custom_invite_mail . html_part . to_s ) . to match ( " #{ Discourse . base_url } /invites/ #{ invite . invite_key } " )
end
end
context " custom message does not include invite link " do
2016-06-07 13:24:45 -04:00
let ( :custom_invite_without_link ) { InviteMailer . send_invite ( invite , " Hello, \n \n You've been invited to join \n \n > **{site_title}** \n > \n > {site_description} " ) }
2016-06-05 13:22:46 -04:00
it 'renders default body' do
expect ( custom_invite_without_link . body ) . to be_present
end
it 'does not render html' do
expect ( custom_invite_without_link . html_part ) . to eq ( nil )
end
it 'renders invite link' do
expect ( custom_invite_without_link . body . encoded ) . to match ( " #{ Discourse . base_url } /invites/ #{ invite . invite_key } " )
end
end
2014-07-08 13:03:11 -04:00
end
end
2016-06-07 13:24:45 -04:00
2014-07-08 13:03:11 -04:00
context " invite to topic " do
let ( :topic ) { Fabricate ( :topic , excerpt : " Topic invite support is now available in Discourse! " ) }
let ( :invite ) { topic . invite ( topic . user , 'name@example.com' ) }
2013-02-05 14:16:51 -05:00
2016-06-07 13:24:45 -04:00
context " default invite message " do
let ( :invite_mail ) { InviteMailer . send_invite ( invite ) }
2014-07-08 13:03:11 -04:00
2016-06-07 13:24:45 -04:00
it 'renders the invitee email' do
expect ( invite_mail . to ) . to eql ( [ 'name@example.com' ] )
end
2014-07-08 13:03:11 -04:00
2016-06-07 13:24:45 -04:00
it 'renders the subject' do
expect ( invite_mail . subject ) . to be_present
end
2014-07-10 00:33:09 -04:00
2016-06-07 13:24:45 -04:00
it 'renders topic title in subject' do
expect ( invite_mail . subject ) . to match ( topic . title )
end
2014-07-10 00:33:09 -04:00
2016-06-07 13:24:45 -04:00
it 'renders site domain name in subject' do
expect ( invite_mail . subject ) . to match ( Discourse . current_hostname )
end
2014-07-08 13:03:11 -04:00
2016-06-07 13:24:45 -04:00
it 'renders the body' do
expect ( invite_mail . body ) . to be_present
end
2014-07-08 13:03:11 -04:00
2016-06-07 13:24:45 -04:00
it 'renders the inviter email' do
expect ( invite_mail . from ) . to eql ( [ SiteSetting . notification_email ] )
end
it 'renders invite link' do
expect ( invite_mail . body . encoded ) . to match ( " #{ Discourse . base_url } /invites/ #{ invite . invite_key } " )
end
it 'renders topic title' do
expect ( invite_mail . body . encoded ) . to match ( topic . title )
end
2014-07-08 13:03:11 -04:00
end
2016-06-07 13:24:45 -04:00
context " custom invite message " do
let ( :custom_invite_mail ) { InviteMailer . send_invite ( invite , " Hello, \n \n You've been invited to a discussion \n \n <a href= \" javascript:alert('HACK!') \" >Click me.</a> \n \n > **{site_title}** -- {site_description} \n \n If you're interested, click the link below: \n \n {invite_link} \n \n This invitation is from a trusted user, so you can reply to the discussion immediately. " ) }
it 'renders the html' do
expect ( custom_invite_mail . html_part ) . to be_present
end
it 'renders custom_message' do
expect ( custom_invite_mail . html_part . to_s ) . to match ( " You've been invited to a discussion " )
end
it 'sanitizes HTML' do
expect ( custom_invite_mail . html_part . to_s ) . to_not match ( " HACK! " )
end
it 'renders invite link' do
expect ( custom_invite_mail . html_part . to_s ) . to match ( " #{ Discourse . base_url } /invites/ #{ invite . invite_key } " )
end
2014-07-08 13:03:11 -04:00
end
end
end
2013-02-05 14:16:51 -05:00
end