mirror of
https://github.com/internetee/registry.git
synced 2025-05-18 18:29:40 +02:00
Refactor email sending, tests
This commit is contained in:
parent
d3c17ce4e3
commit
12e32af524
3 changed files with 24 additions and 7 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue