Refactor mailer views

#180
This commit is contained in:
Artur Beljajev 2016-11-10 23:32:52 +02:00
parent eac7690345
commit 789468c84f
32 changed files with 334 additions and 346 deletions

View file

@ -2,33 +2,36 @@ require 'rails_helper'
RSpec.describe 'mailers/domain_mailer/expiration.html.erb' do
let(:domain) { instance_spy(DomainPresenter) }
let(:registrar) { instance_spy(RegistrarPresenter) }
let(:lang_count) { 3 }
before :example do
assign(:domain, domain)
assign(:registrar, registrar)
assign(:registrar, nil)
stub_template 'mailers/domain_mailer/registrar/_registrar.et.html' => 'test registrar estonian'
stub_template 'mailers/domain_mailer/registrar/_registrar.en.html' => 'test registrar english'
stub_template 'mailers/domain_mailer/registrar/_registrar.ru.html' => 'test registrar russian'
end
it 'has registrar name' do
mention_count = 2 * lang_count
expect(registrar).to receive(:name).exactly(mention_count).times.and_return('test registrar name')
it 'has registrar info in estonian' do
render
expect(rendered).to have_text('test registrar name', count: mention_count)
expect(rendered).to have_text('test registrar estonian')
end
registrar_attributes = %i(
email
phone
url
)
it 'has registrar info in english' do
render
expect(rendered).to have_text('test registrar english')
end
registrar_attributes.each do |attr_name|
it "has registrar #{attr_name}" do
expect(registrar).to receive(attr_name).exactly(lang_count).times.and_return("test registrar #{attr_name}")
render
expect(rendered).to have_text("test registrar #{attr_name}", count: lang_count)
end
it 'has registrar info in russian' do
render
expect(rendered).to have_text('test registrar russian')
end
it 'has domain name' do
mention_count = 4 * lang_count
expect(domain).to receive(:name).exactly(mention_count).times.and_return('test domain name')
render
expect(rendered).to have_text('test domain name', count: mention_count)
end
domain_attributes = %i(
@ -41,10 +44,10 @@ RSpec.describe 'mailers/domain_mailer/expiration.html.erb' do
)
domain_attributes.each do |attr_name|
it "has :#{attr_name}" do
expect(domain).to receive(attr_name).exactly(lang_count).times.and_return(attr_name.to_s)
it "has domain #{attr_name}" do
expect(domain).to receive(attr_name).exactly(lang_count).times.and_return("test domain #{attr_name}")
render
expect(rendered).to have_text(attr_name.to_s, count: lang_count)
expect(rendered).to have_text("test domain #{attr_name}", count: lang_count)
end
end
end

View file

@ -2,33 +2,36 @@ require 'rails_helper'
RSpec.describe 'mailers/domain_mailer/expiration.text.erb' do
let(:domain) { instance_spy(DomainPresenter) }
let(:registrar) { instance_spy(RegistrarPresenter) }
let(:lang_count) { 3 }
before :example do
assign(:domain, domain)
assign(:registrar, registrar)
assign(:registrar, nil)
stub_template 'mailers/domain_mailer/registrar/_registrar.et.text' => 'test registrar estonian'
stub_template 'mailers/domain_mailer/registrar/_registrar.en.text' => 'test registrar english'
stub_template 'mailers/domain_mailer/registrar/_registrar.ru.text' => 'test registrar russian'
end
it 'has registrar name' do
mention_count = 2 * lang_count
expect(registrar).to receive(:name).exactly(mention_count).times.and_return('test registrar name')
it 'has registrar info in estonian' do
render
expect(rendered).to have_text('test registrar name', count: mention_count)
expect(rendered).to have_text('test registrar estonian')
end
registrar_attributes = %i(
email
phone
url
)
it 'has registrar info in english' do
render
expect(rendered).to have_text('test registrar english')
end
registrar_attributes.each do |attr_name|
it "has registrar #{attr_name}" do
expect(registrar).to receive(attr_name).exactly(lang_count).times.and_return("test registrar #{attr_name}")
render
expect(rendered).to have_text("test registrar #{attr_name}", count: lang_count)
end
it 'has registrar info in russian' do
render
expect(rendered).to have_text('test registrar russian')
end
it 'has domain name' do
mention_count = 4 * lang_count
expect(domain).to receive(:name).exactly(mention_count).times.and_return('test domain name')
render
expect(rendered).to have_text('test domain name', count: mention_count)
end
domain_attributes = %i(
@ -41,10 +44,10 @@ RSpec.describe 'mailers/domain_mailer/expiration.text.erb' do
)
domain_attributes.each do |attr_name|
it "has :#{attr_name}" do
expect(domain).to receive(attr_name).exactly(lang_count).times.and_return(attr_name.to_s)
it "has domain #{attr_name}" do
expect(domain).to receive(attr_name).exactly(lang_count).times.and_return("test domain #{attr_name}")
render
expect(rendered).to have_text(attr_name.to_s, count: lang_count)
expect(rendered).to have_text("test domain #{attr_name}", count: lang_count)
end
end
end

View file

@ -2,13 +2,24 @@ require 'rails_helper'
RSpec.describe 'mailers/domain_mailer/pending_deleted.html.erb' do
let(:domain) { instance_spy(DomainPresenter) }
let(:registrar) { instance_spy(RegistrarPresenter) }
let(:lang_count) { 2 }
before :example do
assign(:domain, domain)
assign(:registrar, registrar)
assign(:verification_url, 'test url')
assign(:registrar, nil)
stub_template 'mailers/domain_mailer/registrar/_registrar.et.html' => 'test registrar estonian'
stub_template 'mailers/domain_mailer/registrar/_registrar.en.html' => 'test registrar english'
assign(:verification_url, 'test verification url')
end
it 'has registrar info in estonian' do
render
expect(rendered).to have_text('test registrar estonian')
end
it 'has registrar info in english' do
render
expect(rendered).to have_text('test registrar english')
end
it 'has domain name' do
@ -21,21 +32,6 @@ RSpec.describe 'mailers/domain_mailer/pending_deleted.html.erb' do
it 'has verification url' do
mention_count = 1 * lang_count
render
expect(rendered).to have_text('test url', count: mention_count)
end
registrar_attributes = %i(
name
email
phone
url
)
registrar_attributes.each do |attr_name|
it "has registrar #{attr_name}" do
expect(registrar).to receive(attr_name).exactly(lang_count).times.and_return("test registrar #{attr_name}")
render
expect(rendered).to have_text("test registrar #{attr_name}", count: lang_count)
end
expect(rendered).to have_text('test verification url', count: mention_count)
end
end

View file

@ -2,12 +2,24 @@ require 'rails_helper'
RSpec.describe 'mailers/domain_mailer/pending_deleted.text.erb' do
let(:domain) { instance_spy(DomainPresenter) }
let(:registrar) { instance_spy(RegistrarPresenter) }
let(:lang_count) { 2 }
before :example do
assign(:domain, domain)
assign(:registrar, registrar)
assign(:registrar, nil)
stub_template 'mailers/domain_mailer/registrar/_registrar.et.text' => 'test registrar estonian'
stub_template 'mailers/domain_mailer/registrar/_registrar.en.text' => 'test registrar english'
assign(:verification_url, 'test verification url')
end
it 'has registrar info in estonian' do
render
expect(rendered).to have_text('test registrar estonian')
end
it 'has registrar info in english' do
render
expect(rendered).to have_text('test registrar english')
end
it 'has domain name' do
@ -19,23 +31,7 @@ RSpec.describe 'mailers/domain_mailer/pending_deleted.text.erb' do
it 'has verification url' do
mention_count = 1 * lang_count
assign(:verification_url, 'test url')
render
expect(rendered).to have_text('test url', count: mention_count)
end
registrar_attributes = %i(
name
email
phone
url
)
registrar_attributes.each do |attr_name|
it "has registrar #{attr_name}" do
expect(registrar).to receive(attr_name).exactly(lang_count).times.and_return("test registrar #{attr_name}")
render
expect(rendered).to have_text("test registrar #{attr_name}", count: lang_count)
end
expect(rendered).to have_text('test verification url', count: mention_count)
end
end

View file

@ -0,0 +1,22 @@
require 'rails_helper'
RSpec.describe 'mailers/domain_mailer/pending_update_notification_for_new_registrant.html.erb' do
let(:domain) { instance_spy(DomainPresenter) }
let(:lang_count) { 2 }
before :example do
assign(:domain, domain)
end
domain_attributes = %i(
name
)
domain_attributes.each do |attr_name|
it "has domain #{attr_name}" do
expect(domain).to receive(attr_name).exactly(lang_count).times.and_return("test domain #{attr_name}")
render
expect(rendered).to have_text("test domain #{attr_name}", count: lang_count)
end
end
end

View file

@ -0,0 +1,22 @@
require 'rails_helper'
RSpec.describe 'mailers/domain_mailer/pending_update_notification_for_new_registrant.text.erb' do
let(:domain) { instance_spy(DomainPresenter) }
let(:lang_count) { 2 }
before :example do
assign(:domain, domain)
end
domain_attributes = %i(
name
)
domain_attributes.each do |attr_name|
it "has domain #{attr_name}" do
expect(domain).to receive(attr_name).exactly(lang_count).times.and_return("test domain #{attr_name}")
render
expect(rendered).to have_text("test domain #{attr_name}", count: lang_count)
end
end
end

