Refactor email sending, tests

This commit is contained in:
Martin Lensment 2015-04-23 10:59:45 +03:00
parent d3c17ce4e3
commit 12e32af524
3 changed files with 24 additions and 7 deletions

View file

@ -20,9 +20,7 @@ class Registrar::InvoicesController < RegistrarController
@invoice.billing_email = params[:invoice][:billing_email]
if @invoice.forward
pdf = @invoice.pdf(render_to_string('pdf', layout: false))
InvoiceMailer.invoice_email(@invoice, pdf).deliver_now
if @invoice.forward(render_to_string('pdf', layout: false))
flash[:notice] = t('invoice_forwared')
redirect_to([:registrar, @invoice])
else

View file

@ -55,11 +55,11 @@ class Invoice < ActiveRecord::Base
"invoice-#{number}.pdf"
end
def forward
def forward(html)
return false unless valid?
return false unless billing_email
return false unless billing_email.present?
# TODO: forward invoice
InvoiceMailer.invoice_email(self, pdf(html)).deliver_now
true
end

View file

@ -4,7 +4,7 @@ feature 'Invoices', type: :feature do
before :all do
create_settings
@user = Fabricate(:api_user)
Fabricate(:invoice)
@invoice = Fabricate(:invoice, buyer: @user.registrar)
end
context 'as unknown user' do
@ -32,5 +32,24 @@ feature 'Invoices', type: :feature do
visit '/registrar/invoices'
page.should have_text('Invoices')
end
it 'should forward invoice' do
visit '/registrar/invoices'
click_link @invoice.to_s
click_link 'Forward invoice'
click_button 'Forward'
page.should have_text('Failed to forward invoice')
fill_in 'Billing email', with: 'test@test.ee'
click_button 'Forward'
page.should have_text('Invoice forwarded')
end
it 'should download invoice' do
visit '/registrar/invoices'
click_link @invoice.to_s
click_link 'Download'
response_headers['Content-Type'].should == 'application/pdf'
response_headers['Content-Disposition'].should == "attachment; filename=\"#{@invoice.pdf_name}\""
end
end
end