View file

@ -2,36 +2,17 @@ require 'rails_helper'
RSpec.describe 'mailers/domain_mailer/pending_update_request_for_old_registrant.html.erb' do
let(:domain) { instance_spy(DomainPresenter) }
let(:registrar) { instance_spy(RegistrarPresenter) }
let(:registrant) { instance_spy(RegistrantPresenter) }
let(:lang_count) { 2 }
before :example do
assign(:domain, domain)
assign(:registrar, registrar)
assign(:registrant, registrant)
assign(:verification_url, 'test url')
assign(:verification_url, 'test verification url')
end
it 'has verification url' do
mention_count = 1 * lang_count
render
expect(rendered).to have_text('test url', count: mention_count)
end
registrar_attributes = %i(
name
email
phone
url
)
registrar_attributes.each do |attr_name|
it "has registrar #{attr_name}" do
expect(registrar).to receive(attr_name).exactly(lang_count).times.and_return("test registrar #{attr_name}")
render
expect(rendered).to have_text("test registrar #{attr_name}", count: lang_count)
end
expect(rendered).to have_text('test verification url', count: mention_count)
end
domain_attributes = %i(
@ -45,20 +26,4 @@ RSpec.describe 'mailers/domain_mailer/pending_update_request_for_old_registrant.
expect(rendered).to have_text(attr_name.to_s, count: lang_count)
end
end
registrant_attributes = %i(
name
ident
street
city
country
)
registrant_attributes.each do |attr_name|
it "has registrant #{attr_name}" do
expect(registrant).to receive(attr_name).exactly(lang_count).times.and_return("test registrant #{attr_name}")
render
expect(rendered).to have_text("test registrant #{attr_name}", count: lang_count)
end
end
end

View file

@ -2,36 +2,17 @@ require 'rails_helper'
RSpec.describe 'mailers/domain_mailer/pending_update_request_for_old_registrant.text.erb' do
let(:domain) { instance_spy(DomainPresenter) }
let(:registrar) { instance_spy(RegistrarPresenter) }
let(:registrant) { instance_spy(RegistrantPresenter) }
let(:lang_count) { 2 }
before :example do
assign(:domain, domain)
assign(:registrar, registrar)
assign(:registrant, registrant)
assign(:verification_url, 'test url')
assign(:verification_url, 'test verification url')
end
it 'has verification url' do
mention_count = 1 * lang_count
render
expect(rendered).to have_text('test url', count: mention_count)
end
registrar_attributes = %i(
name
email
phone
url
)
registrar_attributes.each do |attr_name|
it "has registrar #{attr_name}" do
expect(registrar).to receive(attr_name).exactly(lang_count).times.and_return("test registrar #{attr_name}")
render
expect(rendered).to have_text("test registrar #{attr_name}", count: lang_count)
end
expect(rendered).to have_text('test verification url', count: mention_count)
end
domain_attributes = %i(
@ -45,20 +26,4 @@ RSpec.describe 'mailers/domain_mailer/pending_update_request_for_old_registrant.
expect(rendered).to have_text(attr_name.to_s, count: lang_count)
end
end
registrant_attributes = %i(
name
ident
street
city
country
)
registrant_attributes.each do |attr_name|
it "has registrant #{attr_name}" do
expect(registrant).to receive(attr_name).exactly(lang_count).times.and_return("test registrant #{attr_name}")
render
expect(rendered).to have_text("test registrant #{attr_name}", count: lang_count)
end
end
end

View file

@ -0,0 +1,25 @@
require 'rails_helper'
RSpec.describe 'mailers/domain_mailer/_registrant.et.text.erb' do
let(:registrant) { instance_spy(RegistrantPresenter) }
before :example do
allow(view).to receive(:registrant).and_return(registrant)
end
attributes = %i(
name
ident
street
city
country
)
attributes.each do |attr_name|
it "has #{attr_name}" do
expect(registrant).to receive(attr_name).and_return("test #{attr_name}")
render
expect(rendered).to have_text("test #{attr_name}")
end
end
end

View file

@ -0,0 +1,24 @@
require 'rails_helper'
RSpec.describe 'mailers/domain_mailer/_registrar.et.text.erb' do
let(:registrar) { instance_spy(RegistrarPresenter) }
before :example do
allow(view).to receive(:registrar).and_return(registrar)
end
attributes = %i(
name
email
phone
url
)
attributes.each do |attr_name|
it "has #{attr_name}" do
expect(registrar).to receive(attr_name).and_return("test #{attr_name}")
render
expect(rendered).to have_text("test #{attr_name}")
end
end
end