From ea95bd2f9c53b65a36824bfc6db1f4ca97e0a6ad Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Wed, 26 Oct 2016 16:42:52 +0300 Subject: [PATCH 01/67] Set queue_adapter to :test in test env config #186 --- config/environments/test.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/config/environments/test.rb b/config/environments/test.rb index 46ec2c467..4e0b47bcb 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -62,6 +62,7 @@ Rails.application.configure do Bullet.add_whitelist type: :counter_cache, class_name: 'Contact', association: :versions end + config.active_job.queue_adapter = :test config.logger = ActiveSupport::Logger.new(nil) end From 8c474b24650f34528de10f03dcdf70d314acbf8d Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Wed, 26 Oct 2016 17:46:14 +0300 Subject: [PATCH 02/67] Load all translation files from config/locales #186 --- config/application.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/config/application.rb b/config/application.rb index 2121039dc..323d9b150 100644 --- a/config/application.rb +++ b/config/application.rb @@ -23,12 +23,12 @@ module Registry # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone. # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC. - config.time_zone = ENV['time_zone'] || 'Tallinn' # NB! It should be defined, + config.time_zone = ENV['time_zone'] || 'Tallinn' # NB! It should be defined, # otherwise ActiveRecord usese other class internally. # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded. - # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s] - # config.i18n.default_locale = :de + config.i18n.load_path += Dir[Rails.root.join('config', 'locales', '**', '*.yml').to_s] + config.i18n.default_locale = :en config.paths.add File.join('app', 'api'), glob: File.join('**', '*.rb') config.autoload_paths += Dir[Rails.root.join('app', 'api', '*')] From 666ba69456ce7f3a40527af545b7e1ded948e0f5 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Wed, 26 Oct 2016 17:50:30 +0300 Subject: [PATCH 03/67] Do not create global settings for specs #186 --- spec/models/contact_spec.rb | 41 ++++++++ spec/models/dnskey_spec.rb | 19 ++++ spec/models/domain_spec.rb | 95 ++++++++++++++++++ spec/models/domain_transfer_spec.rb | 19 ++++ spec/models/keyrelay_spec.rb | 19 ++++ spec/models/nameserver_spec.rb | 31 ++++++ spec/models/registrant_verification_spec.rb | 19 ++++ spec/rails_helper.rb | 44 --------- spec/support/request.rb | 104 -------------------- 9 files changed, 243 insertions(+), 148 deletions(-) delete mode 100644 spec/support/request.rb diff --git a/spec/models/contact_spec.rb b/spec/models/contact_spec.rb index a5a680439..b54c5a47f 100644 --- a/spec/models/contact_spec.rb +++ b/spec/models/contact_spec.rb @@ -2,6 +2,25 @@ require 'rails_helper' describe Contact do before :example do + Setting.ds_algorithm = 2 + Setting.ds_data_allowed = true + Setting.ds_data_with_key_allowed = true + Setting.key_data_allowed = true + + Setting.dnskeys_min_count = 0 + Setting.dnskeys_max_count = 9 + Setting.ns_min_count = 2 + Setting.ns_max_count = 11 + + Setting.transfer_wait_time = 0 + + Setting.admin_contacts_min_count = 1 + Setting.admin_contacts_max_count = 10 + Setting.tech_contacts_min_count = 0 + Setting.tech_contacts_max_count = 10 + + Setting.client_side_status_editing_enabled = true + Fabricate(:zonefile_setting, origin: 'ee') @api_user = Fabricate(:api_user) end @@ -363,3 +382,25 @@ describe Contact, '.destroy_orphans' do Contact.count.should == cc end end + +RSpec.describe Contact, db: false do + describe '::names' do + before :example do + expect(described_class).to receive(:pluck).with(:name).and_return('names') + end + + it 'returns names' do + expect(described_class.names).to eq('names') + end + end + + describe '::emails' do + before :example do + expect(described_class).to receive(:pluck).with(:email).and_return('emails') + end + + it 'returns emails' do + expect(described_class.emails).to eq('emails') + end + end +end diff --git a/spec/models/dnskey_spec.rb b/spec/models/dnskey_spec.rb index ef0f52475..5267f3eac 100644 --- a/spec/models/dnskey_spec.rb +++ b/spec/models/dnskey_spec.rb @@ -2,6 +2,25 @@ require 'rails_helper' describe Dnskey do before :example do + Setting.ds_algorithm = 2 + Setting.ds_data_allowed = true + Setting.ds_data_with_key_allowed = true + Setting.key_data_allowed = true + + Setting.dnskeys_min_count = 0 + Setting.dnskeys_max_count = 9 + Setting.ns_min_count = 2 + Setting.ns_max_count = 11 + + Setting.transfer_wait_time = 0 + + Setting.admin_contacts_min_count = 1 + Setting.admin_contacts_max_count = 10 + Setting.tech_contacts_min_count = 0 + Setting.tech_contacts_max_count = 10 + + Setting.client_side_status_editing_enabled = true + Fabricate(:zonefile_setting, origin: 'ee') end diff --git a/spec/models/domain_spec.rb b/spec/models/domain_spec.rb index 9d9c6439e..1d6a63fb8 100644 --- a/spec/models/domain_spec.rb +++ b/spec/models/domain_spec.rb @@ -2,6 +2,25 @@ require 'rails_helper' RSpec.describe Domain do before :example do + Setting.ds_algorithm = 2 + Setting.ds_data_allowed = true + Setting.ds_data_with_key_allowed = true + Setting.key_data_allowed = true + + Setting.dnskeys_min_count = 0 + Setting.dnskeys_max_count = 9 + Setting.ns_min_count = 2 + Setting.ns_max_count = 11 + + Setting.transfer_wait_time = 0 + + Setting.admin_contacts_min_count = 1 + Setting.admin_contacts_max_count = 10 + Setting.tech_contacts_min_count = 0 + Setting.tech_contacts_max_count = 10 + + Setting.client_side_status_editing_enabled = true + Fabricate(:zonefile_setting, origin: 'ee') Fabricate(:zonefile_setting, origin: 'pri.ee') Fabricate(:zonefile_setting, origin: 'med.ee') @@ -842,6 +861,9 @@ RSpec.describe Domain do end RSpec.describe Domain, db: false do + it { is_expected.to alias_attribute(:on_hold_time, :outzone_at) } + it { is_expected.to alias_attribute(:delete_time, :delete_at) } + describe '#set_server_hold' do let(:domain) { described_class.new } @@ -858,4 +880,77 @@ RSpec.describe Domain, db: false do expect(domain.outzone_at).to eq(Time.zone.parse('05.07.2010')) end end + + describe '#admin_contact_names' do + let(:domain) { described_class.new } + + before :example do + expect(Contact).to receive(:names).and_return('names') + end + + it 'returns admin contact names' do + expect(domain.admin_contact_names).to eq('names') + end + end + + describe '#admin_contact_emails' do + let(:domain) { described_class.new } + + before :example do + expect(Contact).to receive(:emails).and_return('emails') + end + + it 'returns admin contact emails' do + expect(domain.admin_contact_emails).to eq('emails') + end + end + + describe '#tech_contact_names' do + let(:domain) { described_class.new } + + before :example do + expect(Contact).to receive(:names).and_return('names') + end + + it 'returns technical contact names' do + expect(domain.tech_contact_names).to eq('names') + end + end + + describe '#nameserver_hostnames' do + let(:domain) { described_class.new } + + before :example do + expect(Nameserver).to receive(:hostnames).and_return('hostnames') + end + + it 'returns name server hostnames' do + expect(domain.nameserver_hostnames).to eq('hostnames') + end + end + + describe '#registered?' do + before :example do + travel_to Time.zone.parse('05.07.2010 00:00:01') + end + + context 'when :valid_to is in the future' do + let(:domain) { described_class.new(valid_to: Time.zone.parse('06.07.2010')) } + + specify { expect(domain).to be_registered } + end + + context 'when :valid_to is the same as current time' do + let(:domain) { described_class.new(valid_to: Time.zone.parse('05.07.2010 00:00:01')) } + + + specify { expect(domain).to be_registered } + end + + context 'when :valid_to is in the past' do + let(:domain) { described_class.new(valid_to: Time.zone.parse('04.07.2010 23:59:59')) } + + specify { expect(domain).to_not be_registered } + end + end end diff --git a/spec/models/domain_transfer_spec.rb b/spec/models/domain_transfer_spec.rb index e46b46aca..3609b2f7d 100644 --- a/spec/models/domain_transfer_spec.rb +++ b/spec/models/domain_transfer_spec.rb @@ -2,6 +2,25 @@ require 'rails_helper' describe DomainTransfer do before :example do + Setting.ds_algorithm = 2 + Setting.ds_data_allowed = true + Setting.ds_data_with_key_allowed = true + Setting.key_data_allowed = true + + Setting.dnskeys_min_count = 0 + Setting.dnskeys_max_count = 9 + Setting.ns_min_count = 2 + Setting.ns_max_count = 11 + + Setting.transfer_wait_time = 0 + + Setting.admin_contacts_min_count = 1 + Setting.admin_contacts_max_count = 10 + Setting.tech_contacts_min_count = 0 + Setting.tech_contacts_max_count = 10 + + Setting.client_side_status_editing_enabled = true + Fabricate(:zonefile_setting, origin: 'ee') end diff --git a/spec/models/keyrelay_spec.rb b/spec/models/keyrelay_spec.rb index 5243cbf6c..73e26a098 100644 --- a/spec/models/keyrelay_spec.rb +++ b/spec/models/keyrelay_spec.rb @@ -2,6 +2,25 @@ require 'rails_helper' describe Keyrelay do before :example do + Setting.ds_algorithm = 2 + Setting.ds_data_allowed = true + Setting.ds_data_with_key_allowed = true + Setting.key_data_allowed = true + + Setting.dnskeys_min_count = 0 + Setting.dnskeys_max_count = 9 + Setting.ns_min_count = 2 + Setting.ns_max_count = 11 + + Setting.transfer_wait_time = 0 + + Setting.admin_contacts_min_count = 1 + Setting.admin_contacts_max_count = 10 + Setting.tech_contacts_min_count = 0 + Setting.tech_contacts_max_count = 10 + + Setting.client_side_status_editing_enabled = true + Fabricate(:zonefile_setting, origin: 'ee') end diff --git a/spec/models/nameserver_spec.rb b/spec/models/nameserver_spec.rb index 586f83390..1844bc0f9 100644 --- a/spec/models/nameserver_spec.rb +++ b/spec/models/nameserver_spec.rb @@ -2,6 +2,25 @@ require 'rails_helper' describe Nameserver do before :example do + Setting.ds_algorithm = 2 + Setting.ds_data_allowed = true + Setting.ds_data_with_key_allowed = true + Setting.key_data_allowed = true + + Setting.dnskeys_min_count = 0 + Setting.dnskeys_max_count = 9 + Setting.ns_min_count = 2 + Setting.ns_max_count = 11 + + Setting.transfer_wait_time = 0 + + Setting.admin_contacts_min_count = 1 + Setting.admin_contacts_max_count = 10 + Setting.tech_contacts_min_count = 0 + Setting.tech_contacts_max_count = 10 + + Setting.client_side_status_editing_enabled = true + Fabricate(:zonefile_setting, origin: 'ee') end @@ -92,3 +111,15 @@ describe Nameserver do end end end + +RSpec.describe Nameserver do + describe '::hostnames', db: false do + before :example do + expect(described_class).to receive(:pluck).with(:hostname).and_return('hostnames') + end + + it 'returns names' do + expect(described_class.hostnames).to eq('hostnames') + end + end +end diff --git a/spec/models/registrant_verification_spec.rb b/spec/models/registrant_verification_spec.rb index fc9b8ab82..5997797c7 100644 --- a/spec/models/registrant_verification_spec.rb +++ b/spec/models/registrant_verification_spec.rb @@ -2,6 +2,25 @@ require 'rails_helper' describe RegistrantVerification do before :example do + Setting.ds_algorithm = 2 + Setting.ds_data_allowed = true + Setting.ds_data_with_key_allowed = true + Setting.key_data_allowed = true + + Setting.dnskeys_min_count = 0 + Setting.dnskeys_max_count = 9 + Setting.ns_min_count = 2 + Setting.ns_max_count = 11 + + Setting.transfer_wait_time = 0 + + Setting.admin_contacts_min_count = 1 + Setting.admin_contacts_max_count = 10 + Setting.tech_contacts_min_count = 0 + Setting.tech_contacts_max_count = 10 + + Setting.client_side_status_editing_enabled = true + Fabricate(:zonefile_setting, origin: 'ee') end context 'with invalid attribute' do diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 2e6927569..3403af964 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -15,33 +15,10 @@ require 'support/matchers/alias_attribute' require 'support/matchers/active_job' require 'support/capybara' require 'support/database_cleaner' -require 'support/request' require 'support/paper_trail' ActiveRecord::Migration.maintain_test_schema! -# create general settings -def create_settings - Setting.ds_algorithm = 2 - Setting.ds_data_allowed = true - Setting.ds_data_with_key_allowed = true - Setting.key_data_allowed = true - - Setting.dnskeys_min_count = 0 - Setting.dnskeys_max_count = 9 - Setting.ns_min_count = 2 - Setting.ns_max_count = 11 - - Setting.transfer_wait_time = 0 - - Setting.admin_contacts_min_count = 1 - Setting.admin_contacts_max_count = 10 - Setting.tech_contacts_min_count = 0 - Setting.tech_contacts_max_count = 10 - - Setting.client_side_status_editing_enabled = true -end - RSpec.configure do |config| config.include ActionView::TestCase::Behavior, type: :presenter config.include ActiveSupport::Testing::TimeHelpers @@ -52,27 +29,6 @@ RSpec.configure do |config| end config.use_transactional_fixtures = false - - config.before(:all) do - create_settings - end - - config.before(:all, epp: true) do - create_settings - end - - config.before(:each, js: true) do - create_settings - end - - config.before(:each, type: :request) do - create_settings - end - - config.before(:each, type: :model) do - create_settings - end - config.infer_spec_type_from_file_location! config.expect_with :rspec do |c| diff --git a/spec/support/request.rb b/spec/support/request.rb deleted file mode 100644 index fedf1ae04..000000000 --- a/spec/support/request.rb +++ /dev/null @@ -1,104 +0,0 @@ -module Request - def get_with_auth(path, params, epp_user) - get path, params, env_with_auth(epp_user) - end - - def delete_with_auth(path, epp_user) - delete path, params, env_with_auth(epp_user) - end - - def post_with_auth(path, params, epp_user) - post path, params, env_with_auth(epp_user) - end - - def patch_with_auth(path, params, epp_user) - patch path, params, env_with_auth(epp_user) - end - - def env - { - 'Accept' => 'application/json', - 'Content-Type' => 'application/json' - } - end - - def env_with_auth(epp_user) - env.merge({ - 'HTTP_AUTHORIZATION' => ActionController::HttpAuthentication::Basic.encode_credentials( - epp_user.username, epp_user.password - ) - }) - end -end - -module Autodoc - class Document - def route_info_doc - return unless example.metadata[:route_info_doc] - route = request.env["rack.routing_args"][:route_info] - return unless route.route_params.is_a?(Hash) - return if route.route_params.empty? - - rows = [ - "| Field name | Required | Type | Allowed values | Description |", - "| ---------- | -------- | ---- | -------------- | ----------- |" - ] - - route.route_params.each do |name, desc| - details = [] - details << "| #{name} " - details << "| #{desc[:required]} " - details << "| #{desc[:type]} " - details << "| #{ranges_from_array(desc[:values])} " - details << "| #{desc[:desc]} |" - rows << details.join - end - - pretty_table(rows).join("\n") - end - - def pretty_table(rows) - # longest_in_col = 0 - matrix_array = [] - rows.each do |x| - matrix_array << x.split('|') + [''] # [''] is because split loses last | - end - - new_arr = [] - matrix_array.transpose.each do |col| - new_col = [] - longest = col.max_by(&:size).size - - col.each do |r| - new_col << r.center(longest) - end - new_arr << new_col - end - - matrix_array = [] - new_arr.transpose.each do |x| - matrix_array << x.join('|') - end - - matrix_array - end - - def ranges_from_array(a) - return unless a - ranges = a.sort.uniq.reduce([]) do |spans, n| - return a if n.is_a?(String) - if spans.empty? || spans.last.last != n - 1 - spans + [n..n] - else - spans[0..-2] + [spans.last.first..n] - end - end - - ranges - end - end -end - -RSpec.configure do |c| - c.include Request, type: :request -end From a882eb2df44fca00ccd3afdd8ceaa1c14e4034d4 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Wed, 26 Oct 2016 17:58:29 +0300 Subject: [PATCH 04/67] Regenerate rspec and spring binaries #186 --- bin/rspec | 4 ++++ bin/spring | 20 ++++++++------------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/bin/rspec b/bin/rspec index 8bc84617e..534d2bb5f 100755 --- a/bin/rspec +++ b/bin/rspec @@ -1,4 +1,8 @@ #!/usr/bin/env ruby +begin + load File.expand_path("../spring", __FILE__) +rescue LoadError +end # # This file was generated by Bundler. # diff --git a/bin/spring b/bin/spring index adc409e83..7b45d374f 100755 --- a/bin/spring +++ b/bin/spring @@ -1,19 +1,15 @@ #!/usr/bin/env ruby -# This file loads spring without using Bundler, in order to be fast -# It gets overwritten when you run the `spring binstub` command +# This file loads spring without using Bundler, in order to be fast. +# It gets overwritten when you run the `spring binstub` command. unless defined?(Spring) - require 'rubygems' - require 'bundler' + require "rubygems" + require "bundler" - match = Bundler.default_lockfile.read.match(/^GEM$.*?^ spring \((.*?)\)$.*?^$/m) - if match - ENV['GEM_PATH'] = ([Bundler.bundle_path.to_s] + Gem.path).join(File::PATH_SEPARATOR) - ENV['GEM_HOME'] = nil - Gem.paths = ENV - - gem 'spring', match[1] - require 'spring/binstub' + if match = Bundler.default_lockfile.read.match(/^GEM$.*?^ (?: )*spring \((.*?)\)$.*?^$/m) + Gem.paths = { "GEM_PATH" => [Bundler.bundle_path.to_s, *Gem.path].uniq } + gem "spring", match[1] + require "spring/binstub" end end From 7a3e900e13e362f23a128b46ee4933bdb1f48706 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Wed, 26 Oct 2016 23:45:56 +0300 Subject: [PATCH 05/67] Add FactoryGirl lint spec #186 --- spec/lint_spec.rb | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 spec/lint_spec.rb diff --git a/spec/lint_spec.rb b/spec/lint_spec.rb new file mode 100644 index 000000000..1fd88debc --- /dev/null +++ b/spec/lint_spec.rb @@ -0,0 +1,7 @@ +require 'rails_helper' + +RSpec.describe 'FactoryGirl' do + it 'lints factories' do + FactoryGirl.lint + end +end From 7e46ba01c2c7e5bfa412985b8d23ff2b169bfc61 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Fri, 28 Oct 2016 00:25:07 +0300 Subject: [PATCH 06/67] Fix FactoryGirl lint spec #186 --- spec/factory_lint_spec.rb | 7 +++++++ spec/lint_spec.rb | 7 ------- 2 files changed, 7 insertions(+), 7 deletions(-) create mode 100644 spec/factory_lint_spec.rb delete mode 100644 spec/lint_spec.rb diff --git a/spec/factory_lint_spec.rb b/spec/factory_lint_spec.rb new file mode 100644 index 000000000..37988cca0 --- /dev/null +++ b/spec/factory_lint_spec.rb @@ -0,0 +1,7 @@ +require_relative 'rails_helper' + +RSpec.describe 'FactoryGirl', db: true do + it 'lints factories' do + FactoryGirl.lint + end +end diff --git a/spec/lint_spec.rb b/spec/lint_spec.rb deleted file mode 100644 index 1fd88debc..000000000 --- a/spec/lint_spec.rb +++ /dev/null @@ -1,7 +0,0 @@ -require 'rails_helper' - -RSpec.describe 'FactoryGirl' do - it 'lints factories' do - FactoryGirl.lint - end -end From 469312d7ee380d7343cd750a5240ed38324f43e9 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Fri, 28 Oct 2016 00:25:43 +0300 Subject: [PATCH 07/67] Add settings rspec support #186 --- spec/rails_helper.rb | 1 + spec/support/settings.rb | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 spec/support/settings.rb diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 3403af964..9411702f5 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -16,6 +16,7 @@ require 'support/matchers/active_job' require 'support/capybara' require 'support/database_cleaner' require 'support/paper_trail' +require 'support/settings' ActiveRecord::Migration.maintain_test_schema! diff --git a/spec/support/settings.rb b/spec/support/settings.rb new file mode 100644 index 000000000..7a5aebf3b --- /dev/null +++ b/spec/support/settings.rb @@ -0,0 +1,26 @@ +RSpec.configure do |config| + config.before :example do |example| + if example.metadata[:db] + Fabricate(:zonefile_setting, origin: 'com') + + Setting.ds_algorithm = 2 + Setting.ds_data_allowed = true + Setting.ds_data_with_key_allowed = true + Setting.key_data_allowed = true + + Setting.dnskeys_min_count = 0 + Setting.dnskeys_max_count = 9 + Setting.ns_min_count = 2 + Setting.ns_max_count = 11 + + Setting.transfer_wait_time = 0 + + Setting.admin_contacts_min_count = 1 + Setting.admin_contacts_max_count = 10 + Setting.tech_contacts_min_count = 0 + Setting.tech_contacts_max_count = 10 + + Setting.client_side_status_editing_enabled = true + end + end +end From 39d7c6ad1d2aaf596f6775b320704c0102ea3ffd Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Fri, 28 Oct 2016 00:29:47 +0300 Subject: [PATCH 08/67] Refactor zonefile_setting's origin list #186 --- app/controllers/admin/zonefiles_controller.rb | 2 +- app/models/zonefile_setting.rb | 4 ++++ app/validators/domain_name_validator.rb | 4 ++-- spec/models/zonefile_setting_spec.rb | 17 +++++++++++++++++ 4 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 spec/models/zonefile_setting_spec.rb diff --git a/app/controllers/admin/zonefiles_controller.rb b/app/controllers/admin/zonefiles_controller.rb index 7d3b68ec6..1c0fed936 100644 --- a/app/controllers/admin/zonefiles_controller.rb +++ b/app/controllers/admin/zonefiles_controller.rb @@ -3,7 +3,7 @@ class Admin::ZonefilesController < ApplicationController # TODO: Refactor this def create - if ZonefileSetting.pluck(:origin).include?(params[:origin]) + if ZonefileSetting.origins.include?(params[:origin]) @zonefile = ActiveRecord::Base.connection.execute( "select generate_zonefile('#{params[:origin]}')" diff --git a/app/models/zonefile_setting.rb b/app/models/zonefile_setting.rb index 4a9656b7a..9f2b2b862 100644 --- a/app/models/zonefile_setting.rb +++ b/app/models/zonefile_setting.rb @@ -32,6 +32,10 @@ class ZonefileSetting < ActiveRecord::Base STDOUT << "#{Time.zone.now.utc} - Successfully generated zonefile #{filename}\n" end + def self.origins + pluck(:origin) + end + def to_s origin end diff --git a/app/validators/domain_name_validator.rb b/app/validators/domain_name_validator.rb index be83f0835..427a330f3 100644 --- a/app/validators/domain_name_validator.rb +++ b/app/validators/domain_name_validator.rb @@ -12,9 +12,9 @@ class DomainNameValidator < ActiveModel::EachValidator return true unless value value = value.mb_chars.downcase.strip - origins = ZonefileSetting.pluck(:origin) + origins = ZonefileSetting.origins # if someone tries to register an origin domain, let this validation pass - # the error will be catched in blocked domains validator + # the error will be caught in blocked domains validator return true if origins.include?(value) general_domains = /(#{origins.join('|')})/ diff --git a/spec/models/zonefile_setting_spec.rb b/spec/models/zonefile_setting_spec.rb new file mode 100644 index 000000000..d1cd61119 --- /dev/null +++ b/spec/models/zonefile_setting_spec.rb @@ -0,0 +1,17 @@ +require 'rails_helper' + +RSpec.describe ZonefileSetting, db: false do + it 'has versions' do + expect(described_class.new.versions).to eq([]) + end + + describe '::origins' do + before :example do + expect(described_class).to receive(:pluck).with(:origin).and_return('origins') + end + + it 'returns origins' do + expect(described_class.origins).to eq('origins') + end + end +end From ad0220088a0a1024c164235f1d1a930bfaf8973c Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Fri, 28 Oct 2016 00:36:12 +0300 Subject: [PATCH 09/67] Refactor domain expiration email #186 --- app/jobs/domain_expiration_email_job.rb | 11 +++ app/mailers/domain_mailer.rb | 21 ++-- app/models/concerns/domain/expirable.rb | 31 ++++++ app/models/contact.rb | 7 ++ app/models/domain.rb | 19 ++++ app/models/nameserver.rb | 6 +- app/presenters/domain_presenter.rb | 33 +++++++ app/presenters/registrar_presenter.rb | 27 ++++++ .../mailers/domain_mailer/expiration.html.erb | 67 +++++++++++++ .../mailers/domain_mailer/expiration.text.erb | 60 ++++++++++++ config/locales/en.yml | 1 - config/locales/mailers/domain.en.yml | 4 + spec/factories/admin_domain_contact.rb | 5 + spec/factories/contact.rb | 16 ++++ spec/factories/dnskey.rb | 15 +++ spec/factories/domain.rb | 15 +++ spec/factories/domain_contact.rb | 5 + spec/factories/nameserver.rb | 6 ++ spec/factories/registrant.rb | 5 + spec/factories/registrar.rb | 13 +++ spec/factories/tech_domain_contact.rb | 5 + spec/jobs/domain_expiration_email_job_spec.rb | 40 ++++++++ spec/mailers/domain_mailer_spec.rb | 38 ++++++++ spec/models/concerns/domain/expirable_spec.rb | 57 +++++++++++ spec/models/contact_spec.rb | 22 +---- spec/models/domain_spec.rb | 25 ----- spec/presenters/domain_presenter_spec.rb | 96 +++++++++++++++++++ spec/presenters/registrar_presenter_spec.rb | 34 +++++++ .../domain_mailer/expiration.html.erb_spec.rb | 36 +++++++ .../domain_mailer/expiration.text.erb_spec.rb | 36 +++++++ 30 files changed, 697 insertions(+), 59 deletions(-) create mode 100644 app/jobs/domain_expiration_email_job.rb create mode 100644 app/models/concerns/domain/expirable.rb create mode 100644 app/presenters/domain_presenter.rb create mode 100644 app/presenters/registrar_presenter.rb create mode 100644 app/views/mailers/domain_mailer/expiration.html.erb create mode 100644 app/views/mailers/domain_mailer/expiration.text.erb create mode 100644 config/locales/mailers/domain.en.yml create mode 100644 spec/factories/admin_domain_contact.rb create mode 100644 spec/factories/contact.rb create mode 100644 spec/factories/dnskey.rb create mode 100644 spec/factories/domain.rb create mode 100644 spec/factories/domain_contact.rb create mode 100644 spec/factories/nameserver.rb create mode 100644 spec/factories/registrant.rb create mode 100644 spec/factories/registrar.rb create mode 100644 spec/factories/tech_domain_contact.rb create mode 100644 spec/jobs/domain_expiration_email_job_spec.rb create mode 100644 spec/mailers/domain_mailer_spec.rb create mode 100644 spec/models/concerns/domain/expirable_spec.rb create mode 100644 spec/presenters/domain_presenter_spec.rb create mode 100644 spec/presenters/registrar_presenter_spec.rb create mode 100644 spec/views/mailers/domain_mailer/expiration.html.erb_spec.rb create mode 100644 spec/views/mailers/domain_mailer/expiration.text.erb_spec.rb diff --git a/app/jobs/domain_expiration_email_job.rb b/app/jobs/domain_expiration_email_job.rb new file mode 100644 index 000000000..1066d3f35 --- /dev/null +++ b/app/jobs/domain_expiration_email_job.rb @@ -0,0 +1,11 @@ +class DomainExpirationEmailJob < ActiveJob::Base + queue_as :default + + def perform(domain_id:) + domain = Domain.find(domain_id) + + return if domain.registered? + + DomainMailer.expiration(domain).deliver! + end +end diff --git a/app/mailers/domain_mailer.rb b/app/mailers/domain_mailer.rb index afdfe89fc..e53c6d596 100644 --- a/app/mailers/domain_mailer.rb +++ b/app/mailers/domain_mailer.rb @@ -117,17 +117,6 @@ class DomainMailer < ApplicationMailer name: @domain.name)} [#{@domain.name}]") end - def expiration_reminder(domain_id) - @domain = Domain.find_by(id: domain_id) - return if @domain.nil? || !@domain.statuses.include?(DomainStatus::EXPIRED) || whitelist_blocked?(@domain.registrant.email) - return if whitelist_blocked?(@domain.registrant.email) - - mail(to: format(@domain.registrant.email), - subject: "#{I18n.t(:expiration_remind_subject, - name: @domain.name)} [#{@domain.name}]") - end - - def force_delete(domain_id, should_deliver) @domain = Domain.find_by(id: domain_id) return if delivery_off?(@domain, should_deliver) @@ -140,6 +129,16 @@ class DomainMailer < ApplicationMailer ) end + def expiration(domain:) + @domain = DomainPresenter.new(domain: domain, view: view_context) + @registrar = RegistrarPresenter.new(registrar: domain.registrar, view: view_context) + + recipients = domain.admin_contact_emails << domain.registrant_email + + subject = default_i18n_subject(domain_name: domain.name) + mail(to: recipients, subject: subject) + end + private # app/models/DomainMailModel provides the data for mail that can be composed_from # which ensures that values of objects are captured when they are valid, not later when this method is executed diff --git a/app/models/concerns/domain/expirable.rb b/app/models/concerns/domain/expirable.rb new file mode 100644 index 000000000..237bdfd34 --- /dev/null +++ b/app/models/concerns/domain/expirable.rb @@ -0,0 +1,31 @@ +module Concerns::Domain::Expirable + extend ActiveSupport::Concern + + included do + alias_attribute :expire_time, :valid_to + end + + class_methods do + def expired + where("#{attribute_alias(:expire_time)} <= ?", Time.zone.now) + end + end + + def registered? + valid_to >= Time.zone.now + end + + def expired? + statuses.include?(DomainStatus::EXPIRED) + end + + def expirable? + return false if valid_to > Time.zone.now + + if expired? && outzone_at.present? && delete_at.present? + return false + end + + true + end +end diff --git a/app/models/contact.rb b/app/models/contact.rb index 50e78ef54..822394d22 100644 --- a/app/models/contact.rb +++ b/app/models/contact.rb @@ -250,6 +250,13 @@ class Contact < ActiveRecord::Base kit.to_pdf end + def names + pluck(:name) + end + + def emails + pluck(:email) + end end def roid diff --git a/app/models/domain.rb b/app/models/domain.rb index 1d96dbfde..7b7087dd9 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -3,12 +3,16 @@ class Domain < ActiveRecord::Base include UserEvents include Versions # version/domain_version.rb include Statuses + include Concerns::Domain::Expirable has_paper_trail class_name: "DomainVersion", meta: { children: :children_log } attr_accessor :roles attr_accessor :legal_document_id + alias_attribute :on_hold_time, :outzone_at + alias_attribute :delete_time, :delete_at + # TODO: whois requests ip whitelist for full info for own domains and partial info for other domains # TODO: most inputs should be trimmed before validatation, probably some global logic? @@ -746,6 +750,21 @@ class Domain < ActiveRecord::Base DomainMailer.send(action, DomainMailModel.new(self).send(action)).deliver end + def admin_contact_names + admin_contacts.names + end + + def admin_contact_emails + admin_contacts.emails + end + + def tech_contact_names + tech_contacts.names + end + + def nameserver_hostnames + nameservers.hostnames + end def self.to_csv CSV.generate do |csv| diff --git a/app/models/nameserver.rb b/app/models/nameserver.rb index 7b4daab3d..fb56f1198 100644 --- a/app/models/nameserver.rb +++ b/app/models/nameserver.rb @@ -18,7 +18,7 @@ class Nameserver < ActiveRecord::Base before_validation :normalize_attributes before_validation :check_puny_symbols before_validation :check_label_length - + delegate :name, to: :domain, prefix: true def epp_code_map @@ -117,5 +117,9 @@ class Nameserver < ActiveRecord::Base # ignoring ips rel end + + def hostnames + pluck(:hostname) + end end end diff --git a/app/presenters/domain_presenter.rb b/app/presenters/domain_presenter.rb new file mode 100644 index 000000000..ea8b0ba22 --- /dev/null +++ b/app/presenters/domain_presenter.rb @@ -0,0 +1,33 @@ +class DomainPresenter + delegate :name, :registrant_name, to: :domain + + def initialize(domain:, view:) + @domain = domain + @view = view + end + + def on_hold_date + view.l(domain.on_hold_time, format: :date) if domain.on_hold_time + end + + def delete_date + view.l(domain.delete_time, format: :date) if domain.delete_time + end + + def admin_contact_names + domain.admin_contact_names.join(', ') + end + + def tech_contact_names + domain.tech_contact_names.join(', ') + end + + def nameserver_names + domain.nameserver_hostnames.join(', ') + end + + private + + attr_reader :domain + attr_reader :view +end diff --git a/app/presenters/registrar_presenter.rb b/app/presenters/registrar_presenter.rb new file mode 100644 index 000000000..1fe415feb --- /dev/null +++ b/app/presenters/registrar_presenter.rb @@ -0,0 +1,27 @@ +class RegistrarPresenter + def initialize(registrar:, view:) + @registrar = registrar + @view = view + end + + def name + registrar.name + end + + def email + registrar.email + end + + def phone + registrar.phone + end + + def url + registrar.url + end + + private + + attr_reader :registrar + attr_reader :view +end diff --git a/app/views/mailers/domain_mailer/expiration.html.erb b/app/views/mailers/domain_mailer/expiration.html.erb new file mode 100644 index 000000000..d06a8803e --- /dev/null +++ b/app/views/mailers/domain_mailer/expiration.html.erb @@ -0,0 +1,67 @@ +Domeen <%= @domain.name %> on aegunud
+Lugupeetud .ee domeeni kasutaja
+
+Domeeninimi <%= @domain.name %> on aegunud ja ei ole alates <%= @domain.on_hold_date %> internetis kättesaadav. Alates <%= @domain.delete_date %> on domeen <%= @domain.name %> avatud registreerimiseks kõigile huvilistele. +

+Domeeni registreeringu pikendamiseks pöörduge palun oma registripidaja <%= @registrar.name %> poole. Registripidajate kontaktid leiate aadressilt www.internet.ee/registripidajad. +

+Domeeni <%= @domain.name %> kohta on registris järgmised andmed: +

+Registreerija: <%= @domain.registrant_name %>
+Halduskontakt: <%= @domain.admin_contact_names %>
+Tehniline kontakt: <%= @domain.tech_contact_names %>
+Registripidaja: <%= @registrar.name %>
+Nimeserverid: <%= @domain.nameserver_names %>
+Ülevaate kõikidest endaga seotud domeenidest saate registreerija portaalist. <%= ENV['registrant_url'] %>.
+

+Lugupidamisega
+Eesti Interneti Sihtasutus +

+
+

+The <%= @domain.name %> domain has expired
+Dear user of .ee domain,
+
+The domain name <%= @domain.name %> has expired and will not be available on the Internet from <%= @domain.on_hold_date %>. From <%= @domain.delete_date %>, the <%= @domain.name %> domain will be available for registration on a first come first served basis. +

+To renew the domain registration, please contact your registrar <%= @registrar.name %>. You can find the registrar's contacts at http://internet.ee/registrars. +

+The following data for the <%= @domain.name %> domain have been entered into the registry: +

+Registrant: <%= @domain.registrant_name %>
+Administrative contact: <%= @domain.admin_contact_names %>
+Technical contact: <%= @domain.tech_contact_names %>
+Registrar: <%= @registrar.name %>
+Name servers: <%= @domain.nameserver_names %>
+You can find an overview of all your domains at the registrant's portal. <%= ENV['registrant_url'] %>.
+

+Best Regards,
+Estonian Internet Foundation +

+
+

+Домен <%= @domain.name %> устарел
+Уважаемый пользователь домена .ee
+
+ +Доменное имя <%= @domain.name %> устарело и с <%= @domain.on_hold_date %> недоступно в Интернете. С <%= @domain.delete_date %> домен <%= @domain.name %> доступен для регистрации всем желающим по принципу "first come, first served". + +

+ +Для продления регистрации домена просим обратиться к своему регистратору <%= @registrar.name %>. Контактные данные регистраторов можно найти по адресу http://internet.ee/registratory. +

+ +Относительно домена <%= @domain.name %> в реестр внесены следующие данные: +

+ +Регистрант: <%= @domain.registrant_name %>
+Административный контакт: <%= @domain.admin_contact_names %>
+Технический контакт: <%= @domain.tech_contact_names %>
+Регистратор: <%= @registrar.name %>
+Серверы доменных имен: <%= @domain.nameserver_names %>
+Обзор всех связанных с Вами доменов можете получить на портале регистранта. <%= ENV['registrant_url'] %>.
+ +

+ +С наилучшими пожеланиями
+Целевое учреждение Eesti Internet diff --git a/app/views/mailers/domain_mailer/expiration.text.erb b/app/views/mailers/domain_mailer/expiration.text.erb new file mode 100644 index 000000000..7cfa9a9fc --- /dev/null +++ b/app/views/mailers/domain_mailer/expiration.text.erb @@ -0,0 +1,60 @@ +Domeen <%= @domain.name %> on aegunud +Lugupeetud .ee domeeni kasutaja + +Domeeninimi <%= @domain.name %> on aegunud ja ei ole alates <%= @domain.on_hold_date %> internetis kättesaadav. Alates <%= @domain.delete_date %> on domeen <%= @domain.name %> avatud registreerimiseks kõigile huvilistele. + +Domeeni registreeringu pikendamiseks pöörduge palun oma registripidaja <%= @registrar.name %> poole. Registripidajate kontaktid leiate aadressilt www.internet.ee/registripidajad. + +Domeeni <%= @domain.name %> kohta on registris järgmised andmed: + +Registreerija: <%= @domain.registrant_name %> +Halduskontakt: <%= @domain.admin_contact_names %> +Tehniline kontakt: <%= @domain.tech_contact_names %> +Registripidaja: <%= @registrar.name %> +Nimeserverid: <%= @domain.nameserver_names %> +Ülevaate kõikidest endaga seotud domeenidest saate registreerija portaalist. <%= ENV['registrant_url'] %>. + +Parimate soovidega +Eesti Interneti Sihtasutus + +-------------------------------------- + +The <%= @domain.name %> domain has expired +Dear user of .ee domain, + +The domain name <%= @domain.name %> has expired and will not be available on the Internet from <%= @domain.on_hold_date %>. From <%= @domain.delete_date %>, the <%= @domain.name %> domain will be available for registration on a first come first served basis. + +To renew the domain registration, please contact your registrar <%= @registrar.name %>. You can find the registrar's contacts at http://internet.ee/registrars. + +The following data for the <%= @domain.name %> domain have been entered into the registry: + +Registrant: <%= @domain.registrant_name %> +Administrative contact: <%= @domain.admin_contact_names %> +Technical contact: <%= @domain.tech_contact_names %> +Registrar: <%= @registrar.name %> +Name servers: <%= @domain.nameserver_names %> +You can find an overview of all your domains at the registrant's portal. <%= ENV['registrant_url'] %>. + +Best Regards, +Estonian Internet Foundation + +-------------------------------------- + +Домен <%= @domain.name %> устарел +Уважаемый пользователь домена .ee + +Доменное имя <%= @domain.name %> устарело и с <%= @domain.on_hold_date %> недоступно в Интернете. С <%= @domain.delete_date %> домен <%= @domain.name %> доступен для регистрации всем желающим по принципу "first come, first served". + +Для продления регистрации домена просим обратиться к своему регистратору <%= @registrar.name %>. Контактные данные регистраторов можно найти по адресу http://internet.ee/registratory. + +Относительно домена <%= @domain %> в реестр внесены следующие данные: + +Регистрант: <%= @domain.registrant_name %> +Административный контакт: <%= @domain.admin_contact_names %> +Технический контакт: <%= @domain.tech_contact_names %> +Регистратор: <%= @registrar.name %> +Серверы доменных имен: <%= @domain.nameserver_names %> +Обзор всех связанных с Вами доменов можете получить на портале регистранта. <%= ENV['registrant_url'] %>. + +С наилучшими пожеланиями +Целевое учреждение Eesti Internet diff --git a/config/locales/en.yml b/config/locales/en.yml index a5bf12885..264502adf 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -945,7 +945,6 @@ en: list_format_is_in_yaml: 'List format is in YAML' if_auth_info_is_left_empty_it_will_be_auto_generated: 'If auth info is left empty, it will be auto generated.' each_domain_name_must_end_with_colon_sign: 'Each domain name must end with colon (:) sign.' - expiration_remind_subject: 'The %{name} domain has expired' next: 'Next' previous: 'Previous' personal_domain_verification_url: 'Personal domain verification url' diff --git a/config/locales/mailers/domain.en.yml b/config/locales/mailers/domain.en.yml new file mode 100644 index 000000000..99dc33a5a --- /dev/null +++ b/config/locales/mailers/domain.en.yml @@ -0,0 +1,4 @@ +en: + domain_mailer: + expiration: + subject: The %{domain_name} domain has expired diff --git a/spec/factories/admin_domain_contact.rb b/spec/factories/admin_domain_contact.rb new file mode 100644 index 000000000..786825214 --- /dev/null +++ b/spec/factories/admin_domain_contact.rb @@ -0,0 +1,5 @@ +FactoryGirl.define do + factory :admin_domain_contact, parent: :domain_contact, class: AdminDomainContact do + + end +end diff --git a/spec/factories/contact.rb b/spec/factories/contact.rb new file mode 100644 index 000000000..5218da399 --- /dev/null +++ b/spec/factories/contact.rb @@ -0,0 +1,16 @@ +FactoryGirl.define do + factory :contact do + name 'test' + sequence(:code) { |n| "test#{n}" } + phone '+123.456789' + email 'test@test.com' + street 'test' + city 'test' + zip 12345 + country_code 'EE' + ident '37605030299' + ident_type 'priv' + ident_country_code 'EE' + registrar + end +end diff --git a/spec/factories/dnskey.rb b/spec/factories/dnskey.rb new file mode 100644 index 000000000..e06387487 --- /dev/null +++ b/spec/factories/dnskey.rb @@ -0,0 +1,15 @@ +FactoryGirl.define do + factory :dnskey do + alg Dnskey::ALGORITHMS.first + flags Dnskey::FLAGS.first + protocol Dnskey::PROTOCOLS.first + ds_digest_type 2 + domain + public_key 'AwEAAaOf5+lz3ftsL+0CCvfJbhUF/NVsNh8BKo61oYs5fXVbuWDiH872 '\ + 'LC8uKDO92TJy7Q4TF9XMAKMMlf1GMAxlRspD749SOCTN00sqfWx1OMTu '\ + 'a28L1PerwHq7665oDJDKqR71btcGqyLKhe2QDvCdA0mENimF1NudX1BJ '\ + 'DDFi6oOZ0xE/0CuveB64I3ree7nCrwLwNs56kXC4LYoX3XdkOMKiJLL/ '\ + 'MAhcxXa60CdZLoRtTEW3z8/oBq4hEAYMCNclpbd6y/exScwBxFTdUfFk '\ + 'KsdNcmvai1lyk9vna0WQrtpYpHKMXvY9LFHaJxCOLR4umfeQ42RuTd82 lqfU6ClMeXs=' + end +end diff --git a/spec/factories/domain.rb b/spec/factories/domain.rb new file mode 100644 index 000000000..5a396362d --- /dev/null +++ b/spec/factories/domain.rb @@ -0,0 +1,15 @@ +FactoryGirl.define do + factory :domain do + sequence(:name) { |n| "test#{n}.com" } + period 1 + period_unit 'y' # Year + registrar + registrant + + after :build do |domain| + domain.nameservers << FactoryGirl.build_pair(:nameserver) + domain.admin_domain_contacts << FactoryGirl.build(:admin_domain_contact) + domain.tech_domain_contacts << FactoryGirl.build(:tech_domain_contact) + end + end +end diff --git a/spec/factories/domain_contact.rb b/spec/factories/domain_contact.rb new file mode 100644 index 000000000..ae05fd293 --- /dev/null +++ b/spec/factories/domain_contact.rb @@ -0,0 +1,5 @@ +FactoryGirl.define do + factory :domain_contact do + contact + end +end diff --git a/spec/factories/nameserver.rb b/spec/factories/nameserver.rb new file mode 100644 index 000000000..ebe7a7909 --- /dev/null +++ b/spec/factories/nameserver.rb @@ -0,0 +1,6 @@ +FactoryGirl.define do + factory :nameserver do + sequence(:hostname) { |n| "ns.test#{n}.ee" } + ipv4 '192.168.1.1' + end +end diff --git a/spec/factories/registrant.rb b/spec/factories/registrant.rb new file mode 100644 index 000000000..c4846fcd4 --- /dev/null +++ b/spec/factories/registrant.rb @@ -0,0 +1,5 @@ +FactoryGirl.define do + factory :registrant, parent: :contact, class: Registrant do + name 'test' + end +end diff --git a/spec/factories/registrar.rb b/spec/factories/registrar.rb new file mode 100644 index 000000000..dd581a1d1 --- /dev/null +++ b/spec/factories/registrar.rb @@ -0,0 +1,13 @@ +FactoryGirl.define do + factory :registrar do + sequence(:name) { |n| "test#{n}" } + sequence(:code) { |n| "test#{n}" } + sequence(:reg_no) { |n| "test#{n}" } + street 'test' + city 'test' + state 'test' + zip 'test' + email 'test@test.com' + country_code 'EE' + end +end diff --git a/spec/factories/tech_domain_contact.rb b/spec/factories/tech_domain_contact.rb new file mode 100644 index 000000000..e407474a3 --- /dev/null +++ b/spec/factories/tech_domain_contact.rb @@ -0,0 +1,5 @@ +FactoryGirl.define do + factory :tech_domain_contact, parent: :domain_contact, class: TechDomainContact do + + end +end diff --git a/spec/jobs/domain_expiration_email_job_spec.rb b/spec/jobs/domain_expiration_email_job_spec.rb new file mode 100644 index 000000000..f435b1f0b --- /dev/null +++ b/spec/jobs/domain_expiration_email_job_spec.rb @@ -0,0 +1,40 @@ +require 'rails_helper' + +RSpec.describe DomainExpirationEmailJob do + it 'queues the job' do + expect { described_class.perform_later }.to have_enqueued_job(described_class) + end + + describe '#perform' do + let(:domain) { instance_double(Domain) } + + before :example do + expect(Domain).to receive(:find).and_return(domain) + end + + context 'when domain is expired' do + let(:message) { instance_double(ActionMailer::MessageDelivery) } + + before :example do + allow(domain).to receive(:registered?).and_return(false) + end + + it 'sends email notification' do + expect(DomainMailer).to receive(:expiration).with(domain: domain).and_return(message) + expect(message).to receive(:deliver!) + described_class.perform_now(domain_id: 1) + end + end + + context 'when domain is registered' do + before :example do + allow(domain).to receive(:registered?).and_return(true) + end + + it 'does not send email notification' do + expect(DomainMailer).to_not receive(:expiration) + described_class.perform_now(domain_id: 1) + end + end + end +end diff --git a/spec/mailers/domain_mailer_spec.rb b/spec/mailers/domain_mailer_spec.rb new file mode 100644 index 000000000..c3679f116 --- /dev/null +++ b/spec/mailers/domain_mailer_spec.rb @@ -0,0 +1,38 @@ +require 'rails_helper' + +RSpec.describe DomainMailer do + describe '#expiration' do + let(:domain) { instance_spy(Domain, + name: 'test.com', + registrant_email: 'registrant@test.com', + admin_contact_emails: ['admin.contact.email@test.com'] + ) } + let(:domain_presenter) { instance_spy(DomainPresenter) } + let(:registrar_presenter) { instance_spy(RegistrarPresenter) } + subject(:message) { described_class.expiration(domain: domain) } + + before :example do + expect(DomainPresenter).to receive(:new).and_return(domain_presenter) + expect(RegistrarPresenter).to receive(:new).and_return(registrar_presenter) + end + + it 'has valid sender' do + message.deliver! + expect(message.from).to eq(['noreply@internet.ee']) + end + + it 'has registrant and administrative contacts as recipient' do + message.deliver! + expect(message.to).to match_array(['registrant@test.com', 'admin.contact.email@test.com']) + end + + it 'has valid subject' do + message.deliver! + expect(message.subject).to eq('The test.com domain has expired') + end + + it 'sends message' do + expect { message.deliver! }.to change { ActionMailer::Base.deliveries.count }.by(1) + end + end +end diff --git a/spec/models/concerns/domain/expirable_spec.rb b/spec/models/concerns/domain/expirable_spec.rb new file mode 100644 index 000000000..72fde82ab --- /dev/null +++ b/spec/models/concerns/domain/expirable_spec.rb @@ -0,0 +1,57 @@ +require 'rails_helper' + +RSpec.describe Domain, db: false do + it { is_expected.to alias_attribute(:expire_time, :valid_to) } + + describe '::expired', db: true do + before :example do + travel_to Time.zone.parse('05.07.2010 00:00') + + FactoryGirl.create(:domain, id: 1, expire_time: Time.zone.parse('04.07.2010 23:59')) + FactoryGirl.create(:domain, id: 2, expire_time: Time.zone.parse('05.07.2010 00:00')) + FactoryGirl.create(:domain, id: 3, expire_time: Time.zone.parse('05.07.2010 00:01')) + end + + it 'returns expired domains' do + expect(described_class.expired.ids).to eq([1, 2]) + end + end + + describe '#registered?' do + before :example do + travel_to Time.zone.parse('05.07.2010 00:00') + end + + context 'when :valid_to is in the future' do + let(:domain) { described_class.new(expire_time: Time.zone.parse('06.07.2010 00:01')) } + + specify { expect(domain).to be_registered } + end + + context 'when :valid_to is the same as current time' do + let(:domain) { described_class.new(expire_time: Time.zone.parse('05.07.2010 00:00')) } + + specify { expect(domain).to_not be_registered } + end + + context 'when :valid_to is in the past' do + let(:domain) { described_class.new(expire_time: Time.zone.parse('04.07.2010 23:59')) } + + specify { expect(domain).to_not be_registered } + end + end + + describe '#expired?' do + context 'when :statuses contains expired status' do + let(:domain) { described_class.new(statuses: [DomainStatus::EXPIRED]) } + + specify { expect(domain).to be_expired } + end + + context 'when :statuses does not contain expired status' do + let(:domain) { described_class.new(statuses: [DomainStatus::CLIENT_HOLD]) } + + specify { expect(domain).to_not be_expired } + end + end +end diff --git a/spec/models/contact_spec.rb b/spec/models/contact_spec.rb index b54c5a47f..b20f4bf60 100644 --- a/spec/models/contact_spec.rb +++ b/spec/models/contact_spec.rb @@ -1,28 +1,8 @@ require 'rails_helper' -describe Contact do +RSpec.describe Contact do before :example do - Setting.ds_algorithm = 2 - Setting.ds_data_allowed = true - Setting.ds_data_with_key_allowed = true - Setting.key_data_allowed = true - - Setting.dnskeys_min_count = 0 - Setting.dnskeys_max_count = 9 - Setting.ns_min_count = 2 - Setting.ns_max_count = 11 - - Setting.transfer_wait_time = 0 - - Setting.admin_contacts_min_count = 1 - Setting.admin_contacts_max_count = 10 - Setting.tech_contacts_min_count = 0 - Setting.tech_contacts_max_count = 10 - - Setting.client_side_status_editing_enabled = true - Fabricate(:zonefile_setting, origin: 'ee') - @api_user = Fabricate(:api_user) end context 'about class' do diff --git a/spec/models/domain_spec.rb b/spec/models/domain_spec.rb index 1d6a63fb8..a8384372c 100644 --- a/spec/models/domain_spec.rb +++ b/spec/models/domain_spec.rb @@ -928,29 +928,4 @@ RSpec.describe Domain, db: false do expect(domain.nameserver_hostnames).to eq('hostnames') end end - - describe '#registered?' do - before :example do - travel_to Time.zone.parse('05.07.2010 00:00:01') - end - - context 'when :valid_to is in the future' do - let(:domain) { described_class.new(valid_to: Time.zone.parse('06.07.2010')) } - - specify { expect(domain).to be_registered } - end - - context 'when :valid_to is the same as current time' do - let(:domain) { described_class.new(valid_to: Time.zone.parse('05.07.2010 00:00:01')) } - - - specify { expect(domain).to be_registered } - end - - context 'when :valid_to is in the past' do - let(:domain) { described_class.new(valid_to: Time.zone.parse('04.07.2010 23:59:59')) } - - specify { expect(domain).to_not be_registered } - end - end end diff --git a/spec/presenters/domain_presenter_spec.rb b/spec/presenters/domain_presenter_spec.rb new file mode 100644 index 000000000..a6799095b --- /dev/null +++ b/spec/presenters/domain_presenter_spec.rb @@ -0,0 +1,96 @@ +require 'rails_helper' + +RSpec.describe DomainPresenter do + let(:presenter) { described_class.new(domain: domain, view: view) } + + describe '#on_hold_date' do + subject(:on_hold_date) { presenter.on_hold_date } + + context 'when present' do + let(:domain) { instance_double(Domain, on_hold_time: '05.07.2010') } + + it 'returns localized date' do + expect(view).to receive(:l).with('05.07.2010', format: :date).and_return('on hold date') + expect(on_hold_date).to eq('on hold date') + end + end + + context 'when absent' do + let(:domain) { instance_double(Domain, on_hold_time: nil) } + + specify { expect(on_hold_date).to be_nil } + end + end + + describe '#delete_date' do + subject(:delete_date) { presenter.delete_date } + + context 'when present' do + let(:domain) { instance_double(Domain, delete_time: '05.07.2010') } + + it 'returns localized date' do + expect(view).to receive(:l).with('05.07.2010', format: :date).and_return('delete date') + expect(delete_date).to eq('delete date') + end + end + + context 'when absent' do + let(:domain) { instance_double(Domain, delete_time: nil) } + + specify { expect(delete_date).to be_nil } + end + end + + describe '#admin_contact_names' do + let(:domain) { instance_double(Domain) } + + before :example do + expect(domain).to receive(:admin_contact_names).and_return(%w(test1 test2 test3)) + end + + it 'returns admin contact names' do + expect(presenter.admin_contact_names).to eq('test1, test2, test3') + end + end + + describe '#tech_contact_names' do + let(:domain) { instance_double(Domain) } + + before :example do + expect(domain).to receive(:tech_contact_names).and_return(%w(test1 test2 test3)) + end + + it 'returns technical contact names' do + expect(presenter.tech_contact_names).to eq('test1, test2, test3') + end + end + + describe '#nameserver_names' do + let(:domain) { instance_double(Domain) } + + before :example do + expect(domain).to receive(:nameserver_hostnames).and_return(%w(test1 test2 test3)) + end + + it 'returns nameserver names' do + expect(presenter.nameserver_names).to eq('test1, test2, test3') + end + end + + + domain_delegatable_attributes = %i( + name + registrant_name + ) + + domain_delegatable_attributes.each do |attribute_name| + describe "##{attribute_name}" do + let(:domain) { instance_spy(Domain) } + + it 'delegates to domain' do + presenter.send(attribute_name) + expect(domain).to have_received(attribute_name) + end + end + end +end diff --git a/spec/presenters/registrar_presenter_spec.rb b/spec/presenters/registrar_presenter_spec.rb new file mode 100644 index 000000000..462f8049c --- /dev/null +++ b/spec/presenters/registrar_presenter_spec.rb @@ -0,0 +1,34 @@ +require 'rails_helper' + +RSpec.describe RegistrarPresenter do + let(:registrar) { instance_double(Registrar) } + let(:presenter) { described_class.new(registrar: registrar, view: nil) } + + describe '#name' do + it 'returns name' do + expect(registrar).to receive(:name).and_return('test name') + expect(presenter.name).to eq('test name') + end + end + + describe '#email' do + it 'returns email' do + expect(registrar).to receive(:email).and_return('test email') + expect(presenter.email).to eq('test email') + end + end + + describe '#phone' do + it 'returns phone' do + expect(registrar).to receive(:phone).and_return('test phone') + expect(presenter.phone).to eq('test phone') + end + end + + describe '#url' do + it 'returns url' do + expect(registrar).to receive(:url).and_return('test url') + expect(presenter.url).to eq('test url') + end + end +end diff --git a/spec/views/mailers/domain_mailer/expiration.html.erb_spec.rb b/spec/views/mailers/domain_mailer/expiration.html.erb_spec.rb new file mode 100644 index 000000000..fc1e18e61 --- /dev/null +++ b/spec/views/mailers/domain_mailer/expiration.html.erb_spec.rb @@ -0,0 +1,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) + 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') + render + expect(rendered).to have_text('test registrar name', count: mention_count) + end + + attributes = %i( + on_hold_date + delete_date + registrant_name + admin_contact_names + tech_contact_names + nameserver_names + ) + + 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) + render + expect(rendered).to have_text(attr_name.to_s, count: lang_count) + end + end +end diff --git a/spec/views/mailers/domain_mailer/expiration.text.erb_spec.rb b/spec/views/mailers/domain_mailer/expiration.text.erb_spec.rb new file mode 100644 index 000000000..39a36cdb7 --- /dev/null +++ b/spec/views/mailers/domain_mailer/expiration.text.erb_spec.rb @@ -0,0 +1,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) + 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') + render + expect(rendered).to have_text('test registrar name', count: mention_count) + end + + attributes = %i( + on_hold_date + delete_date + registrant_name + admin_contact_names + tech_contact_names + nameserver_names + ) + + 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) + render + expect(rendered).to have_text(attr_name.to_s, count: lang_count) + end + end +end From 0de7512adc647c149b5ebb1ec036a38347cdfa10 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Fri, 28 Oct 2016 14:55:29 +0300 Subject: [PATCH 10/67] Move expiration logic from domain's callback to epp::domain.new_from_epp #186 --- app/models/domain.rb | 8 -------- app/models/epp/domain.rb | 3 +++ spec/models/epp/domain_spec.rb | 34 ++++++++++++++++++++++++++++++++++ spec/models/epp_domain_spec.rb | 7 ------- 4 files changed, 37 insertions(+), 15 deletions(-) create mode 100644 spec/models/epp/domain_spec.rb delete mode 100644 spec/models/epp_domain_spec.rb diff --git a/app/models/domain.rb b/app/models/domain.rb index 7b7087dd9..7f2380abf 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -77,7 +77,6 @@ class Domain < ActiveRecord::Base end before_create :generate_auth_info - before_create :set_validity_dates before_create -> { self.reserved = in_reserved_list?; nil } before_save :manage_automatic_statuses @@ -546,13 +545,6 @@ class Domain < ActiveRecord::Base end # rubocop:enable Lint/Loop - def set_validity_dates - self.registered_at = Time.zone.now - self.valid_from = Time.zone.now - # we need + 1 day as this is more correct from juridical side - self.valid_to = valid_from.utc.beginning_of_day + self.class.convert_period_to_time(period, period_unit) + 1.day - end - # rubocop:disable Metrics/AbcSize # rubocop:disable Metrics/MethodLength def set_force_delete diff --git a/app/models/epp/domain.rb b/app/models/epp/domain.rb index 61ee6a2d8..2441555c1 100644 --- a/app/models/epp/domain.rb +++ b/app/models/epp/domain.rb @@ -51,6 +51,9 @@ class Epp::Domain < Domain class << self def new_from_epp(frame, current_user) domain = Epp::Domain.new + domain.registered_at = Time.zone.now + domain.valid_from = Time.zone.now + domain.expire_time = domain.valid_from.beginning_of_day + convert_period_to_time(domain.period, domain.period_unit) + 1.day domain.attributes = domain.attrs_from(frame, current_user) domain.attach_default_contacts domain diff --git a/spec/models/epp/domain_spec.rb b/spec/models/epp/domain_spec.rb new file mode 100644 index 000000000..4b91b8947 --- /dev/null +++ b/spec/models/epp/domain_spec.rb @@ -0,0 +1,34 @@ +require 'rails_helper' + +RSpec.describe Epp::Domain, db: false do + describe '::new_from_epp' do + let(:domain_blueprint) { described_class.new } + subject(:domain) { described_class.new_from_epp(nil, nil) } + + before :example do + travel_to Time.zone.parse('05.07.2010') + + domain_blueprint.period = 1 + domain_blueprint.period_unit = 'y' + + expect(described_class).to receive(:new).and_return(domain_blueprint) + expect(domain_blueprint).to receive(:attrs_from).and_return({}) + expect(domain_blueprint).to receive(:attach_default_contacts) + end + + describe 'domain' do + it 'has :registered_at set to now' do + expect(domain.registered_at).to eq(Time.zone.parse('05.07.2010')) + end + + it 'has :valid_from set to now' do + expect(domain.valid_from).to eq(Time.zone.parse('05.07.2010')) + end + + it 'has :expire_time set to now' do + expire_time = Time.zone.parse('05.07.2010') + 1.year + 1.day + expect(domain.expire_time).to eq(expire_time) + end + end + end +end diff --git a/spec/models/epp_domain_spec.rb b/spec/models/epp_domain_spec.rb deleted file mode 100644 index 9dab00c8a..000000000 --- a/spec/models/epp_domain_spec.rb +++ /dev/null @@ -1,7 +0,0 @@ -require 'rails_helper' - -describe Epp::Domain do - context 'with sufficient settings' do - let(:domain) { Fabricate(:epp_domain) } - end -end From 9dca942b789027bd64df78b625f4ccf28e53980e Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Fri, 28 Oct 2016 15:00:21 +0300 Subject: [PATCH 11/67] Do not redefine time zone in test env #186 --- config/environments/test.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/config/environments/test.rb b/config/environments/test.rb index 4e0b47bcb..9f6a888d1 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -36,8 +36,6 @@ Rails.application.configure do # For rails-settings-cached conflict config.cache_store = :file_store, 'tmp/cache_test' - config.time_zone = 'UTC' - config.action_view.raise_on_missing_translations = true # The available log levels are: :debug, :info, :warn, :error, :fatal, and :unknown, From 14c5c3efed756d167e2b91c6a6e95ab86d25183c Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Fri, 28 Oct 2016 16:19:25 +0300 Subject: [PATCH 12/67] Extract domain cron specs #186 --- app/models/domain.rb | 5 ---- spec/models/domain_cron_spec.rb | 41 +++++++++++++++++++++++++++++++++ spec/models/domain_spec.rb | 32 ------------------------- 3 files changed, 41 insertions(+), 37 deletions(-) create mode 100644 spec/models/domain_cron_spec.rb diff --git a/app/models/domain.rb b/app/models/domain.rb index 7f2380abf..db0f15d2c 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -210,11 +210,6 @@ class Domain < ActiveRecord::Base DomainCron.send(__method__) end - def self.start_expire_period - ActiveSupport::Deprecation.instance.deprecation_warning(DomainCron, __method__) - DomainCron.send(__method__) - end - def self.start_redemption_grace_period ActiveSupport::Deprecation.instance.deprecation_warning(DomainCron, __method__) DomainCron.send(__method__) diff --git a/spec/models/domain_cron_spec.rb b/spec/models/domain_cron_spec.rb new file mode 100644 index 000000000..505b3dc1d --- /dev/null +++ b/spec/models/domain_cron_spec.rb @@ -0,0 +1,41 @@ +require 'rails_helper' + +RSpec.describe DomainCron do + before :example do + Fabricate(:zonefile_setting, origin: 'ee') + + @domain = Fabricate(:domain) + end + + it 'should expire domains' do + Setting.expire_warning_period = 1 + Setting.redemption_grace_period = 1 + + described_class.start_expire_period + @domain.statuses.include?(DomainStatus::EXPIRED).should == false + + old_valid_to = Time.zone.now - 10.days + @domain.valid_to = old_valid_to + @domain.save + + described_class.start_expire_period + @domain.reload + @domain.statuses.include?(DomainStatus::EXPIRED).should == true + + described_class.start_expire_period + @domain.reload + @domain.statuses.include?(DomainStatus::EXPIRED).should == true + end + + it 'should start redemption grace period' do + old_valid_to = Time.zone.now - 10.days + @domain.valid_to = old_valid_to + @domain.statuses = [DomainStatus::EXPIRED] + @domain.outzone_at, @domain.delete_at = nil, nil + @domain.save + + described_class.start_expire_period + @domain.reload + @domain.statuses.include?(DomainStatus::EXPIRED).should == true + end +end diff --git a/spec/models/domain_spec.rb b/spec/models/domain_spec.rb index a8384372c..f47128759 100644 --- a/spec/models/domain_spec.rb +++ b/spec/models/domain_spec.rb @@ -148,38 +148,6 @@ RSpec.describe Domain do domain.pending_json.should == {} end - it 'should expire domains' do - Setting.expire_warning_period = 1 - Setting.redemption_grace_period = 1 - - DomainCron.start_expire_period - @domain.statuses.include?(DomainStatus::EXPIRED).should == false - - old_valid_to = Time.zone.now - 10.days - @domain.valid_to = old_valid_to - @domain.save - - DomainCron.start_expire_period - @domain.reload - @domain.statuses.include?(DomainStatus::EXPIRED).should == true - - DomainCron.start_expire_period - @domain.reload - @domain.statuses.include?(DomainStatus::EXPIRED).should == true - end - - it 'should start redemption grace period' do - old_valid_to = Time.zone.now - 10.days - @domain.valid_to = old_valid_to - @domain.statuses = [DomainStatus::EXPIRED] - @domain.outzone_at, @domain.delete_at = nil, nil - @domain.save - - DomainCron.start_expire_period - @domain.reload - @domain.statuses.include?(DomainStatus::EXPIRED).should == true - end - it 'should start redemption grace period' do DomainCron.start_redemption_grace_period @domain.reload From 0cc3a53deb4a33b9fd7b9e60b080706f7e4ba1d1 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Sat, 29 Oct 2016 00:51:42 +0300 Subject: [PATCH 13/67] Refactor domain expirable #186 --- app/models/concerns/domain/expirable.rb | 6 +-- app/models/domain.rb | 10 ----- spec/models/concerns/domain/expirable_spec.rb | 40 +++++++++++-------- 3 files changed, 26 insertions(+), 30 deletions(-) diff --git a/app/models/concerns/domain/expirable.rb b/app/models/concerns/domain/expirable.rb index 237bdfd34..5c9afdc95 100644 --- a/app/models/concerns/domain/expirable.rb +++ b/app/models/concerns/domain/expirable.rb @@ -12,17 +12,17 @@ module Concerns::Domain::Expirable end def registered? - valid_to >= Time.zone.now + !expired? end def expired? - statuses.include?(DomainStatus::EXPIRED) + expire_time <= Time.zone.now end def expirable? return false if valid_to > Time.zone.now - if expired? && outzone_at.present? && delete_at.present? + if statuses.include?(DomainStatus::EXPIRED) && outzone_at.present? && delete_at.present? return false end diff --git a/app/models/domain.rb b/app/models/domain.rb index db0f15d2c..156f9bafa 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -283,16 +283,6 @@ class Domain < ActiveRecord::Base domain_transfers.find_by(status: DomainTransfer::PENDING) end - def expirable? - return false if valid_to > Time.zone.now - - if statuses.include?(DomainStatus::EXPIRED) && outzone_at.present? && delete_at.present? - return false - end - - true - end - def server_holdable? return false if statuses.include?(DomainStatus::SERVER_HOLD) return false if statuses.include?(DomainStatus::SERVER_MANUAL_INZONE) diff --git a/spec/models/concerns/domain/expirable_spec.rb b/spec/models/concerns/domain/expirable_spec.rb index 72fde82ab..f7d78f80b 100644 --- a/spec/models/concerns/domain/expirable_spec.rb +++ b/spec/models/concerns/domain/expirable_spec.rb @@ -18,38 +18,44 @@ RSpec.describe Domain, db: false do end describe '#registered?' do - before :example do - travel_to Time.zone.parse('05.07.2010 00:00') - end + let(:domain) { described_class.new } - context 'when :valid_to is in the future' do - let(:domain) { described_class.new(expire_time: Time.zone.parse('06.07.2010 00:01')) } + context 'when not expired' do + before :example do + expect(domain).to receive(:expired?).and_return(false) + end specify { expect(domain).to be_registered } end - context 'when :valid_to is the same as current time' do - let(:domain) { described_class.new(expire_time: Time.zone.parse('05.07.2010 00:00')) } - - specify { expect(domain).to_not be_registered } - end - - context 'when :valid_to is in the past' do - let(:domain) { described_class.new(expire_time: Time.zone.parse('04.07.2010 23:59')) } + context 'when expired' do + before :example do + expect(domain).to receive(:expired?).and_return(true) + end specify { expect(domain).to_not be_registered } end end describe '#expired?' do - context 'when :statuses contains expired status' do - let(:domain) { described_class.new(statuses: [DomainStatus::EXPIRED]) } + before :example do + travel_to Time.zone.parse('05.07.2010 00:00') + end + + context 'when :expire_time is in the past' do + let(:domain) { described_class.new(expire_time: Time.zone.parse('04.07.2010 23:59')) } specify { expect(domain).to be_expired } end - context 'when :statuses does not contain expired status' do - let(:domain) { described_class.new(statuses: [DomainStatus::CLIENT_HOLD]) } + context 'when :expire_time is now' do + let(:domain) { described_class.new(expire_time: Time.zone.parse('05.07.2010 00:00')) } + + specify { expect(domain).to be_expired } + end + + context 'when :expire_time is in the future' do + let(:domain) { described_class.new(expire_time: Time.zone.parse('05.07.2010 00:01')) } specify { expect(domain).to_not be_expired } end From f127716a3962d0bb8d8386aa0d6c8790dc4cfdff Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Sat, 29 Oct 2016 00:53:00 +0300 Subject: [PATCH 14/67] Refactor domain expiration email #186 --- app/jobs/domain_expiration_email_job.rb | 8 +++---- app/models/domain_cron.rb | 15 +++++++++--- spec/jobs/domain_expiration_email_job_spec.rb | 10 +++----- spec/models/domain_cron_spec.rb | 23 ++++++++++++++----- spec/presenters/registrar_presenter_spec.rb | 2 +- 5 files changed, 36 insertions(+), 22 deletions(-) diff --git a/app/jobs/domain_expiration_email_job.rb b/app/jobs/domain_expiration_email_job.rb index 1066d3f35..478ecb0da 100644 --- a/app/jobs/domain_expiration_email_job.rb +++ b/app/jobs/domain_expiration_email_job.rb @@ -1,11 +1,9 @@ -class DomainExpirationEmailJob < ActiveJob::Base - queue_as :default - - def perform(domain_id:) +class DomainExpirationEmailJob < Que::Job + def run(domain_id:) domain = Domain.find(domain_id) return if domain.registered? - DomainMailer.expiration(domain).deliver! + DomainMailer.expiration(domain: domain).deliver! end end diff --git a/app/models/domain_cron.rb b/app/models/domain_cron.rb index 549e3b1da..84e9b6640 100644 --- a/app/models/domain_cron.rb +++ b/app/models/domain_cron.rb @@ -32,18 +32,27 @@ class DomainCron end def self.start_expire_period - STDOUT << "#{Time.zone.now.utc} - Expiring domains\n" unless Rails.env.test? + Rails.logger.info('Expiring domains') ::PaperTrail.whodunnit = "cron - #{__method__}" - domains = Domain.where('valid_to <= ?', Time.zone.now) + + domains = Domain.expired marked = 0 real = 0 + domains.each do |domain| next unless domain.expirable? real += 1 domain.set_graceful_expired STDOUT << "#{Time.zone.now.utc} DomainCron.start_expire_period: ##{domain.id} (#{domain.name}) #{domain.changes}\n" unless Rails.env.test? - domain.save(validate: false) and marked += 1 + + send_time = domain.valid_to + Setting.expiration_reminder_mail.to_i.days + saved = domain.save(validate: false) + + if saved + DomainExpirationEmailJob.enqueue(domain_id: domain.id, run_at: send_time) + marked += 1 + end end STDOUT << "#{Time.zone.now.utc} - Successfully expired #{marked} of #{real} domains\n" unless Rails.env.test? diff --git a/spec/jobs/domain_expiration_email_job_spec.rb b/spec/jobs/domain_expiration_email_job_spec.rb index f435b1f0b..cb5e032bb 100644 --- a/spec/jobs/domain_expiration_email_job_spec.rb +++ b/spec/jobs/domain_expiration_email_job_spec.rb @@ -1,11 +1,7 @@ require 'rails_helper' RSpec.describe DomainExpirationEmailJob do - it 'queues the job' do - expect { described_class.perform_later }.to have_enqueued_job(described_class) - end - - describe '#perform' do + describe '#run' do let(:domain) { instance_double(Domain) } before :example do @@ -22,7 +18,7 @@ RSpec.describe DomainExpirationEmailJob do it 'sends email notification' do expect(DomainMailer).to receive(:expiration).with(domain: domain).and_return(message) expect(message).to receive(:deliver!) - described_class.perform_now(domain_id: 1) + described_class.enqueue(domain_id: 1) end end @@ -33,7 +29,7 @@ RSpec.describe DomainExpirationEmailJob do it 'does not send email notification' do expect(DomainMailer).to_not receive(:expiration) - described_class.perform_now(domain_id: 1) + described_class.enqueue(domain_id: 1) end end end diff --git a/spec/models/domain_cron_spec.rb b/spec/models/domain_cron_spec.rb index 505b3dc1d..a9c3e2d2f 100644 --- a/spec/models/domain_cron_spec.rb +++ b/spec/models/domain_cron_spec.rb @@ -1,13 +1,10 @@ require 'rails_helper' RSpec.describe DomainCron do - before :example do - Fabricate(:zonefile_setting, origin: 'ee') - - @domain = Fabricate(:domain) - end - it 'should expire domains' do + Fabricate(:zonefile_setting, origin: 'ee') + @domain = Fabricate(:domain) + Setting.expire_warning_period = 1 Setting.redemption_grace_period = 1 @@ -28,6 +25,9 @@ RSpec.describe DomainCron do end it 'should start redemption grace period' do + Fabricate(:zonefile_setting, origin: 'ee') + @domain = Fabricate(:domain) + old_valid_to = Time.zone.now - 10.days @domain.valid_to = old_valid_to @domain.statuses = [DomainStatus::EXPIRED] @@ -38,4 +38,15 @@ RSpec.describe DomainCron do @domain.reload @domain.statuses.include?(DomainStatus::EXPIRED).should == true end + + describe '::start_expire_period', db: false do + before :example do + travel_to Time.zone.parse('05.07.2010') + end + + it 'logs start time' do + expect(Rails.logger).to receive(:info).with('Expiring domains') + described_class.start_expire_period + end + end end diff --git a/spec/presenters/registrar_presenter_spec.rb b/spec/presenters/registrar_presenter_spec.rb index 462f8049c..8223341a8 100644 --- a/spec/presenters/registrar_presenter_spec.rb +++ b/spec/presenters/registrar_presenter_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' RSpec.describe RegistrarPresenter do let(:registrar) { instance_double(Registrar) } - let(:presenter) { described_class.new(registrar: registrar, view: nil) } + let(:presenter) { described_class.new(registrar: registrar, view: view) } describe '#name' do it 'returns name' do From aa196d7d95dea564bd1fc9492ca56f91fbfe16f8 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Sat, 29 Oct 2016 01:00:48 +0300 Subject: [PATCH 15/67] Remove old domain mailer views #186 --- .../expiration_reminder.html.erb | 60 ------------------- .../expiration_reminder.text.erb | 60 ------------------- 2 files changed, 120 deletions(-) delete mode 100644 app/views/mailers/domain_mailer/expiration_reminder.html.erb delete mode 100644 app/views/mailers/domain_mailer/expiration_reminder.text.erb diff --git a/app/views/mailers/domain_mailer/expiration_reminder.html.erb b/app/views/mailers/domain_mailer/expiration_reminder.html.erb deleted file mode 100644 index 9404838ae..000000000 --- a/app/views/mailers/domain_mailer/expiration_reminder.html.erb +++ /dev/null @@ -1,60 +0,0 @@ -Domeen <%= @domain.name %> on aegunud
-Lugupeetud .ee domeeni kasutaja
-
-Domeeninimi <%= @domain.name %> on aegunud ja ei ole alates <%= l(@domain.outzone_at, format: :date) %> internetis kättesaadav. Alates <%= l(@domain.delete_at, format: :date) %> on domeen <%= @domain.name %> avatud registreerimiseks kõigile huvilistele. -

-Domeeni registreeringu pikendamiseks pöörduge palun oma registripidaja <%= @domain.registrar.name %> poole. Registripidajate kontaktid leiate aadressilt www.internet.ee/registripidajad. -

-Domeeni <%= @domain.name %> kohta on registris järgmised andmed: -

-Registreerija: <%= @domain.registrant_name %>
-Halduskontakt: <%= @domain.admin_contacts.map(&:name).join ', ' %>
-Tehniline kontakt: <%= @domain.tech_contacts.map(&:name).join ', ' %>
-Registripidaja: <%= @domain.registrar.name %>
-Nimeserverid: <%= @domain.nameservers.join(', ') %>
-Ülevaate kõikidest endaga seotud domeenidest saate registreerija portaalist. <%= ENV['registrant_url'] %>.
-

-Lugupidamisega
-Eesti Interneti Sihtasutus -

-
-

-The <%= @domain.name %> domain has expired
-Dear user of .ee domain,
-
-The domain name <%= @domain.name %> has expired and will not be available on the Internet from <%= l(@domain.outzone_at, format: :date) %>. From <%= l(@domain.delete_at, format: :date) %>, the <%= @domain.name %> domain will be available for registration on a first come first served basis. -

-To renew the domain registration, please contact your registrar <%= @domain.registrar.name %>. You can find the registrar's contacts at http://internet.ee/registrars. -

-The following data for the <%= @domain.name %> domain have been entered into the registry: -

-Registrant: <%= @domain.registrant_name %>
-Administrative contact: <%= @domain.admin_contacts.map(&:name).join ', ' %>
-Technical contact: <%= @domain.tech_contacts.map(&:name).join ', ' %>
-Registrar: <%= @domain.registrar.name %>
-Name servers: <%= @domain.nameservers.join(', ') %>
-You can find an overview of all your domains at the registrant's portal. <%= ENV['registrant_url'] %>.
-

-Best Regards,
-Estonian Internet Foundation -

-
-

-Домен <%= @domain.name %> устарел
-Уважаемый пользователь домена .ee
-
-Доменное имя <%= @domain.name %> устарело и с <%= l(@domain.outzone_at, format: :date) %> недоступно в Интернете. С <%= l(@domain.delete_at, format: :date) %> домен <%= @domain.name %> доступен для регистрации всем желающим по принципу "first come, first served". -

-Для продления регистрации домена просим обратиться к своему регистратору <%= @domain.registrar.name %>. Контактные данные регистраторов можно найти по адресу http://internet.ee/registratory. -

-Относительно домена <%= @domain.name %> в реестр внесены следующие данные: -

-Регистрант: <%= @domain.registrant_name %>
-Административный контакт: <%= @domain.admin_contacts.map(&:name).join ', ' %>
-Технический контакт: <%= @domain.tech_contacts.map(&:name).join ', ' %>
-Регистратор: <%= @domain.registrar.name %>
-Серверы доменных имен: <%= @domain.nameservers.join(', ') %>
-Обзор всех связанных с Вами доменов можете получить на портале регистранта. <%= ENV['registrant_url'] %>.
-

-С наилучшими пожеланиями
-Целевое учреждение Eesti Internet diff --git a/app/views/mailers/domain_mailer/expiration_reminder.text.erb b/app/views/mailers/domain_mailer/expiration_reminder.text.erb deleted file mode 100644 index 5148df211..000000000 --- a/app/views/mailers/domain_mailer/expiration_reminder.text.erb +++ /dev/null @@ -1,60 +0,0 @@ -Domeen <%= @domain.name %> on aegunud -Lugupeetud .ee domeeni kasutaja - -Domeeninimi <%= @domain.name %> on aegunud ja ei ole alates <%= l(@domain.outzone_at, format: :date) %> internetis kättesaadav. Alates <%= l(@domain.delete_at, format: :date) %> on domeen <%= @domain.name %> avatud registreerimiseks kõigile huvilistele. - -Domeeni registreeringu pikendamiseks pöörduge palun oma registripidaja <%= @domain.registrar.name %> poole. Registripidajate kontaktid leiate aadressilt www.internet.ee/registripidajad. - -Domeeni <%= @domain.name %> kohta on registris järgmised andmed: - -Registreerija: <%= @domain.registrant_name %> -Halduskontakt: <%= @domain.admin_contacts.map(&:name).join ', ' %> -Tehniline kontakt: <%= @domain.tech_contacts.map(&:name).join ', ' %> -Registripidaja: <%= @domain.registrar.name %> -Nimeserverid: <%= @domain.nameservers.join(', ') %> -Ülevaate kõikidest endaga seotud domeenidest saate registreerija portaalist. <%= ENV['registrant_url'] %>. - -Parimate soovidega -Eesti Interneti Sihtasutus - --------------------------------------- - -The <%= @domain.name %> domain has expired -Dear user of .ee domain, - -The domain name <%= @domain.name %> has expired and will not be available on the Internet from <%= l(@domain.outzone_at, format: :date) %>. From <%= l(@domain.delete_at, format: :date) %>, the <%= @domain.name %> domain will be available for registration on a first come first served basis. - -To renew the domain registration, please contact your registrar <%= @domain.registrar.name %>. You can find the registrar's contacts at http://internet.ee/registrars. - -The following data for the <%= @domain.name %> domain have been entered into the registry: - -Registrant: <%= @domain.registrant_name %> -Administrative contact: <%= @domain.admin_contacts.map(&:name).join ', ' %> -Technical contact: <%= @domain.tech_contacts.map(&:name).join ', ' %> -Registrar: <%= @domain.registrar.name %> -Name servers: <%= @domain.nameservers.join(', ') %> -You can find an overview of all your domains at the registrant's portal. <%= ENV['registrant_url'] %>. - -Best Regards, -Estonian Internet Foundation - --------------------------------------- - -Домен <%= @domain.name %> устарел -Уважаемый пользователь домена .ee - -Доменное имя <%= @domain.name %> устарело и с <%= l(@domain.outzone_at, format: :date) %> недоступно в Интернете. С <%= l(@domain.delete_at, format: :date) %> домен <%= @domain.name %> доступен для регистрации всем желающим по принципу "first come, first served". - -Для продления регистрации домена просим обратиться к своему регистратору <%= @domain.registrar.name %>. Контактные данные регистраторов можно найти по адресу http://internet.ee/registratory. - -Относительно домена <%= @domain.name %> в реестр внесены следующие данные: - -Регистрант: <%= @domain.registrant_name %> -Административный контакт: <%= @domain.admin_contacts.map(&:name).join ', ' %> -Технический контакт: <%= @domain.tech_contacts.map(&:name).join ', ' %> -Регистратор: <%= @domain.registrar.name %> -Серверы доменных имен: <%= @domain.nameservers.join(', ') %> -Обзор всех связанных с Вами доменов можете получить на портале регистранта. <%= ENV['registrant_url'] %>. - -С наилучшими пожеланиями -Целевое учреждение Eesti Internet From 66800402cb00d7a310d16b3c3770042d29f2caf1 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Mon, 31 Oct 2016 14:55:20 +0200 Subject: [PATCH 16/67] Introduce registrant presenter registry-180 --- app/presenters/registrant_presenter.rb | 19 +++++++++++++++++++ spec/presenters/registrant_presenter_spec.rb | 20 ++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 app/presenters/registrant_presenter.rb create mode 100644 spec/presenters/registrant_presenter_spec.rb diff --git a/app/presenters/registrant_presenter.rb b/app/presenters/registrant_presenter.rb new file mode 100644 index 000000000..67ae93d68 --- /dev/null +++ b/app/presenters/registrant_presenter.rb @@ -0,0 +1,19 @@ +class RegistrantPresenter + def initialize(registrant:, view:) + @registrant = registrant + @view = view + end + + def name + registrant.name + end + + def ident + registrant.ident + end + + private + + attr_reader :registrant + attr_reader :view +end diff --git a/spec/presenters/registrant_presenter_spec.rb b/spec/presenters/registrant_presenter_spec.rb new file mode 100644 index 000000000..0cec65ff6 --- /dev/null +++ b/spec/presenters/registrant_presenter_spec.rb @@ -0,0 +1,20 @@ +require 'rails_helper' + +RSpec.describe RegistrantPresenter do + let(:registrant) { instance_double(Registrant) } + let(:presenter) { described_class.new(registrant: registrant, view: view) } + + describe '#name' do + it 'returns name' do + expect(registrant).to receive(:name).and_return('test name') + expect(presenter.name).to eq('test name') + end + end + + describe '#ident' do + it 'returns ident' do + expect(registrant).to receive(:ident).and_return('test ident') + expect(presenter.ident).to eq('test ident') + end + end +end From 411079f654825a6e9978f04617d7376764d23ed9 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Mon, 31 Oct 2016 17:28:02 +0200 Subject: [PATCH 17/67] Fix domain factory registry-180 --- spec/factories/domain.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/spec/factories/domain.rb b/spec/factories/domain.rb index 5a396362d..b4079c5d7 100644 --- a/spec/factories/domain.rb +++ b/spec/factories/domain.rb @@ -7,6 +7,7 @@ FactoryGirl.define do registrant after :build do |domain| + domain.class.skip_callback(:commit, :after, :update_whois_record) # Otherwise FactoryGirl reports Domain#json= method as undefined domain.nameservers << FactoryGirl.build_pair(:nameserver) domain.admin_domain_contacts << FactoryGirl.build(:admin_domain_contact) domain.tech_domain_contacts << FactoryGirl.build(:tech_domain_contact) From 69be717b91aed199a21decde6558956cd0411117 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Mon, 31 Oct 2016 17:56:51 +0200 Subject: [PATCH 18/67] Add extended registrar's info to "expiration" and "force_delete" mailers registry-180 --- app/mailers/domain_mailer.rb | 18 ++---- app/models/domain.rb | 7 ++- app/presenters/domain_presenter.rb | 4 ++ .../mailers/domain_mailer/expiration.html.erb | 24 ++++++- .../mailers/domain_mailer/expiration.text.erb | 24 ++++++- .../domain_mailer/force_delete.html.erb | 59 ++++++++++------- .../domain_mailer/force_delete.text.erb | 50 +++++++++------ config/locales/en.yml | 1 - config/locales/mailers/domain.en.yml | 2 + spec/factories/domain.rb | 1 - spec/mailers/domain_mailer_spec.rb | 47 +++++++++++--- spec/models/domain_spec.rb | 17 +++++ spec/presenters/domain_presenter_spec.rb | 19 ++++++ .../domain_mailer/expiration.html.erb_spec.rb | 18 +++++- .../domain_mailer/expiration.text.erb_spec.rb | 18 +++++- .../force_delete.html.erb_spec.rb | 63 +++++++++++++++++++ .../force_delete.text.erb_spec.rb | 63 +++++++++++++++++++ 17 files changed, 362 insertions(+), 73 deletions(-) create mode 100644 spec/views/mailers/domain_mailer/force_delete.html.erb_spec.rb create mode 100644 spec/views/mailers/domain_mailer/force_delete.text.erb_spec.rb diff --git a/app/mailers/domain_mailer.rb b/app/mailers/domain_mailer.rb index e53c6d596..905927344 100644 --- a/app/mailers/domain_mailer.rb +++ b/app/mailers/domain_mailer.rb @@ -117,26 +117,20 @@ class DomainMailer < ApplicationMailer name: @domain.name)} [#{@domain.name}]") end - def force_delete(domain_id, should_deliver) - @domain = Domain.find_by(id: domain_id) - return if delivery_off?(@domain, should_deliver) - emails = ([@domain.registrant.email] + @domain.admin_contacts.map { |x| format(x.email) }).uniq - return if whitelist_blocked?(emails) + def force_delete(domain:) + @domain = DomainPresenter.new(domain: domain, view: view_context) + @registrar = RegistrarPresenter.new(registrar: domain.registrar, view: view_context) + @registrant = RegistrantPresenter.new(registrant: domain.registrant, view: view_context) - formatted_emails = emails.map { |x| format(x) } - mail(to: formatted_emails, - subject: "#{I18n.t(:force_delete_subject)}" - ) + mail(to: domain.primary_contact_emails) end def expiration(domain:) @domain = DomainPresenter.new(domain: domain, view: view_context) @registrar = RegistrarPresenter.new(registrar: domain.registrar, view: view_context) - recipients = domain.admin_contact_emails << domain.registrant_email - subject = default_i18n_subject(domain_name: domain.name) - mail(to: recipients, subject: subject) + mail(to: domain.primary_contact_emails, subject: subject) end private diff --git a/app/models/domain.rb b/app/models/domain.rb index 156f9bafa..fad363bed 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -12,6 +12,7 @@ class Domain < ActiveRecord::Base alias_attribute :on_hold_time, :outzone_at alias_attribute :delete_time, :delete_at + alias_attribute :force_delete_time, :force_delete_at # TODO: whois requests ip whitelist for full info for own domains and partial info for other domains # TODO: most inputs should be trimmed before validatation, probably some global logic? @@ -564,7 +565,7 @@ class Domain < ActiveRecord::Base registrar.messages.create!( body: I18n.t('force_delete_set_on_domain', domain: name) ) - DomainMailer.force_delete(id, true).deliver + DomainMailer.force_delete(domain: self).deliver return true end false @@ -743,6 +744,10 @@ class Domain < ActiveRecord::Base nameservers.hostnames end + def primary_contact_emails + admin_contact_emails << registrant_email + end + def self.to_csv CSV.generate do |csv| csv << column_names diff --git a/app/presenters/domain_presenter.rb b/app/presenters/domain_presenter.rb index ea8b0ba22..b09743c5e 100644 --- a/app/presenters/domain_presenter.rb +++ b/app/presenters/domain_presenter.rb @@ -14,6 +14,10 @@ class DomainPresenter view.l(domain.delete_time, format: :date) if domain.delete_time end + def force_delete_date + view.l(domain.force_delete_time, format: :date) if domain.force_delete_time + end + def admin_contact_names domain.admin_contact_names.join(', ') end diff --git a/app/views/mailers/domain_mailer/expiration.html.erb b/app/views/mailers/domain_mailer/expiration.html.erb index d06a8803e..9c1d925f2 100644 --- a/app/views/mailers/domain_mailer/expiration.html.erb +++ b/app/views/mailers/domain_mailer/expiration.html.erb @@ -10,8 +10,14 @@ Domeeni <%= @domain.name %> kohta on registris järgmised andmed: Registreerija: <%= @domain.registrant_name %>
Halduskontakt: <%= @domain.admin_contact_names %>
Tehniline kontakt: <%= @domain.tech_contact_names %>
-Registripidaja: <%= @registrar.name %>
Nimeserverid: <%= @domain.nameserver_names %>
+ +

Registripidaja:
+<%= @registrar.name %>
+Email: <%= @registrar.email %>
+Telefon: <%= @registrar.phone %>
+Veebileht: <%= @registrar.url %>

+ Ülevaate kõikidest endaga seotud domeenidest saate registreerija portaalist. <%= ENV['registrant_url'] %>.


Lugupidamisega
@@ -31,8 +37,14 @@ The following data for the <%= @domain.name %> domain have been entered into the Registrant: <%= @domain.registrant_name %>
Administrative contact: <%= @domain.admin_contact_names %>
Technical contact: <%= @domain.tech_contact_names %>
-Registrar: <%= @registrar.name %>
Name servers: <%= @domain.nameserver_names %>
+ +

Registrar:
+<%= @registrar.name %>
+Email: <%= @registrar.email %>
+Telefon: <%= @registrar.phone %>
+Veebileht: <%= @registrar.url %>

+ You can find an overview of all your domains at the registrant's portal. <%= ENV['registrant_url'] %>.


Best Regards,
@@ -57,8 +69,14 @@ Estonian Internet Foundation Регистрант: <%= @domain.registrant_name %>
Административный контакт: <%= @domain.admin_contact_names %>
Технический контакт: <%= @domain.tech_contact_names %>
-Регистратор: <%= @registrar.name %>
Серверы доменных имен: <%= @domain.nameserver_names %>
+ +

Регистратор:
+<%= @registrar.name %>
+Электронная почта: <%= @registrar.email %>
+Телефон: <%= @registrar.phone %>
+Веб-сайт: <%= @registrar.url %>

+ Обзор всех связанных с Вами доменов можете получить на портале регистранта. <%= ENV['registrant_url'] %>.


diff --git a/app/views/mailers/domain_mailer/expiration.text.erb b/app/views/mailers/domain_mailer/expiration.text.erb index 7cfa9a9fc..ef8cce36c 100644 --- a/app/views/mailers/domain_mailer/expiration.text.erb +++ b/app/views/mailers/domain_mailer/expiration.text.erb @@ -10,8 +10,14 @@ Domeeni <%= @domain.name %> kohta on registris järgmised andmed: Registreerija: <%= @domain.registrant_name %> Halduskontakt: <%= @domain.admin_contact_names %> Tehniline kontakt: <%= @domain.tech_contact_names %> -Registripidaja: <%= @registrar.name %> Nimeserverid: <%= @domain.nameserver_names %> + +Registripidaja: +<%= @registrar.name %> +Email: <%= @registrar.email %> +Telefon: <%= @registrar.phone %> +Veebileht: <%= @registrar.url %> + Ülevaate kõikidest endaga seotud domeenidest saate registreerija portaalist. <%= ENV['registrant_url'] %>. Parimate soovidega @@ -31,8 +37,14 @@ The following data for the <%= @domain.name %> domain have been entered into the Registrant: <%= @domain.registrant_name %> Administrative contact: <%= @domain.admin_contact_names %> Technical contact: <%= @domain.tech_contact_names %> -Registrar: <%= @registrar.name %> Name servers: <%= @domain.nameserver_names %> + +Registrar: +<%= @registrar.name %> +Email: <%= @registrar.email %> +Phone: <%= @registrar.phone %> +Website: <%= @registrar.url %> + You can find an overview of all your domains at the registrant's portal. <%= ENV['registrant_url'] %>. Best Regards, @@ -52,8 +64,14 @@ Estonian Internet Foundation Регистрант: <%= @domain.registrant_name %> Административный контакт: <%= @domain.admin_contact_names %> Технический контакт: <%= @domain.tech_contact_names %> -Регистратор: <%= @registrar.name %> Серверы доменных имен: <%= @domain.nameserver_names %> + +Регистратор: +<%= @registrar.name %> +Электронная почта: <%= @registrar.email %> +Телефон: <%= @registrar.phone %> +Веб-сайт: <%= @registrar.url %> + Обзор всех связанных с Вами доменов можете получить на портале регистранта. <%= ENV['registrant_url'] %>. С наилучшими пожеланиями diff --git a/app/views/mailers/domain_mailer/force_delete.html.erb b/app/views/mailers/domain_mailer/force_delete.html.erb index adb8a5f70..134c8d91b 100644 --- a/app/views/mailers/domain_mailer/force_delete.html.erb +++ b/app/views/mailers/domain_mailer/force_delete.html.erb @@ -1,7 +1,4 @@ -
-

Eesti Interneti Sihtasutus

-
-
@@ -11,56 +8,74 @@

.ee domeeniregistrisse on domeeni <%= @domain.name %> kohta kantud järgmised andmed:

-

Registreerija nimi: <%= @domain.registrant %>
-Registrikood: <%= @domain.registrant.try(:ident) %>

+

Registreerija nimi: <%= @registrant.name %>
+Registrikood: <%= @registrant.ident %>

-

Eesti Interneti Sihtasutusele (EIS) on saanud teatavaks, et juriidiline isik registrikoodiga <%= @domain.registrant.try(:ident) %> on äriregistrist kustutatud.

+

Eesti Interneti Sihtasutusele (EIS) on saanud teatavaks, et juriidiline isik registrikoodiga <%= @registrant.ident %> on äriregistrist kustutatud.

Kuivõrd äriregistrist kustutatud juriidiline isik ei saa olla domeeni registreerijaks, siis algatas EIS <%= l(Time.zone.now, format: :date) %> vastavalt Domeenireeglite (http://www.internet.ee/domeenid/) punktile 6.4 domeeni <%= @domain.name %> suhtes 30 päeva pikkuse kustutusmenetluse. Kustutamise käigus jääb domeen internetis kättesaadavaks.

-

Domeenireeglite punktist 6.4 tulenevalt on domeeni suhtes õigust omaval registreerijal võimalus esitada domeeni <%= @domain.name %> registripidajale <%= @domain.registrar %> domeeni üleandmise taotlus Domeenireeglite p 5.3.6.2 kohaselt. Taotlusele tuleb lisada domeeni omandamist tõendavad dokumendid, mis asendavad Domeenireeglite punktis 5.3.6.3 sätestatud üleandva registreerija nõusolekut. Vastav dokumentatsioon tuleb esitada Registripidajale esimesel võimalusel.

+

Domeenireeglite punktist 6.4 tulenevalt on domeeni suhtes õigust omaval registreerijal võimalus esitada domeeni <%= @domain.name %> registripidajale <%= @registrar.name %> domeeni üleandmise taotlus Domeenireeglite p 5.3.6.2 kohaselt. Taotlusele tuleb lisada domeeni omandamist tõendavad dokumendid, mis asendavad Domeenireeglite punktis 5.3.6.3 sätestatud üleandva registreerija nõusolekut. Vastav dokumentatsioon tuleb esitada Registripidajale esimesel võimalusel.

-

Kui üleandmine ei ole 30 päeva jooksul toimunud, kustub domeen <%= @domain.name %> 24 tunni jooksul <%= l(@domain.force_delete_at, format: :date) %> juhuslikult valitud ajahetkel. Soovi korral on võimalik domeen pärast selle kustumist registrist “kes ees, see mees” põhimõttel uuesti registreerida.

+

Kui üleandmine ei ole 30 päeva jooksul toimunud, kustub domeen <%= @domain.name %> 24 tunni jooksul <%= @domain.force_delete_date %> juhuslikult valitud ajahetkel. Soovi korral on võimalik domeen pärast selle kustumist registrist “kes ees, see mees” põhimõttel uuesti registreerida.

-

Lisaküsimuste korral võtke palun ühendust oma registripidajaga <%= @domain.registrar %>. Registripidajate kontaktid leiate aadressilt http://www.internet.ee/registripidajad



+

Lisaküsimuste korral võtke palun ühendust oma registripidajaga:

+

<%= @registrar.name %>
+Email: <%= @registrar.email %>
+Telefon: <%= @registrar.phone %>
+Veebileht: <%= @registrar.url %>

+
Dear contact of <%= @domain.name %> domain

The following details for domain name <%= @domain.name %> have been entered into the .ee domain registry:

-

Registrant's name: <%= @domain.registrant %>
-Registry code: <%= @domain.registrant.try(:ident) %>

+

Registrant's name: <%= @registrant.name %>
+Registry code: <%= @registrant.ident %>

-

Estonian Internet Foundation (EIS) has learned that the legal person with registry code <%= @domain.registrant.try(:ident) %> has been deleted from the Business Registry.

+

Estonian Internet Foundation (EIS) has learned that the legal person with registry code <%= @registrant.ident %> has been deleted from the Business Registry.

As a terminated legal person cannot be the registrant of a domain, the EIS started the deletion process of <%= @domain.name %> domain on <%= l(Time.zone.now, format: :date) %> according to the Domain Regulation (http://www.internet.ee/domains/), using the 30-day delete procedure. The domain will remain available on the Internet during the delete procedure.

-

According to paragraph 6.4 of the Domain Regulation, the registrant holding a right to the domain name <%= @domain.name %> can submit a domain name transfer application to the registrar <%= @domain.registrar %> in accordance with paragraph 5.3.6.2 of the Domain Regulation. The application must be submitted together with documents certifying the acquisition of the domain that will replace the consent of the surrendering registrant as laid down in paragraph 5.3.6.3 of the Domain Regulation. The relevant documents should be submitted to the registrar as soon as possible.

+

According to paragraph 6.4 of the Domain Regulation, the registrant holding a right to the domain name <%= @domain.name %> can submit a domain name transfer application to the registrar <%= @registrar.name %> in accordance with paragraph 5.3.6.2 of the Domain Regulation. The application must be submitted together with documents certifying the acquisition of the domain that will replace the consent of the surrendering registrant as laid down in paragraph 5.3.6.3 of the Domain Regulation. The relevant documents should be submitted to the registrar as soon as possible.

-

If the transfer has not been made in 30 days, the domain <%= @domain.name %> will be deleted at a randomly chosen moment within 24 hours on <%= l(@domain.force_delete_at, format: :date) %>. After deletion it is possible to reregister the domain on a "first come, first served" basis.

+

If the transfer has not been made in 30 days, the domain <%= @domain.name %> will be deleted at a randomly chosen moment within 24 hours on <%= @domain.force_delete_date %>. After deletion it is possible to reregister the domain on a "first come, first served" basis.

-

Should you have additional questions, please contact your registrar <%= @domain.registrar %>, whose contact information can be found at http://www.internet.ee/registrars/



+

Should you have additional questions, please contact your registrar:

+

<%= @registrar.name %>
+Email: <%= @registrar.email %>
+Phone: <%= @registrar.phone %>
+Website: <%= @registrar.url %>

+
Уважаемое контактное лицо домена <%= @domain.name %>

В регистр доменов Целевого учреждения Eesti Internet (EIS) внесены следующие данные относительно домена <%= @domain.name %>:

-

Имя регистранта: <%= @domain.registrant %>
-Регистрационный код: <%= @domain.registrant.try(:ident) %>

+

Имя регистранта: <%= @registrant.name %>
+Регистрационный код: <%= @registrant.ident %>

-

EIS стало известно, что юридическое лицо с регистрационным кодом <%= @domain.registrant.try(:ident) %> удалено из коммерческого реестра.

+

EIS стало известно, что юридическое лицо с регистрационным кодом <%= @registrant.ident %> удалено из коммерческого реестра.

Поскольку прекратившее деятельность юридическое лицо не может являться регистрантом домена, то согласно пункту 6.4 Правил домена (http://www.internet.ee/domeny/) EIS <%= l(Time.zone.now, format: :date) %> инициировало удаление домена <%= @domain.name %> с применением 30-дневной процедуры удаления. На протяжении процесса удаления домен остается доступным в Интернете.

-

Согласно пункту 6.4 Правил домена регистрант, имеющий право на домен, может подать регистратору <%= @domain.registrar %> домена <%= @domain.name %> ходатайство о передаче домена в соответствии с п. 5.3.6.2 Правил домена. К ходатайству следует приложить подтверждающие приобретение домена документы, заменяющие в соответствии с пунктом 5.3.6.3 Правил домена согласие передающего доменное имя регистранта. EIS предлагает представить соответствующую документацию Регистратору при первой возможности, начиная с инициирования процедуры удаления.

+

Согласно пункту 6.4 Правил домена регистрант, имеющий право на домен, может подать регистратору <%= @registrar.name %> домена <%= @domain.name %> ходатайство о передаче домена в соответствии с п. 5.3.6.2 Правил домена. К ходатайству следует приложить подтверждающие приобретение домена документы, заменяющие в соответствии с пунктом 5.3.6.3 Правил домена согласие передающего доменное имя регистранта. EIS предлагает представить соответствующую документацию Регистратору при первой возможности, начиная с инициирования процедуры удаления.

-

Если в течение 30 дней передача не произошла, домен <%= @domain.name %> удаляется по истечении 24 часов <%= l(@domain.force_delete_at, format: :date) %> в случайный момент времени. По желанию после удаления из регистра домен можно снова зарегистрировать по принципу "кто успел, тот и съел".

+

Если в течение 30 дней передача не произошла, домен <%= @domain.name %> удаляется по истечении 24 часов <%= @domain.force_delete_date %> в случайный момент времени. По желанию после удаления из регистра домен можно снова зарегистрировать по принципу "кто успел, тот и съел".

-

Просим обратиться к своему регистратору <%= @domain.registrar %>. Контактные данные регистраторов можно найти по адресу http://www.internet.ee/registratory/



+

Просим обратиться к своему регистратору:

+ +

<%= @registrar.name %>
+Электронная почта: <%= @registrar.email %>
+Телефон: <%= @registrar.phone %>
+Веб-сайт: <%= @registrar.url %>

+ + +

@@ -73,4 +88,4 @@ Registry code: <%= @domain.registrant.try(:ident) %>

+
diff --git a/app/views/mailers/domain_mailer/force_delete.text.erb b/app/views/mailers/domain_mailer/force_delete.text.erb index 12f3af85f..871cdb7d8 100644 --- a/app/views/mailers/domain_mailer/force_delete.text.erb +++ b/app/views/mailers/domain_mailer/force_delete.text.erb @@ -2,18 +2,23 @@ Lugupeetud domeeni <%= @domain.name %> kontaktisik .ee domeeniregistrisse on domeeni <%= @domain.name %> kohta kantud järgmised andmed: -Registreerija nimi: <%= @domain.registrant %> -Registrikood: <%= @domain.registrant.try(:ident) %> +Registreerija nimi: <%= @registrant.name %> +Registrikood: <%= @registrant.ident %> -Eesti Interneti Sihtasutusele (EIS) on saanud teatavaks, et juriidiline isik registrikoodiga <%= @domain.registrant.try(:ident) %> on äriregistrist kustutatud. +Eesti Interneti Sihtasutusele (EIS) on saanud teatavaks, et juriidiline isik registrikoodiga <%= @registrant.ident %> on äriregistrist kustutatud. Kuivõrd äriregistrist kustutatud juriidiline isik ei saa olla domeeni registreerijaks, siis algatas EIS <%= l(Time.zone.now, format: :date) %> vastavalt Domeenireeglite (http://www.internet.ee/domeenid/) punktile 6.4 domeeni <%= @domain.name %> suhtes 30 päeva pikkuse kustutusmenetluse. Kustutamise käigus jääb domeen internetis kättesaadavaks. -Domeenireeglite punktist 6.4 tulenevalt on domeeni suhtes õigust omaval registreerijal võimalus esitada domeeni <%= @domain.name %> registripidajale <%= @domain.registrar %> domeeni üleandmise taotlus Domeenireeglite p 5.3.6.2 kohaselt. Taotlusele tuleb lisada domeeni omandamist tõendavad dokumendid, mis asendavad Domeenireeglite punktis 5.3.6.3 sätestatud üleandva registreerija nõusolekut. Vastav dokumentatsioon tuleb esitada Registripidajale esimesel võimalusel. +Domeenireeglite punktist 6.4 tulenevalt on domeeni suhtes õigust omaval registreerijal võimalus esitada domeeni <%= @domain.name %> registripidajale <%= @registrar.name %> domeeni üleandmise taotlus Domeenireeglite p 5.3.6.2 kohaselt. Taotlusele tuleb lisada domeeni omandamist tõendavad dokumendid, mis asendavad Domeenireeglite punktis 5.3.6.3 sätestatud üleandva registreerija nõusolekut. Vastav dokumentatsioon tuleb esitada Registripidajale esimesel võimalusel. -Kui üleandmine ei ole 30 päeva jooksul toimunud, kustub domeen <%= @domain.name %> 24 tunni jooksul <%= l(@domain.force_delete_at, format: :date) %> juhuslikult valitud ajahetkel. Soovi korral on võimalik domeen pärast selle kustumist registrist "kes ees, see mees" põhimõttel uuesti registreerida. +Kui üleandmine ei ole 30 päeva jooksul toimunud, kustub domeen <%= @domain.name %> 24 tunni jooksul <%= @domain.force_delete_date %> juhuslikult valitud ajahetkel. Soovi korral on võimalik domeen pärast selle kustumist registrist "kes ees, see mees" põhimõttel uuesti registreerida. -Lisaküsimuste korral võtke palun ühendust oma registripidajaga <%= @domain.registrar %>. Registripidajate kontaktid leiate aadressilt http://www.internet.ee/registripidajad/ +Lisaküsimuste korral võtke palun ühendust oma registripidajaga: + +<%= @registrar.name %> +Email: <%= @registrar.email %> +Telefon: <%= @registrar.phone %> +Veebileht: <%= @registrar.url %> @@ -21,18 +26,23 @@ Dear contact of <%= @domain.name %> domain The following details for domain name <%= @domain.name %> have been entered into the .ee domain registry: -Registrant's name: <%= @domain.registrant %> -Registry code: <%= @domain.registrant.try(:ident) %> +Registrant's name: <%= @registrant.name %> +Registry code: <%= @registrant.ident %> -Estonian Internet Foundation (EIS) has learned that the legal person with registry code <%= @domain.registrant.try(:ident) %> has been deleted from the Business Registry. +Estonian Internet Foundation (EIS) has learned that the legal person with registry code <%= @registrant.ident %> has been deleted from the Business Registry. As a terminated legal person cannot be the registrant of a domain, the EIS started the deletion process of <%= @domain.name %> domain on <%= l(Time.zone.now, format: :date) %> according to the Domain Regulation (http://www.internet.ee/domains/), using the 30-day delete procedure. The domain will remain available on the Internet during the delete procedure. -According to paragraph 6.4 of the Domain Regulation, the registrant holding a right to the domain name <%= @domain.name %> can submit a domain name transfer application to the registrar <%= @domain.registrar %> in accordance with paragraph 5.3.6.2 of the Domain Regulation. The application must be submitted together with documents certifying the acquisition of the domain that will replace the consent of the surrendering registrant as laid down in paragraph 5.3.6.3 of the Domain Regulation. The relevant documents should be submitted to the registrar as soon as possible. +According to paragraph 6.4 of the Domain Regulation, the registrant holding a right to the domain name <%= @domain.name %> can submit a domain name transfer application to the registrar <%= @registrar.name %> in accordance with paragraph 5.3.6.2 of the Domain Regulation. The application must be submitted together with documents certifying the acquisition of the domain that will replace the consent of the surrendering registrant as laid down in paragraph 5.3.6.3 of the Domain Regulation. The relevant documents should be submitted to the registrar as soon as possible. -If the transfer has not been made in 30 days, the domain <%= @domain.name %> will be deleted at a randomly chosen moment within 24 hours on <%= l(@domain.force_delete_at, format: :date) %>. After deletion it is possible to reregister the domain on a "first come, first served" basis. +If the transfer has not been made in 30 days, the domain <%= @domain.name %> will be deleted at a randomly chosen moment within 24 hours on <%= @domain.force_delete_date %>. After deletion it is possible to reregister the domain on a "first come, first served" basis. -Should you have additional questions, please contact your registrar <%= @domain.registrar %>, whose contact information can be found at http://www.internet.ee/registrars/ +Should you have additional questions, please contact your registrar: + +<%= @registrar.name %> +Email: <%= @registrar.email %> +Phone: <%= @registrar.phone %> +Website: <%= @registrar.url %> @@ -40,19 +50,23 @@ Should you have additional questions, please contact your registrar <%= @domain. В регистр доменов Целевого учреждения Eesti Internet (EIS) внесены следующие данные относительно домена <%= @domain.name %>: -Имя регистранта: <%= @domain.registrant %> -Регистрационный код: <%= @domain.registrant.try(:ident) %> +Имя регистранта: <%= @registrant.name %> +Регистрационный код: <%= @registrant.ident %> -EIS стало известно, что юридическое лицо с регистрационным кодом <%= @domain.registrant.try(:ident) %> удалено из коммерческого реестра. +EIS стало известно, что юридическое лицо с регистрационным кодом <%= @registrant.ident %> удалено из коммерческого реестра. Поскольку прекратившее деятельность юридическое лицо не может являться регистрантом домена, то согласно пункту 6.4 Правил домена (http://www.internet.ee/domeny) EIS <%= l(Time.zone.now, format: :date) %> инициировало удаление домена <%= @domain.name %> с применением 30-дневной процедуры удаления. На протяжении процесса удаления домен остается доступным в Интернете. -Согласно пункту 6.4 Правил домена регистрант, имеющий право на домен, может подать регистратору <%= @domain.registrar %> домена <%= @domain.name %> ходатайство о передаче домена в соответствии с п. 5.3.6.2 Правил домена. К ходатайству следует приложить подтверждающие приобретение домена документы, заменяющие в соответствии с пунктом 5.3.6.3 Правил домена согласие передающего доменное имя регистранта. EIS предлагает представить соответствующую документацию Регистратору при первой возможности, начиная с инициирования процедуры удаления. +Согласно пункту 6.4 Правил домена регистрант, имеющий право на домен, может подать регистратору <%= @registrar.name %> домена <%= @domain.name %> ходатайство о передаче домена в соответствии с п. 5.3.6.2 Правил домена. К ходатайству следует приложить подтверждающие приобретение домена документы, заменяющие в соответствии с пунктом 5.3.6.3 Правил домена согласие передающего доменное имя регистранта. EIS предлагает представить соответствующую документацию Регистратору при первой возможности, начиная с инициирования процедуры удаления. -Если в течение 30 дней передача не произошла, домен <%= @domain.name %> удаляется по истечении 24 часов <%= l(@domain.force_delete_at, format: :date) %> в случайный момент времени. По желанию после удаления из регистра домен можно снова зарегистрировать по принципу "кто успел, тот и съел". +Если в течение 30 дней передача не произошла, домен <%= @domain.name %> удаляется по истечении 24 часов <%= @domain.force_delete_date %> в случайный момент времени. По желанию после удаления из регистра домен можно снова зарегистрировать по принципу "кто успел, тот и съел". -Просим обратиться к своему регистратору <%= @domain.registrar %>. Контактные данные регистраторов можно найти по адресу http://www.internet.ee/registratory +Просим обратиться к своему регистратору: +<%= @registrar.name %> +Электронная почта: <%= @registrar.email %> +Телефон: <%= @registrar.phone %> +Веб-сайт: <%= @registrar.url %> Lugupidamisega, diff --git a/config/locales/en.yml b/config/locales/en.yml index 264502adf..5c301d0d2 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -939,7 +939,6 @@ en: new_mail_template: New mail template failure: "It was not saved" contact_is_not_valid: 'Contact %{value} is not valid, please fix the invalid contact' - force_delete_subject: 'Kustutusmenetluse teade' welcome_to_eis_registrar_portal: 'Welcome to EIS Registrar portal' interfaces: 'Interfaces' list_format_is_in_yaml: 'List format is in YAML' diff --git a/config/locales/mailers/domain.en.yml b/config/locales/mailers/domain.en.yml index 99dc33a5a..07b3a8f89 100644 --- a/config/locales/mailers/domain.en.yml +++ b/config/locales/mailers/domain.en.yml @@ -2,3 +2,5 @@ en: domain_mailer: expiration: subject: The %{domain_name} domain has expired + force_delete: + subject: Kustutusmenetluse teade diff --git a/spec/factories/domain.rb b/spec/factories/domain.rb index b4079c5d7..5a396362d 100644 --- a/spec/factories/domain.rb +++ b/spec/factories/domain.rb @@ -7,7 +7,6 @@ FactoryGirl.define do registrant after :build do |domain| - domain.class.skip_callback(:commit, :after, :update_whois_record) # Otherwise FactoryGirl reports Domain#json= method as undefined domain.nameservers << FactoryGirl.build_pair(:nameserver) domain.admin_domain_contacts << FactoryGirl.build(:admin_domain_contact) domain.tech_domain_contacts << FactoryGirl.build(:tech_domain_contact) diff --git a/spec/mailers/domain_mailer_spec.rb b/spec/mailers/domain_mailer_spec.rb index c3679f116..2f7a38afe 100644 --- a/spec/mailers/domain_mailer_spec.rb +++ b/spec/mailers/domain_mailer_spec.rb @@ -1,12 +1,42 @@ require 'rails_helper' RSpec.describe DomainMailer do + describe '#force_delete' do + let(:domain) { instance_spy(Domain, name: 'test.com') } + let(:domain_presenter) { instance_spy(DomainPresenter) } + let(:registrar_presenter) { instance_spy(RegistrarPresenter) } + let(:registrant_presenter) { instance_spy(RegistrantPresenter) } + subject(:message) { described_class.force_delete(domain: domain) } + + before :example do + expect(DomainPresenter).to receive(:new).and_return(domain_presenter) + expect(RegistrarPresenter).to receive(:new).and_return(registrar_presenter) + expect(RegistrantPresenter).to receive(:new).and_return(registrant_presenter) + end + + it 'has sender' do + message.deliver! + expect(message.from).to eq(['noreply@internet.ee']) + end + + it 'has recipient' do + expect(domain).to receive(:primary_contact_emails).and_return(['recipient@test.com']) + message.deliver! + expect(message.to).to match_array(['recipient@test.com']) + end + + it 'has valid subject' do + message.deliver! + expect(message.subject).to eq('Kustutusmenetluse teade') + end + + it 'sends message' do + expect { message.deliver! }.to change { ActionMailer::Base.deliveries.count }.by(1) + end + end + describe '#expiration' do - let(:domain) { instance_spy(Domain, - name: 'test.com', - registrant_email: 'registrant@test.com', - admin_contact_emails: ['admin.contact.email@test.com'] - ) } + let(:domain) { instance_spy(Domain, name: 'test.com') } let(:domain_presenter) { instance_spy(DomainPresenter) } let(:registrar_presenter) { instance_spy(RegistrarPresenter) } subject(:message) { described_class.expiration(domain: domain) } @@ -16,14 +46,15 @@ RSpec.describe DomainMailer do expect(RegistrarPresenter).to receive(:new).and_return(registrar_presenter) end - it 'has valid sender' do + it 'has sender' do message.deliver! expect(message.from).to eq(['noreply@internet.ee']) end - it 'has registrant and administrative contacts as recipient' do + it 'has recipient' do + expect(domain).to receive(:primary_contact_emails).and_return(['recipient@test.com']) message.deliver! - expect(message.to).to match_array(['registrant@test.com', 'admin.contact.email@test.com']) + expect(message.to).to match_array(['recipient@test.com']) end it 'has valid subject' do diff --git a/spec/models/domain_spec.rb b/spec/models/domain_spec.rb index f47128759..c6627d877 100644 --- a/spec/models/domain_spec.rb +++ b/spec/models/domain_spec.rb @@ -831,6 +831,7 @@ end RSpec.describe Domain, db: false do it { is_expected.to alias_attribute(:on_hold_time, :outzone_at) } it { is_expected.to alias_attribute(:delete_time, :delete_at) } + it { is_expected.to alias_attribute(:force_delete_time, :force_delete_at) } describe '#set_server_hold' do let(:domain) { described_class.new } @@ -896,4 +897,20 @@ RSpec.describe Domain, db: false do expect(domain.nameserver_hostnames).to eq('hostnames') end end + + describe '#primary_contact_emails' do + let(:domain) { described_class.new } + + before :example do + expect(domain).to receive(:registrant_email).and_return('registrant@test.com') + expect(domain).to receive(:admin_contact_emails).and_return(['admin.contact.email@test.com']) + end + + it 'returns registrant and administrative contact emails' do + expect(domain.primary_contact_emails).to match_array(%w( + registrant@test.com + admin.contact.email@test.com + )) + end + end end diff --git a/spec/presenters/domain_presenter_spec.rb b/spec/presenters/domain_presenter_spec.rb index a6799095b..79adcc68f 100644 --- a/spec/presenters/domain_presenter_spec.rb +++ b/spec/presenters/domain_presenter_spec.rb @@ -41,6 +41,25 @@ RSpec.describe DomainPresenter do end end + describe '#force_delete_date' do + subject(:force_delete_date) { presenter.force_delete_date } + + context 'when present' do + let(:domain) { instance_double(Domain, force_delete_time: '05.07.2010') } + + it 'returns localized date' do + expect(view).to receive(:l).with('05.07.2010', format: :date).and_return('delete date') + expect(force_delete_date).to eq('delete date') + end + end + + context 'when absent' do + let(:domain) { instance_double(Domain, force_delete_time: nil) } + + specify { expect(force_delete_date).to be_nil } + end + end + describe '#admin_contact_names' do let(:domain) { instance_double(Domain) } diff --git a/spec/views/mailers/domain_mailer/expiration.html.erb_spec.rb b/spec/views/mailers/domain_mailer/expiration.html.erb_spec.rb index fc1e18e61..735f0199c 100644 --- a/spec/views/mailers/domain_mailer/expiration.html.erb_spec.rb +++ b/spec/views/mailers/domain_mailer/expiration.html.erb_spec.rb @@ -17,7 +17,21 @@ RSpec.describe 'mailers/domain_mailer/expiration.html.erb' do expect(rendered).to have_text('test registrar name', count: mention_count) end - attributes = %i( + registrar_attributes = %i( + 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 + end + + domain_attributes = %i( on_hold_date delete_date registrant_name @@ -26,7 +40,7 @@ RSpec.describe 'mailers/domain_mailer/expiration.html.erb' do nameserver_names ) - attributes.each do |attr_name| + 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) render diff --git a/spec/views/mailers/domain_mailer/expiration.text.erb_spec.rb b/spec/views/mailers/domain_mailer/expiration.text.erb_spec.rb index 39a36cdb7..9af9978b7 100644 --- a/spec/views/mailers/domain_mailer/expiration.text.erb_spec.rb +++ b/spec/views/mailers/domain_mailer/expiration.text.erb_spec.rb @@ -17,7 +17,21 @@ RSpec.describe 'mailers/domain_mailer/expiration.text.erb' do expect(rendered).to have_text('test registrar name', count: mention_count) end - attributes = %i( + registrar_attributes = %i( + 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 + end + + domain_attributes = %i( on_hold_date delete_date registrant_name @@ -26,7 +40,7 @@ RSpec.describe 'mailers/domain_mailer/expiration.text.erb' do nameserver_names ) - attributes.each do |attr_name| + 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) render diff --git a/spec/views/mailers/domain_mailer/force_delete.html.erb_spec.rb b/spec/views/mailers/domain_mailer/force_delete.html.erb_spec.rb new file mode 100644 index 000000000..408777cc9 --- /dev/null +++ b/spec/views/mailers/domain_mailer/force_delete.html.erb_spec.rb @@ -0,0 +1,63 @@ +require 'rails_helper' + +RSpec.describe 'mailers/domain_mailer/force_delete.html.erb' do + let(:domain) { instance_spy(DomainPresenter) } + let(:registrar) { instance_spy(RegistrarPresenter) } + let(:registrant) { instance_spy(RegistrantPresenter) } + let(:lang_count) { 3 } + + before :example do + assign(:domain, domain) + assign(:registrar, registrar) + assign(:registrant, registrant) + end + + it 'has domain name' do + mention_count = 5 * 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 + + it 'has domain force delete date' do + mention_count = 1 * lang_count + expect(domain).to receive(:force_delete_date).exactly(mention_count).times.and_return('test domain force delete date') + render + expect(rendered).to have_text('test domain force delete date', count: mention_count) + 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') + render + expect(rendered).to have_text('test registrar name', count: mention_count) + end + + registrar_attributes = %i( + 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 + end + + it 'has registrant name' do + mention_count = 1 * lang_count + expect(registrant).to receive(:name).exactly(mention_count).times.and_return('test registrant name') + render + expect(rendered).to have_text('test registrant name', count: mention_count) + end + + it 'has registrant ident' do + mention_count = 2 * lang_count + expect(registrant).to receive(:ident).exactly(mention_count).times.and_return('test registrant ident') + render + expect(rendered).to have_text('test registrant ident', count: mention_count) + end +end diff --git a/spec/views/mailers/domain_mailer/force_delete.text.erb_spec.rb b/spec/views/mailers/domain_mailer/force_delete.text.erb_spec.rb new file mode 100644 index 000000000..500e746af --- /dev/null +++ b/spec/views/mailers/domain_mailer/force_delete.text.erb_spec.rb @@ -0,0 +1,63 @@ +require 'rails_helper' + +RSpec.describe 'mailers/domain_mailer/force_delete.text.erb' do + let(:domain) { instance_spy(DomainPresenter) } + let(:registrar) { instance_spy(RegistrarPresenter) } + let(:registrant) { instance_spy(RegistrantPresenter) } + let(:lang_count) { 3 } + + before :example do + assign(:domain, domain) + assign(:registrar, registrar) + assign(:registrant, registrant) + end + + it 'has domain name' do + mention_count = 5 * 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 + + it 'has domain force delete date' do + mention_count = 1 * lang_count + expect(domain).to receive(:force_delete_date).exactly(mention_count).times.and_return('test domain force delete date') + render + expect(rendered).to have_text('test domain force delete date', count: mention_count) + 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') + render + expect(rendered).to have_text('test registrar name', count: mention_count) + end + + registrar_attributes = %i( + 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 + end + + it 'has registrant name' do + mention_count = 1 * lang_count + expect(registrant).to receive(:name).exactly(mention_count).times.and_return('test registrant name') + render + expect(rendered).to have_text('test registrant name', count: mention_count) + end + + it 'has registrant ident' do + mention_count = 2 * lang_count + expect(registrant).to receive(:ident).exactly(mention_count).times.and_return('test registrant ident') + render + expect(rendered).to have_text('test registrant ident', count: mention_count) + end +end From 837ef067e72295f5e7b9b3647e78bb00f7d3cd75 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Mon, 31 Oct 2016 18:39:14 +0200 Subject: [PATCH 19/67] Fix domain contact spec registry-180 --- spec/models/domain_contact_spec.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/spec/models/domain_contact_spec.rb b/spec/models/domain_contact_spec.rb index de62276df..14a1aa258 100644 --- a/spec/models/domain_contact_spec.rb +++ b/spec/models/domain_contact_spec.rb @@ -1,12 +1,12 @@ require 'rails_helper' describe DomainContact do - before :all do + before :example do @api_user = Fabricate(:domain_contact) end context 'with invalid attribute' do - before :all do + before :example do @domain_contact = DomainContact.new end @@ -31,7 +31,7 @@ describe DomainContact do end context 'with valid attributes' do - before :all do + before :example do @domain_contact = Fabricate(:domain_contact) end @@ -62,7 +62,7 @@ describe DomainContact do end context 'with valid attributes with tech domain contact' do - before :all do + before :example do @domain_contact = Fabricate(:tech_domain_contact) end @@ -93,7 +93,7 @@ describe DomainContact do end context 'with valid attributes with admin domain contact' do - before :all do + before :example do @domain_contact = Fabricate(:admin_domain_contact) end From 3bdfb4b4eb3fdd67d3c6270b278f5fd01922f906 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Tue, 1 Nov 2016 15:43:32 +0200 Subject: [PATCH 20/67] Remove/fix outdated specs --- spec/models/bank_transaction_spec.rb | 11 --- spec/models/domain_contact_spec.rb | 14 ++-- spec/models/domain_spec.rb | 112 --------------------------- 3 files changed, 9 insertions(+), 128 deletions(-) diff --git a/spec/models/bank_transaction_spec.rb b/spec/models/bank_transaction_spec.rb index 27640453c..627427d57 100644 --- a/spec/models/bank_transaction_spec.rb +++ b/spec/models/bank_transaction_spec.rb @@ -34,17 +34,6 @@ describe BankTransaction do @bank_transaction.errors.full_messages.should match_array([]) end - it 'should bind transaction with invoice manually' do - r = Fabricate(:registrar_with_no_account_activities, reference_no: 'RF7086666663') - invoice = r.issue_prepayment_invoice(200, 'add some money') - - bt = Fabricate(:bank_transaction, { sum: 240 }) - bt.bind_invoice(invoice.number) - - invoice.receipt_date.should_not be_blank - r.cash_account.balance.should == 200.0 - end - it 'should not bind transaction with mismatching sums' do r = Fabricate(:registrar_with_no_account_activities, reference_no: 'RF7086666663') invoice = r.issue_prepayment_invoice(200, 'add some money') diff --git a/spec/models/domain_contact_spec.rb b/spec/models/domain_contact_spec.rb index 14a1aa258..783d7e69b 100644 --- a/spec/models/domain_contact_spec.rb +++ b/spec/models/domain_contact_spec.rb @@ -51,10 +51,12 @@ describe DomainContact do end it 'should have one version' do + @domain_contact = Fabricate.create(:domain_contact) + with_versioning do @domain_contact.versions.reload.should == [] - @domain_contact.updated_at = Time.zone.now # trigger new version - @domain_contact.save + @domain_contact.contact = Fabricate.create(:contact) + @domain_contact.save! @domain_contact.errors.full_messages.should match_array([]) @domain_contact.versions.size.should == 1 end @@ -82,10 +84,12 @@ describe DomainContact do end it 'should have one version' do + @domain_contact = Fabricate.create(:domain_contact) + with_versioning do @domain_contact.versions.reload.should == [] - @domain_contact.updated_at = Time.zone.now # trigger new version - @domain_contact.save + @domain_contact.contact = Fabricate.create(:contact) + @domain_contact.save! @domain_contact.errors.full_messages.should match_array([]) @domain_contact.versions.size.should == 1 end @@ -115,7 +119,7 @@ describe DomainContact do it 'should have one version' do with_versioning do @domain_contact.versions.reload.should == [] - @domain_contact.updated_at = Time.zone.now # trigger new version + @domain_contact.contact = Fabricate.create(:contact) @domain_contact.save @domain_contact.errors.full_messages.should match_array([]) @domain_contact.versions.size.should == 1 diff --git a/spec/models/domain_spec.rb b/spec/models/domain_spec.rb index c6627d877..5b8752d8d 100644 --- a/spec/models/domain_spec.rb +++ b/spec/models/domain_spec.rb @@ -353,118 +353,6 @@ RSpec.describe Domain do domain.statuses.should == ['expired'] end - it 'should know its create price' do - Fabricate(:pricelist, { - category: 'ee', - operation_category: 'create', - duration: '1year', - price: 1.50, - valid_from: Time.zone.parse('2015-01-01'), - valid_to: nil - }) - - domain = Fabricate(:domain) - domain.pricelist('create').price.amount.should == 1.50 - - domain = Fabricate(:domain, period: 12, period_unit: 'm') - domain.pricelist('create').price.amount.should == 1.50 - - domain = Fabricate(:domain, period: 365, period_unit: 'd') - domain.pricelist('create').price.amount.should == 1.50 - - Fabricate(:pricelist, { - category: 'ee', - operation_category: 'create', - duration: '2years', - price: 3, - valid_from: Time.zone.parse('2015-01-01'), - valid_to: nil - }) - - domain = Fabricate(:domain, period: 2) - domain.pricelist('create').price.amount.should == 3.0 - - domain = Fabricate(:domain, period: 24, period_unit: 'm') - domain.pricelist('create').price.amount.should == 3.0 - - domain = Fabricate(:domain, period: 730, period_unit: 'd') - domain.pricelist('create').price.amount.should == 3.0 - - Fabricate(:pricelist, { - category: 'ee', - operation_category: 'create', - duration: '3years', - price: 6, - valid_from: Time.zone.parse('2015-01-01'), - valid_to: nil - }) - - domain = Fabricate(:domain, period: 3) - domain.pricelist('create').price.amount.should == 6.0 - - domain = Fabricate(:domain, period: 36, period_unit: 'm') - domain.pricelist('create').price.amount.should == 6.0 - - domain = Fabricate(:domain, period: 1095, period_unit: 'd') - domain.pricelist('create').price.amount.should == 6.0 - end - - it 'should know its renew price' do - Fabricate(:pricelist, { - category: 'ee', - operation_category: 'renew', - duration: '1year', - price: 1.30, - valid_from: Time.zone.parse('2015-01-01'), - valid_to: nil - }) - - domain = Fabricate(:domain) - domain.pricelist('renew').price.amount.should == 1.30 - - domain = Fabricate(:domain, period: 12, period_unit: 'm') - domain.pricelist('renew').price.amount.should == 1.30 - - domain = Fabricate(:domain, period: 365, period_unit: 'd') - domain.pricelist('renew').price.amount.should == 1.30 - - Fabricate(:pricelist, { - category: 'ee', - operation_category: 'renew', - duration: '2years', - price: 3.1, - valid_from: Time.zone.parse('2015-01-01'), - valid_to: nil - }) - - domain = Fabricate(:domain, period: 2) - domain.pricelist('renew').price.amount.should == 3.1 - - domain = Fabricate(:domain, period: 24, period_unit: 'm') - domain.pricelist('renew').price.amount.should == 3.1 - - domain = Fabricate(:domain, period: 730, period_unit: 'd') - domain.pricelist('renew').price.amount.should == 3.1 - - Fabricate(:pricelist, { - category: 'ee', - operation_category: 'renew', - duration: '3years', - price: 6.1, - valid_from: Time.zone.parse('2015-01-01'), - valid_to: nil - }) - - domain = Fabricate(:domain, period: 3) - domain.pricelist('renew').price.amount.should == 6.1 - - domain = Fabricate(:domain, period: 36, period_unit: 'm') - domain.pricelist('renew').price.amount.should == 6.1 - - domain = Fabricate(:domain, period: 1095, period_unit: 'd') - domain.pricelist('renew').price.amount.should == 6.1 - end - it 'should set pending update' do @domain.statuses = DomainStatus::OK # restore @domain.save From bebd49e5f4b39089f0d34ddddeb04ff8b15f0ac1 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Thu, 3 Nov 2016 20:16:01 +0200 Subject: [PATCH 21/67] Add extended registrar's info to "pending_deleted" mailer #180 --- app/mailers/domain_mailer.rb | 28 +++--------- app/models/domain.rb | 3 +- .../domain_mailer/pending_deleted.html.erb | 20 ++++++++- .../domain_mailer/pending_deleted.text.erb | 18 ++++++-- config/locales/en.yml | 1 - config/locales/mailers/domain.en.yml | 2 + spec/mailers/domain_mailer_spec.rb | 45 ++++++++++++++++--- spec/models/domain_spec.rb | 18 ++++++++ .../domain_delete_confirms_routing_spec.rb | 9 ++++ .../pending_deleted.html.erb_spec.rb | 41 +++++++++++++++++ .../pending_deleted.text.erb_spec.rb | 41 +++++++++++++++++ 11 files changed, 190 insertions(+), 36 deletions(-) create mode 100644 spec/routing/registrant/domain_delete_confirms_routing_spec.rb create mode 100644 spec/views/mailers/domain_mailer/pending_deleted.html.erb_spec.rb create mode 100644 spec/views/mailers/domain_mailer/pending_deleted.text.erb_spec.rb diff --git a/app/mailers/domain_mailer.rb b/app/mailers/domain_mailer.rb index 905927344..06a18b426 100644 --- a/app/mailers/domain_mailer.rb +++ b/app/mailers/domain_mailer.rb @@ -47,29 +47,13 @@ class DomainMailer < ApplicationMailer compose_from(params) end - def pending_deleted(domain_id, old_registrant_id, should_deliver) - @domain = Domain.find_by(id: domain_id) - @old_registrant = Registrant.find(old_registrant_id) - return unless @domain - return if delivery_off?(@domain, should_deliver) + def pending_deleted(domain:, registrant:) + @domain = DomainPresenter.new(domain: domain, view: view_context) + @registrar = RegistrarPresenter.new(registrar: domain.registrar, view: view_context) + @verification_url = registrant_domain_delete_confirm_url(domain, token: domain.registrant_verification_token) - if @domain.registrant_verification_token.blank? - logger.warn "EMAIL NOT DELIVERED: registrant_verification_token is missing for #{@domain.name}" - return - end - - if @domain.registrant_verification_asked_at.blank? - logger.warn "EMAIL NOT DELIVERED: registrant_verification_asked_at is missing for #{@domain.name}" - return - end - - confirm_path = "#{ENV['registrant_url']}/registrant/domain_delete_confirms" - @verification_url = "#{confirm_path}/#{@domain.id}?token=#{@domain.registrant_verification_token}" - - return if whitelist_blocked?(@old_registrant.email) - mail(to: format(@old_registrant.email), - subject: "#{I18n.t(:domain_pending_deleted_subject, - name: @domain.name)} [#{@domain.name}]") + subject = default_i18n_subject(domain_name: domain.name) + mail(to: registrant.email, subject: subject) end def pending_delete_rejected_notification(domain_id, should_deliver) diff --git a/app/models/domain.rb b/app/models/domain.rb index fad363bed..9960b12a0 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -439,7 +439,8 @@ class Domain < ActiveRecord::Base pending_delete_confirmation! save(validate: false) # should check if this did succeed - DomainMailer.pending_deleted(id, registrant_id_was, deliver_emails).deliver + previous_registrant = Registrant.find(registrant_id_was) + DomainMailer.pending_deleted(domain: self, registrant: previous_registrant).deliver end def cancel_pending_delete diff --git a/app/views/mailers/domain_mailer/pending_deleted.html.erb b/app/views/mailers/domain_mailer/pending_deleted.html.erb index 6d0a47f57..10960019c 100644 --- a/app/views/mailers/domain_mailer/pending_deleted.html.erb +++ b/app/views/mailers/domain_mailer/pending_deleted.html.erb @@ -1,6 +1,14 @@ Tere

-Registrisse laekus taotlus domeeni <%= @domain.name %> kustutamiseks. Palun veenduge, et muudatus on korrektne ning probleemide korral pöörduge oma registripidaja <%= @domain.registrar_name %> poole. +Registrisse laekus taotlus domeeni <%= @domain.name %> kustutamiseks. Palun veenduge, et muudatus on korrektne ning probleemide korral pöörduge oma registripidaja poole: + +

+ <%= @registrar.name %>
+ Email: <%= @registrar.email %>
+ Telefon: <%= @registrar.phone %>
+ Veebileht: <%= @registrar.url %> +

+

Muudatuse kinnitamiseks külastage palun allolevat lehekülge, kontrollige uuesti üle muudatuse andmed ning vajutage nuppu kinnitan.

@@ -14,7 +22,15 @@ Eesti Interneti Sihtasutus

Hi,

-Application for deletion of your domain <%= @domain.name %> has been filed. Please make sure that the application is correct. Incase of problems please contact your registrar <%= @domain.registrar_name %>. +Application for deletion of your domain <%= @domain.name %> has been filed. Please make sure that the application is correct. Incase of problems please contact your registrar: + +

+ <%= @registrar.name %>
+ Email: <%= @registrar.email %>
+ Phone: <%= @registrar.phone %>
+ Website: <%= @registrar.url %> +

+

To confirm the update please visit this website, once again review the data and press approve:
<%= link_to @verification_url, @verification_url %> diff --git a/app/views/mailers/domain_mailer/pending_deleted.text.erb b/app/views/mailers/domain_mailer/pending_deleted.text.erb index cc49cbbb0..1c8877740 100644 --- a/app/views/mailers/domain_mailer/pending_deleted.text.erb +++ b/app/views/mailers/domain_mailer/pending_deleted.text.erb @@ -1,11 +1,16 @@ Tere -Registrisse laekus taotlus domeeni <%= @domain.name %> kustutamiseks. Palun veenduge, et muudatus on korrektne ning probleemide korral pöörduge oma registripidaja <%= @domain.registrar_name %> poole. +Registrisse laekus taotlus domeeni <%= @domain.name %> kustutamiseks. Palun veenduge, et muudatus on korrektne ning probleemide korral pöörduge oma registripidaja poole: + +<%= @registrar.name %> +Email: <%= @registrar.email %> +Telefon: <%= @registrar.phone %> +Veebileht: <%= @registrar.url %> Muudatuse kinnitamiseks külastage palun allolevat lehekülge, kontrollige uuesti üle muudatuse andmed ning vajutage nuppu kinnitan. Taotlus on aktiivne <%= Setting.expire_pending_confirmation %> tundi ja lükatakse automaatselt tagasi kui te seda enne ise ei kinnita või tagasi lükka. -<%= link_to @verification_url, @verification_url %> +<%= @verification_url %> Lugupidamisega Eesti Interneti Sihtasutus @@ -14,10 +19,15 @@ Eesti Interneti Sihtasutus Hi, -Application for deletion of your domain <%= @domain.name %> has been filed. Please make sure that the application is correct. Incase of problems please contact your registrar <%= @domain.registrar_name %>. +Application for deletion of your domain <%= @domain.name %> has been filed. Please make sure that the application is correct. In case of problems please contact your registrar: + +<%= @registrar.name %> +Email: <%= @registrar.email %> +Phone: <%= @registrar.phone %> +Website: <%= @registrar.url %> To confirm the update please visit this website, once again review the data and press approve: -<%= link_to @verification_url, @verification_url %> +<%= @verification_url %> The application will remain in pending status for <%= Setting.expire_pending_confirmation %> hrs and will be automatically rejected if it is not approved nor rejected before. diff --git a/config/locales/en.yml b/config/locales/en.yml index 5c301d0d2..cbc61b29c 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -803,7 +803,6 @@ en: pending_update_expired_notification_for_new_registrant_subject: "Domeeni %{name} registreerija vahetuse taotlus on tühistatud / %{name} registrant change cancelled" registrant_updated_notification_for_new_registrant_subject: 'Domeeni %{name} registreerija vahetus teostatud / Registrant change of %{name} has been finished.' registrant_updated_notification_for_old_registrant_subject: 'Domeeni %{name} registreerija vahetus teostatud / Registrant change of %{name} has been finished.' - domain_pending_deleted_subject: "Kinnitustaotlus domeeni %{name} kustutamiseks .ee registrist / Application for approval for deletion of %{name}" pending_delete_rejected_notification_subject: "Domeeni %{name} kustutamise taotlus tagasi lükatud / %{name} deletion declined" pending_delete_expired_notification_subject: "Domeeni %{name} kustutamise taotlus on tühistatud / %{name} deletion cancelled" delete_confirmation_subject: "Domeeni %{name} kustutatud / %{name} deleted" diff --git a/config/locales/mailers/domain.en.yml b/config/locales/mailers/domain.en.yml index 07b3a8f89..c28ba6b00 100644 --- a/config/locales/mailers/domain.en.yml +++ b/config/locales/mailers/domain.en.yml @@ -4,3 +4,5 @@ en: subject: The %{domain_name} domain has expired force_delete: subject: Kustutusmenetluse teade + pending_deleted: + subject: Kinnitustaotlus domeeni %{domain_name} kustutamiseks .ee registrist / Application for approval for deletion of %{domain_name} diff --git a/spec/mailers/domain_mailer_spec.rb b/spec/mailers/domain_mailer_spec.rb index 2f7a38afe..1edc35f6a 100644 --- a/spec/mailers/domain_mailer_spec.rb +++ b/spec/mailers/domain_mailer_spec.rb @@ -1,6 +1,45 @@ require 'rails_helper' RSpec.describe DomainMailer do + describe '#pending_deleted' do + let(:domain) { instance_spy(Domain, name: 'test.com') } + let(:registrant) { instance_spy(Registrant, email: 'registrant@test.com') } + let(:domain_presenter) { instance_spy(DomainPresenter) } + let(:registrar_presenter) { instance_spy(RegistrarPresenter) } + subject(:message) { described_class.pending_deleted(domain: domain, registrant: registrant) } + + before :example do + expect(DomainPresenter).to receive(:new).and_return(domain_presenter) + expect(RegistrarPresenter).to receive(:new).and_return(registrar_presenter) + end + + it 'has sender' do + expect(message.from).to eq(['noreply@internet.ee']) + end + + it 'has registrant email as a recipient' do + expect(message.to).to match_array(['registrant@test.com']) + end + + it 'has subject' do + subject = 'Kinnitustaotlus domeeni test.com kustutamiseks .ee registrist' \ + ' / Application for approval for deletion of test.com' + + expect(message.subject).to eq(subject) + end + + it 'has confirmation url' do + allow(domain).to receive(:id).and_return(1) + expect(domain).to receive(:registrant_verification_token).and_return('test') + url = registrant_domain_delete_confirm_url(domain, token: 'test') + expect(message.body.parts.first.decoded).to include(url) + end + + it 'sends message' do + expect { message.deliver! }.to change { ActionMailer::Base.deliveries.count }.by(1) + end + end + describe '#force_delete' do let(:domain) { instance_spy(Domain, name: 'test.com') } let(:domain_presenter) { instance_spy(DomainPresenter) } @@ -15,18 +54,15 @@ RSpec.describe DomainMailer do end it 'has sender' do - message.deliver! expect(message.from).to eq(['noreply@internet.ee']) end it 'has recipient' do expect(domain).to receive(:primary_contact_emails).and_return(['recipient@test.com']) - message.deliver! expect(message.to).to match_array(['recipient@test.com']) end it 'has valid subject' do - message.deliver! expect(message.subject).to eq('Kustutusmenetluse teade') end @@ -47,18 +83,15 @@ RSpec.describe DomainMailer do end it 'has sender' do - message.deliver! expect(message.from).to eq(['noreply@internet.ee']) end it 'has recipient' do expect(domain).to receive(:primary_contact_emails).and_return(['recipient@test.com']) - message.deliver! expect(message.to).to match_array(['recipient@test.com']) end it 'has valid subject' do - message.deliver! expect(message.subject).to eq('The test.com domain has expired') end diff --git a/spec/models/domain_spec.rb b/spec/models/domain_spec.rb index 5b8752d8d..896280299 100644 --- a/spec/models/domain_spec.rb +++ b/spec/models/domain_spec.rb @@ -801,4 +801,22 @@ RSpec.describe Domain, db: false do )) end end + + describe '#pending_delete!' do + let(:domain) { described_class.new } + let(:previous_registrant) { instance_double(Registrant) } + let(:message) { instance_double(Mail::Message) } + + before :example do + expect(Registrant).to receive(:find).and_return(previous_registrant) + allow(domain).to receive(:registrant_verification_asked?).and_return(true) + allow(domain).to receive(:save) + end + + it 'sends notification email' do + expect(DomainMailer).to receive(:pending_deleted).with(domain: domain, registrant: previous_registrant).and_return(message) + expect(message).to receive(:deliver) + domain.pending_delete! + end + end end diff --git a/spec/routing/registrant/domain_delete_confirms_routing_spec.rb b/spec/routing/registrant/domain_delete_confirms_routing_spec.rb new file mode 100644 index 000000000..cf7691bb4 --- /dev/null +++ b/spec/routing/registrant/domain_delete_confirms_routing_spec.rb @@ -0,0 +1,9 @@ +require 'rails_helper' + +RSpec.describe Registrant::DomainDeleteConfirmsController do + describe 'routing' do + it 'routes to #show' do + expect(get: '/registrant/domain_delete_confirms/1').to route_to('registrant/domain_delete_confirms#show', id: '1') + end + end +end diff --git a/spec/views/mailers/domain_mailer/pending_deleted.html.erb_spec.rb b/spec/views/mailers/domain_mailer/pending_deleted.html.erb_spec.rb new file mode 100644 index 000000000..7d58f3146 --- /dev/null +++ b/spec/views/mailers/domain_mailer/pending_deleted.html.erb_spec.rb @@ -0,0 +1,41 @@ +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') + end + + it 'has domain name' do + mention_count = 1 * 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 + + 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 + end +end diff --git a/spec/views/mailers/domain_mailer/pending_deleted.text.erb_spec.rb b/spec/views/mailers/domain_mailer/pending_deleted.text.erb_spec.rb new file mode 100644 index 000000000..cc12bee64 --- /dev/null +++ b/spec/views/mailers/domain_mailer/pending_deleted.text.erb_spec.rb @@ -0,0 +1,41 @@ +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) + end + + it 'has domain name' do + mention_count = 1 * 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 + + 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 + end +end From 34c1e0d323acc527211f933fe6e1d9145af8cd60 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Thu, 3 Nov 2016 21:13:53 +0200 Subject: [PATCH 22/67] Fix "expiration" mailer #180 --- app/views/mailers/domain_mailer/expiration.html.erb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/mailers/domain_mailer/expiration.html.erb b/app/views/mailers/domain_mailer/expiration.html.erb index 9c1d925f2..69bda1627 100644 --- a/app/views/mailers/domain_mailer/expiration.html.erb +++ b/app/views/mailers/domain_mailer/expiration.html.erb @@ -42,8 +42,8 @@ Name servers: <%= @domain.nameserver_names %>

Registrar:
<%= @registrar.name %>
Email: <%= @registrar.email %>
-Telefon: <%= @registrar.phone %>
-Veebileht: <%= @registrar.url %>

+Phone: <%= @registrar.phone %>
+Website: <%= @registrar.url %>

You can find an overview of all your domains at the registrant's portal. <%= ENV['registrant_url'] %>.


From fc9104a232550a62d4cd6d1e15cff3eb62ec0d26 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Mon, 7 Nov 2016 02:22:03 +0200 Subject: [PATCH 23/67] Add extended registrar's info to "pending_update_request_for_old_registrant" mailer #180 --- app/mailers/domain_mailer.rb | 10 ++- app/presenters/registrant_presenter.rb | 10 +-- ...update_request_for_old_registrant.html.erb | 36 ++++++++--- ...update_request_for_old_registrant.text.erb | 30 ++++++--- config/locales/en.yml | 2 - config/locales/mailers/domain.en.yml | 2 + spec/mailers/domain_mailer_spec.rb | 43 +++++++++++++ spec/presenters/registrant_presenter_spec.rb | 7 +++ .../domain_update_confirms_routing_spec.rb | 9 +++ ...equest_for_old_registrant.html.erb_spec.rb | 61 +++++++++++++++++++ ...equest_for_old_registrant.text.erb_spec.rb | 61 +++++++++++++++++++ 11 files changed, 239 insertions(+), 32 deletions(-) create mode 100644 spec/routing/registrant/domain_update_confirms_routing_spec.rb create mode 100644 spec/views/mailers/domain_mailer/pending_update_request_for_old_registrant.html.erb_spec.rb create mode 100644 spec/views/mailers/domain_mailer/pending_update_request_for_old_registrant.text.erb_spec.rb diff --git a/app/mailers/domain_mailer.rb b/app/mailers/domain_mailer.rb index 06a18b426..b6cd9c309 100644 --- a/app/mailers/domain_mailer.rb +++ b/app/mailers/domain_mailer.rb @@ -1,8 +1,14 @@ class DomainMailer < ApplicationMailer include Que::Mailer - def pending_update_request_for_old_registrant(params) - compose_from(params) + def pending_update_request_for_old_registrant(domain:, registrant:) + @domain = DomainPresenter.new(domain: domain, view: view_context) + @registrar = RegistrarPresenter.new(registrar: domain.registrar, view: view_context) + @registrant = RegistrantPresenter.new(registrant: registrant, view: view_context) + @verification_url = registrant_domain_update_confirm_url(domain, token: domain.registrant_verification_token) + + subject = default_i18n_subject(domain_name: domain.name) + mail(to: registrant.email, subject: subject) end def pending_update_notification_for_new_registrant(params) diff --git a/app/presenters/registrant_presenter.rb b/app/presenters/registrant_presenter.rb index 67ae93d68..af523a29e 100644 --- a/app/presenters/registrant_presenter.rb +++ b/app/presenters/registrant_presenter.rb @@ -1,17 +1,11 @@ class RegistrantPresenter + delegate :name, :ident, :email, to: :registrant + def initialize(registrant:, view:) @registrant = registrant @view = view end - def name - registrant.name - end - - def ident - registrant.ident - end - private attr_reader :registrant diff --git a/app/views/mailers/domain_mailer/pending_update_request_for_old_registrant.html.erb b/app/views/mailers/domain_mailer/pending_update_request_for_old_registrant.html.erb index 9015a8945..4db2d2d9a 100644 --- a/app/views/mailers/domain_mailer/pending_update_request_for_old_registrant.html.erb +++ b/app/views/mailers/domain_mailer/pending_update_request_for_old_registrant.html.erb @@ -1,13 +1,21 @@ Tere

-Registrisse laekus taotlus domeeni <%= @params[:name] %> registreerija vahetuseks. Palun veenduge, et muudatus on korrektne ning probleemide korral pöörduge oma registripidaja <%= @params[:registrar_name] %> poole. +Registrisse laekus taotlus domeeni <%= @domain.name %> registreerija vahetuseks. Palun veenduge, et muudatus on korrektne ning probleemide korral pöörduge oma registripidaja poole: + +

+ <%= @registrar.name %>
+ Email: <%= @registrar.email %>
+ Telefon: <%= @registrar.phone %>
+ Veebileht: <%= @registrar.url %> +

+

Uue registreerija andmed:
-Nimi: <%= @params[:registrant_name] %>
+Nimi: <%= @registrant.name %>
<% if @params[:registrant_priv] %> -Isikukood: <%= @params[:registrant_ident] %>
+Isikukood: <%= @registrant.ident %>
<% else %> -Äriregistrikood: <%= @params[:registrant_ident] %>
+Äriregistrikood: <%= @registrant.ident %>
<% end %> Tänav: <%= @params[:registrant_street] %>
Linn: <%= @params[:registrant_city] %>
@@ -17,7 +25,7 @@ Taotlus on aktiivne <%= Setting.expire_pending_confirmation %> tundi ja lükatak

Muudatuse kinnitamiseks külastage palun allolevat lehekülge, kontrollige uuesti üle muudatuse andmed ning vajutage nuppu kinnitan:
-<%= link_to @params[:verification_url], @params[:verification_url] %> +<%= link_to @verification_url, @verification_url %>

Lugupidamisega
Eesti Interneti Sihtasutus @@ -26,14 +34,22 @@ Eesti Interneti Sihtasutus

Hi,

-Application for changing registrant of your domain <%= @params[:name] %> has been filed. Please make sure that the update and information are correct. Incase of problems please turn to your registrar. Your registrar is <%= @params[:registrar_name] %> +Application for changing registrant of your domain <%= @domain.name %> has been filed. Please make sure that the update and information are correct. Incase of problems please turn to your registrar: + +

+ <%= @registrar.name %>
+ Email: <%= @registrar.email %>
+ Phone: <%= @registrar.phone %>
+ Website: <%= @registrar.url %> +

+

New registrant:
-Name: <%= @params[:registrant_name] %>
+Name: <%= @registrant.name %>
<% if @params[:registrant_priv] %> -Personal code: <%= @params[:registrant_ident] %>
+Personal code: <%= @registrant.ident %>
<% else %> -Business Registry code: <%= @params[:registrant_ident] %>
+Business Registry code: <%= @registrant.ident %>
<% end %> Street: <%= @params[:registrant_street] %>
City: <%= @params[:registrant_city] %>
@@ -42,7 +58,7 @@ Country: <%= @params[:registrant_country] %> The application will remain in pending status for <%= Setting.expire_pending_confirmation %> hrs and will be automaticcally rejected if it is not approved nor rejected before.

To confirm the update please visit this website, once again review the data and press approve:
-<%= link_to @params[:verification_url], @params[:verification_url] %> +<%= link_to @verification_url, @verification_url %>

Best Regards,
Estonian Internet Foundation diff --git a/app/views/mailers/domain_mailer/pending_update_request_for_old_registrant.text.erb b/app/views/mailers/domain_mailer/pending_update_request_for_old_registrant.text.erb index d2ee28479..863ef9fa4 100644 --- a/app/views/mailers/domain_mailer/pending_update_request_for_old_registrant.text.erb +++ b/app/views/mailers/domain_mailer/pending_update_request_for_old_registrant.text.erb @@ -1,13 +1,18 @@ Tere -Registrisse laekus taotlus domeeni <%= @params[:name] %> registreerija vahetuseks. Palun veenduge, et muudatus on korrektne ning probleemide korral pöörduge oma registripidaja <%= @params[:registrar_name] %> poole. +Registrisse laekus taotlus domeeni <%= @domain.name %> registreerija vahetuseks. Palun veenduge, et muudatus on korrektne ning probleemide korral pöörduge oma registripidaja poole: + +<%= @registrar.name %> +Email: <%= @registrar.email %> +Telefon: <%= @registrar.phone %> +Veebileht: <%= @registrar.url %> Uue registreerija andmed: -Nimi: <%= @params[:registrant_name] %> +Nimi: <%= @registrant.name %> <% if @params[:registrant_priv] %> -Isikukood: <%= @params[:registrant_ident] %> + Isikukood: <%= @registrant.ident %> <% else %> -Äriregistrikood: <%= @params[:registrant_ident] %> + Äriregistrikood: <%= @registrant.ident %> <% end %> Tänav: <%= @params[:registrant_street] %> Linn: <%= @params[:registrant_city] %> @@ -15,7 +20,7 @@ Riik: <%= @params[:registrant_country] %> Taotlus on aktiivne <%= Setting.expire_pending_confirmation %> tundi ja lükatakse automaatselt tagasi kui te seda enne ei kinnita või tagasi lükka. Muudatuse kinnitamiseks külastage palun allolevat lehekülge, kontrollige uuesti üle muudatuse andmed ning vajutage nuppu kinnitan: -<%= @params[:verification_url] %> +<%= @verification_url %> Lugupidamisega Eesti Interneti Sihtasutus @@ -24,14 +29,19 @@ Eesti Interneti Sihtasutus Hi, -Application for changing registrant of your domain <%= @params[:name] %> has been filed. Please make sure that the update and information are correct. Incase of problems please turn to your registrar. Your registrar is <%= @params[:registrar_name] %> +Application for changing registrant of your domain <%= @domain.name %> has been filed. Please make sure that the update and information are correct. In case of problems please turn to your registrar: + +<%= @registrar.name %> +Email: <%= @registrar.email %> +Phone: <%= @registrar.phone %> +Website: <%= @registrar.url %> New registrant: -Name: <%= @params[:registrant_name] %> +Name: <%= @registrant.name %> <% if @params[:registrant_priv] %> -Personal code: <%= @params[:registrant_ident] %> + Personal code: <%= @registrant.ident %> <% else %> -Business Registry code: <%= @params[:registrant_ident] %> + Business Registry code: <%= @registrant.ident %> <% end %> Street: <%= @params[:registrant_street] %> City: <%= @params[:registrant_city] %> @@ -39,7 +49,7 @@ Country: <%= @params[:registrant_country] %> The application will remain in pending status for <%= Setting.expire_pending_confirmation %> hrs and will be automaticcally rejected if it is not approved nor rejected before. To confirm the update please visit this website, once again review the data and press approve: -<%= @params[:verification_url] %> +<%= @verification_url %> Best Regards, Estonian Internet Foundation diff --git a/config/locales/en.yml b/config/locales/en.yml index cbc61b29c..725dfffc3 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -339,7 +339,6 @@ en: contact_details: 'Contact details' ident: 'Ident' ident_type: 'Ident type' - address: 'Address' country: 'Country' city: 'City' street: 'Street' @@ -797,7 +796,6 @@ en: unimplemented_object_service: 'Unimplemented object service' contact_email_update_subject: 'Teie domeenide kontakt epostiaadress on muutunud / Contact e-mail addresses of your domains have changed' object_status_prohibits_operation: 'Object status prohibits operation' - pending_update_request_for_old_registrant_subject: "Kinnitustaotlus domeeni %{name} registreerija vahetuseks / Application for approval for registrant change of %{name}" pending_update_notification_for_new_registrant_subject: "Domeeni %{name} registreerija vahetus protseduur on algatatud / %{name} registrant change" pending_update_rejected_notification_for_new_registrant_subject: "Domeeni %{name} registreerija vahetuse taotlus tagasi lükatud / %{name} registrant change declined" pending_update_expired_notification_for_new_registrant_subject: "Domeeni %{name} registreerija vahetuse taotlus on tühistatud / %{name} registrant change cancelled" diff --git a/config/locales/mailers/domain.en.yml b/config/locales/mailers/domain.en.yml index c28ba6b00..f0d021f68 100644 --- a/config/locales/mailers/domain.en.yml +++ b/config/locales/mailers/domain.en.yml @@ -1,5 +1,7 @@ en: domain_mailer: + pending_update_request_for_old_registrant: + subject: Kinnitustaotlus domeeni %{domain_name} registreerija vahetuseks / Application for approval for registrant change of %{domain_name} expiration: subject: The %{domain_name} domain has expired force_delete: diff --git a/spec/mailers/domain_mailer_spec.rb b/spec/mailers/domain_mailer_spec.rb index 1edc35f6a..2363d57ea 100644 --- a/spec/mailers/domain_mailer_spec.rb +++ b/spec/mailers/domain_mailer_spec.rb @@ -1,6 +1,49 @@ require 'rails_helper' RSpec.describe DomainMailer do + describe '#pending_update_request_for_old_registrant' do + let(:domain) { instance_spy(Domain, name: 'test.com') } + let(:registrant) { instance_spy(Registrant, email: 'registrant@test.com') } + let(:domain_presenter) { instance_spy(DomainPresenter) } + let(:registrar_presenter) { instance_spy(RegistrarPresenter) } + let(:registrant_presenter) { instance_spy(RegistrantPresenter) } + subject(:message) { described_class.pending_update_request_for_old_registrant(domain: domain, + registrant: registrant, + ) } + + before :example do + expect(DomainPresenter).to receive(:new).and_return(domain_presenter) + expect(RegistrarPresenter).to receive(:new).and_return(registrar_presenter) + expect(RegistrantPresenter).to receive(:new).and_return(registrant_presenter) + end + + it 'has sender' do + expect(message.from).to eq(['noreply@internet.ee']) + end + + it 'has registrant email as a recipient' do + expect(message.to).to match_array(['registrant@test.com']) + end + + it 'has subject' do + subject = 'Kinnitustaotlus domeeni test.com registreerija vahetuseks' \ + ' / Application for approval for registrant change of test.com' + + expect(message.subject).to eq(subject) + end + + it 'has confirmation url' do + allow(domain).to receive(:id).and_return(1) + expect(domain).to receive(:registrant_verification_token).and_return('test') + url = registrant_domain_update_confirm_url(domain, token: 'test') + expect(message.body.parts.first.decoded).to include(url) + end + + it 'sends message' do + expect { message.deliver! }.to change { ActionMailer::Base.deliveries.count }.by(1) + end + end + describe '#pending_deleted' do let(:domain) { instance_spy(Domain, name: 'test.com') } let(:registrant) { instance_spy(Registrant, email: 'registrant@test.com') } diff --git a/spec/presenters/registrant_presenter_spec.rb b/spec/presenters/registrant_presenter_spec.rb index 0cec65ff6..7e29196de 100644 --- a/spec/presenters/registrant_presenter_spec.rb +++ b/spec/presenters/registrant_presenter_spec.rb @@ -17,4 +17,11 @@ RSpec.describe RegistrantPresenter do expect(presenter.ident).to eq('test ident') end end + + describe '#email' do + it 'returns email' do + expect(registrant).to receive(:email).and_return('test email') + expect(presenter.email).to eq('test email') + end + end end diff --git a/spec/routing/registrant/domain_update_confirms_routing_spec.rb b/spec/routing/registrant/domain_update_confirms_routing_spec.rb new file mode 100644 index 000000000..9bc98c391 --- /dev/null +++ b/spec/routing/registrant/domain_update_confirms_routing_spec.rb @@ -0,0 +1,9 @@ +require 'rails_helper' + +RSpec.describe Registrant::DomainUpdateConfirmsController do + describe 'routing' do + it 'routes to #show' do + expect(get: '/registrant/domain_update_confirms/1').to route_to('registrant/domain_update_confirms#show', id: '1') + end + end +end diff --git a/spec/views/mailers/domain_mailer/pending_update_request_for_old_registrant.html.erb_spec.rb b/spec/views/mailers/domain_mailer/pending_update_request_for_old_registrant.html.erb_spec.rb new file mode 100644 index 000000000..36a426bac --- /dev/null +++ b/spec/views/mailers/domain_mailer/pending_update_request_for_old_registrant.html.erb_spec.rb @@ -0,0 +1,61 @@ +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') + 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 + end + + domain_attributes = %i( + name + ) + + 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) + render + expect(rendered).to have_text(attr_name.to_s, count: lang_count) + end + end + + registrant_attributes = %i( + name + ident + ) + + 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 diff --git a/spec/views/mailers/domain_mailer/pending_update_request_for_old_registrant.text.erb_spec.rb b/spec/views/mailers/domain_mailer/pending_update_request_for_old_registrant.text.erb_spec.rb new file mode 100644 index 000000000..da9765873 --- /dev/null +++ b/spec/views/mailers/domain_mailer/pending_update_request_for_old_registrant.text.erb_spec.rb @@ -0,0 +1,61 @@ +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') + 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 + end + + domain_attributes = %i( + name + ) + + 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) + render + expect(rendered).to have_text(attr_name.to_s, count: lang_count) + end + end + + registrant_attributes = %i( + name + ident + ) + + 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 From 4fd18c4a26fc67c4adb836eb1a3102405d3e05e4 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Mon, 7 Nov 2016 14:40:25 +0200 Subject: [PATCH 24/67] Revert e53980e and 7cdfa10 #180 --- app/models/domain.rb | 8 ++++++++ app/models/epp/domain.rb | 3 --- config/environments/test.rb | 2 ++ spec/models/epp/domain_spec.rb | 34 ---------------------------------- 4 files changed, 10 insertions(+), 37 deletions(-) delete mode 100644 spec/models/epp/domain_spec.rb diff --git a/app/models/domain.rb b/app/models/domain.rb index 9960b12a0..1ea6d0b98 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -78,6 +78,7 @@ class Domain < ActiveRecord::Base end before_create :generate_auth_info + before_create :set_validity_dates before_create -> { self.reserved = in_reserved_list?; nil } before_save :manage_automatic_statuses @@ -532,6 +533,13 @@ class Domain < ActiveRecord::Base end # rubocop:enable Lint/Loop + def set_validity_dates + self.registered_at = Time.zone.now + self.valid_from = Time.zone.now + # we need + 1 day as this is more correct from juridical side + self.valid_to = valid_from.utc.beginning_of_day + self.class.convert_period_to_time(period, period_unit) + 1.day + end + # rubocop:disable Metrics/AbcSize # rubocop:disable Metrics/MethodLength def set_force_delete diff --git a/app/models/epp/domain.rb b/app/models/epp/domain.rb index 2441555c1..61ee6a2d8 100644 --- a/app/models/epp/domain.rb +++ b/app/models/epp/domain.rb @@ -51,9 +51,6 @@ class Epp::Domain < Domain class << self def new_from_epp(frame, current_user) domain = Epp::Domain.new - domain.registered_at = Time.zone.now - domain.valid_from = Time.zone.now - domain.expire_time = domain.valid_from.beginning_of_day + convert_period_to_time(domain.period, domain.period_unit) + 1.day domain.attributes = domain.attrs_from(frame, current_user) domain.attach_default_contacts domain diff --git a/config/environments/test.rb b/config/environments/test.rb index 9f6a888d1..4e0b47bcb 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -36,6 +36,8 @@ Rails.application.configure do # For rails-settings-cached conflict config.cache_store = :file_store, 'tmp/cache_test' + config.time_zone = 'UTC' + config.action_view.raise_on_missing_translations = true # The available log levels are: :debug, :info, :warn, :error, :fatal, and :unknown, diff --git a/spec/models/epp/domain_spec.rb b/spec/models/epp/domain_spec.rb deleted file mode 100644 index 4b91b8947..000000000 --- a/spec/models/epp/domain_spec.rb +++ /dev/null @@ -1,34 +0,0 @@ -require 'rails_helper' - -RSpec.describe Epp::Domain, db: false do - describe '::new_from_epp' do - let(:domain_blueprint) { described_class.new } - subject(:domain) { described_class.new_from_epp(nil, nil) } - - before :example do - travel_to Time.zone.parse('05.07.2010') - - domain_blueprint.period = 1 - domain_blueprint.period_unit = 'y' - - expect(described_class).to receive(:new).and_return(domain_blueprint) - expect(domain_blueprint).to receive(:attrs_from).and_return({}) - expect(domain_blueprint).to receive(:attach_default_contacts) - end - - describe 'domain' do - it 'has :registered_at set to now' do - expect(domain.registered_at).to eq(Time.zone.parse('05.07.2010')) - end - - it 'has :valid_from set to now' do - expect(domain.valid_from).to eq(Time.zone.parse('05.07.2010')) - end - - it 'has :expire_time set to now' do - expire_time = Time.zone.parse('05.07.2010') + 1.year + 1.day - expect(domain.expire_time).to eq(expire_time) - end - end - end -end From e653d8b56e84f6583e75de96a39f07b058980313 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Mon, 7 Nov 2016 23:12:19 +0200 Subject: [PATCH 25/67] Extract expirable concern from domain model #238 --- app/models/concerns/domain/expirable.rb | 31 +++++++++ app/models/domain.rb | 18 ++--- app/models/domain_cron.rb | 2 +- spec/models/concerns/domain/expirable_spec.rb | 65 +++++++++++++++++++ 4 files changed, 102 insertions(+), 14 deletions(-) create mode 100644 app/models/concerns/domain/expirable.rb create mode 100644 spec/models/concerns/domain/expirable_spec.rb diff --git a/app/models/concerns/domain/expirable.rb b/app/models/concerns/domain/expirable.rb new file mode 100644 index 000000000..abfeed400 --- /dev/null +++ b/app/models/concerns/domain/expirable.rb @@ -0,0 +1,31 @@ +module Concerns::Domain::Expirable + extend ActiveSupport::Concern + + included do + alias_attribute :expire_time, :valid_to + end + + class_methods do + def expired + where("#{attribute_alias(:expire_time)} < ?", Time.zone.now) + end + end + + def registered? + !expired? + end + + def expired? + expire_time.past? + end + + def expirable? + return false if expire_time > Time.zone.now + + if statuses.include?(DomainStatus::EXPIRED) && outzone_at.present? && delete_at.present? + return false + end + + true + end +end diff --git a/app/models/domain.rb b/app/models/domain.rb index 0b3f6cdea..479a3d453 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -3,6 +3,8 @@ class Domain < ActiveRecord::Base include UserEvents include Versions # version/domain_version.rb include Statuses + include Concerns::Domain::Expirable + has_paper_trail class_name: "DomainVersion", meta: { children: :children_log } attr_accessor :roles @@ -284,16 +286,6 @@ class Domain < ActiveRecord::Base domain_transfers.find_by(status: DomainTransfer::PENDING) end - def expirable? - return false if valid_to > Time.zone.now - - if statuses.include?(DomainStatus::EXPIRED) && outzone_at.present? && delete_at.present? - return false - end - - true - end - def server_holdable? return false if statuses.include?(DomainStatus::SERVER_HOLD) return false if statuses.include?(DomainStatus::SERVER_MANUAL_INZONE) @@ -310,7 +302,7 @@ class Domain < ActiveRecord::Base def renewable? if Setting.days_to_renew_domain_before_expire != 0 # if you can renew domain at days_to_renew before domain expiration - if (valid_to.to_date - Date.today) + 1 > Setting.days_to_renew_domain_before_expire + if (expire_time.to_date - Date.today) + 1 > Setting.days_to_renew_domain_before_expire return false end end @@ -597,7 +589,7 @@ class Domain < ActiveRecord::Base end def set_graceful_expired - self.outzone_at = valid_to + self.class.expire_warning_period + self.outzone_at = expire_time + self.class.expire_warning_period self.delete_at = outzone_at + self.class.redemption_grace_period self.statuses |= [DomainStatus::EXPIRED] end @@ -627,7 +619,7 @@ class Domain < ActiveRecord::Base when DomainStatus::SERVER_MANUAL_INZONE # removal causes server hold to set self.outzone_at = Time.zone.now if self.force_delete_at.present? when DomainStatus::DomainStatus::EXPIRED # removal causes server hold to set - self.outzone_at = self.valid_to + 15.day + self.outzone_at = self.expire_time + 15.day when DomainStatus::DomainStatus::SERVER_HOLD # removal causes server hold to set self.outzone_at = nil end diff --git a/app/models/domain_cron.rb b/app/models/domain_cron.rb index 549e3b1da..dd1faa10e 100644 --- a/app/models/domain_cron.rb +++ b/app/models/domain_cron.rb @@ -35,7 +35,7 @@ class DomainCron STDOUT << "#{Time.zone.now.utc} - Expiring domains\n" unless Rails.env.test? ::PaperTrail.whodunnit = "cron - #{__method__}" - domains = Domain.where('valid_to <= ?', Time.zone.now) + domains = Domain.expired marked = 0 real = 0 domains.each do |domain| diff --git a/spec/models/concerns/domain/expirable_spec.rb b/spec/models/concerns/domain/expirable_spec.rb new file mode 100644 index 000000000..4f29354f6 --- /dev/null +++ b/spec/models/concerns/domain/expirable_spec.rb @@ -0,0 +1,65 @@ +require 'rails_helper' + +RSpec.describe Domain, db: false do + it { is_expected.to alias_attribute(:expire_time, :valid_to) } + + describe '::expired', db: true do + before :example do + travel_to Time.zone.parse('05.07.2010 00:00') + + Fabricate(:zonefile_setting, origin: 'ee') + + Fabricate.create(:domain, id: 1, expire_time: Time.zone.parse('04.07.2010 23:59')) + Fabricate.create(:domain, id: 2, expire_time: Time.zone.parse('05.07.2010 00:00')) + Fabricate.create(:domain, id: 3, expire_time: Time.zone.parse('05.07.2010 00:01')) + end + + it 'returns expired domains' do + expect(described_class.expired.ids).to eq([1]) + end + end + + describe '#registered?' do + let(:domain) { described_class.new } + + context 'when not expired' do + before :example do + expect(domain).to receive(:expired?).and_return(false) + end + + specify { expect(domain).to be_registered } + end + + context 'when expired' do + before :example do + expect(domain).to receive(:expired?).and_return(true) + end + + specify { expect(domain).to_not be_registered } + end + end + + describe '#expired?' do + before :example do + travel_to Time.zone.parse('05.07.2010 00:00') + end + + context 'when :expire_time is in the past' do + let(:domain) { described_class.new(expire_time: Time.zone.parse('04.07.2010 23:59')) } + + specify { expect(domain).to be_expired } + end + + context 'when :expire_time is now' do + let(:domain) { described_class.new(expire_time: Time.zone.parse('05.07.2010 00:00')) } + + specify { expect(domain).to_not be_expired } + end + + context 'when :expire_time is in the future' do + let(:domain) { described_class.new(expire_time: Time.zone.parse('05.07.2010 00:01')) } + + specify { expect(domain).to_not be_expired } + end + end +end From aa29c781f62e7b6bc396056ba3ee03706fca5331 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Tue, 8 Nov 2016 02:30:20 +0200 Subject: [PATCH 26/67] Improve domain's outzone and delete logic - Encapsulate outzone and delete candidate logic into domain model - Fix the logic itself Fixes #238 --- app/models/domain.rb | 11 +++++++++++ app/models/domain_cron.rb | 20 ++++++++++++-------- spec/models/domain_spec.rb | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+), 8 deletions(-) diff --git a/app/models/domain.rb b/app/models/domain.rb index 479a3d453..ffe1d94c7 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -11,6 +11,9 @@ class Domain < ActiveRecord::Base attr_accessor :legal_document_id + alias_attribute :outzone_time, :outzone_at + alias_attribute :delete_time, :delete_at + # TODO: whois requests ip whitelist for full info for own domains and partial info for other domains # TODO: most inputs should be trimmed before validatation, probably some global logic? @@ -739,5 +742,13 @@ class Domain < ActiveRecord::Base def self.redemption_grace_period Setting.redemption_grace_period.days end + + def self.outzone_candidates + where("#{attribute_alias(:outzone_time)} < ?", Time.zone.now) + end + + def self.delete_candidates + where("#{attribute_alias(:delete_time)} < ?", Time.zone.now) + end end # rubocop: enable Metrics/ClassLength diff --git a/app/models/domain_cron.rb b/app/models/domain_cron.rb index dd1faa10e..4f60407cd 100644 --- a/app/models/domain_cron.rb +++ b/app/models/domain_cron.rb @@ -53,10 +53,12 @@ class DomainCron STDOUT << "#{Time.zone.now.utc} - Setting server_hold to domains\n" unless Rails.env.test? ::PaperTrail.whodunnit = "cron - #{__method__}" - d = Domain.where('outzone_at <= ?', Time.zone.now) + + domains = Domain.outzone_candidates marked = 0 real = 0 - d.each do |domain| + + domains.each do |domain| next unless domain.server_holdable? real += 1 domain.statuses << DomainStatus::SERVER_HOLD @@ -96,16 +98,18 @@ class DomainCron c = 0 - Domain.where('delete_at <= ?', Time.zone.now.end_of_day.utc).each do |x| - next unless x.delete_candidateable? + domains = Domain.delete_candidates - x.statuses << DomainStatus::DELETE_CANDIDATE + domains.each do |domain| + next unless domain.delete_candidateable? + + domain.statuses << DomainStatus::DELETE_CANDIDATE # If domain successfully saved, add it to delete schedule - if x.save(validate: false) + if domain.save(validate: false) ::PaperTrail.whodunnit = "cron - #{__method__}" - DomainDeleteJob.enqueue(x.id, run_at: rand(((24*60) - (DateTime.now.hour * 60 + DateTime.now.minute))).minutes.from_now) - STDOUT << "#{Time.zone.now.utc} Domain.destroy_delete_candidates: job added by deleteCandidate status ##{x.id} (#{x.name})\n" unless Rails.env.test? + DomainDeleteJob.enqueue(domain.id, run_at: rand(((24*60) - (DateTime.now.hour * 60 + DateTime.now.minute))).minutes.from_now) + STDOUT << "#{Time.zone.now.utc} Domain.destroy_delete_candidates: job added by deleteCandidate status ##{domain.id} (#{domain.name})\n" unless Rails.env.test? c += 1 end end diff --git a/spec/models/domain_spec.rb b/spec/models/domain_spec.rb index 9560f7505..521983e1d 100644 --- a/spec/models/domain_spec.rb +++ b/spec/models/domain_spec.rb @@ -826,6 +826,9 @@ RSpec.describe Domain do end RSpec.describe Domain, db: false do + it { is_expected.to alias_attribute(:outzone_time, :outzone_at) } + it { is_expected.to alias_attribute(:delete_time, :delete_at) } + describe '::expire_warning_period', db: true do before :example do Setting.expire_warning_period = 1 @@ -882,4 +885,36 @@ RSpec.describe Domain, db: false do expect(domain.delete_at).to eq(Time.zone.parse('08.07.2010 10:30')) end end + + describe '::outzone_candidates', db: true do + before :example do + travel_to Time.zone.parse('05.07.2010 00:00') + + Fabricate(:zonefile_setting, origin: 'ee') + + Fabricate.create(:domain, id: 1, outzone_time: Time.zone.parse('04.07.2010 23:59')) + Fabricate.create(:domain, id: 2, outzone_time: Time.zone.parse('05.07.2010 00:00')) + Fabricate.create(:domain, id: 3, outzone_time: Time.zone.parse('05.07.2010 00:01')) + end + + it 'returns domains with outzone time in the past' do + expect(described_class.outzone_candidates.ids).to eq([1]) + end + end + + describe '::delete_candidates', db: true do + before :example do + travel_to Time.zone.parse('05.07.2010 00:00') + + Fabricate(:zonefile_setting, origin: 'ee') + + Fabricate.create(:domain, id: 1, delete_time: Time.zone.parse('04.07.2010 23:59')) + Fabricate.create(:domain, id: 2, delete_time: Time.zone.parse('05.07.2010 00:00')) + Fabricate.create(:domain, id: 3, delete_time: Time.zone.parse('05.07.2010 00:01')) + end + + it 'returns domains with delete time in the past' do + expect(described_class.delete_candidates.ids).to eq([1]) + end + end end From 877e6999dc65d90a3429e68b14d1b87597b44a8d Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Tue, 8 Nov 2016 10:07:41 +0200 Subject: [PATCH 27/67] Consider domains having current time at "expire_time" attribute expired Fixes #238 --- app/models/concerns/domain/expirable.rb | 4 ++-- spec/models/concerns/domain/expirable_spec.rb | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/models/concerns/domain/expirable.rb b/app/models/concerns/domain/expirable.rb index abfeed400..be1928826 100644 --- a/app/models/concerns/domain/expirable.rb +++ b/app/models/concerns/domain/expirable.rb @@ -7,7 +7,7 @@ module Concerns::Domain::Expirable class_methods do def expired - where("#{attribute_alias(:expire_time)} < ?", Time.zone.now) + where("#{attribute_alias(:expire_time)} <= ?", Time.zone.now) end end @@ -16,7 +16,7 @@ module Concerns::Domain::Expirable end def expired? - expire_time.past? + expire_time <= Time.zone.now end def expirable? diff --git a/spec/models/concerns/domain/expirable_spec.rb b/spec/models/concerns/domain/expirable_spec.rb index 4f29354f6..2a2c9b9cf 100644 --- a/spec/models/concerns/domain/expirable_spec.rb +++ b/spec/models/concerns/domain/expirable_spec.rb @@ -15,7 +15,7 @@ RSpec.describe Domain, db: false do end it 'returns expired domains' do - expect(described_class.expired.ids).to eq([1]) + expect(described_class.expired.ids).to eq([1, 2]) end end @@ -53,7 +53,7 @@ RSpec.describe Domain, db: false do context 'when :expire_time is now' do let(:domain) { described_class.new(expire_time: Time.zone.parse('05.07.2010 00:00')) } - specify { expect(domain).to_not be_expired } + specify { expect(domain).to be_expired } end context 'when :expire_time is in the future' do From 3b120f0362db17d684964edfc18c544f2c38a6a5 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Tue, 8 Nov 2016 12:26:04 +0200 Subject: [PATCH 28/67] Revert domain expirable #186 --- app/models/concerns/domain/expirable.rb | 31 --------- app/models/domain.rb | 12 +++- spec/models/concerns/domain/expirable_spec.rb | 63 ------------------- 3 files changed, 10 insertions(+), 96 deletions(-) delete mode 100644 app/models/concerns/domain/expirable.rb delete mode 100644 spec/models/concerns/domain/expirable_spec.rb diff --git a/app/models/concerns/domain/expirable.rb b/app/models/concerns/domain/expirable.rb deleted file mode 100644 index 5c9afdc95..000000000 --- a/app/models/concerns/domain/expirable.rb +++ /dev/null @@ -1,31 +0,0 @@ -module Concerns::Domain::Expirable - extend ActiveSupport::Concern - - included do - alias_attribute :expire_time, :valid_to - end - - class_methods do - def expired - where("#{attribute_alias(:expire_time)} <= ?", Time.zone.now) - end - end - - def registered? - !expired? - end - - def expired? - expire_time <= Time.zone.now - end - - def expirable? - return false if valid_to > Time.zone.now - - if statuses.include?(DomainStatus::EXPIRED) && outzone_at.present? && delete_at.present? - return false - end - - true - end -end diff --git a/app/models/domain.rb b/app/models/domain.rb index 1ea6d0b98..ee22e2ed0 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -3,7 +3,6 @@ class Domain < ActiveRecord::Base include UserEvents include Versions # version/domain_version.rb include Statuses - include Concerns::Domain::Expirable has_paper_trail class_name: "DomainVersion", meta: { children: :children_log } attr_accessor :roles @@ -11,7 +10,6 @@ class Domain < ActiveRecord::Base attr_accessor :legal_document_id alias_attribute :on_hold_time, :outzone_at - alias_attribute :delete_time, :delete_at alias_attribute :force_delete_time, :force_delete_at # TODO: whois requests ip whitelist for full info for own domains and partial info for other domains @@ -285,6 +283,16 @@ class Domain < ActiveRecord::Base domain_transfers.find_by(status: DomainTransfer::PENDING) end + def expirable? + return false if valid_to > Time.zone.now + + if statuses.include?(DomainStatus::EXPIRED) && outzone_at.present? && delete_at.present? + return false + end + + true + end + def server_holdable? return false if statuses.include?(DomainStatus::SERVER_HOLD) return false if statuses.include?(DomainStatus::SERVER_MANUAL_INZONE) diff --git a/spec/models/concerns/domain/expirable_spec.rb b/spec/models/concerns/domain/expirable_spec.rb deleted file mode 100644 index f7d78f80b..000000000 --- a/spec/models/concerns/domain/expirable_spec.rb +++ /dev/null @@ -1,63 +0,0 @@ -require 'rails_helper' - -RSpec.describe Domain, db: false do - it { is_expected.to alias_attribute(:expire_time, :valid_to) } - - describe '::expired', db: true do - before :example do - travel_to Time.zone.parse('05.07.2010 00:00') - - FactoryGirl.create(:domain, id: 1, expire_time: Time.zone.parse('04.07.2010 23:59')) - FactoryGirl.create(:domain, id: 2, expire_time: Time.zone.parse('05.07.2010 00:00')) - FactoryGirl.create(:domain, id: 3, expire_time: Time.zone.parse('05.07.2010 00:01')) - end - - it 'returns expired domains' do - expect(described_class.expired.ids).to eq([1, 2]) - end - end - - describe '#registered?' do - let(:domain) { described_class.new } - - context 'when not expired' do - before :example do - expect(domain).to receive(:expired?).and_return(false) - end - - specify { expect(domain).to be_registered } - end - - context 'when expired' do - before :example do - expect(domain).to receive(:expired?).and_return(true) - end - - specify { expect(domain).to_not be_registered } - end - end - - describe '#expired?' do - before :example do - travel_to Time.zone.parse('05.07.2010 00:00') - end - - context 'when :expire_time is in the past' do - let(:domain) { described_class.new(expire_time: Time.zone.parse('04.07.2010 23:59')) } - - specify { expect(domain).to be_expired } - end - - context 'when :expire_time is now' do - let(:domain) { described_class.new(expire_time: Time.zone.parse('05.07.2010 00:00')) } - - specify { expect(domain).to be_expired } - end - - context 'when :expire_time is in the future' do - let(:domain) { described_class.new(expire_time: Time.zone.parse('05.07.2010 00:01')) } - - specify { expect(domain).to_not be_expired } - end - end -end From 0c6c5831845f008a25d17101323457de54f7b635 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Tue, 8 Nov 2016 12:32:02 +0200 Subject: [PATCH 29/67] Revert domain expirable #186 --- app/models/domain_cron.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/app/models/domain_cron.rb b/app/models/domain_cron.rb index 84e9b6640..8b2891e3b 100644 --- a/app/models/domain_cron.rb +++ b/app/models/domain_cron.rb @@ -35,11 +35,9 @@ class DomainCron Rails.logger.info('Expiring domains') ::PaperTrail.whodunnit = "cron - #{__method__}" - - domains = Domain.expired + domains = Domain.where('valid_to <= ?', Time.zone.now) marked = 0 real = 0 - domains.each do |domain| next unless domain.expirable? real += 1 From 820dfebfbfbe5f6e772ca2e21ea670c08e6a8c2e Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Tue, 8 Nov 2016 13:46:54 +0200 Subject: [PATCH 30/67] Revert domain spec #186 --- spec/models/domain_spec.rb | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/spec/models/domain_spec.rb b/spec/models/domain_spec.rb index a85effbcf..22b3dd5a2 100644 --- a/spec/models/domain_spec.rb +++ b/spec/models/domain_spec.rb @@ -350,17 +350,6 @@ RSpec.describe Domain do @domain.statuses.include?(DomainStatus::SERVER_HOLD).should == true end - - it 'should set expired status and update outzone_at and delete_at' do - domain = Fabricate(:domain) - domain.statuses.should == ['ok'] - domain.set_expired - domain.changes.keys.should == ['statuses', 'outzone_at', 'delete_at'] - domain.save - - domain.statuses.should == ['expired'] - end - it 'should set pending update' do @domain.statuses = DomainStatus::OK # restore @domain.save From ccb062cb0bff770617b20d1fd6abbc9c58d2ecb1 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Wed, 9 Nov 2016 04:26:35 +0200 Subject: [PATCH 31/67] Update "pending_update_request_for_old_registrant" mailer #180 --- app/presenters/registrant_presenter.rb | 2 +- .../pending_update_request_for_old_registrant.html.erb | 10 +++++----- .../pending_update_request_for_old_registrant.text.erb | 6 +++--- spec/presenters/registrant_presenter_spec.rb | 7 +++++++ 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/app/presenters/registrant_presenter.rb b/app/presenters/registrant_presenter.rb index af523a29e..69dffddfc 100644 --- a/app/presenters/registrant_presenter.rb +++ b/app/presenters/registrant_presenter.rb @@ -1,5 +1,5 @@ class RegistrantPresenter - delegate :name, :ident, :email, to: :registrant + delegate :name, :ident, :email, :priv?, to: :registrant def initialize(registrant:, view:) @registrant = registrant diff --git a/app/views/mailers/domain_mailer/pending_update_request_for_old_registrant.html.erb b/app/views/mailers/domain_mailer/pending_update_request_for_old_registrant.html.erb index 4db2d2d9a..37081076c 100644 --- a/app/views/mailers/domain_mailer/pending_update_request_for_old_registrant.html.erb +++ b/app/views/mailers/domain_mailer/pending_update_request_for_old_registrant.html.erb @@ -12,13 +12,13 @@ Registrisse laekus taotlus domeeni <%= @domain.name %> registreerija vahetuseks.

Uue registreerija andmed:
Nimi: <%= @registrant.name %>
-<% if @params[:registrant_priv] %> -Isikukood: <%= @registrant.ident %>
+<% if @registrant.priv? %> + Isikukood: <%= @registrant.ident %>
<% else %> -Äriregistrikood: <%= @registrant.ident %>
+ Äriregistrikood: <%= @registrant.ident %>
<% end %> -Tänav: <%= @params[:registrant_street] %>
-Linn: <%= @params[:registrant_city] %>
+Tänav: <%= @registrant.street %>
+Linn: <%= @registrant.city %>
Riik: <%= @params[:registrant_country] %>

Taotlus on aktiivne <%= Setting.expire_pending_confirmation %> tundi ja lükatakse automaatselt tagasi kui te seda enne ei kinnita või tagasi lükka. diff --git a/app/views/mailers/domain_mailer/pending_update_request_for_old_registrant.text.erb b/app/views/mailers/domain_mailer/pending_update_request_for_old_registrant.text.erb index 863ef9fa4..5cbb47b7c 100644 --- a/app/views/mailers/domain_mailer/pending_update_request_for_old_registrant.text.erb +++ b/app/views/mailers/domain_mailer/pending_update_request_for_old_registrant.text.erb @@ -9,13 +9,13 @@ Veebileht: <%= @registrar.url %> Uue registreerija andmed: Nimi: <%= @registrant.name %> -<% if @params[:registrant_priv] %> +<% if @registrant.priv? %> Isikukood: <%= @registrant.ident %> <% else %> Äriregistrikood: <%= @registrant.ident %> <% end %> -Tänav: <%= @params[:registrant_street] %> -Linn: <%= @params[:registrant_city] %> +Tänav: <%= @registrant.street %> +Linn: <%= @registrant.city %> Riik: <%= @params[:registrant_country] %> Taotlus on aktiivne <%= Setting.expire_pending_confirmation %> tundi ja lükatakse automaatselt tagasi kui te seda enne ei kinnita või tagasi lükka. diff --git a/spec/presenters/registrant_presenter_spec.rb b/spec/presenters/registrant_presenter_spec.rb index 7e29196de..014dbd54d 100644 --- a/spec/presenters/registrant_presenter_spec.rb +++ b/spec/presenters/registrant_presenter_spec.rb @@ -24,4 +24,11 @@ RSpec.describe RegistrantPresenter do expect(presenter.email).to eq('test email') end end + + describe '#priv?' do + it 'delegates to registrant' do + expect(registrant).to receive(:priv?).and_return('test') + expect(presenter.priv?).to eq('test') + end + end end From d0b7168d32eecf6604fa06427f16233141c03a6c Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Thu, 10 Nov 2016 00:52:16 +0200 Subject: [PATCH 32/67] Revert "Load all translation files from config/locales" This reverts commit 8c474b24650f34528de10f03dcdf70d314acbf8d. --- config/application.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/config/application.rb b/config/application.rb index 70b97c6f9..95d286c9b 100644 --- a/config/application.rb +++ b/config/application.rb @@ -23,12 +23,12 @@ module Registry # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone. # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC. - config.time_zone = ENV['time_zone'] || 'Tallinn' # NB! It should be defined, + config.time_zone = ENV['time_zone'] || 'Tallinn' # NB! It should be defined, # otherwise ActiveRecord usese other class internally. # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded. - config.i18n.load_path += Dir[Rails.root.join('config', 'locales', '**', '*.yml').to_s] - config.i18n.default_locale = :en + # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s] + # config.i18n.default_locale = :de config.paths.add File.join('app', 'api'), glob: File.join('**', '*.rb') config.autoload_paths += Dir[Rails.root.join('app', 'api', '*')] From eac7690345d464650aee91e77647477a094a6ea9 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Thu, 10 Nov 2016 01:36:23 +0200 Subject: [PATCH 33/67] Update "pending_update_request_for_old_registrant" mailer #180 --- app/presenters/registrant_presenter.rb | 6 ++- ...update_request_for_old_registrant.html.erb | 14 +++---- ...update_request_for_old_registrant.text.erb | 10 ++--- spec/presenters/registrant_presenter_spec.rb | 40 +++++++++---------- ...equest_for_old_registrant.html.erb_spec.rb | 3 ++ ...equest_for_old_registrant.text.erb_spec.rb | 3 ++ 6 files changed, 41 insertions(+), 35 deletions(-) diff --git a/app/presenters/registrant_presenter.rb b/app/presenters/registrant_presenter.rb index 69dffddfc..f7fcb3094 100644 --- a/app/presenters/registrant_presenter.rb +++ b/app/presenters/registrant_presenter.rb @@ -1,11 +1,15 @@ class RegistrantPresenter - delegate :name, :ident, :email, :priv?, to: :registrant + delegate :name, :ident, :email, :priv?, :street, :city, to: :registrant def initialize(registrant:, view:) @registrant = registrant @view = view end + def country + + end + private attr_reader :registrant diff --git a/app/views/mailers/domain_mailer/pending_update_request_for_old_registrant.html.erb b/app/views/mailers/domain_mailer/pending_update_request_for_old_registrant.html.erb index 37081076c..3c2527913 100644 --- a/app/views/mailers/domain_mailer/pending_update_request_for_old_registrant.html.erb +++ b/app/views/mailers/domain_mailer/pending_update_request_for_old_registrant.html.erb @@ -19,7 +19,7 @@ Nimi: <%= @registrant.name %>
<% end %> Tänav: <%= @registrant.street %>
Linn: <%= @registrant.city %>
-Riik: <%= @params[:registrant_country] %> +Riik: <%= @registrant.country %>

Taotlus on aktiivne <%= Setting.expire_pending_confirmation %> tundi ja lükatakse automaatselt tagasi kui te seda enne ei kinnita või tagasi lükka.

@@ -46,14 +46,14 @@ Application for changing registrant of your domain <%= @domain.name %> has been

New registrant:
Name: <%= @registrant.name %>
-<% if @params[:registrant_priv] %> -Personal code: <%= @registrant.ident %>
+<% if @registrant.priv? %> + Personal code: <%= @registrant.ident %>
<% else %> -Business Registry code: <%= @registrant.ident %>
+ Business Registry code: <%= @registrant.ident %>
<% end %> -Street: <%= @params[:registrant_street] %>
-City: <%= @params[:registrant_city] %>
-Country: <%= @params[:registrant_country] %> +Street: <%= @registrant.street %>
+City: <%= @registrant.city %>
+Country: <%= @registrant.country %>

The application will remain in pending status for <%= Setting.expire_pending_confirmation %> hrs and will be automaticcally rejected if it is not approved nor rejected before.

diff --git a/app/views/mailers/domain_mailer/pending_update_request_for_old_registrant.text.erb b/app/views/mailers/domain_mailer/pending_update_request_for_old_registrant.text.erb index 5cbb47b7c..cf770bd6d 100644 --- a/app/views/mailers/domain_mailer/pending_update_request_for_old_registrant.text.erb +++ b/app/views/mailers/domain_mailer/pending_update_request_for_old_registrant.text.erb @@ -16,7 +16,7 @@ Nimi: <%= @registrant.name %> <% end %> Tänav: <%= @registrant.street %> Linn: <%= @registrant.city %> -Riik: <%= @params[:registrant_country] %> +Riik: <%= @registrant.country %> Taotlus on aktiivne <%= Setting.expire_pending_confirmation %> tundi ja lükatakse automaatselt tagasi kui te seda enne ei kinnita või tagasi lükka. Muudatuse kinnitamiseks külastage palun allolevat lehekülge, kontrollige uuesti üle muudatuse andmed ning vajutage nuppu kinnitan: @@ -38,14 +38,14 @@ Website: <%= @registrar.url %> New registrant: Name: <%= @registrant.name %> -<% if @params[:registrant_priv] %> +<% if @registrant.priv? %> Personal code: <%= @registrant.ident %> <% else %> Business Registry code: <%= @registrant.ident %> <% end %> -Street: <%= @params[:registrant_street] %> -City: <%= @params[:registrant_city] %> -Country: <%= @params[:registrant_country] %> +Street: <%= @registrant.street %> +City: <%= @registrant.city %> +Country: <%= @registrant.country %> The application will remain in pending status for <%= Setting.expire_pending_confirmation %> hrs and will be automaticcally rejected if it is not approved nor rejected before. To confirm the update please visit this website, once again review the data and press approve: diff --git a/spec/presenters/registrant_presenter_spec.rb b/spec/presenters/registrant_presenter_spec.rb index 014dbd54d..894dd40d5 100644 --- a/spec/presenters/registrant_presenter_spec.rb +++ b/spec/presenters/registrant_presenter_spec.rb @@ -4,31 +4,27 @@ RSpec.describe RegistrantPresenter do let(:registrant) { instance_double(Registrant) } let(:presenter) { described_class.new(registrant: registrant, view: view) } - describe '#name' do - it 'returns name' do - expect(registrant).to receive(:name).and_return('test name') - expect(presenter.name).to eq('test name') + registrant_delegate_attributes = %i( + name + ident + email + priv? + street + city + ) + + registrant_delegate_attributes.each do |attribute_name| + describe "##{attribute_name}" do + it 'delegetes to registrant' do + expect(registrant).to receive(attribute_name).and_return('test') + expect(presenter.send(attribute_name)).to eq('test') + end end end - describe '#ident' do - it 'returns ident' do - expect(registrant).to receive(:ident).and_return('test ident') - expect(presenter.ident).to eq('test ident') - end - end - - describe '#email' do - it 'returns email' do - expect(registrant).to receive(:email).and_return('test email') - expect(presenter.email).to eq('test email') - end - end - - describe '#priv?' do - it 'delegates to registrant' do - expect(registrant).to receive(:priv?).and_return('test') - expect(presenter.priv?).to eq('test') + describe '#country' do + it 'returns country name' do + expect(presenter.country).to be_nil end end end diff --git a/spec/views/mailers/domain_mailer/pending_update_request_for_old_registrant.html.erb_spec.rb b/spec/views/mailers/domain_mailer/pending_update_request_for_old_registrant.html.erb_spec.rb index 36a426bac..3722d9093 100644 --- a/spec/views/mailers/domain_mailer/pending_update_request_for_old_registrant.html.erb_spec.rb +++ b/spec/views/mailers/domain_mailer/pending_update_request_for_old_registrant.html.erb_spec.rb @@ -49,6 +49,9 @@ RSpec.describe 'mailers/domain_mailer/pending_update_request_for_old_registrant. registrant_attributes = %i( name ident + street + city + country ) registrant_attributes.each do |attr_name| diff --git a/spec/views/mailers/domain_mailer/pending_update_request_for_old_registrant.text.erb_spec.rb b/spec/views/mailers/domain_mailer/pending_update_request_for_old_registrant.text.erb_spec.rb index da9765873..9478e0238 100644 --- a/spec/views/mailers/domain_mailer/pending_update_request_for_old_registrant.text.erb_spec.rb +++ b/spec/views/mailers/domain_mailer/pending_update_request_for_old_registrant.text.erb_spec.rb @@ -49,6 +49,9 @@ RSpec.describe 'mailers/domain_mailer/pending_update_request_for_old_registrant. registrant_attributes = %i( name ident + street + city + country ) registrant_attributes.each do |attr_name| From 789468c84f01fb8c07f635e0536ec35b317c60e7 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Thu, 10 Nov 2016 23:32:52 +0200 Subject: [PATCH 34/67] Refactor mailer views #180 --- .../mailers/domain_mailer/expiration.html.erb | 24 +++------- .../mailers/domain_mailer/expiration.text.erb | 32 ++++--------- .../domain_mailer/pending_deleted.html.erb | 14 +----- .../domain_mailer/pending_deleted.text.erb | 10 +--- ...d_notification_for_new_registrant.html.erb | 14 ++++-- ...d_notification_for_new_registrant.text.erb | 12 +++-- ...e_notification_for_new_registrant.html.erb | 46 +++++++------------ ...e_notification_for_new_registrant.text.erb | 44 ++++++------------ ...d_notification_for_new_registrant.html.erb | 14 ++++-- ...d_notification_for_new_registrant.text.erb | 13 ++++-- ...update_request_for_old_registrant.html.erb | 36 ++------------- ...update_request_for_old_registrant.text.erb | 30 ++---------- .../registrant/_registrant.en.html.erb | 9 ++++ .../registrant/_registrant.en.text.erb | 9 ++++ .../registrant/_registrant.et.html.erb | 9 ++++ .../registrant/_registrant.et.text.erb | 9 ++++ .../registrar/_registrar.en.html.erb | 6 +++ .../registrar/_registrar.en.text.erb | 4 ++ .../registrar/_registrar.et.html.erb | 6 +++ .../registrar/_registrar.et.text.erb | 4 ++ .../registrar/_registrar.ru.html.erb | 6 +++ .../registrar/_registrar.ru.text.erb | 4 ++ .../domain_mailer/expiration.html.erb_spec.rb | 43 +++++++++-------- .../domain_mailer/expiration.text.erb_spec.rb | 43 +++++++++-------- .../pending_deleted.html.erb_spec.rb | 34 ++++++-------- .../pending_deleted.text.erb_spec.rb | 34 ++++++-------- ...cation_for_new_registrant.html.erb_spec.rb | 22 +++++++++ ...cation_for_new_registrant.text.erb_spec.rb | 22 +++++++++ ...equest_for_old_registrant.html.erb_spec.rb | 39 +--------------- ...equest_for_old_registrant.text.erb_spec.rb | 39 +--------------- .../registrant.et.text.erb_spec.rb | 25 ++++++++++ .../registrar.et.text.erb_spec.rb | 24 ++++++++++ 32 files changed, 334 insertions(+), 346 deletions(-) create mode 100644 app/views/mailers/domain_mailer/registrant/_registrant.en.html.erb create mode 100644 app/views/mailers/domain_mailer/registrant/_registrant.en.text.erb create mode 100644 app/views/mailers/domain_mailer/registrant/_registrant.et.html.erb create mode 100644 app/views/mailers/domain_mailer/registrant/_registrant.et.text.erb create mode 100644 app/views/mailers/domain_mailer/registrar/_registrar.en.html.erb create mode 100644 app/views/mailers/domain_mailer/registrar/_registrar.en.text.erb create mode 100644 app/views/mailers/domain_mailer/registrar/_registrar.et.html.erb create mode 100644 app/views/mailers/domain_mailer/registrar/_registrar.et.text.erb create mode 100644 app/views/mailers/domain_mailer/registrar/_registrar.ru.html.erb create mode 100644 app/views/mailers/domain_mailer/registrar/_registrar.ru.text.erb create mode 100644 spec/views/mailers/domain_mailer/pending_update_notification_for_new_registrant.html.erb_spec.rb create mode 100644 spec/views/mailers/domain_mailer/pending_update_notification_for_new_registrant.text.erb_spec.rb create mode 100644 spec/views/mailers/domain_mailer/registrant.et.text.erb_spec.rb create mode 100644 spec/views/mailers/domain_mailer/registrar.et.text.erb_spec.rb diff --git a/app/views/mailers/domain_mailer/expiration.html.erb b/app/views/mailers/domain_mailer/expiration.html.erb index 69bda1627..3c66159e9 100644 --- a/app/views/mailers/domain_mailer/expiration.html.erb +++ b/app/views/mailers/domain_mailer/expiration.html.erb @@ -3,7 +3,8 @@ Lugupeetud .ee domeeni kasutaja

Domeeninimi <%= @domain.name %> on aegunud ja ei ole alates <%= @domain.on_hold_date %> internetis kättesaadav. Alates <%= @domain.delete_date %> on domeen <%= @domain.name %> avatud registreerimiseks kõigile huvilistele.

-Domeeni registreeringu pikendamiseks pöörduge palun oma registripidaja <%= @registrar.name %> poole. Registripidajate kontaktid leiate aadressilt www.internet.ee/registripidajad. +Domeeni registreeringu pikendamiseks pöörduge palun oma registripidaja: +<%= render 'mailers/domain_mailer/registrar/registrar.et.html', registrar: @registrar %>

Domeeni <%= @domain.name %> kohta on registris järgmised andmed:

@@ -12,11 +13,6 @@ Halduskontakt: <%= @domain.admin_contact_names %>
Tehniline kontakt: <%= @domain.tech_contact_names %>
Nimeserverid: <%= @domain.nameserver_names %>
-

Registripidaja:
-<%= @registrar.name %>
-Email: <%= @registrar.email %>
-Telefon: <%= @registrar.phone %>
-Veebileht: <%= @registrar.url %>

Ülevaate kõikidest endaga seotud domeenidest saate registreerija portaalist. <%= ENV['registrant_url'] %>.


@@ -30,7 +26,8 @@ Dear user of .ee domain,

The domain name <%= @domain.name %> has expired and will not be available on the Internet from <%= @domain.on_hold_date %>. From <%= @domain.delete_date %>, the <%= @domain.name %> domain will be available for registration on a first come first served basis.

-To renew the domain registration, please contact your registrar <%= @registrar.name %>. You can find the registrar's contacts at http://internet.ee/registrars. +To renew the domain registration, please contact your registrar: +<%= render 'mailers/domain_mailer/registrar/registrar.en.html', registrar: @registrar %>

The following data for the <%= @domain.name %> domain have been entered into the registry:

@@ -39,11 +36,6 @@ Administrative contact: <%= @domain.admin_contact_names %>
Technical contact: <%= @domain.tech_contact_names %>
Name servers: <%= @domain.nameserver_names %>
-

Registrar:
-<%= @registrar.name %>
-Email: <%= @registrar.email %>
-Phone: <%= @registrar.phone %>
-Website: <%= @registrar.url %>

You can find an overview of all your domains at the registrant's portal. <%= ENV['registrant_url'] %>.


@@ -60,7 +52,8 @@ Estonian Internet Foundation

-Для продления регистрации домена просим обратиться к своему регистратору <%= @registrar.name %>. Контактные данные регистраторов можно найти по адресу http://internet.ee/registratory. +Для продления регистрации домена просим обратиться к своему регистратору: +<%= render 'mailers/domain_mailer/registrar/registrar.ru.html', registrar: @registrar %>

Относительно домена <%= @domain.name %> в реестр внесены следующие данные: @@ -71,11 +64,6 @@ Estonian Internet Foundation Технический контакт: <%= @domain.tech_contact_names %>
Серверы доменных имен: <%= @domain.nameserver_names %>
-

Регистратор:
-<%= @registrar.name %>
-Электронная почта: <%= @registrar.email %>
-Телефон: <%= @registrar.phone %>
-Веб-сайт: <%= @registrar.url %>

Обзор всех связанных с Вами доменов можете получить на портале регистранта. <%= ENV['registrant_url'] %>.
diff --git a/app/views/mailers/domain_mailer/expiration.text.erb b/app/views/mailers/domain_mailer/expiration.text.erb index ef8cce36c..fc9351300 100644 --- a/app/views/mailers/domain_mailer/expiration.text.erb +++ b/app/views/mailers/domain_mailer/expiration.text.erb @@ -3,7 +3,9 @@ Lugupeetud .ee domeeni kasutaja Domeeninimi <%= @domain.name %> on aegunud ja ei ole alates <%= @domain.on_hold_date %> internetis kättesaadav. Alates <%= @domain.delete_date %> on domeen <%= @domain.name %> avatud registreerimiseks kõigile huvilistele. -Domeeni registreeringu pikendamiseks pöörduge palun oma registripidaja <%= @registrar.name %> poole. Registripidajate kontaktid leiate aadressilt www.internet.ee/registripidajad. +Domeeni registreeringu pikendamiseks pöörduge palun oma registripidaja: + +<%= render 'mailers/domain_mailer/registrar/registrar.et.text', registrar: @registrar %> Domeeni <%= @domain.name %> kohta on registris järgmised andmed: @@ -12,12 +14,6 @@ Halduskontakt: <%= @domain.admin_contact_names %> Tehniline kontakt: <%= @domain.tech_contact_names %> Nimeserverid: <%= @domain.nameserver_names %> -Registripidaja: -<%= @registrar.name %> -Email: <%= @registrar.email %> -Telefon: <%= @registrar.phone %> -Veebileht: <%= @registrar.url %> - Ülevaate kõikidest endaga seotud domeenidest saate registreerija portaalist. <%= ENV['registrant_url'] %>. Parimate soovidega @@ -30,7 +26,9 @@ Dear user of .ee domain, The domain name <%= @domain.name %> has expired and will not be available on the Internet from <%= @domain.on_hold_date %>. From <%= @domain.delete_date %>, the <%= @domain.name %> domain will be available for registration on a first come first served basis. -To renew the domain registration, please contact your registrar <%= @registrar.name %>. You can find the registrar's contacts at http://internet.ee/registrars. +To renew the domain registration, please contact your registrar: + +<%= render 'mailers/domain_mailer/registrar/registrar.en.text', registrar: @registrar %> The following data for the <%= @domain.name %> domain have been entered into the registry: @@ -39,12 +37,6 @@ Administrative contact: <%= @domain.admin_contact_names %> Technical contact: <%= @domain.tech_contact_names %> Name servers: <%= @domain.nameserver_names %> -Registrar: -<%= @registrar.name %> -Email: <%= @registrar.email %> -Phone: <%= @registrar.phone %> -Website: <%= @registrar.url %> - You can find an overview of all your domains at the registrant's portal. <%= ENV['registrant_url'] %>. Best Regards, @@ -57,21 +49,17 @@ Estonian Internet Foundation Доменное имя <%= @domain.name %> устарело и с <%= @domain.on_hold_date %> недоступно в Интернете. С <%= @domain.delete_date %> домен <%= @domain.name %> доступен для регистрации всем желающим по принципу "first come, first served". -Для продления регистрации домена просим обратиться к своему регистратору <%= @registrar.name %>. Контактные данные регистраторов можно найти по адресу http://internet.ee/registratory. +Для продления регистрации домена просим обратиться к своему регистратору: -Относительно домена <%= @domain %> в реестр внесены следующие данные: +<%= render 'mailers/domain_mailer/registrar/registrar.ru.text', registrar: @registrar %> + +Относительно домена <%= @domain.name %> в реестр внесены следующие данные: Регистрант: <%= @domain.registrant_name %> Административный контакт: <%= @domain.admin_contact_names %> Технический контакт: <%= @domain.tech_contact_names %> Серверы доменных имен: <%= @domain.nameserver_names %> -Регистратор: -<%= @registrar.name %> -Электронная почта: <%= @registrar.email %> -Телефон: <%= @registrar.phone %> -Веб-сайт: <%= @registrar.url %> - Обзор всех связанных с Вами доменов можете получить на портале регистранта. <%= ENV['registrant_url'] %>. С наилучшими пожеланиями diff --git a/app/views/mailers/domain_mailer/pending_deleted.html.erb b/app/views/mailers/domain_mailer/pending_deleted.html.erb index 10960019c..8a6c8e2bc 100644 --- a/app/views/mailers/domain_mailer/pending_deleted.html.erb +++ b/app/views/mailers/domain_mailer/pending_deleted.html.erb @@ -2,12 +2,7 @@ Tere

Registrisse laekus taotlus domeeni <%= @domain.name %> kustutamiseks. Palun veenduge, et muudatus on korrektne ning probleemide korral pöörduge oma registripidaja poole: -

- <%= @registrar.name %>
- Email: <%= @registrar.email %>
- Telefon: <%= @registrar.phone %>
- Veebileht: <%= @registrar.url %> -

+<%= render 'mailers/domain_mailer/registrar/registrar.et.html', registrar: @registrar %>

Muudatuse kinnitamiseks külastage palun allolevat lehekülge, kontrollige uuesti üle muudatuse andmed ning vajutage nuppu kinnitan. @@ -24,12 +19,7 @@ Hi,

Application for deletion of your domain <%= @domain.name %> has been filed. Please make sure that the application is correct. Incase of problems please contact your registrar: -

- <%= @registrar.name %>
- Email: <%= @registrar.email %>
- Phone: <%= @registrar.phone %>
- Website: <%= @registrar.url %> -

+<%= render 'mailers/domain_mailer/registrar/registrar.en.html', registrar: @registrar %>

To confirm the update please visit this website, once again review the data and press approve:
diff --git a/app/views/mailers/domain_mailer/pending_deleted.text.erb b/app/views/mailers/domain_mailer/pending_deleted.text.erb index 1c8877740..39460443a 100644 --- a/app/views/mailers/domain_mailer/pending_deleted.text.erb +++ b/app/views/mailers/domain_mailer/pending_deleted.text.erb @@ -2,10 +2,7 @@ Tere Registrisse laekus taotlus domeeni <%= @domain.name %> kustutamiseks. Palun veenduge, et muudatus on korrektne ning probleemide korral pöörduge oma registripidaja poole: -<%= @registrar.name %> -Email: <%= @registrar.email %> -Telefon: <%= @registrar.phone %> -Veebileht: <%= @registrar.url %> +<%= render 'mailers/domain_mailer/registrar/registrar.et.text', registrar: @registrar %> Muudatuse kinnitamiseks külastage palun allolevat lehekülge, kontrollige uuesti üle muudatuse andmed ning vajutage nuppu kinnitan. @@ -21,10 +18,7 @@ Hi, Application for deletion of your domain <%= @domain.name %> has been filed. Please make sure that the application is correct. In case of problems please contact your registrar: -<%= @registrar.name %> -Email: <%= @registrar.email %> -Phone: <%= @registrar.phone %> -Website: <%= @registrar.url %> +<%= render 'mailers/domain_mailer/registrar/registrar.en.text', registrar: @registrar %> To confirm the update please visit this website, once again review the data and press approve: <%= @verification_url %> diff --git a/app/views/mailers/domain_mailer/pending_update_expired_notification_for_new_registrant.html.erb b/app/views/mailers/domain_mailer/pending_update_expired_notification_for_new_registrant.html.erb index 800ff33e1..139e0a850 100644 --- a/app/views/mailers/domain_mailer/pending_update_expired_notification_for_new_registrant.html.erb +++ b/app/views/mailers/domain_mailer/pending_update_expired_notification_for_new_registrant.html.erb @@ -1,8 +1,11 @@ Tere

-Domeeni <%= @params[:name] %> registreerija <%= @params[:registrant_name] %> ei kinnitanud tähtaegselt registreerija vahetuse taotlust. Domeeni <%= @params[:name] %> registreerija vahetus on sellest tulenevalt tühistatud. +Domeeni <%= @domain.name %> registreerija <%= @registrant.name %> ei kinnitanud tähtaegselt registreerija vahetuse taotlust. Domeeni <%= @domain.name %> registreerija vahetus on sellest tulenevalt tühistatud.

-Küsimuste korral palun võtke ühendust oma registripidajaga <%= @params[:registrar_name] %>. Registripidajate kontaktid leiate aadressilt www.internet.ee/registripidajad. +Küsimuste korral palun võtke ühendust oma registripidajaga: + +<%= render 'registrar.et.html', registrar: @registrar %> +

Lugupidamisega
Eesti Interneti Sihtasutus @@ -11,9 +14,12 @@ Eesti Interneti Sihtasutus

Hi,

-Domain registrant change request has been expired for the domain <%= @params[:name] %>. +Domain registrant change request has been expired for the domain <%= @domain.name %>.

-Please contact to your registrar <%= @params[:registrar_name] %> if you have any questions. You can find the registrar's contacts at http://internet.ee/registrars. +Please contact to your registrar if you have any questions: + +<%= render 'registrar.en.html', registrar: @registrar %> +

Best Regards,
Estonian Internet Foundation diff --git a/app/views/mailers/domain_mailer/pending_update_expired_notification_for_new_registrant.text.erb b/app/views/mailers/domain_mailer/pending_update_expired_notification_for_new_registrant.text.erb index 88ddefe9d..dfdcc0a5d 100644 --- a/app/views/mailers/domain_mailer/pending_update_expired_notification_for_new_registrant.text.erb +++ b/app/views/mailers/domain_mailer/pending_update_expired_notification_for_new_registrant.text.erb @@ -1,8 +1,10 @@ Tere -Domeeni <%= @params[:name] %> registreerija <%= @params[:registrant_name] %> ei kinnitanud tähtaegselt registreerija vahetuse taotlust. Domeeni <%= @params[:name] %> registreerija vahetus on sellest tulenevalt tühistatud. +Domeeni <%= @domain.name %> registreerija <%= @registrant.name %> ei kinnitanud tähtaegselt registreerija vahetuse taotlust. Domeeni <%= @domain.name %> registreerija vahetus on sellest tulenevalt tühistatud. -Küsimuste korral palun võtke ühendust oma registripidajaga <%= @params[:registrar_name] %>. Registripidajate kontaktid leiate aadressilt www.internet.ee/registripidajad. +Küsimuste korral palun võtke ühendust oma registripidajaga: + +<%= render 'registrar.et.text', registrar: @registrar %> Lugupidamisega Eesti Interneti Sihtasutus @@ -11,9 +13,11 @@ Eesti Interneti Sihtasutus Hi, -Domain registrant change request has been expired for the domain <%= @params[:name] %>. +Domain registrant change request has been expired for the domain <%= @domain.name %>. -Please contact to your registrar <%= @params[:registrar_name] %> if you have any questions. You can find the registrar's contacts at http://internet.ee/registrars. +Please contact to your registrar if you have any questions: + +<%= render 'registrar.en.text', registrar: @registrar %> Best Regards, Estonian Internet Foundation diff --git a/app/views/mailers/domain_mailer/pending_update_notification_for_new_registrant.html.erb b/app/views/mailers/domain_mailer/pending_update_notification_for_new_registrant.html.erb index a58aaef12..78f0458dc 100644 --- a/app/views/mailers/domain_mailer/pending_update_notification_for_new_registrant.html.erb +++ b/app/views/mailers/domain_mailer/pending_update_notification_for_new_registrant.html.erb @@ -1,25 +1,18 @@ Tere

-Registripidaja <%= @params[:registrar_name] %> vahendusel on algatatud <%= @params[:name] %> domeeni omanikuvahetuse protseduur. +Registripidaja <%= @registrar.name %> vahendusel on algatatud <%= @domain.name %> domeeni omanikuvahetuse protseduur.

-Palun veenduge, et muudatus on korrektne ning probleemide korral pöörduge oma registripidaja <%= @params[:registrar_name] %> poole. +Palun veenduge, et muudatus on korrektne ning probleemide korral pöörduge oma registripidaja poole: + +<%= render 'registrar.et.html', registrar: @registrar %> +

Uue registreerija andmed:
-Nimi: <%= @params[:registrant_name] %>
-<% if @params[:registrant_priv] %> - Isikukood: <%= @params[:registrant_ident] %>
-<% else %> - Äriregistrikood: <%= @params[:registrant_ident] %>
-<% end %> -Tänav: <%= @params[:registrant_street] %>
-Linn: <%= @params[:registrant_city] %>
-Riik: <%= @params[:registrant_country] %> +<%= render 'registrant.et.html', registrant: @new_registrant %>

-Juhime Teie tähelepanu asjaolule, et omanikuvahetuse protseduur viiakse lõpule vaid juhul, kui domeeni hetkel kehtiv registreerija <%= @params[:old_registrant_name] %> omanikuvahetuse tähtaegselt kinnitab. +Juhime Teie tähelepanu asjaolule, et omanikuvahetuse protseduur viiakse lõpule vaid juhul, kui domeeni hetkel kehtiv registreerija <%= @current_registrant.name %> omanikuvahetuse tähtaegselt kinnitab.

-Juhul kui <%= @params[:old_registrant_name] %> lükkab omanikuvahetuse taotluse tagasi või ei anna kinnitust enne <%= Setting.expire_pending_confirmation %> tundi, omanikuvahetuse protseduur tühistatakse. -

-Küsimuste korral palun võtke ühendust registripidajaga <%= @params[:registrar_name] %>. Registripidajate kontaktid leiate aadressilt www.internet.ee/registripidajad. +Juhul kui <%= @current_registrant.name %> lükkab omanikuvahetuse taotluse tagasi või ei anna kinnitust enne <%= Setting.expire_pending_confirmation %> tundi, omanikuvahetuse protseduur tühistatakse.

Lugupidamisega
Eesti Interneti Sihtasutus @@ -28,26 +21,19 @@ Eesti Interneti Sihtasutus

Hi,

-Registrant change process for the domain <%= @params[:name] %> has been started. +Registrant change process for the domain <%= @domain.name %> has been started.

-Please verify the details of the following change request. In case of problems contact your registrar <%= @params[:registrar_name] %> +Please verify the details of the following change request. In case of problems contact your registrar: + +<%= render 'registrar.en.html', registrar: @registrar %> +

New registrant:
-Name: <%= @params[:registrant_name] %>
-<% if @params[:registrant_priv] %> -Personal code: <%= @params[:registrant_ident] %>
-<% else %> -Business Registry code: <%= @params[:registrant_ident] %>
-<% end %> -Street: <%= @params[:registrant_street] %>
-City: <%= @params[:registrant_city] %>
-Country: <%= @params[:registrant_country] %> +<%= render 'registrant.en.html', registrant: @new_registrant %>

-The registrant change procedure will be completed only after the current registrant <%= @params[:old_registrant_name] %> has approved it. +The registrant change procedure will be completed only after the current registrant <%= @current_registrant.name %> has approved it.

-Change request will be cancelled in case <%= @params[:old_registrant_name] %> rejects or does not approve it in <%= Setting.expire_pending_confirmation %> hours. -

-Please contact registrar <%= @params[:registrar_name] %> in case of questions. You can find the registrar's contacts at http://internet.ee/registrars. +Change request will be cancelled in case <%= @current_registrant.name %> rejects or does not approve it in <%= Setting.expire_pending_confirmation %> hours.

Best Regards,
Estonian Internet Foundation diff --git a/app/views/mailers/domain_mailer/pending_update_notification_for_new_registrant.text.erb b/app/views/mailers/domain_mailer/pending_update_notification_for_new_registrant.text.erb index 9c1a6aebe..ac781506e 100644 --- a/app/views/mailers/domain_mailer/pending_update_notification_for_new_registrant.text.erb +++ b/app/views/mailers/domain_mailer/pending_update_notification_for_new_registrant.text.erb @@ -1,25 +1,17 @@ Tere -Registripidaja <%= @params[:registrar_name] %> vahendusel on algatatud <%= @params[:name] %> domeeni omanikuvahetuse protseduur. +Registripidaja <%= @registrar.name %> vahendusel on algatatud <%= @domain.name %> domeeni omanikuvahetuse protseduur. -Palun veenduge, et muudatus on korrektne ning probleemide korral pöörduge oma registripidaja <%= @params[:registrar_name] %> poole. +Palun veenduge, et muudatus on korrektne ning probleemide korral pöörduge oma registripidaja poole: + +<%= render 'registrar.et.text', registrar: @registrar %> Uue registreerija andmed: -Nimi: <%= @params[:registrant_name] %> -<% if @params[:registrant_priv] %> -Isikukood: <%= @params[:registrant_ident] %> -<% else %> -Äriregistrikood: <%= @params[:registrant_ident] %> -<% end %> -Tänav: <%= @params[:registrant_street] %> -Linn: <%= @params[:registrant_city] %> -Riik: <%= @params[:registrant_country] %> +<%= render 'registrant.et.text', registrant: @new_registrant %> -Juhime Teie tähelepanu asjaolule, et omanikuvahetuse protseduur viiakse lõpule vaid juhul, kui domeeni hetkel kehtiv registreerija <%= @params[:old_registrant_name] %> omanikuvahetuse tähtaegselt kinnitab. +Juhime Teie tähelepanu asjaolule, et omanikuvahetuse protseduur viiakse lõpule vaid juhul, kui domeeni hetkel kehtiv registreerija <%= @current_registrant.name %> omanikuvahetuse tähtaegselt kinnitab. -Juhul kui <%= @params[:old_registrant_name] %> lükkab omanikuvahetuse taotluse tagasi või ei anna kinnitust enne <%= Setting.expire_pending_confirmation %> tundi, omanikuvahetuse protseduur tühistatakse. - -Küsimuste korral palun võtke ühendust registripidajaga <%= @params[:registrar_name] %>. Registripidajate kontaktid leiate aadressilt www.internet.ee/registripidajad. +Juhul kui <%= @current_registrant.name %> lükkab omanikuvahetuse taotluse tagasi või ei anna kinnitust enne <%= Setting.expire_pending_confirmation %> tundi, omanikuvahetuse protseduur tühistatakse. Lugupidamisega Eesti Interneti Sihtasutus @@ -28,26 +20,18 @@ Eesti Interneti Sihtasutus Hi, -Registrant change process for the domain <%= @params[:name] %> has been started. +Registrant change process for the domain <%= @domain.name %> has been started. -Please verify the details of the following change request. In case of problems contact your registrar <%= @params[:registrar_name] %> +Please verify the details of the following change request. In case of problems contact your registrar: + +<%= render 'registrar.en.text', registrar: @registrar %> New registrant: -Name: <%= @params[:registrant_name] %> -<% if @params[:registrant_priv] %> -Personal code: <%= @params[:registrant_ident] %> -<% else %> -Business Registry code: <%= @params[:registrant_ident] %> -<% end %> -Street: <%= @params[:registrant_street] %> -City: <%= @params[:registrant_city] %> -Country: <%= @params[:registrant_country] %> +<%= render 'registrant.en.text', registrant: @new_registrant %> -The registrant change procedure will be completed only after the current registrant <%= @params[:old_registrant_name] %> has approved it. +The registrant change procedure will be completed only after the current registrant <%= @current_registrant.name %> has approved it. -Change request will be cancelled in case <%= @params[:old_registrant_name] %> rejects or does not approve it in <%= Setting.expire_pending_confirmation %> hours. - -Please contact registrar <%= @params[:registrar_name] %> in case of questions. You can find the registrar's contacts at http://internet.ee/registrars. +Change request will be cancelled in case <%= @current_registrant.name %> rejects or does not approve it in <%= Setting.expire_pending_confirmation %> hours. Best Regards, Estonian Internet Foundation diff --git a/app/views/mailers/domain_mailer/pending_update_rejected_notification_for_new_registrant.html.erb b/app/views/mailers/domain_mailer/pending_update_rejected_notification_for_new_registrant.html.erb index 0dca95ee9..97413078a 100644 --- a/app/views/mailers/domain_mailer/pending_update_rejected_notification_for_new_registrant.html.erb +++ b/app/views/mailers/domain_mailer/pending_update_rejected_notification_for_new_registrant.html.erb @@ -1,8 +1,11 @@ Tere

-Domeeni <%= @params[:name] %> registreerija <%= @params[:old_registrant_name] %> on domeeni registreerija vahetamise taotluse tagasi lükanud. +Domeeni <%= @domain.name %> registreerija <%= @current_registrant.name %> on domeeni registreerija vahetamise taotluse tagasi lükanud.

-Küsimuste korral võtke palun ühendust oma registripidajaga <%= @params[:registrar_name] %>. Registripidajate kontaktid leiate aadressilt www.internet.ee/registripidajad. +Küsimuste korral võtke palun ühendust oma registripidajaga: + +<%= render 'registrar.et.html', registrar: @registrar %> +

Lugupidamisega
Eesti Interneti Sihtasutus @@ -11,9 +14,12 @@ Eesti Interneti Sihtasutus

Hi,

-Registrant change for the domain <%= @params[:name] %> was rejected by the registrant <%= @params[:old_registrant_name] %>. +Registrant change for the domain <%= @domain.name %> was rejected by the registrant <%= @current_registrant.name %>.

-Please contact your registrar <%= @params[:registrar_name] %> if you have any questions. You can find the registrar's contacts at http://internet.ee/registrars. +Please contact your registrar if you have any questions: + +<%= render 'registrar.en.html', registrar: @registrar %> +

Best Regards,
Estonian Internet Foundation diff --git a/app/views/mailers/domain_mailer/pending_update_rejected_notification_for_new_registrant.text.erb b/app/views/mailers/domain_mailer/pending_update_rejected_notification_for_new_registrant.text.erb index bf9ecc80a..b54636f6e 100644 --- a/app/views/mailers/domain_mailer/pending_update_rejected_notification_for_new_registrant.text.erb +++ b/app/views/mailers/domain_mailer/pending_update_rejected_notification_for_new_registrant.text.erb @@ -1,8 +1,10 @@ Tere -Domeeni <%= @params[:name] %> registreerija <%= @params[:old_registrant_name] %> on domeeni registreerija vahetamise taotluse tagasi lükanud. +Domeeni <%= @domain.name %> registreerija <%= @current_registrant.name %> on domeeni registreerija vahetamise taotluse tagasi lükanud. -Küsimuste korral võtke palun ühendust oma registripidajaga <%= @params[:registrar_name] %>. Registripidajate kontaktid leiate aadressilt www.internet.ee/registripidajad. +Küsimuste korral võtke palun ühendust oma registripidajaga: + +<%= render 'registrar.et.text', registrar: @registrar %> Lugupidamisega Eesti Interneti Sihtasutus @@ -11,10 +13,11 @@ Eesti Interneti Sihtasutus Hi, -Registrant change for the domain <%= @params[:name] %> was rejected by the registrant <%= @params[:old_registrant_name] %> -. +Registrant change for the domain <%= @domain.name %> was rejected by the registrant <%= @current_registrant.name %>. -Please contact your registrar <%= @params[:registrar_name] %> if you have any questions. You can find the registrar's contacts at http://internet.ee/registrars. +Please contact your registrar if you have any questions: + +<%= render 'registrar.en.text', registrar: @registrar %> Best Regards, Estonian Internet Foundation diff --git a/app/views/mailers/domain_mailer/pending_update_request_for_old_registrant.html.erb b/app/views/mailers/domain_mailer/pending_update_request_for_old_registrant.html.erb index 3c2527913..45174273a 100644 --- a/app/views/mailers/domain_mailer/pending_update_request_for_old_registrant.html.erb +++ b/app/views/mailers/domain_mailer/pending_update_request_for_old_registrant.html.erb @@ -2,24 +2,11 @@ Tere

Registrisse laekus taotlus domeeni <%= @domain.name %> registreerija vahetuseks. Palun veenduge, et muudatus on korrektne ning probleemide korral pöörduge oma registripidaja poole: -

- <%= @registrar.name %>
- Email: <%= @registrar.email %>
- Telefon: <%= @registrar.phone %>
- Veebileht: <%= @registrar.url %> -

+<%= render 'registrar.et.html', registrar: @registrar %>

Uue registreerija andmed:
-Nimi: <%= @registrant.name %>
-<% if @registrant.priv? %> - Isikukood: <%= @registrant.ident %>
-<% else %> - Äriregistrikood: <%= @registrant.ident %>
-<% end %> -Tänav: <%= @registrant.street %>
-Linn: <%= @registrant.city %>
-Riik: <%= @registrant.country %> +<%= render 'registrant.et.html', registrant: @registrant %>

Taotlus on aktiivne <%= Setting.expire_pending_confirmation %> tundi ja lükatakse automaatselt tagasi kui te seda enne ei kinnita või tagasi lükka.

@@ -34,26 +21,13 @@ Eesti Interneti Sihtasutus

Hi,

-Application for changing registrant of your domain <%= @domain.name %> has been filed. Please make sure that the update and information are correct. Incase of problems please turn to your registrar: +Application for changing registrant of your domain <%= @domain.name %> has been filed. Please make sure that the update and information are correct. In case of problems please turn to your registrar: -

- <%= @registrar.name %>
- Email: <%= @registrar.email %>
- Phone: <%= @registrar.phone %>
- Website: <%= @registrar.url %> -

+<%= render 'registrar.en.html', registrar: @registrar %>

New registrant:
-Name: <%= @registrant.name %>
-<% if @registrant.priv? %> - Personal code: <%= @registrant.ident %>
-<% else %> - Business Registry code: <%= @registrant.ident %>
-<% end %> -Street: <%= @registrant.street %>
-City: <%= @registrant.city %>
-Country: <%= @registrant.country %> +<%= render 'registrant.en.html', registrant: @registrant %>

The application will remain in pending status for <%= Setting.expire_pending_confirmation %> hrs and will be automaticcally rejected if it is not approved nor rejected before.

diff --git a/app/views/mailers/domain_mailer/pending_update_request_for_old_registrant.text.erb b/app/views/mailers/domain_mailer/pending_update_request_for_old_registrant.text.erb index cf770bd6d..b5d55d80d 100644 --- a/app/views/mailers/domain_mailer/pending_update_request_for_old_registrant.text.erb +++ b/app/views/mailers/domain_mailer/pending_update_request_for_old_registrant.text.erb @@ -2,21 +2,10 @@ Tere Registrisse laekus taotlus domeeni <%= @domain.name %> registreerija vahetuseks. Palun veenduge, et muudatus on korrektne ning probleemide korral pöörduge oma registripidaja poole: -<%= @registrar.name %> -Email: <%= @registrar.email %> -Telefon: <%= @registrar.phone %> -Veebileht: <%= @registrar.url %> +<%= render 'registrar.et.text', registrar: @registrar %> Uue registreerija andmed: -Nimi: <%= @registrant.name %> -<% if @registrant.priv? %> - Isikukood: <%= @registrant.ident %> -<% else %> - Äriregistrikood: <%= @registrant.ident %> -<% end %> -Tänav: <%= @registrant.street %> -Linn: <%= @registrant.city %> -Riik: <%= @registrant.country %> +<%= render 'registrant.et.text', registrant: @registrant %> Taotlus on aktiivne <%= Setting.expire_pending_confirmation %> tundi ja lükatakse automaatselt tagasi kui te seda enne ei kinnita või tagasi lükka. Muudatuse kinnitamiseks külastage palun allolevat lehekülge, kontrollige uuesti üle muudatuse andmed ning vajutage nuppu kinnitan: @@ -31,21 +20,10 @@ Hi, Application for changing registrant of your domain <%= @domain.name %> has been filed. Please make sure that the update and information are correct. In case of problems please turn to your registrar: -<%= @registrar.name %> -Email: <%= @registrar.email %> -Phone: <%= @registrar.phone %> -Website: <%= @registrar.url %> +<%= render 'registrar.en.text', registrar: @registrar %> New registrant: -Name: <%= @registrant.name %> -<% if @registrant.priv? %> - Personal code: <%= @registrant.ident %> -<% else %> - Business Registry code: <%= @registrant.ident %> -<% end %> -Street: <%= @registrant.street %> -City: <%= @registrant.city %> -Country: <%= @registrant.country %> +<%= render 'registrant.en.text', registrant: @registrant %> The application will remain in pending status for <%= Setting.expire_pending_confirmation %> hrs and will be automaticcally rejected if it is not approved nor rejected before. To confirm the update please visit this website, once again review the data and press approve: diff --git a/app/views/mailers/domain_mailer/registrant/_registrant.en.html.erb b/app/views/mailers/domain_mailer/registrant/_registrant.en.html.erb new file mode 100644 index 000000000..300157c83 --- /dev/null +++ b/app/views/mailers/domain_mailer/registrant/_registrant.en.html.erb @@ -0,0 +1,9 @@ +Name: <%= registrant.name %>
+<% if registrant.priv? %> + Personal code: <%= registrant.ident %>
+<% else %> + Business Registry code: <%= registrant.ident %>
+<% end %> +Street: <%= registrant.street %>
+City: <%= registrant.city %>
+Country: <%= registrant.country %> diff --git a/app/views/mailers/domain_mailer/registrant/_registrant.en.text.erb b/app/views/mailers/domain_mailer/registrant/_registrant.en.text.erb new file mode 100644 index 000000000..649e2c452 --- /dev/null +++ b/app/views/mailers/domain_mailer/registrant/_registrant.en.text.erb @@ -0,0 +1,9 @@ +Name: <%= registrant.name %> +<% if registrant.priv? %> + Personal code: <%= registrant.ident %> +<% else %> + Business Registry code: <%= registrant.ident %> +<% end %> +Street: <%= registrant.street %> +City: <%= registrant.city %> +Country: <%= registrant.country %> diff --git a/app/views/mailers/domain_mailer/registrant/_registrant.et.html.erb b/app/views/mailers/domain_mailer/registrant/_registrant.et.html.erb new file mode 100644 index 000000000..789b88490 --- /dev/null +++ b/app/views/mailers/domain_mailer/registrant/_registrant.et.html.erb @@ -0,0 +1,9 @@ +Nimi: <%= registrant.name %>
+<% if registrant.priv? %> + Isikukood: <%= registrant.ident %>
+<% else %> + Äriregistrikood: <%= registrant.ident %>
+<% end %> +Tänav: <%= registrant.street %>
+Linn: <%= registrant.city %>
+Riik: <%= registrant.country %> diff --git a/app/views/mailers/domain_mailer/registrant/_registrant.et.text.erb b/app/views/mailers/domain_mailer/registrant/_registrant.et.text.erb new file mode 100644 index 000000000..01ece5e67 --- /dev/null +++ b/app/views/mailers/domain_mailer/registrant/_registrant.et.text.erb @@ -0,0 +1,9 @@ +Nimi: <%= registrant.name %> +<% if registrant.priv? %> + Isikukood: <%= registrant.ident %> +<% else %> + Äriregistrikood: <%= registrant.ident %> +<% end %> +Tänav: <%= registrant.street %> +Linn: <%= registrant.city %> +Riik: <%= registrant.country %> diff --git a/app/views/mailers/domain_mailer/registrar/_registrar.en.html.erb b/app/views/mailers/domain_mailer/registrar/_registrar.en.html.erb new file mode 100644 index 000000000..699fcd19d --- /dev/null +++ b/app/views/mailers/domain_mailer/registrar/_registrar.en.html.erb @@ -0,0 +1,6 @@ +

+ <%= registrar.name %>
+ Email: <%= registrar.email %>
+ Phone: <%= registrar.phone %>
+ Website: <%= registrar.url %> +

diff --git a/app/views/mailers/domain_mailer/registrar/_registrar.en.text.erb b/app/views/mailers/domain_mailer/registrar/_registrar.en.text.erb new file mode 100644 index 000000000..96882b11d --- /dev/null +++ b/app/views/mailers/domain_mailer/registrar/_registrar.en.text.erb @@ -0,0 +1,4 @@ +<%= registrar.name %> +Email: <%= registrar.email %> +Phone: <%= registrar.phone %> +Website: <%= registrar.url %> diff --git a/app/views/mailers/domain_mailer/registrar/_registrar.et.html.erb b/app/views/mailers/domain_mailer/registrar/_registrar.et.html.erb new file mode 100644 index 000000000..199115210 --- /dev/null +++ b/app/views/mailers/domain_mailer/registrar/_registrar.et.html.erb @@ -0,0 +1,6 @@ +

+ <%= registrar.name %>
+ Email: <%= registrar.email %>
+ Telefon: <%= registrar.phone %>
+ Veebileht: <%= registrar.url %> +

diff --git a/app/views/mailers/domain_mailer/registrar/_registrar.et.text.erb b/app/views/mailers/domain_mailer/registrar/_registrar.et.text.erb new file mode 100644 index 000000000..0e8b16e30 --- /dev/null +++ b/app/views/mailers/domain_mailer/registrar/_registrar.et.text.erb @@ -0,0 +1,4 @@ +<%= registrar.name %> +Email: <%= registrar.email %> +Telefon: <%= registrar.phone %> +Veebileht: <%= registrar.url %> diff --git a/app/views/mailers/domain_mailer/registrar/_registrar.ru.html.erb b/app/views/mailers/domain_mailer/registrar/_registrar.ru.html.erb new file mode 100644 index 000000000..1c258f10d --- /dev/null +++ b/app/views/mailers/domain_mailer/registrar/_registrar.ru.html.erb @@ -0,0 +1,6 @@ +

+ <%= registrar.name %>
+ Электронная почта: <%= registrar.email %>
+ Телефон: <%= registrar.phone %>
+ Веб-сайт: <%= registrar.url %> +

diff --git a/app/views/mailers/domain_mailer/registrar/_registrar.ru.text.erb b/app/views/mailers/domain_mailer/registrar/_registrar.ru.text.erb new file mode 100644 index 000000000..0a74e8974 --- /dev/null +++ b/app/views/mailers/domain_mailer/registrar/_registrar.ru.text.erb @@ -0,0 +1,4 @@ +<%= registrar.name %> +Электронная почта: <%= registrar.email %> +Телефон: <%= registrar.phone %> +Веб-сайт: <%= registrar.url %> diff --git a/spec/views/mailers/domain_mailer/expiration.html.erb_spec.rb b/spec/views/mailers/domain_mailer/expiration.html.erb_spec.rb index 735f0199c..d09af8d52 100644 --- a/spec/views/mailers/domain_mailer/expiration.html.erb_spec.rb +++ b/spec/views/mailers/domain_mailer/expiration.html.erb_spec.rb @@ -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 diff --git a/spec/views/mailers/domain_mailer/expiration.text.erb_spec.rb b/spec/views/mailers/domain_mailer/expiration.text.erb_spec.rb index 9af9978b7..3c6209eb2 100644 --- a/spec/views/mailers/domain_mailer/expiration.text.erb_spec.rb +++ b/spec/views/mailers/domain_mailer/expiration.text.erb_spec.rb @@ -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 diff --git a/spec/views/mailers/domain_mailer/pending_deleted.html.erb_spec.rb b/spec/views/mailers/domain_mailer/pending_deleted.html.erb_spec.rb index 7d58f3146..f56ca3b8a 100644 --- a/spec/views/mailers/domain_mailer/pending_deleted.html.erb_spec.rb +++ b/spec/views/mailers/domain_mailer/pending_deleted.html.erb_spec.rb @@ -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 diff --git a/spec/views/mailers/domain_mailer/pending_deleted.text.erb_spec.rb b/spec/views/mailers/domain_mailer/pending_deleted.text.erb_spec.rb index cc12bee64..e65f69988 100644 --- a/spec/views/mailers/domain_mailer/pending_deleted.text.erb_spec.rb +++ b/spec/views/mailers/domain_mailer/pending_deleted.text.erb_spec.rb @@ -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 diff --git a/spec/views/mailers/domain_mailer/pending_update_notification_for_new_registrant.html.erb_spec.rb b/spec/views/mailers/domain_mailer/pending_update_notification_for_new_registrant.html.erb_spec.rb new file mode 100644 index 000000000..8e27ca7cb --- /dev/null +++ b/spec/views/mailers/domain_mailer/pending_update_notification_for_new_registrant.html.erb_spec.rb @@ -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 diff --git a/spec/views/mailers/domain_mailer/pending_update_notification_for_new_registrant.text.erb_spec.rb b/spec/views/mailers/domain_mailer/pending_update_notification_for_new_registrant.text.erb_spec.rb new file mode 100644 index 000000000..99b6b2d91 --- /dev/null +++ b/spec/views/mailers/domain_mailer/pending_update_notification_for_new_registrant.text.erb_spec.rb @@ -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 diff --git a/spec/views/mailers/domain_mailer/pending_update_request_for_old_registrant.html.erb_spec.rb b/spec/views/mailers/domain_mailer/pending_update_request_for_old_registrant.html.erb_spec.rb index 3722d9093..b30624d75 100644 --- a/spec/views/mailers/domain_mailer/pending_update_request_for_old_registrant.html.erb_spec.rb +++ b/spec/views/mailers/domain_mailer/pending_update_request_for_old_registrant.html.erb_spec.rb @@ -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 diff --git a/spec/views/mailers/domain_mailer/pending_update_request_for_old_registrant.text.erb_spec.rb b/spec/views/mailers/domain_mailer/pending_update_request_for_old_registrant.text.erb_spec.rb index 9478e0238..80bd7202e 100644 --- a/spec/views/mailers/domain_mailer/pending_update_request_for_old_registrant.text.erb_spec.rb +++ b/spec/views/mailers/domain_mailer/pending_update_request_for_old_registrant.text.erb_spec.rb @@ -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 diff --git a/spec/views/mailers/domain_mailer/registrant.et.text.erb_spec.rb b/spec/views/mailers/domain_mailer/registrant.et.text.erb_spec.rb new file mode 100644 index 000000000..cf427e994 --- /dev/null +++ b/spec/views/mailers/domain_mailer/registrant.et.text.erb_spec.rb @@ -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 diff --git a/spec/views/mailers/domain_mailer/registrar.et.text.erb_spec.rb b/spec/views/mailers/domain_mailer/registrar.et.text.erb_spec.rb new file mode 100644 index 000000000..11ac13db6 --- /dev/null +++ b/spec/views/mailers/domain_mailer/registrar.et.text.erb_spec.rb @@ -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 From 962e98317dc774340dfe14597c7c636b4366ae31 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Fri, 11 Nov 2016 01:54:57 +0200 Subject: [PATCH 35/67] Refactor domain mailer views #180 --- .../domain_mailer/force_delete.html.erb | 15 +---- .../domain_mailer/force_delete.text.erb | 16 +---- ...update_request_for_old_registrant.html.erb | 8 +-- ...update_request_for_old_registrant.text.erb | 8 +-- .../domain_mailer/expiration.html.erb_spec.rb | 45 +------------- .../domain_mailer/expiration.text.erb_spec.rb | 45 +------------- .../domain_mailer/expiration_shared.rb | 53 ++++++++++++++++ .../force_delete.html.erb_spec.rb | 61 ++----------------- .../force_delete.text.erb_spec.rb | 61 ++----------------- .../domain_mailer/force_delete_shared.rb | 43 +++++++++++++ .../pending_deleted.html.erb_spec.rb | 30 +-------- .../pending_deleted.text.erb_spec.rb | 30 +-------- .../domain_mailer/pending_deleted_shared.rb | 35 +++++++++++ ...cation_for_new_registrant.html.erb_spec.rb | 20 +----- ...cation_for_new_registrant.text.erb_spec.rb | 17 +----- ..._notification_for_new_registrant_shared.rb | 40 ++++++++++++ ...equest_for_old_registrant.html.erb_spec.rb | 28 ++------- ...equest_for_old_registrant.text.erb_spec.rb | 28 ++------- ...pdate_request_for_old_registrant_shared.rb | 51 ++++++++++++++++ .../_registrant.en.html.erb_spec.rb | 6 ++ .../_registrant.en.text.erb_spec.rb | 6 ++ .../_registrant.et.html.erb_spec.rb | 6 ++ .../_registrant.et.text.erb_spec.rb | 6 ++ .../registrant_shared.rb} | 2 +- .../registrar/_registrar.en.html.erb_spec.rb | 6 ++ .../registrar/_registrar.en.text.erb_spec.rb | 6 ++ .../registrar/_registrar.et.html.erb_spec.rb | 6 ++ .../registrar/_registrar.et.text.erb_spec.rb | 6 ++ .../registrar/_registrar.ru.html.erb_spec.rb | 6 ++ .../registrar/_registrar.ru.text.erb_spec.rb | 6 ++ .../registrar_shared.rb} | 2 +- 31 files changed, 332 insertions(+), 366 deletions(-) create mode 100644 spec/views/mailers/domain_mailer/expiration_shared.rb create mode 100644 spec/views/mailers/domain_mailer/force_delete_shared.rb create mode 100644 spec/views/mailers/domain_mailer/pending_deleted_shared.rb create mode 100644 spec/views/mailers/domain_mailer/pending_update_notification_for_new_registrant_shared.rb create mode 100644 spec/views/mailers/domain_mailer/pending_update_request_for_old_registrant_shared.rb create mode 100644 spec/views/mailers/domain_mailer/registrant/_registrant.en.html.erb_spec.rb create mode 100644 spec/views/mailers/domain_mailer/registrant/_registrant.en.text.erb_spec.rb create mode 100644 spec/views/mailers/domain_mailer/registrant/_registrant.et.html.erb_spec.rb create mode 100644 spec/views/mailers/domain_mailer/registrant/_registrant.et.text.erb_spec.rb rename spec/views/mailers/domain_mailer/{registrant.et.text.erb_spec.rb => registrant/registrant_shared.rb} (87%) create mode 100644 spec/views/mailers/domain_mailer/registrar/_registrar.en.html.erb_spec.rb create mode 100644 spec/views/mailers/domain_mailer/registrar/_registrar.en.text.erb_spec.rb create mode 100644 spec/views/mailers/domain_mailer/registrar/_registrar.et.html.erb_spec.rb create mode 100644 spec/views/mailers/domain_mailer/registrar/_registrar.et.text.erb_spec.rb create mode 100644 spec/views/mailers/domain_mailer/registrar/_registrar.ru.html.erb_spec.rb create mode 100644 spec/views/mailers/domain_mailer/registrar/_registrar.ru.text.erb_spec.rb rename spec/views/mailers/domain_mailer/{registrar.et.text.erb_spec.rb => registrar/registrar_shared.rb} (87%) diff --git a/app/views/mailers/domain_mailer/force_delete.html.erb b/app/views/mailers/domain_mailer/force_delete.html.erb index 134c8d91b..47f54f9b4 100644 --- a/app/views/mailers/domain_mailer/force_delete.html.erb +++ b/app/views/mailers/domain_mailer/force_delete.html.erb @@ -21,10 +21,7 @@ Registrikood: <%= @registrant.ident %>

Lisaküsimuste korral võtke palun ühendust oma registripidajaga:

-

<%= @registrar.name %>
-Email: <%= @registrar.email %>
-Telefon: <%= @registrar.phone %>
-Veebileht: <%= @registrar.url %>

+<%= render 'mailers/domain_mailer/registrar/registrar.et.html', registrar: @registrar %>
@@ -45,10 +42,7 @@ Registry code: <%= @registrant.ident %>

Should you have additional questions, please contact your registrar:

-

<%= @registrar.name %>
-Email: <%= @registrar.email %>
-Phone: <%= @registrar.phone %>
-Website: <%= @registrar.url %>

+<%= render 'mailers/domain_mailer/registrar/registrar.en.html', registrar: @registrar %>
@@ -69,10 +63,7 @@ Website: <%= @registrar.url %>

Просим обратиться к своему регистратору:

-

<%= @registrar.name %>
-Электронная почта: <%= @registrar.email %>
-Телефон: <%= @registrar.phone %>
-Веб-сайт: <%= @registrar.url %>

+<%= render 'mailers/domain_mailer/registrar/registrar.ru.html', registrar: @registrar %>

diff --git a/app/views/mailers/domain_mailer/force_delete.text.erb b/app/views/mailers/domain_mailer/force_delete.text.erb index 871cdb7d8..7ac6ceb26 100644 --- a/app/views/mailers/domain_mailer/force_delete.text.erb +++ b/app/views/mailers/domain_mailer/force_delete.text.erb @@ -15,10 +15,7 @@ Kui üleandmine ei ole 30 päeva jooksul toimunud, kustub domeen <%= @domain.nam Lisaküsimuste korral võtke palun ühendust oma registripidajaga: -<%= @registrar.name %> -Email: <%= @registrar.email %> -Telefon: <%= @registrar.phone %> -Veebileht: <%= @registrar.url %> +<%= render 'mailers/domain_mailer/registrar/registrar.et.text', registrar: @registrar %> @@ -39,11 +36,7 @@ If the transfer has not been made in 30 days, the domain <%= @domain.name %> wil Should you have additional questions, please contact your registrar: -<%= @registrar.name %> -Email: <%= @registrar.email %> -Phone: <%= @registrar.phone %> -Website: <%= @registrar.url %> - +<%= render 'mailers/domain_mailer/registrar/registrar.en.text', registrar: @registrar %> Уважаемое контактное лицо домена <%= @domain.name %> @@ -63,10 +56,7 @@ EIS стало известно, что юридическое лицо с ре Просим обратиться к своему регистратору: -<%= @registrar.name %> -Электронная почта: <%= @registrar.email %> -Телефон: <%= @registrar.phone %> -Веб-сайт: <%= @registrar.url %> +<%= render 'mailers/domain_mailer/registrar/registrar.ru.text', registrar: @registrar %> Lugupidamisega, diff --git a/app/views/mailers/domain_mailer/pending_update_request_for_old_registrant.html.erb b/app/views/mailers/domain_mailer/pending_update_request_for_old_registrant.html.erb index 45174273a..cba83c6e0 100644 --- a/app/views/mailers/domain_mailer/pending_update_request_for_old_registrant.html.erb +++ b/app/views/mailers/domain_mailer/pending_update_request_for_old_registrant.html.erb @@ -2,11 +2,11 @@ Tere

Registrisse laekus taotlus domeeni <%= @domain.name %> registreerija vahetuseks. Palun veenduge, et muudatus on korrektne ning probleemide korral pöörduge oma registripidaja poole: -<%= render 'registrar.et.html', registrar: @registrar %> +<%= render 'mailers/domain_mailer/registrar/registrar.et.html', registrar: @registrar %>

Uue registreerija andmed:
-<%= render 'registrant.et.html', registrant: @registrant %> +<%= render 'mailers/domain_mailer/registrant/registrant.et.html', registrant: @new_registrant %>

Taotlus on aktiivne <%= Setting.expire_pending_confirmation %> tundi ja lükatakse automaatselt tagasi kui te seda enne ei kinnita või tagasi lükka.

@@ -23,11 +23,11 @@ Hi,

Application for changing registrant of your domain <%= @domain.name %> has been filed. Please make sure that the update and information are correct. In case of problems please turn to your registrar: -<%= render 'registrar.en.html', registrar: @registrar %> +<%= render 'mailers/domain_mailer/registrar/registrar.en.html', registrar: @registrar %>

New registrant:
-<%= render 'registrant.en.html', registrant: @registrant %> +<%= render 'mailers/domain_mailer/registrant/registrant.en.html', registrant: @new_registrant %>

The application will remain in pending status for <%= Setting.expire_pending_confirmation %> hrs and will be automaticcally rejected if it is not approved nor rejected before.

diff --git a/app/views/mailers/domain_mailer/pending_update_request_for_old_registrant.text.erb b/app/views/mailers/domain_mailer/pending_update_request_for_old_registrant.text.erb index b5d55d80d..f4ff079f2 100644 --- a/app/views/mailers/domain_mailer/pending_update_request_for_old_registrant.text.erb +++ b/app/views/mailers/domain_mailer/pending_update_request_for_old_registrant.text.erb @@ -2,10 +2,10 @@ Tere Registrisse laekus taotlus domeeni <%= @domain.name %> registreerija vahetuseks. Palun veenduge, et muudatus on korrektne ning probleemide korral pöörduge oma registripidaja poole: -<%= render 'registrar.et.text', registrar: @registrar %> +<%= render 'mailers/domain_mailer/registrar/registrar.et.text', registrar: @registrar %> Uue registreerija andmed: -<%= render 'registrant.et.text', registrant: @registrant %> +<%= render 'mailers/domain_mailer/registrant/registrant.et.text', registrant: @new_registrant %> Taotlus on aktiivne <%= Setting.expire_pending_confirmation %> tundi ja lükatakse automaatselt tagasi kui te seda enne ei kinnita või tagasi lükka. Muudatuse kinnitamiseks külastage palun allolevat lehekülge, kontrollige uuesti üle muudatuse andmed ning vajutage nuppu kinnitan: @@ -20,10 +20,10 @@ Hi, Application for changing registrant of your domain <%= @domain.name %> has been filed. Please make sure that the update and information are correct. In case of problems please turn to your registrar: -<%= render 'registrar.en.text', registrar: @registrar %> +<%= render 'mailers/domain_mailer/registrar/registrar.en.text', registrar: @registrar %> New registrant: -<%= render 'registrant.en.text', registrant: @registrant %> +<%= render 'mailers/domain_mailer/registrant/registrant.en.text', registrant: @new_registrant %> The application will remain in pending status for <%= Setting.expire_pending_confirmation %> hrs and will be automaticcally rejected if it is not approved nor rejected before. To confirm the update please visit this website, once again review the data and press approve: diff --git a/spec/views/mailers/domain_mailer/expiration.html.erb_spec.rb b/spec/views/mailers/domain_mailer/expiration.html.erb_spec.rb index d09af8d52..31f54be1b 100644 --- a/spec/views/mailers/domain_mailer/expiration.html.erb_spec.rb +++ b/spec/views/mailers/domain_mailer/expiration.html.erb_spec.rb @@ -1,53 +1,12 @@ require 'rails_helper' +require_relative 'expiration_shared' RSpec.describe 'mailers/domain_mailer/expiration.html.erb' do - let(:domain) { instance_spy(DomainPresenter) } - let(:lang_count) { 3 } - before :example do - assign(:domain, domain) - 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 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 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( - on_hold_date - delete_date - registrant_name - admin_contact_names - tech_contact_names - nameserver_names - ) - - 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 + include_examples 'domain mailer expiration' end diff --git a/spec/views/mailers/domain_mailer/expiration.text.erb_spec.rb b/spec/views/mailers/domain_mailer/expiration.text.erb_spec.rb index 3c6209eb2..3c315b47b 100644 --- a/spec/views/mailers/domain_mailer/expiration.text.erb_spec.rb +++ b/spec/views/mailers/domain_mailer/expiration.text.erb_spec.rb @@ -1,53 +1,12 @@ require 'rails_helper' +require_relative 'expiration_shared' RSpec.describe 'mailers/domain_mailer/expiration.text.erb' do - let(:domain) { instance_spy(DomainPresenter) } - let(:lang_count) { 3 } - before :example do - assign(:domain, domain) - 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 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 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( - on_hold_date - delete_date - registrant_name - admin_contact_names - tech_contact_names - nameserver_names - ) - - 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 + include_examples 'domain mailer expiration' end diff --git a/spec/views/mailers/domain_mailer/expiration_shared.rb b/spec/views/mailers/domain_mailer/expiration_shared.rb new file mode 100644 index 000000000..115ea4ef1 --- /dev/null +++ b/spec/views/mailers/domain_mailer/expiration_shared.rb @@ -0,0 +1,53 @@ +require 'rails_helper' + +RSpec.shared_examples 'domain mailer expiration' do + let(:domain) { instance_spy(DomainPresenter) } + let(:registrar) { instance_spy(RegistrarPresenter) } + let(:registrant) { instance_spy(RegistrantPresenter) } + let(:lang_count) { 3 } + + before :example do + assign(:domain, domain) + assign(:registrar, registrar) + assign(:registrant, registrant) + 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 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( + on_hold_date + delete_date + registrant_name + admin_contact_names + tech_contact_names + nameserver_names + ) + + 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 diff --git a/spec/views/mailers/domain_mailer/force_delete.html.erb_spec.rb b/spec/views/mailers/domain_mailer/force_delete.html.erb_spec.rb index 408777cc9..d201a6540 100644 --- a/spec/views/mailers/domain_mailer/force_delete.html.erb_spec.rb +++ b/spec/views/mailers/domain_mailer/force_delete.html.erb_spec.rb @@ -1,63 +1,12 @@ require 'rails_helper' +require_relative 'force_delete_shared' RSpec.describe 'mailers/domain_mailer/force_delete.html.erb' do - let(:domain) { instance_spy(DomainPresenter) } - let(:registrar) { instance_spy(RegistrarPresenter) } - let(:registrant) { instance_spy(RegistrantPresenter) } - let(:lang_count) { 3 } - before :example do - assign(:domain, domain) - assign(:registrar, registrar) - assign(:registrant, registrant) + 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 domain name' do - mention_count = 5 * 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 - - it 'has domain force delete date' do - mention_count = 1 * lang_count - expect(domain).to receive(:force_delete_date).exactly(mention_count).times.and_return('test domain force delete date') - render - expect(rendered).to have_text('test domain force delete date', count: mention_count) - 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') - render - expect(rendered).to have_text('test registrar name', count: mention_count) - end - - registrar_attributes = %i( - 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 - end - - it 'has registrant name' do - mention_count = 1 * lang_count - expect(registrant).to receive(:name).exactly(mention_count).times.and_return('test registrant name') - render - expect(rendered).to have_text('test registrant name', count: mention_count) - end - - it 'has registrant ident' do - mention_count = 2 * lang_count - expect(registrant).to receive(:ident).exactly(mention_count).times.and_return('test registrant ident') - render - expect(rendered).to have_text('test registrant ident', count: mention_count) - end + include_examples 'domain mailer force delete' end diff --git a/spec/views/mailers/domain_mailer/force_delete.text.erb_spec.rb b/spec/views/mailers/domain_mailer/force_delete.text.erb_spec.rb index 500e746af..824746208 100644 --- a/spec/views/mailers/domain_mailer/force_delete.text.erb_spec.rb +++ b/spec/views/mailers/domain_mailer/force_delete.text.erb_spec.rb @@ -1,63 +1,12 @@ require 'rails_helper' +require_relative 'force_delete_shared' RSpec.describe 'mailers/domain_mailer/force_delete.text.erb' do - let(:domain) { instance_spy(DomainPresenter) } - let(:registrar) { instance_spy(RegistrarPresenter) } - let(:registrant) { instance_spy(RegistrantPresenter) } - let(:lang_count) { 3 } - before :example do - assign(:domain, domain) - assign(:registrar, registrar) - assign(:registrant, registrant) + 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 domain name' do - mention_count = 5 * 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 - - it 'has domain force delete date' do - mention_count = 1 * lang_count - expect(domain).to receive(:force_delete_date).exactly(mention_count).times.and_return('test domain force delete date') - render - expect(rendered).to have_text('test domain force delete date', count: mention_count) - 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') - render - expect(rendered).to have_text('test registrar name', count: mention_count) - end - - registrar_attributes = %i( - 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 - end - - it 'has registrant name' do - mention_count = 1 * lang_count - expect(registrant).to receive(:name).exactly(mention_count).times.and_return('test registrant name') - render - expect(rendered).to have_text('test registrant name', count: mention_count) - end - - it 'has registrant ident' do - mention_count = 2 * lang_count - expect(registrant).to receive(:ident).exactly(mention_count).times.and_return('test registrant ident') - render - expect(rendered).to have_text('test registrant ident', count: mention_count) - end + include_examples 'domain mailer force delete' end diff --git a/spec/views/mailers/domain_mailer/force_delete_shared.rb b/spec/views/mailers/domain_mailer/force_delete_shared.rb new file mode 100644 index 000000000..36c407bb3 --- /dev/null +++ b/spec/views/mailers/domain_mailer/force_delete_shared.rb @@ -0,0 +1,43 @@ +require 'rails_helper' + +RSpec.shared_examples 'domain mailer force delete' do + let(:domain) { instance_spy(DomainPresenter) } + let(:registrar) { instance_spy(RegistrarPresenter) } + let(:registrant) { instance_spy(RegistrantPresenter) } + let(:lang_count) { 3 } + + before :example do + assign(:domain, domain) + assign(:registrar, registrar) + assign(:registrant, registrant) + 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 registrar info in russian' do + render + expect(rendered).to have_text('test registrar russian') + end + + it 'has domain name' do + mention_count = 5 * 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 + + it 'has domain force delete date' do + mention_count = 1 * lang_count + expect(domain).to receive(:force_delete_date).exactly(mention_count).times.and_return('test domain force delete date') + render + expect(rendered).to have_text('test domain force delete date', count: mention_count) + end +end diff --git a/spec/views/mailers/domain_mailer/pending_deleted.html.erb_spec.rb b/spec/views/mailers/domain_mailer/pending_deleted.html.erb_spec.rb index f56ca3b8a..cb3e96ec9 100644 --- a/spec/views/mailers/domain_mailer/pending_deleted.html.erb_spec.rb +++ b/spec/views/mailers/domain_mailer/pending_deleted.html.erb_spec.rb @@ -1,37 +1,11 @@ require 'rails_helper' +require_relative 'pending_deleted_shared' RSpec.describe 'mailers/domain_mailer/pending_deleted.html.erb' do - let(:domain) { instance_spy(DomainPresenter) } - let(:lang_count) { 2 } - before :example do - assign(:domain, domain) - 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 - mention_count = 1 * 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 - - it 'has verification url' do - mention_count = 1 * lang_count - render - expect(rendered).to have_text('test verification url', count: mention_count) - end + include_examples 'domain mailer pending deleted' end diff --git a/spec/views/mailers/domain_mailer/pending_deleted.text.erb_spec.rb b/spec/views/mailers/domain_mailer/pending_deleted.text.erb_spec.rb index e65f69988..2326cc9e1 100644 --- a/spec/views/mailers/domain_mailer/pending_deleted.text.erb_spec.rb +++ b/spec/views/mailers/domain_mailer/pending_deleted.text.erb_spec.rb @@ -1,37 +1,11 @@ require 'rails_helper' +require_relative 'pending_deleted_shared' RSpec.describe 'mailers/domain_mailer/pending_deleted.text.erb' do - let(:domain) { instance_spy(DomainPresenter) } - let(:lang_count) { 2 } - before :example do - assign(:domain, domain) - 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 - mention_count = 1 * 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 - - it 'has verification url' do - mention_count = 1 * lang_count - render - expect(rendered).to have_text('test verification url', count: mention_count) - end + include_examples 'domain mailer pending deleted' end diff --git a/spec/views/mailers/domain_mailer/pending_deleted_shared.rb b/spec/views/mailers/domain_mailer/pending_deleted_shared.rb new file mode 100644 index 000000000..950ec0309 --- /dev/null +++ b/spec/views/mailers/domain_mailer/pending_deleted_shared.rb @@ -0,0 +1,35 @@ +require 'rails_helper' + +RSpec.shared_examples 'domain mailer pending deleted' do + let(:domain) { instance_spy(DomainPresenter) } + let(:lang_count) { 2 } + + before :example do + assign(:domain, domain) + assign(:registrar, nil) + 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 + mention_count = 1 * 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 + + it 'has verification url' do + mention_count = 1 * lang_count + render + expect(rendered).to have_text('test verification url', count: mention_count) + end +end diff --git a/spec/views/mailers/domain_mailer/pending_update_notification_for_new_registrant.html.erb_spec.rb b/spec/views/mailers/domain_mailer/pending_update_notification_for_new_registrant.html.erb_spec.rb index 8e27ca7cb..9b6519654 100644 --- a/spec/views/mailers/domain_mailer/pending_update_notification_for_new_registrant.html.erb_spec.rb +++ b/spec/views/mailers/domain_mailer/pending_update_notification_for_new_registrant.html.erb_spec.rb @@ -1,22 +1,6 @@ require 'rails_helper' +require_relative 'pending_update_notification_for_new_registrant_shared' 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 + include_examples 'domain mailer pending update notification for new registrant' end diff --git a/spec/views/mailers/domain_mailer/pending_update_notification_for_new_registrant.text.erb_spec.rb b/spec/views/mailers/domain_mailer/pending_update_notification_for_new_registrant.text.erb_spec.rb index 99b6b2d91..cf39231b4 100644 --- a/spec/views/mailers/domain_mailer/pending_update_notification_for_new_registrant.text.erb_spec.rb +++ b/spec/views/mailers/domain_mailer/pending_update_notification_for_new_registrant.text.erb_spec.rb @@ -1,22 +1,9 @@ require 'rails_helper' +require_relative 'pending_update_notification_for_new_registrant_shared' RSpec.describe 'mailers/domain_mailer/pending_update_notification_for_new_registrant.text.erb' do - let(:domain) { instance_spy(DomainPresenter) } - let(:lang_count) { 2 } + include_examples 'domain mailer pending update notification for new registrant' - 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 diff --git a/spec/views/mailers/domain_mailer/pending_update_notification_for_new_registrant_shared.rb b/spec/views/mailers/domain_mailer/pending_update_notification_for_new_registrant_shared.rb new file mode 100644 index 000000000..9b95af51b --- /dev/null +++ b/spec/views/mailers/domain_mailer/pending_update_notification_for_new_registrant_shared.rb @@ -0,0 +1,40 @@ +require 'rails_helper' + +RSpec.shared_examples 'domain mailer pending update notification for new registrant' do + let(:domain) { instance_spy(DomainPresenter) } + let(:registrar) { instance_spy(RegistrarPresenter) } + let(:lang_count) { 2 } + + before :example do + assign(:domain, domain) + assign(:registrar, registrar) + 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 registrar name' do + expect(registrar).to receive(:name).and_return('test registrar name') + render + expect(rendered).to have_text('test registrar name') + 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 diff --git a/spec/views/mailers/domain_mailer/pending_update_request_for_old_registrant.html.erb_spec.rb b/spec/views/mailers/domain_mailer/pending_update_request_for_old_registrant.html.erb_spec.rb index b30624d75..b987759b5 100644 --- a/spec/views/mailers/domain_mailer/pending_update_request_for_old_registrant.html.erb_spec.rb +++ b/spec/views/mailers/domain_mailer/pending_update_request_for_old_registrant.html.erb_spec.rb @@ -1,29 +1,13 @@ require 'rails_helper' +require_relative 'pending_update_request_for_old_registrant_shared' RSpec.describe 'mailers/domain_mailer/pending_update_request_for_old_registrant.html.erb' do - let(:domain) { instance_spy(DomainPresenter) } - let(:lang_count) { 2 } - before :example do - assign(:domain, domain) - assign(:verification_url, 'test verification url') + 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/registrant/_registrant.et.html' => 'test new registrant estonian' + stub_template 'mailers/domain_mailer/registrant/_registrant.en.html' => 'test new registrant english' end - it 'has verification url' do - mention_count = 1 * lang_count - render - expect(rendered).to have_text('test verification url', count: mention_count) - end - - domain_attributes = %i( - name - ) - - 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) - render - expect(rendered).to have_text(attr_name.to_s, count: lang_count) - end - end + include_examples 'domain mailer pending update request for old registrant' end diff --git a/spec/views/mailers/domain_mailer/pending_update_request_for_old_registrant.text.erb_spec.rb b/spec/views/mailers/domain_mailer/pending_update_request_for_old_registrant.text.erb_spec.rb index 80bd7202e..4ca88bce1 100644 --- a/spec/views/mailers/domain_mailer/pending_update_request_for_old_registrant.text.erb_spec.rb +++ b/spec/views/mailers/domain_mailer/pending_update_request_for_old_registrant.text.erb_spec.rb @@ -1,29 +1,13 @@ require 'rails_helper' +require_relative 'pending_update_request_for_old_registrant_shared' RSpec.describe 'mailers/domain_mailer/pending_update_request_for_old_registrant.text.erb' do - let(:domain) { instance_spy(DomainPresenter) } - let(:lang_count) { 2 } - before :example do - assign(:domain, domain) - assign(:verification_url, 'test verification url') + 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/registrant/_registrant.et.text' => 'test new registrant estonian' + stub_template 'mailers/domain_mailer/registrant/_registrant.en.text' => 'test new registrant english' end - it 'has verification url' do - mention_count = 1 * lang_count - render - expect(rendered).to have_text('test verification url', count: mention_count) - end - - domain_attributes = %i( - name - ) - - 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) - render - expect(rendered).to have_text(attr_name.to_s, count: lang_count) - end - end + include_examples 'domain mailer pending update request for old registrant' end diff --git a/spec/views/mailers/domain_mailer/pending_update_request_for_old_registrant_shared.rb b/spec/views/mailers/domain_mailer/pending_update_request_for_old_registrant_shared.rb new file mode 100644 index 000000000..ed760aeed --- /dev/null +++ b/spec/views/mailers/domain_mailer/pending_update_request_for_old_registrant_shared.rb @@ -0,0 +1,51 @@ +require 'rails_helper' + +RSpec.shared_examples 'domain mailer pending update request for old registrant' do + let(:domain) { instance_spy(DomainPresenter) } + let(:lang_count) { 2 } + + before :example do + assign(:domain, domain) + assign(:registrar, nil) + assign(:new_registrant, nil) + 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 new registrant info in estonian' do + render + expect(rendered).to have_text('test new registrant estonian') + end + + it 'has new registrant info in english' do + render + expect(rendered).to have_text('test new registrant english') + end + + it 'has verification url' do + mention_count = 1 * lang_count + render + expect(rendered).to have_text('test verification url', count: mention_count) + 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(attr_name.to_s) + render + expect(rendered).to have_text(attr_name.to_s, count: lang_count) + end + end +end diff --git a/spec/views/mailers/domain_mailer/registrant/_registrant.en.html.erb_spec.rb b/spec/views/mailers/domain_mailer/registrant/_registrant.en.html.erb_spec.rb new file mode 100644 index 000000000..b93b592e6 --- /dev/null +++ b/spec/views/mailers/domain_mailer/registrant/_registrant.en.html.erb_spec.rb @@ -0,0 +1,6 @@ +require 'rails_helper' +require_relative 'registrant_shared' + +RSpec.describe 'mailers/domain_mailer/registrant/_registrant.en.html.erb' do + include_examples 'domain mailer registrant info' +end diff --git a/spec/views/mailers/domain_mailer/registrant/_registrant.en.text.erb_spec.rb b/spec/views/mailers/domain_mailer/registrant/_registrant.en.text.erb_spec.rb new file mode 100644 index 000000000..3a2310fff --- /dev/null +++ b/spec/views/mailers/domain_mailer/registrant/_registrant.en.text.erb_spec.rb @@ -0,0 +1,6 @@ +require 'rails_helper' +require_relative 'registrant_shared' + +RSpec.describe 'mailers/domain_mailer/registrant/_registrant.en.text.erb' do + include_examples 'domain mailer registrant info' +end diff --git a/spec/views/mailers/domain_mailer/registrant/_registrant.et.html.erb_spec.rb b/spec/views/mailers/domain_mailer/registrant/_registrant.et.html.erb_spec.rb new file mode 100644 index 000000000..952bb5223 --- /dev/null +++ b/spec/views/mailers/domain_mailer/registrant/_registrant.et.html.erb_spec.rb @@ -0,0 +1,6 @@ +require 'rails_helper' +require_relative 'registrant_shared' + +RSpec.describe 'mailers/domain_mailer/registrant/_registrant.et.html.erb' do + include_examples 'domain mailer registrant info' +end diff --git a/spec/views/mailers/domain_mailer/registrant/_registrant.et.text.erb_spec.rb b/spec/views/mailers/domain_mailer/registrant/_registrant.et.text.erb_spec.rb new file mode 100644 index 000000000..ea05cbfa5 --- /dev/null +++ b/spec/views/mailers/domain_mailer/registrant/_registrant.et.text.erb_spec.rb @@ -0,0 +1,6 @@ +require 'rails_helper' +require_relative 'registrant_shared' + +RSpec.describe 'mailers/domain_mailer/registrant/_registrant.et.text.erb' do + include_examples 'domain mailer registrant info' +end diff --git a/spec/views/mailers/domain_mailer/registrant.et.text.erb_spec.rb b/spec/views/mailers/domain_mailer/registrant/registrant_shared.rb similarity index 87% rename from spec/views/mailers/domain_mailer/registrant.et.text.erb_spec.rb rename to spec/views/mailers/domain_mailer/registrant/registrant_shared.rb index cf427e994..07fcc3b1e 100644 --- a/spec/views/mailers/domain_mailer/registrant.et.text.erb_spec.rb +++ b/spec/views/mailers/domain_mailer/registrant/registrant_shared.rb @@ -1,6 +1,6 @@ require 'rails_helper' -RSpec.describe 'mailers/domain_mailer/_registrant.et.text.erb' do +RSpec.shared_examples 'domain mailer registrant info' do let(:registrant) { instance_spy(RegistrantPresenter) } before :example do diff --git a/spec/views/mailers/domain_mailer/registrar/_registrar.en.html.erb_spec.rb b/spec/views/mailers/domain_mailer/registrar/_registrar.en.html.erb_spec.rb new file mode 100644 index 000000000..62fe5d068 --- /dev/null +++ b/spec/views/mailers/domain_mailer/registrar/_registrar.en.html.erb_spec.rb @@ -0,0 +1,6 @@ +require 'rails_helper' +require_relative 'registrar_shared' + +RSpec.describe 'mailers/domain_mailer/registrar/_registrar.en.html.erb' do + include_examples 'domain mailer registrar info' +end diff --git a/spec/views/mailers/domain_mailer/registrar/_registrar.en.text.erb_spec.rb b/spec/views/mailers/domain_mailer/registrar/_registrar.en.text.erb_spec.rb new file mode 100644 index 000000000..542d8aaee --- /dev/null +++ b/spec/views/mailers/domain_mailer/registrar/_registrar.en.text.erb_spec.rb @@ -0,0 +1,6 @@ +require 'rails_helper' +require_relative 'registrar_shared' + +RSpec.describe 'mailers/domain_mailer/registrar/_registrar.en.text.erb' do + include_examples 'domain mailer registrar info' +end diff --git a/spec/views/mailers/domain_mailer/registrar/_registrar.et.html.erb_spec.rb b/spec/views/mailers/domain_mailer/registrar/_registrar.et.html.erb_spec.rb new file mode 100644 index 000000000..e9eab5b94 --- /dev/null +++ b/spec/views/mailers/domain_mailer/registrar/_registrar.et.html.erb_spec.rb @@ -0,0 +1,6 @@ +require 'rails_helper' +require_relative 'registrar_shared' + +RSpec.describe 'mailers/domain_mailer/registrar/_registrar.et.html.erb' do + include_examples 'domain mailer registrar info' +end diff --git a/spec/views/mailers/domain_mailer/registrar/_registrar.et.text.erb_spec.rb b/spec/views/mailers/domain_mailer/registrar/_registrar.et.text.erb_spec.rb new file mode 100644 index 000000000..6493be41c --- /dev/null +++ b/spec/views/mailers/domain_mailer/registrar/_registrar.et.text.erb_spec.rb @@ -0,0 +1,6 @@ +require 'rails_helper' +require_relative 'registrar_shared' + +RSpec.describe 'mailers/domain_mailer/registrar/_registrar.et.text.erb' do + include_examples 'domain mailer registrar info' +end diff --git a/spec/views/mailers/domain_mailer/registrar/_registrar.ru.html.erb_spec.rb b/spec/views/mailers/domain_mailer/registrar/_registrar.ru.html.erb_spec.rb new file mode 100644 index 000000000..384beec23 --- /dev/null +++ b/spec/views/mailers/domain_mailer/registrar/_registrar.ru.html.erb_spec.rb @@ -0,0 +1,6 @@ +require 'rails_helper' +require_relative 'registrar_shared' + +RSpec.describe 'mailers/domain_mailer/registrar/_registrar.ru.html.erb' do + include_examples 'domain mailer registrar info' +end diff --git a/spec/views/mailers/domain_mailer/registrar/_registrar.ru.text.erb_spec.rb b/spec/views/mailers/domain_mailer/registrar/_registrar.ru.text.erb_spec.rb new file mode 100644 index 000000000..f26eca18f --- /dev/null +++ b/spec/views/mailers/domain_mailer/registrar/_registrar.ru.text.erb_spec.rb @@ -0,0 +1,6 @@ +require 'rails_helper' +require_relative 'registrar_shared' + +RSpec.describe 'mailers/domain_mailer/registrar/_registrar.ru.text.erb' do + include_examples 'domain mailer registrar info' +end diff --git a/spec/views/mailers/domain_mailer/registrar.et.text.erb_spec.rb b/spec/views/mailers/domain_mailer/registrar/registrar_shared.rb similarity index 87% rename from spec/views/mailers/domain_mailer/registrar.et.text.erb_spec.rb rename to spec/views/mailers/domain_mailer/registrar/registrar_shared.rb index 11ac13db6..f9c98c94a 100644 --- a/spec/views/mailers/domain_mailer/registrar.et.text.erb_spec.rb +++ b/spec/views/mailers/domain_mailer/registrar/registrar_shared.rb @@ -1,6 +1,6 @@ require 'rails_helper' -RSpec.describe 'mailers/domain_mailer/_registrar.et.text.erb' do +RSpec.shared_examples 'domain mailer registrar info' do let(:registrar) { instance_spy(RegistrarPresenter) } before :example do From a6de3761c5b6a6aee1febb1e2768b81de795f86f Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Sat, 12 Nov 2016 01:14:11 +0200 Subject: [PATCH 36/67] Refactor domain mailer views #180 --- app/mailers/delete_domain_mailer.rb | 18 ++++ app/mailers/domain_mailer.rb | 32 -------- app/mailers/registrant_change_mailer.rb | 45 ++++++++++ app/models/domain.rb | 7 +- app/models/domain_mail_model.rb | 33 +++----- .../pending.html.erb} | 4 +- .../pending.text.erb} | 4 +- ...d_notification_for_new_registrant.html.erb | 2 +- ...d_notification_for_new_registrant.text.erb | 0 ...e_notification_for_new_registrant.html.erb | 0 ...e_notification_for_new_registrant.text.erb | 0 ...d_notification_for_new_registrant.html.erb | 0 ...d_notification_for_new_registrant.text.erb | 0 ...update_request_for_old_registrant.html.erb | 0 ...update_request_for_old_registrant.text.erb | 0 .../registrant/_registrant.en.html.erb | 0 .../registrant/_registrant.en.text.erb | 0 .../registrant/_registrant.et.html.erb | 0 .../registrant/_registrant.et.text.erb | 0 .../registrar/_registrar.en.html.erb | 0 .../registrar/_registrar.en.text.erb | 0 .../registrar/_registrar.et.html.erb | 0 .../registrar/_registrar.et.text.erb | 0 .../registrar/_registrar.ru.html.erb | 0 .../registrar/_registrar.ru.text.erb | 0 config/locales/mailers/delete_domain.en.yml | 6 ++ config/locales/mailers/domain.en.yml | 10 +-- .../locales/mailers/registrant_change.en.yml | 4 + spec/mailers/delete_domain_mailer_spec.rb | 42 ++++++++++ spec/mailers/domain_mailer_spec.rb | 82 ------------------- spec/mailers/registrant_change_mailer_spec.rb | 46 +++++++++++ spec/models/domain_spec.rb | 8 +- .../pending.html.erb_spec.rb | 11 +++ .../pending.text.erb_spec.rb | 11 +++ .../pending_shared.rb} | 2 +- .../pending_deleted.html.erb_spec.rb | 11 --- .../pending_deleted.text.erb_spec.rb | 11 --- ...equest_for_old_registrant.html.erb_spec.rb | 13 --- ...equest_for_old_registrant.text.erb_spec.rb | 13 --- .../confirmation.html.erb_spec.rb | 13 +++ .../confirmation.text.erb_spec.rb | 13 +++ .../confirmation_shared.rb} | 0 ...cation_for_new_registrant.html.erb_spec.rb | 0 ...cation_for_new_registrant.text.erb_spec.rb | 0 ..._notification_for_new_registrant_shared.rb | 0 .../_registrant.en.html.erb_spec.rb | 0 .../_registrant.en.text.erb_spec.rb | 0 .../_registrant.et.html.erb_spec.rb | 0 .../_registrant.et.text.erb_spec.rb | 0 .../registrant/registrant_shared.rb | 0 .../registrar/_registrar.en.html.erb_spec.rb | 0 .../registrar/_registrar.en.text.erb_spec.rb | 0 .../registrar/_registrar.et.html.erb_spec.rb | 0 .../registrar/_registrar.et.text.erb_spec.rb | 0 .../registrar/_registrar.ru.html.erb_spec.rb | 0 .../registrar/_registrar.ru.text.erb_spec.rb | 0 .../registrar/registrar_shared.rb | 0 57 files changed, 238 insertions(+), 203 deletions(-) create mode 100644 app/mailers/delete_domain_mailer.rb create mode 100644 app/mailers/registrant_change_mailer.rb rename app/views/mailers/{domain_mailer/pending_deleted.html.erb => delete_domain_mailer/pending.html.erb} (87%) rename app/views/mailers/{domain_mailer/pending_deleted.text.erb => delete_domain_mailer/pending.text.erb} (86%) rename app/views/mailers/{domain_mailer => registrant_change_mailer}/pending_update_expired_notification_for_new_registrant.html.erb (91%) rename app/views/mailers/{domain_mailer => registrant_change_mailer}/pending_update_expired_notification_for_new_registrant.text.erb (100%) rename app/views/mailers/{domain_mailer => registrant_change_mailer}/pending_update_notification_for_new_registrant.html.erb (100%) rename app/views/mailers/{domain_mailer => registrant_change_mailer}/pending_update_notification_for_new_registrant.text.erb (100%) rename app/views/mailers/{domain_mailer => registrant_change_mailer}/pending_update_rejected_notification_for_new_registrant.html.erb (100%) rename app/views/mailers/{domain_mailer => registrant_change_mailer}/pending_update_rejected_notification_for_new_registrant.text.erb (100%) rename app/views/mailers/{domain_mailer => registrant_change_mailer}/pending_update_request_for_old_registrant.html.erb (100%) rename app/views/mailers/{domain_mailer => registrant_change_mailer}/pending_update_request_for_old_registrant.text.erb (100%) rename app/views/mailers/{domain_mailer => shared}/registrant/_registrant.en.html.erb (100%) rename app/views/mailers/{domain_mailer => shared}/registrant/_registrant.en.text.erb (100%) rename app/views/mailers/{domain_mailer => shared}/registrant/_registrant.et.html.erb (100%) rename app/views/mailers/{domain_mailer => shared}/registrant/_registrant.et.text.erb (100%) rename app/views/mailers/{domain_mailer => shared}/registrar/_registrar.en.html.erb (100%) rename app/views/mailers/{domain_mailer => shared}/registrar/_registrar.en.text.erb (100%) rename app/views/mailers/{domain_mailer => shared}/registrar/_registrar.et.html.erb (100%) rename app/views/mailers/{domain_mailer => shared}/registrar/_registrar.et.text.erb (100%) rename app/views/mailers/{domain_mailer => shared}/registrar/_registrar.ru.html.erb (100%) rename app/views/mailers/{domain_mailer => shared}/registrar/_registrar.ru.text.erb (100%) create mode 100644 config/locales/mailers/delete_domain.en.yml create mode 100644 config/locales/mailers/registrant_change.en.yml create mode 100644 spec/mailers/delete_domain_mailer_spec.rb create mode 100644 spec/mailers/registrant_change_mailer_spec.rb create mode 100644 spec/views/mailers/delete_domain_mailer/pending.html.erb_spec.rb create mode 100644 spec/views/mailers/delete_domain_mailer/pending.text.erb_spec.rb rename spec/views/mailers/{domain_mailer/pending_deleted_shared.rb => delete_domain_mailer/pending_shared.rb} (94%) delete mode 100644 spec/views/mailers/domain_mailer/pending_deleted.html.erb_spec.rb delete mode 100644 spec/views/mailers/domain_mailer/pending_deleted.text.erb_spec.rb delete mode 100644 spec/views/mailers/domain_mailer/pending_update_request_for_old_registrant.html.erb_spec.rb delete mode 100644 spec/views/mailers/domain_mailer/pending_update_request_for_old_registrant.text.erb_spec.rb create mode 100644 spec/views/mailers/registrant_change_mailer/confirmation.html.erb_spec.rb create mode 100644 spec/views/mailers/registrant_change_mailer/confirmation.text.erb_spec.rb rename spec/views/mailers/{domain_mailer/pending_update_request_for_old_registrant_shared.rb => registrant_change_mailer/confirmation_shared.rb} (100%) rename spec/views/mailers/{domain_mailer => registrant_change_mailer}/pending_update_notification_for_new_registrant.html.erb_spec.rb (100%) rename spec/views/mailers/{domain_mailer => registrant_change_mailer}/pending_update_notification_for_new_registrant.text.erb_spec.rb (100%) rename spec/views/mailers/{domain_mailer => registrant_change_mailer}/pending_update_notification_for_new_registrant_shared.rb (100%) rename spec/views/mailers/{domain_mailer => shared}/registrant/_registrant.en.html.erb_spec.rb (100%) rename spec/views/mailers/{domain_mailer => shared}/registrant/_registrant.en.text.erb_spec.rb (100%) rename spec/views/mailers/{domain_mailer => shared}/registrant/_registrant.et.html.erb_spec.rb (100%) rename spec/views/mailers/{domain_mailer => shared}/registrant/_registrant.et.text.erb_spec.rb (100%) rename spec/views/mailers/{domain_mailer => shared}/registrant/registrant_shared.rb (100%) rename spec/views/mailers/{domain_mailer => shared}/registrar/_registrar.en.html.erb_spec.rb (100%) rename spec/views/mailers/{domain_mailer => shared}/registrar/_registrar.en.text.erb_spec.rb (100%) rename spec/views/mailers/{domain_mailer => shared}/registrar/_registrar.et.html.erb_spec.rb (100%) rename spec/views/mailers/{domain_mailer => shared}/registrar/_registrar.et.text.erb_spec.rb (100%) rename spec/views/mailers/{domain_mailer => shared}/registrar/_registrar.ru.html.erb_spec.rb (100%) rename spec/views/mailers/{domain_mailer => shared}/registrar/_registrar.ru.text.erb_spec.rb (100%) rename spec/views/mailers/{domain_mailer => shared}/registrar/registrar_shared.rb (100%) diff --git a/app/mailers/delete_domain_mailer.rb b/app/mailers/delete_domain_mailer.rb new file mode 100644 index 000000000..4a8f4f7c4 --- /dev/null +++ b/app/mailers/delete_domain_mailer.rb @@ -0,0 +1,18 @@ +class DeleteDomainMailer < ApplicationMailer + include Que::Mailer + + def pending(domain:, old_registrant:) + @domain = DomainPresenter.new(domain: domain, view: view_context) + @registrar = RegistrarPresenter.new(registrar: domain.registrar, view: view_context) + @verification_url = verification_url(domain) + + subject = default_i18n_subject(domain_name: domain.name) + mail(to: old_registrant.email, subject: subject) + end + + private + + def verification_url(domain) + registrant_domain_delete_confirm_url(domain, token: domain.registrant_verification_token) + end +end diff --git a/app/mailers/domain_mailer.rb b/app/mailers/domain_mailer.rb index b6cd9c309..915fffa57 100644 --- a/app/mailers/domain_mailer.rb +++ b/app/mailers/domain_mailer.rb @@ -1,21 +1,6 @@ class DomainMailer < ApplicationMailer include Que::Mailer - def pending_update_request_for_old_registrant(domain:, registrant:) - @domain = DomainPresenter.new(domain: domain, view: view_context) - @registrar = RegistrarPresenter.new(registrar: domain.registrar, view: view_context) - @registrant = RegistrantPresenter.new(registrant: registrant, view: view_context) - @verification_url = registrant_domain_update_confirm_url(domain, token: domain.registrant_verification_token) - - subject = default_i18n_subject(domain_name: domain.name) - mail(to: registrant.email, subject: subject) - end - - def pending_update_notification_for_new_registrant(params) - compose_from(params) - end - - def registrant_updated_notification_for_new_registrant(domain_id, old_registrant_id, new_registrant_id, should_deliver) @domain = Domain.find_by(id: domain_id) return unless @domain @@ -45,23 +30,6 @@ class DomainMailer < ApplicationMailer name: @domain.name)} [#{@domain.name}]") end - def pending_update_rejected_notification_for_new_registrant(params) - compose_from(params) - end - - def pending_update_expired_notification_for_new_registrant(params) - compose_from(params) - end - - def pending_deleted(domain:, registrant:) - @domain = DomainPresenter.new(domain: domain, view: view_context) - @registrar = RegistrarPresenter.new(registrar: domain.registrar, view: view_context) - @verification_url = registrant_domain_delete_confirm_url(domain, token: domain.registrant_verification_token) - - subject = default_i18n_subject(domain_name: domain.name) - mail(to: registrant.email, subject: subject) - end - def pending_delete_rejected_notification(domain_id, should_deliver) @domain = Domain.find_by(id: domain_id) return unless @domain diff --git a/app/mailers/registrant_change_mailer.rb b/app/mailers/registrant_change_mailer.rb new file mode 100644 index 000000000..a29f3aee1 --- /dev/null +++ b/app/mailers/registrant_change_mailer.rb @@ -0,0 +1,45 @@ +class RegistrantChangeMailer < ApplicationMailer + include Que::Mailer + + def confirmation(domain:, registrant:) + @domain = DomainPresenter.new(domain: domain, view: view_context) + @registrar = RegistrarPresenter.new(registrar: domain.registrar, view: view_context) + @registrant = RegistrantPresenter.new(registrant: registrant, view: view_context) + @verification_url = confirm_url(domain) + + subject = default_i18n_subject(domain_name: domain.name) + mail(to: registrant.email, subject: subject) + end + + def pending_update_notification_for_new_registrant(params) + compose_from(params) + end + + def registrant_updated_notification_for_old_registrant(domain_id, old_registrant_id, new_registrant_id, should_deliver) + @domain = Domain.find_by(id: domain_id) + return unless @domain + return if delivery_off?(@domain, should_deliver) + + @old_registrant = Registrant.find(old_registrant_id) + @new_registrant = Registrant.find(new_registrant_id) + + return if whitelist_blocked?(@old_registrant.email) + mail(to: format(@old_registrant.email), + subject: "#{I18n.t(:registrant_updated_notification_for_old_registrant_subject, + name: @domain.name)} [#{@domain.name}]") + end + + def pending_update_rejected_notification_for_new_registrant(params) + compose_from(params) + end + + def pending_update_expired_notification_for_new_registrant(params) + compose_from(params) + end + + private + + def confirm_url(domain) + registrant_domain_update_confirm_url(domain, token: domain.registrant_verification_token) + end +end diff --git a/app/models/domain.rb b/app/models/domain.rb index a9d5147a6..c97877047 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -379,6 +379,9 @@ class Domain < ActiveRecord::Base new_registrant_email = registrant.email new_registrant_name = registrant.name + current_registrant = Registrant.find(registrant_id_was) + RegistrantChangeMailer.confirmation(domain: self, current_registrant: current_registrant).deliver + send_mail :pending_update_request_for_old_registrant send_mail :pending_update_notification_for_new_registrant @@ -441,8 +444,8 @@ class Domain < ActiveRecord::Base pending_delete_confirmation! save(validate: false) # should check if this did succeed - previous_registrant = Registrant.find(registrant_id_was) - DomainMailer.pending_deleted(domain: self, registrant: previous_registrant).deliver + old_registrant = Registrant.find(registrant_id_was) + DeleteDomainMailer.pending(domain: self, old_registrant: old_registrant).deliver end def cancel_pending_delete diff --git a/app/models/domain_mail_model.rb b/app/models/domain_mail_model.rb index d443d8783..49effbb1f 100644 --- a/app/models/domain_mail_model.rb +++ b/app/models/domain_mail_model.rb @@ -1,6 +1,6 @@ class DomainMailModel # Capture current values used in app/views/mailers/domain_mailer/* and app/mailers/domain_mailer will send later - + def initialize(domain) @domain = domain @params = {errors: [], deliver_emails: domain.deliver_emails, id: domain.id} @@ -15,13 +15,13 @@ class DomainMailModel end def pending_update_notification_for_new_registrant - registrant # new registrant at this point + registrant # new registrant at this point subject(:pending_update_notification_for_new_registrant_subject) domain_info compose end - + def pending_update_rejected_notification_for_new_registrant registrant_pending subject(:pending_update_rejected_notification_for_new_registrant_subject) @@ -37,13 +37,6 @@ class DomainMailModel compose end - def pending_deleted - registrant - subject(:domain_pending_deleted_subject) - confirm_delete - compose - end - def pending_delete_rejected_notification registrant subject(:pending_delete_rejected_notification_subject) @@ -69,11 +62,11 @@ class DomainMailModel end private - + def registrant_old @params[:recipient] = format Registrant.find(@domain.registrant_id_was).email end - + def registrant @params[:recipient] = format @domain.registrant.email end @@ -83,7 +76,7 @@ class DomainMailModel @params[:new_registrant_name] = @domain.pending_json['new_registrant_name'] @params[:old_registrant_name] = @domain.registrant.name end - + # registrant and domain admin contacts def admins emails = ([@domain.registrant.email] + @domain.admin_contacts.map { |x| format(x.email) }) @@ -106,26 +99,22 @@ class DomainMailModel def confirm_update verification_url('domain_update_confirms') end - - def confirm_delete - verification_url('domain_delete_confirms') - end def compose @params end - + def verification_url(path) token = verification_token or return @params[:verification_url] = "#{ENV['registrant_url']}/registrant/#{path}/#{@domain.id}?token=#{token}" end - + def verification_token return warn_missing(:registrant_verification_token) if @domain.registrant_verification_token.blank? return warn_missing(:registrant_verification_asked_at) if @domain.registrant_verification_asked_at.blank? @domain.registrant_verification_token end - + def domain_info [:name, :registrar_name, :registrant_name, :registrant_ident, :registrant_email, @@ -143,7 +132,7 @@ class DomainMailModel warn_missing item nil end - + def warn_missing(item) warn_not_delivered "#{item.to_s} is missing for #{@domain.name}" end @@ -154,6 +143,6 @@ class DomainMailModel # Rails.logger.warn message nil end - + end diff --git a/app/views/mailers/domain_mailer/pending_deleted.html.erb b/app/views/mailers/delete_domain_mailer/pending.html.erb similarity index 87% rename from app/views/mailers/domain_mailer/pending_deleted.html.erb rename to app/views/mailers/delete_domain_mailer/pending.html.erb index 8a6c8e2bc..ced759234 100644 --- a/app/views/mailers/domain_mailer/pending_deleted.html.erb +++ b/app/views/mailers/delete_domain_mailer/pending.html.erb @@ -2,7 +2,7 @@ Tere

Registrisse laekus taotlus domeeni <%= @domain.name %> kustutamiseks. Palun veenduge, et muudatus on korrektne ning probleemide korral pöörduge oma registripidaja poole: -<%= render 'mailers/domain_mailer/registrar/registrar.et.html', registrar: @registrar %> +<%= render 'mailers/shared/registrar/registrar.et.html', registrar: @registrar %>

Muudatuse kinnitamiseks külastage palun allolevat lehekülge, kontrollige uuesti üle muudatuse andmed ning vajutage nuppu kinnitan. @@ -19,7 +19,7 @@ Hi,

Application for deletion of your domain <%= @domain.name %> has been filed. Please make sure that the application is correct. Incase of problems please contact your registrar: -<%= render 'mailers/domain_mailer/registrar/registrar.en.html', registrar: @registrar %> +<%= render 'mailers/shared/registrar/registrar.en.html', registrar: @registrar %>

To confirm the update please visit this website, once again review the data and press approve:
diff --git a/app/views/mailers/domain_mailer/pending_deleted.text.erb b/app/views/mailers/delete_domain_mailer/pending.text.erb similarity index 86% rename from app/views/mailers/domain_mailer/pending_deleted.text.erb rename to app/views/mailers/delete_domain_mailer/pending.text.erb index 39460443a..a16fd82ff 100644 --- a/app/views/mailers/domain_mailer/pending_deleted.text.erb +++ b/app/views/mailers/delete_domain_mailer/pending.text.erb @@ -2,7 +2,7 @@ Tere Registrisse laekus taotlus domeeni <%= @domain.name %> kustutamiseks. Palun veenduge, et muudatus on korrektne ning probleemide korral pöörduge oma registripidaja poole: -<%= render 'mailers/domain_mailer/registrar/registrar.et.text', registrar: @registrar %> +<%= render 'mailers/shared/registrar/registrar.et.text', registrar: @registrar %> Muudatuse kinnitamiseks külastage palun allolevat lehekülge, kontrollige uuesti üle muudatuse andmed ning vajutage nuppu kinnitan. @@ -18,7 +18,7 @@ Hi, Application for deletion of your domain <%= @domain.name %> has been filed. Please make sure that the application is correct. In case of problems please contact your registrar: -<%= render 'mailers/domain_mailer/registrar/registrar.en.text', registrar: @registrar %> +<%= render 'mailers/shared/registrar/registrar.en.text', registrar: @registrar %> To confirm the update please visit this website, once again review the data and press approve: <%= @verification_url %> diff --git a/app/views/mailers/domain_mailer/pending_update_expired_notification_for_new_registrant.html.erb b/app/views/mailers/registrant_change_mailer/pending_update_expired_notification_for_new_registrant.html.erb similarity index 91% rename from app/views/mailers/domain_mailer/pending_update_expired_notification_for_new_registrant.html.erb rename to app/views/mailers/registrant_change_mailer/pending_update_expired_notification_for_new_registrant.html.erb index 139e0a850..90d17462b 100644 --- a/app/views/mailers/domain_mailer/pending_update_expired_notification_for_new_registrant.html.erb +++ b/app/views/mailers/registrant_change_mailer/pending_update_expired_notification_for_new_registrant.html.erb @@ -16,7 +16,7 @@ Hi,

Domain registrant change request has been expired for the domain <%= @domain.name %>.

-Please contact to your registrar if you have any questions: +Please contact to your registrar if you have any questions: <%= render 'registrar.en.html', registrar: @registrar %> diff --git a/app/views/mailers/domain_mailer/pending_update_expired_notification_for_new_registrant.text.erb b/app/views/mailers/registrant_change_mailer/pending_update_expired_notification_for_new_registrant.text.erb similarity index 100% rename from app/views/mailers/domain_mailer/pending_update_expired_notification_for_new_registrant.text.erb rename to app/views/mailers/registrant_change_mailer/pending_update_expired_notification_for_new_registrant.text.erb diff --git a/app/views/mailers/domain_mailer/pending_update_notification_for_new_registrant.html.erb b/app/views/mailers/registrant_change_mailer/pending_update_notification_for_new_registrant.html.erb similarity index 100% rename from app/views/mailers/domain_mailer/pending_update_notification_for_new_registrant.html.erb rename to app/views/mailers/registrant_change_mailer/pending_update_notification_for_new_registrant.html.erb diff --git a/app/views/mailers/domain_mailer/pending_update_notification_for_new_registrant.text.erb b/app/views/mailers/registrant_change_mailer/pending_update_notification_for_new_registrant.text.erb similarity index 100% rename from app/views/mailers/domain_mailer/pending_update_notification_for_new_registrant.text.erb rename to app/views/mailers/registrant_change_mailer/pending_update_notification_for_new_registrant.text.erb diff --git a/app/views/mailers/domain_mailer/pending_update_rejected_notification_for_new_registrant.html.erb b/app/views/mailers/registrant_change_mailer/pending_update_rejected_notification_for_new_registrant.html.erb similarity index 100% rename from app/views/mailers/domain_mailer/pending_update_rejected_notification_for_new_registrant.html.erb rename to app/views/mailers/registrant_change_mailer/pending_update_rejected_notification_for_new_registrant.html.erb diff --git a/app/views/mailers/domain_mailer/pending_update_rejected_notification_for_new_registrant.text.erb b/app/views/mailers/registrant_change_mailer/pending_update_rejected_notification_for_new_registrant.text.erb similarity index 100% rename from app/views/mailers/domain_mailer/pending_update_rejected_notification_for_new_registrant.text.erb rename to app/views/mailers/registrant_change_mailer/pending_update_rejected_notification_for_new_registrant.text.erb diff --git a/app/views/mailers/domain_mailer/pending_update_request_for_old_registrant.html.erb b/app/views/mailers/registrant_change_mailer/pending_update_request_for_old_registrant.html.erb similarity index 100% rename from app/views/mailers/domain_mailer/pending_update_request_for_old_registrant.html.erb rename to app/views/mailers/registrant_change_mailer/pending_update_request_for_old_registrant.html.erb diff --git a/app/views/mailers/domain_mailer/pending_update_request_for_old_registrant.text.erb b/app/views/mailers/registrant_change_mailer/pending_update_request_for_old_registrant.text.erb similarity index 100% rename from app/views/mailers/domain_mailer/pending_update_request_for_old_registrant.text.erb rename to app/views/mailers/registrant_change_mailer/pending_update_request_for_old_registrant.text.erb diff --git a/app/views/mailers/domain_mailer/registrant/_registrant.en.html.erb b/app/views/mailers/shared/registrant/_registrant.en.html.erb similarity index 100% rename from app/views/mailers/domain_mailer/registrant/_registrant.en.html.erb rename to app/views/mailers/shared/registrant/_registrant.en.html.erb diff --git a/app/views/mailers/domain_mailer/registrant/_registrant.en.text.erb b/app/views/mailers/shared/registrant/_registrant.en.text.erb similarity index 100% rename from app/views/mailers/domain_mailer/registrant/_registrant.en.text.erb rename to app/views/mailers/shared/registrant/_registrant.en.text.erb diff --git a/app/views/mailers/domain_mailer/registrant/_registrant.et.html.erb b/app/views/mailers/shared/registrant/_registrant.et.html.erb similarity index 100% rename from app/views/mailers/domain_mailer/registrant/_registrant.et.html.erb rename to app/views/mailers/shared/registrant/_registrant.et.html.erb diff --git a/app/views/mailers/domain_mailer/registrant/_registrant.et.text.erb b/app/views/mailers/shared/registrant/_registrant.et.text.erb similarity index 100% rename from app/views/mailers/domain_mailer/registrant/_registrant.et.text.erb rename to app/views/mailers/shared/registrant/_registrant.et.text.erb diff --git a/app/views/mailers/domain_mailer/registrar/_registrar.en.html.erb b/app/views/mailers/shared/registrar/_registrar.en.html.erb similarity index 100% rename from app/views/mailers/domain_mailer/registrar/_registrar.en.html.erb rename to app/views/mailers/shared/registrar/_registrar.en.html.erb diff --git a/app/views/mailers/domain_mailer/registrar/_registrar.en.text.erb b/app/views/mailers/shared/registrar/_registrar.en.text.erb similarity index 100% rename from app/views/mailers/domain_mailer/registrar/_registrar.en.text.erb rename to app/views/mailers/shared/registrar/_registrar.en.text.erb diff --git a/app/views/mailers/domain_mailer/registrar/_registrar.et.html.erb b/app/views/mailers/shared/registrar/_registrar.et.html.erb similarity index 100% rename from app/views/mailers/domain_mailer/registrar/_registrar.et.html.erb rename to app/views/mailers/shared/registrar/_registrar.et.html.erb diff --git a/app/views/mailers/domain_mailer/registrar/_registrar.et.text.erb b/app/views/mailers/shared/registrar/_registrar.et.text.erb similarity index 100% rename from app/views/mailers/domain_mailer/registrar/_registrar.et.text.erb rename to app/views/mailers/shared/registrar/_registrar.et.text.erb diff --git a/app/views/mailers/domain_mailer/registrar/_registrar.ru.html.erb b/app/views/mailers/shared/registrar/_registrar.ru.html.erb similarity index 100% rename from app/views/mailers/domain_mailer/registrar/_registrar.ru.html.erb rename to app/views/mailers/shared/registrar/_registrar.ru.html.erb diff --git a/app/views/mailers/domain_mailer/registrar/_registrar.ru.text.erb b/app/views/mailers/shared/registrar/_registrar.ru.text.erb similarity index 100% rename from app/views/mailers/domain_mailer/registrar/_registrar.ru.text.erb rename to app/views/mailers/shared/registrar/_registrar.ru.text.erb diff --git a/config/locales/mailers/delete_domain.en.yml b/config/locales/mailers/delete_domain.en.yml new file mode 100644 index 000000000..07b3a8f89 --- /dev/null +++ b/config/locales/mailers/delete_domain.en.yml @@ -0,0 +1,6 @@ +en: + domain_mailer: + expiration: + subject: The %{domain_name} domain has expired + force_delete: + subject: Kustutusmenetluse teade diff --git a/config/locales/mailers/domain.en.yml b/config/locales/mailers/domain.en.yml index f0d021f68..43cfff784 100644 --- a/config/locales/mailers/domain.en.yml +++ b/config/locales/mailers/domain.en.yml @@ -1,10 +1,4 @@ en: - domain_mailer: - pending_update_request_for_old_registrant: - subject: Kinnitustaotlus domeeni %{domain_name} registreerija vahetuseks / Application for approval for registrant change of %{domain_name} - expiration: - subject: The %{domain_name} domain has expired - force_delete: - subject: Kustutusmenetluse teade - pending_deleted: + delete_domain_mailer: + pending: subject: Kinnitustaotlus domeeni %{domain_name} kustutamiseks .ee registrist / Application for approval for deletion of %{domain_name} diff --git a/config/locales/mailers/registrant_change.en.yml b/config/locales/mailers/registrant_change.en.yml new file mode 100644 index 000000000..e7a5437b0 --- /dev/null +++ b/config/locales/mailers/registrant_change.en.yml @@ -0,0 +1,4 @@ +en: + registrant_change_mailer: + confirmation: + subject: Kinnitustaotlus domeeni %{domain_name} registreerija vahetuseks / Application for approval for registrant change of %{domain_name} diff --git a/spec/mailers/delete_domain_mailer_spec.rb b/spec/mailers/delete_domain_mailer_spec.rb new file mode 100644 index 000000000..3b80c8765 --- /dev/null +++ b/spec/mailers/delete_domain_mailer_spec.rb @@ -0,0 +1,42 @@ +require 'rails_helper' + +RSpec.describe DeleteDomainMailer do + describe '#pending' do + let(:domain) { instance_spy(Domain, name: 'test.com') } + let(:old_registrant) { instance_spy(Registrant, email: 'registrant@test.com') } + let(:domain_presenter) { instance_spy(DomainPresenter) } + let(:registrar_presenter) { instance_spy(RegistrarPresenter) } + subject(:message) { described_class.pending(domain: domain, old_registrant: old_registrant) } + + before :example do + expect(DomainPresenter).to receive(:new).and_return(domain_presenter) + expect(RegistrarPresenter).to receive(:new).and_return(registrar_presenter) + end + + it 'has sender' do + expect(message.from).to eq(['noreply@internet.ee']) + end + + it 'has old registrant email as a recipient' do + expect(message.to).to match_array(['registrant@test.com']) + end + + it 'has subject' do + subject = 'Kinnitustaotlus domeeni test.com kustutamiseks .ee registrist' \ + ' / Application for approval for deletion of test.com' + + expect(message.subject).to eq(subject) + end + + it 'has confirmation url' do + allow(domain).to receive(:id).and_return(1) + expect(domain).to receive(:registrant_verification_token).and_return('test') + url = registrant_domain_delete_confirm_url(domain, token: 'test') + expect(message.body.parts.first.decoded).to include(url) + end + + it 'sends message' do + expect { message.deliver! }.to change { ActionMailer::Base.deliveries.count }.by(1) + end + end +end diff --git a/spec/mailers/domain_mailer_spec.rb b/spec/mailers/domain_mailer_spec.rb index 2363d57ea..2ba338fc7 100644 --- a/spec/mailers/domain_mailer_spec.rb +++ b/spec/mailers/domain_mailer_spec.rb @@ -1,88 +1,6 @@ require 'rails_helper' RSpec.describe DomainMailer do - describe '#pending_update_request_for_old_registrant' do - let(:domain) { instance_spy(Domain, name: 'test.com') } - let(:registrant) { instance_spy(Registrant, email: 'registrant@test.com') } - let(:domain_presenter) { instance_spy(DomainPresenter) } - let(:registrar_presenter) { instance_spy(RegistrarPresenter) } - let(:registrant_presenter) { instance_spy(RegistrantPresenter) } - subject(:message) { described_class.pending_update_request_for_old_registrant(domain: domain, - registrant: registrant, - ) } - - before :example do - expect(DomainPresenter).to receive(:new).and_return(domain_presenter) - expect(RegistrarPresenter).to receive(:new).and_return(registrar_presenter) - expect(RegistrantPresenter).to receive(:new).and_return(registrant_presenter) - end - - it 'has sender' do - expect(message.from).to eq(['noreply@internet.ee']) - end - - it 'has registrant email as a recipient' do - expect(message.to).to match_array(['registrant@test.com']) - end - - it 'has subject' do - subject = 'Kinnitustaotlus domeeni test.com registreerija vahetuseks' \ - ' / Application for approval for registrant change of test.com' - - expect(message.subject).to eq(subject) - end - - it 'has confirmation url' do - allow(domain).to receive(:id).and_return(1) - expect(domain).to receive(:registrant_verification_token).and_return('test') - url = registrant_domain_update_confirm_url(domain, token: 'test') - expect(message.body.parts.first.decoded).to include(url) - end - - it 'sends message' do - expect { message.deliver! }.to change { ActionMailer::Base.deliveries.count }.by(1) - end - end - - describe '#pending_deleted' do - let(:domain) { instance_spy(Domain, name: 'test.com') } - let(:registrant) { instance_spy(Registrant, email: 'registrant@test.com') } - let(:domain_presenter) { instance_spy(DomainPresenter) } - let(:registrar_presenter) { instance_spy(RegistrarPresenter) } - subject(:message) { described_class.pending_deleted(domain: domain, registrant: registrant) } - - before :example do - expect(DomainPresenter).to receive(:new).and_return(domain_presenter) - expect(RegistrarPresenter).to receive(:new).and_return(registrar_presenter) - end - - it 'has sender' do - expect(message.from).to eq(['noreply@internet.ee']) - end - - it 'has registrant email as a recipient' do - expect(message.to).to match_array(['registrant@test.com']) - end - - it 'has subject' do - subject = 'Kinnitustaotlus domeeni test.com kustutamiseks .ee registrist' \ - ' / Application for approval for deletion of test.com' - - expect(message.subject).to eq(subject) - end - - it 'has confirmation url' do - allow(domain).to receive(:id).and_return(1) - expect(domain).to receive(:registrant_verification_token).and_return('test') - url = registrant_domain_delete_confirm_url(domain, token: 'test') - expect(message.body.parts.first.decoded).to include(url) - end - - it 'sends message' do - expect { message.deliver! }.to change { ActionMailer::Base.deliveries.count }.by(1) - end - end - describe '#force_delete' do let(:domain) { instance_spy(Domain, name: 'test.com') } let(:domain_presenter) { instance_spy(DomainPresenter) } diff --git a/spec/mailers/registrant_change_mailer_spec.rb b/spec/mailers/registrant_change_mailer_spec.rb new file mode 100644 index 000000000..a26b507d3 --- /dev/null +++ b/spec/mailers/registrant_change_mailer_spec.rb @@ -0,0 +1,46 @@ +require 'rails_helper' + +RSpec.describe RegistrantChangeMailer do + describe '#confirmation' do + let(:domain) { instance_spy(Domain, name: 'test.com') } + let(:registrant) { instance_spy(Registrant, email: 'registrant@test.com') } + let(:domain_presenter) { instance_spy(DomainPresenter) } + let(:registrar_presenter) { instance_spy(RegistrarPresenter) } + let(:registrant_presenter) { instance_spy(RegistrantPresenter) } + subject(:message) { described_class.confirmation(domain: domain, + registrant: registrant, + ) } + + before :example do + expect(DomainPresenter).to receive(:new).and_return(domain_presenter) + expect(RegistrarPresenter).to receive(:new).and_return(registrar_presenter) + expect(RegistrantPresenter).to receive(:new).and_return(registrant_presenter) + end + + it 'has sender' do + expect(message.from).to eq(['noreply@internet.ee']) + end + + it 'has registrant email as a recipient' do + expect(message.to).to match_array(['registrant@test.com']) + end + + it 'has subject' do + subject = 'Kinnitustaotlus domeeni test.com registreerija vahetuseks' \ + ' / Application for approval for registrant change of test.com' + + expect(message.subject).to eq(subject) + end + + it 'has confirmation url' do + allow(domain).to receive(:id).and_return(1) + expect(domain).to receive(:registrant_verification_token).and_return('test') + url = registrant_domain_update_confirm_url(domain, token: 'test') + expect(message.body.parts.first.decoded).to include(url) + end + + it 'sends message' do + expect { message.deliver! }.to change { ActionMailer::Base.deliveries.count }.by(1) + end + end +end diff --git a/spec/models/domain_spec.rb b/spec/models/domain_spec.rb index 22b3dd5a2..1a3e47bc6 100644 --- a/spec/models/domain_spec.rb +++ b/spec/models/domain_spec.rb @@ -822,17 +822,19 @@ RSpec.describe Domain, db: false do describe '#pending_delete!' do let(:domain) { described_class.new } - let(:previous_registrant) { instance_double(Registrant) } + let(:old_registrant) { instance_double(Registrant) } let(:message) { instance_double(Mail::Message) } before :example do - expect(Registrant).to receive(:find).and_return(previous_registrant) + expect(Registrant).to receive(:find).and_return(old_registrant) allow(domain).to receive(:registrant_verification_asked?).and_return(true) allow(domain).to receive(:save) end it 'sends notification email' do - expect(DomainMailer).to receive(:pending_deleted).with(domain: domain, registrant: previous_registrant).and_return(message) + expect(DeleteDomainMailer).to receive(:pending) + .with(domain: domain, old_registrant: old_registrant) + .and_return(message) expect(message).to receive(:deliver) domain.pending_delete! end diff --git a/spec/views/mailers/delete_domain_mailer/pending.html.erb_spec.rb b/spec/views/mailers/delete_domain_mailer/pending.html.erb_spec.rb new file mode 100644 index 000000000..e36208916 --- /dev/null +++ b/spec/views/mailers/delete_domain_mailer/pending.html.erb_spec.rb @@ -0,0 +1,11 @@ +require 'rails_helper' +require_relative 'pending_shared' + +RSpec.describe 'mailers/delete_domain_mailer/pending.html.erb' do + before :example do + stub_template 'mailers/shared/registrar/_registrar.et.html' => 'test registrar estonian' + stub_template 'mailers/shared/registrar/_registrar.en.html' => 'test registrar english' + end + + include_examples 'delete domain mailer pending' +end diff --git a/spec/views/mailers/delete_domain_mailer/pending.text.erb_spec.rb b/spec/views/mailers/delete_domain_mailer/pending.text.erb_spec.rb new file mode 100644 index 000000000..87aea70ab --- /dev/null +++ b/spec/views/mailers/delete_domain_mailer/pending.text.erb_spec.rb @@ -0,0 +1,11 @@ +require 'rails_helper' +require_relative 'pending_shared' + +RSpec.describe 'mailers/delete_domain_mailer/pending.text.erb' do + before :example do + stub_template 'mailers/shared/registrar/_registrar.et.text' => 'test registrar estonian' + stub_template 'mailers/shared/registrar/_registrar.en.text' => 'test registrar english' + end + + include_examples 'delete domain mailer pending' +end diff --git a/spec/views/mailers/domain_mailer/pending_deleted_shared.rb b/spec/views/mailers/delete_domain_mailer/pending_shared.rb similarity index 94% rename from spec/views/mailers/domain_mailer/pending_deleted_shared.rb rename to spec/views/mailers/delete_domain_mailer/pending_shared.rb index 950ec0309..2b38eca85 100644 --- a/spec/views/mailers/domain_mailer/pending_deleted_shared.rb +++ b/spec/views/mailers/delete_domain_mailer/pending_shared.rb @@ -1,6 +1,6 @@ require 'rails_helper' -RSpec.shared_examples 'domain mailer pending deleted' do +RSpec.shared_examples 'delete domain mailer pending' do let(:domain) { instance_spy(DomainPresenter) } let(:lang_count) { 2 } diff --git a/spec/views/mailers/domain_mailer/pending_deleted.html.erb_spec.rb b/spec/views/mailers/domain_mailer/pending_deleted.html.erb_spec.rb deleted file mode 100644 index cb3e96ec9..000000000 --- a/spec/views/mailers/domain_mailer/pending_deleted.html.erb_spec.rb +++ /dev/null @@ -1,11 +0,0 @@ -require 'rails_helper' -require_relative 'pending_deleted_shared' - -RSpec.describe 'mailers/domain_mailer/pending_deleted.html.erb' do - before :example do - stub_template 'mailers/domain_mailer/registrar/_registrar.et.html' => 'test registrar estonian' - stub_template 'mailers/domain_mailer/registrar/_registrar.en.html' => 'test registrar english' - end - - include_examples 'domain mailer pending deleted' -end diff --git a/spec/views/mailers/domain_mailer/pending_deleted.text.erb_spec.rb b/spec/views/mailers/domain_mailer/pending_deleted.text.erb_spec.rb deleted file mode 100644 index 2326cc9e1..000000000 --- a/spec/views/mailers/domain_mailer/pending_deleted.text.erb_spec.rb +++ /dev/null @@ -1,11 +0,0 @@ -require 'rails_helper' -require_relative 'pending_deleted_shared' - -RSpec.describe 'mailers/domain_mailer/pending_deleted.text.erb' do - before :example do - stub_template 'mailers/domain_mailer/registrar/_registrar.et.text' => 'test registrar estonian' - stub_template 'mailers/domain_mailer/registrar/_registrar.en.text' => 'test registrar english' - end - - include_examples 'domain mailer pending deleted' -end diff --git a/spec/views/mailers/domain_mailer/pending_update_request_for_old_registrant.html.erb_spec.rb b/spec/views/mailers/domain_mailer/pending_update_request_for_old_registrant.html.erb_spec.rb deleted file mode 100644 index b987759b5..000000000 --- a/spec/views/mailers/domain_mailer/pending_update_request_for_old_registrant.html.erb_spec.rb +++ /dev/null @@ -1,13 +0,0 @@ -require 'rails_helper' -require_relative 'pending_update_request_for_old_registrant_shared' - -RSpec.describe 'mailers/domain_mailer/pending_update_request_for_old_registrant.html.erb' do - before :example do - 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/registrant/_registrant.et.html' => 'test new registrant estonian' - stub_template 'mailers/domain_mailer/registrant/_registrant.en.html' => 'test new registrant english' - end - - include_examples 'domain mailer pending update request for old registrant' -end diff --git a/spec/views/mailers/domain_mailer/pending_update_request_for_old_registrant.text.erb_spec.rb b/spec/views/mailers/domain_mailer/pending_update_request_for_old_registrant.text.erb_spec.rb deleted file mode 100644 index 4ca88bce1..000000000 --- a/spec/views/mailers/domain_mailer/pending_update_request_for_old_registrant.text.erb_spec.rb +++ /dev/null @@ -1,13 +0,0 @@ -require 'rails_helper' -require_relative 'pending_update_request_for_old_registrant_shared' - -RSpec.describe 'mailers/domain_mailer/pending_update_request_for_old_registrant.text.erb' do - before :example do - 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/registrant/_registrant.et.text' => 'test new registrant estonian' - stub_template 'mailers/domain_mailer/registrant/_registrant.en.text' => 'test new registrant english' - end - - include_examples 'domain mailer pending update request for old registrant' -end diff --git a/spec/views/mailers/registrant_change_mailer/confirmation.html.erb_spec.rb b/spec/views/mailers/registrant_change_mailer/confirmation.html.erb_spec.rb new file mode 100644 index 000000000..c59dd4e55 --- /dev/null +++ b/spec/views/mailers/registrant_change_mailer/confirmation.html.erb_spec.rb @@ -0,0 +1,13 @@ +require 'rails_helper' +require_relative 'confirmation_shared' + +RSpec.describe 'mailers/registrant_change_mailer/confirmation.html.erb' do + before :example do + stub_template 'mailers/shared/registrar/_registrar.et.html' => 'test registrar estonian' + stub_template 'mailers/shared/registrar/_registrar.en.html' => 'test registrar english' + stub_template 'mailers/shared/registrant/_registrant.et.html' => 'test new registrant estonian' + stub_template 'mailers/shared/registrant/_registrant.en.html' => 'test new registrant english' + end + + include_examples 'domain mailer pending update request for old registrant' +end diff --git a/spec/views/mailers/registrant_change_mailer/confirmation.text.erb_spec.rb b/spec/views/mailers/registrant_change_mailer/confirmation.text.erb_spec.rb new file mode 100644 index 000000000..37edf78e9 --- /dev/null +++ b/spec/views/mailers/registrant_change_mailer/confirmation.text.erb_spec.rb @@ -0,0 +1,13 @@ +require 'rails_helper' +require_relative 'confirmation_shared' + +RSpec.describe 'mailers/registrant_change_mailer/confirmation.text.erb' do + before :example do + stub_template 'mailers/shared/registrar/_registrar.et.text' => 'test registrar estonian' + stub_template 'mailers/shared/registrar/_registrar.en.text' => 'test registrar english' + stub_template 'mailers/shared/registrant/_registrant.et.text' => 'test new registrant estonian' + stub_template 'mailers/shared/registrant/_registrant.en.text' => 'test new registrant english' + end + + include_examples 'domain mailer pending update request for old registrant' +end diff --git a/spec/views/mailers/domain_mailer/pending_update_request_for_old_registrant_shared.rb b/spec/views/mailers/registrant_change_mailer/confirmation_shared.rb similarity index 100% rename from spec/views/mailers/domain_mailer/pending_update_request_for_old_registrant_shared.rb rename to spec/views/mailers/registrant_change_mailer/confirmation_shared.rb diff --git a/spec/views/mailers/domain_mailer/pending_update_notification_for_new_registrant.html.erb_spec.rb b/spec/views/mailers/registrant_change_mailer/pending_update_notification_for_new_registrant.html.erb_spec.rb similarity index 100% rename from spec/views/mailers/domain_mailer/pending_update_notification_for_new_registrant.html.erb_spec.rb rename to spec/views/mailers/registrant_change_mailer/pending_update_notification_for_new_registrant.html.erb_spec.rb diff --git a/spec/views/mailers/domain_mailer/pending_update_notification_for_new_registrant.text.erb_spec.rb b/spec/views/mailers/registrant_change_mailer/pending_update_notification_for_new_registrant.text.erb_spec.rb similarity index 100% rename from spec/views/mailers/domain_mailer/pending_update_notification_for_new_registrant.text.erb_spec.rb rename to spec/views/mailers/registrant_change_mailer/pending_update_notification_for_new_registrant.text.erb_spec.rb diff --git a/spec/views/mailers/domain_mailer/pending_update_notification_for_new_registrant_shared.rb b/spec/views/mailers/registrant_change_mailer/pending_update_notification_for_new_registrant_shared.rb similarity index 100% rename from spec/views/mailers/domain_mailer/pending_update_notification_for_new_registrant_shared.rb rename to spec/views/mailers/registrant_change_mailer/pending_update_notification_for_new_registrant_shared.rb diff --git a/spec/views/mailers/domain_mailer/registrant/_registrant.en.html.erb_spec.rb b/spec/views/mailers/shared/registrant/_registrant.en.html.erb_spec.rb similarity index 100% rename from spec/views/mailers/domain_mailer/registrant/_registrant.en.html.erb_spec.rb rename to spec/views/mailers/shared/registrant/_registrant.en.html.erb_spec.rb diff --git a/spec/views/mailers/domain_mailer/registrant/_registrant.en.text.erb_spec.rb b/spec/views/mailers/shared/registrant/_registrant.en.text.erb_spec.rb similarity index 100% rename from spec/views/mailers/domain_mailer/registrant/_registrant.en.text.erb_spec.rb rename to spec/views/mailers/shared/registrant/_registrant.en.text.erb_spec.rb diff --git a/spec/views/mailers/domain_mailer/registrant/_registrant.et.html.erb_spec.rb b/spec/views/mailers/shared/registrant/_registrant.et.html.erb_spec.rb similarity index 100% rename from spec/views/mailers/domain_mailer/registrant/_registrant.et.html.erb_spec.rb rename to spec/views/mailers/shared/registrant/_registrant.et.html.erb_spec.rb diff --git a/spec/views/mailers/domain_mailer/registrant/_registrant.et.text.erb_spec.rb b/spec/views/mailers/shared/registrant/_registrant.et.text.erb_spec.rb similarity index 100% rename from spec/views/mailers/domain_mailer/registrant/_registrant.et.text.erb_spec.rb rename to spec/views/mailers/shared/registrant/_registrant.et.text.erb_spec.rb diff --git a/spec/views/mailers/domain_mailer/registrant/registrant_shared.rb b/spec/views/mailers/shared/registrant/registrant_shared.rb similarity index 100% rename from spec/views/mailers/domain_mailer/registrant/registrant_shared.rb rename to spec/views/mailers/shared/registrant/registrant_shared.rb diff --git a/spec/views/mailers/domain_mailer/registrar/_registrar.en.html.erb_spec.rb b/spec/views/mailers/shared/registrar/_registrar.en.html.erb_spec.rb similarity index 100% rename from spec/views/mailers/domain_mailer/registrar/_registrar.en.html.erb_spec.rb rename to spec/views/mailers/shared/registrar/_registrar.en.html.erb_spec.rb diff --git a/spec/views/mailers/domain_mailer/registrar/_registrar.en.text.erb_spec.rb b/spec/views/mailers/shared/registrar/_registrar.en.text.erb_spec.rb similarity index 100% rename from spec/views/mailers/domain_mailer/registrar/_registrar.en.text.erb_spec.rb rename to spec/views/mailers/shared/registrar/_registrar.en.text.erb_spec.rb diff --git a/spec/views/mailers/domain_mailer/registrar/_registrar.et.html.erb_spec.rb b/spec/views/mailers/shared/registrar/_registrar.et.html.erb_spec.rb similarity index 100% rename from spec/views/mailers/domain_mailer/registrar/_registrar.et.html.erb_spec.rb rename to spec/views/mailers/shared/registrar/_registrar.et.html.erb_spec.rb diff --git a/spec/views/mailers/domain_mailer/registrar/_registrar.et.text.erb_spec.rb b/spec/views/mailers/shared/registrar/_registrar.et.text.erb_spec.rb similarity index 100% rename from spec/views/mailers/domain_mailer/registrar/_registrar.et.text.erb_spec.rb rename to spec/views/mailers/shared/registrar/_registrar.et.text.erb_spec.rb diff --git a/spec/views/mailers/domain_mailer/registrar/_registrar.ru.html.erb_spec.rb b/spec/views/mailers/shared/registrar/_registrar.ru.html.erb_spec.rb similarity index 100% rename from spec/views/mailers/domain_mailer/registrar/_registrar.ru.html.erb_spec.rb rename to spec/views/mailers/shared/registrar/_registrar.ru.html.erb_spec.rb diff --git a/spec/views/mailers/domain_mailer/registrar/_registrar.ru.text.erb_spec.rb b/spec/views/mailers/shared/registrar/_registrar.ru.text.erb_spec.rb similarity index 100% rename from spec/views/mailers/domain_mailer/registrar/_registrar.ru.text.erb_spec.rb rename to spec/views/mailers/shared/registrar/_registrar.ru.text.erb_spec.rb diff --git a/spec/views/mailers/domain_mailer/registrar/registrar_shared.rb b/spec/views/mailers/shared/registrar/registrar_shared.rb similarity index 100% rename from spec/views/mailers/domain_mailer/registrar/registrar_shared.rb rename to spec/views/mailers/shared/registrar/registrar_shared.rb From 2c3dbc6e322d8b8be13518659499d7278353288a Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Mon, 14 Nov 2016 01:35:47 +0200 Subject: [PATCH 37/67] Refactor domain mailer views #180 --- app/jobs/domain_update_confirm_job.rb | 4 +- app/mailers/.keep | 0 app/mailers/registrant_change_mailer.rb | 42 ++++--- app/models/domain.rb | 18 +-- app/models/domain_mail_model.rb | 24 ---- .../domain_mailer/force_delete.html.erb | 6 +- .../domain_mailer/force_delete.text.erb | 6 +- ...d_registrant.html.erb => confirm.html.erb} | 12 +- ...d_registrant.text.erb => confirm.text.erb} | 12 +- ...ew_registrant.html.erb => notice.html.erb} | 8 +- ...ew_registrant.text.erb => notice.text.erb} | 8 +- ...d_notification_for_new_registrant.text.erb | 23 ---- ..._registrant.html.erb => rejected.html.erb} | 8 +- .../rejected.text.erb | 23 ++++ config/locales/en.yml | 2 - .../locales/mailers/registrant_change.en.yml | 6 +- spec/mailers/registrant_change_mailer_spec.rb | 106 ++++++++++++++++-- spec/models/domain_spec.rb | 48 ++++++++ .../force_delete.html.erb_spec.rb | 6 +- .../force_delete.text.erb_spec.rb | 6 +- ...l.erb_spec.rb => confirm.html.erb_spec.rb} | 6 +- ...t.erb_spec.rb => confirm.text.erb_spec.rb} | 6 +- ...nfirmation_shared.rb => confirm_shared.rb} | 8 +- .../notice.html.erb_spec.rb | 13 +++ .../notice.text.erb_spec.rb | 13 +++ ..._registrant_shared.rb => notice_shared.rb} | 15 ++- ...cation_for_new_registrant.html.erb_spec.rb | 6 - ...cation_for_new_registrant.text.erb_spec.rb | 9 -- .../rejected.html.erb_spec.rb | 11 ++ .../rejected.text.erb_spec.rb | 11 ++ .../rejected_shared.rb | 48 ++++++++ 31 files changed, 361 insertions(+), 153 deletions(-) delete mode 100644 app/mailers/.keep rename app/views/mailers/registrant_change_mailer/{pending_update_request_for_old_registrant.html.erb => confirm.html.erb} (71%) rename app/views/mailers/registrant_change_mailer/{pending_update_request_for_old_registrant.text.erb => confirm.text.erb} (72%) rename app/views/mailers/registrant_change_mailer/{pending_update_notification_for_new_registrant.html.erb => notice.html.erb} (80%) rename app/views/mailers/registrant_change_mailer/{pending_update_notification_for_new_registrant.text.erb => notice.text.erb} (78%) delete mode 100644 app/views/mailers/registrant_change_mailer/pending_update_rejected_notification_for_new_registrant.text.erb rename app/views/mailers/registrant_change_mailer/{pending_update_rejected_notification_for_new_registrant.html.erb => rejected.html.erb} (52%) create mode 100644 app/views/mailers/registrant_change_mailer/rejected.text.erb rename spec/views/mailers/registrant_change_mailer/{confirmation.html.erb_spec.rb => confirm.html.erb_spec.rb} (69%) rename spec/views/mailers/registrant_change_mailer/{confirmation.text.erb_spec.rb => confirm.text.erb_spec.rb} (69%) rename spec/views/mailers/registrant_change_mailer/{confirmation_shared.rb => confirm_shared.rb} (81%) create mode 100644 spec/views/mailers/registrant_change_mailer/notice.html.erb_spec.rb create mode 100644 spec/views/mailers/registrant_change_mailer/notice.text.erb_spec.rb rename spec/views/mailers/registrant_change_mailer/{pending_update_notification_for_new_registrant_shared.rb => notice_shared.rb} (65%) delete mode 100644 spec/views/mailers/registrant_change_mailer/pending_update_notification_for_new_registrant.html.erb_spec.rb delete mode 100644 spec/views/mailers/registrant_change_mailer/pending_update_notification_for_new_registrant.text.erb_spec.rb create mode 100644 spec/views/mailers/registrant_change_mailer/rejected.html.erb_spec.rb create mode 100644 spec/views/mailers/registrant_change_mailer/rejected.text.erb_spec.rb create mode 100644 spec/views/mailers/registrant_change_mailer/rejected_shared.rb diff --git a/app/jobs/domain_update_confirm_job.rb b/app/jobs/domain_update_confirm_job.rb index 4a47cc364..c1c6d0995 100644 --- a/app/jobs/domain_update_confirm_job.rb +++ b/app/jobs/domain_update_confirm_job.rb @@ -16,7 +16,9 @@ class DomainUpdateConfirmJob < Que::Job domain.clean_pendings! raise_errors!(domain) when RegistrantVerification::REJECTED - domain.send_mail :pending_update_rejected_notification_for_new_registrant + RegistrantChangeMailer.rejected(domain: domain, registrar: domain.registrar, registrant: domain.registrant) + .deliver + domain.poll_message!(:poll_pending_update_rejected_by_registrant) domain.clean_pendings_lowlevel end diff --git a/app/mailers/.keep b/app/mailers/.keep deleted file mode 100644 index e69de29bb..000000000 diff --git a/app/mailers/registrant_change_mailer.rb b/app/mailers/registrant_change_mailer.rb index a29f3aee1..c5efced86 100644 --- a/app/mailers/registrant_change_mailer.rb +++ b/app/mailers/registrant_change_mailer.rb @@ -1,36 +1,34 @@ class RegistrantChangeMailer < ApplicationMailer include Que::Mailer - def confirmation(domain:, registrant:) + def confirm(domain:, registrar:, current_registrant:, new_registrant:) @domain = DomainPresenter.new(domain: domain, view: view_context) - @registrar = RegistrarPresenter.new(registrar: domain.registrar, view: view_context) - @registrant = RegistrantPresenter.new(registrant: registrant, view: view_context) - @verification_url = confirm_url(domain) + @registrar = RegistrarPresenter.new(registrar: registrar, view: view_context) + @new_registrant = RegistrantPresenter.new(registrant: new_registrant, view: view_context) + @confirm_url = confirm_url(domain) subject = default_i18n_subject(domain_name: domain.name) - mail(to: registrant.email, subject: subject) + mail(to: current_registrant.email, subject: subject) end - def pending_update_notification_for_new_registrant(params) - compose_from(params) + def notice(domain:, registrar:, current_registrant:, new_registrant:) + @domain = DomainPresenter.new(domain: domain, view: view_context) + @registrar = RegistrarPresenter.new(registrar: registrar, view: view_context) + @current_registrant = RegistrantPresenter.new(registrant: current_registrant, view: view_context) + @new_registrant = RegistrantPresenter.new(registrant: new_registrant, view: view_context) + @confirm_url = confirm_url(domain) + + subject = default_i18n_subject(domain_name: domain.name) + mail(to: new_registrant.email, subject: subject) end - def registrant_updated_notification_for_old_registrant(domain_id, old_registrant_id, new_registrant_id, should_deliver) - @domain = Domain.find_by(id: domain_id) - return unless @domain - return if delivery_off?(@domain, should_deliver) + def rejected(domain:, registrar:, registrant:) + @domain = DomainPresenter.new(domain: domain, view: view_context) + @registrar = RegistrarPresenter.new(registrar: registrar, view: view_context) + @registrant = RegistrantPresenter.new(registrant: registrant, view: view_context) - @old_registrant = Registrant.find(old_registrant_id) - @new_registrant = Registrant.find(new_registrant_id) - - return if whitelist_blocked?(@old_registrant.email) - mail(to: format(@old_registrant.email), - subject: "#{I18n.t(:registrant_updated_notification_for_old_registrant_subject, - name: @domain.name)} [#{@domain.name}]") - end - - def pending_update_rejected_notification_for_new_registrant(params) - compose_from(params) + subject = default_i18n_subject(domain_name: domain.name) + mail(to: domain.new_registrant_email, subject: subject) end def pending_update_expired_notification_for_new_registrant(params) diff --git a/app/models/domain.rb b/app/models/domain.rb index c97877047..33bfdfefc 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -380,12 +380,12 @@ class Domain < ActiveRecord::Base new_registrant_name = registrant.name current_registrant = Registrant.find(registrant_id_was) - RegistrantChangeMailer.confirmation(domain: self, current_registrant: current_registrant).deliver + RegistrantChangeMailer.confirm(domain: self, registrar: registrar, current_registrant: current_registrant, + new_registrant: registrant).deliver + RegistrantChangeMailer.notice(domain: self, registrar: registrar, current_registrant: current_registrant, + new_registrant: registrant).deliver - send_mail :pending_update_request_for_old_registrant - send_mail :pending_update_notification_for_new_registrant - - reload # revert back to original + reload self.pending_json = pending_json_cache self.registrant_verification_token = token @@ -397,8 +397,8 @@ class Domain < ActiveRecord::Base pending_json['new_registrant_name'] = new_registrant_name # This pending_update! method is triggered by before_update - # Note, all before_save callbacks are excecuted before before_update, - # thus automatic statuses has already excectued by this point + # Note, all before_save callbacks are executed before before_update, + # thus automatic statuses has already executed by this point # and we need to trigger automatic statuses manually (second time). manage_automatic_statuses end @@ -741,6 +741,10 @@ class Domain < ActiveRecord::Base admin_contact_emails << registrant_email end + def new_registrant_email + pending_json['new_registrant_email'] + end + def self.to_csv CSV.generate do |csv| csv << column_names diff --git a/app/models/domain_mail_model.rb b/app/models/domain_mail_model.rb index 49effbb1f..ef248774b 100644 --- a/app/models/domain_mail_model.rb +++ b/app/models/domain_mail_model.rb @@ -6,30 +6,6 @@ class DomainMailModel @params = {errors: [], deliver_emails: domain.deliver_emails, id: domain.id} end - def pending_update_request_for_old_registrant - registrant_old - subject(:pending_update_request_for_old_registrant_subject) - confirm_update - domain_info - compose - end - - def pending_update_notification_for_new_registrant - registrant # new registrant at this point - subject(:pending_update_notification_for_new_registrant_subject) - domain_info - compose - end - - - def pending_update_rejected_notification_for_new_registrant - registrant_pending - subject(:pending_update_rejected_notification_for_new_registrant_subject) - @params[:deliver_emails] = true # triggered from que - @params[:registrar_name] = @domain.registrar.name - compose - end - def pending_update_expired_notification_for_new_registrant registrant_pending subject(:pending_update_expired_notification_for_new_registrant_subject) diff --git a/app/views/mailers/domain_mailer/force_delete.html.erb b/app/views/mailers/domain_mailer/force_delete.html.erb index 47f54f9b4..4b984bf57 100644 --- a/app/views/mailers/domain_mailer/force_delete.html.erb +++ b/app/views/mailers/domain_mailer/force_delete.html.erb @@ -21,7 +21,7 @@ Registrikood: <%= @registrant.ident %>

Lisaküsimuste korral võtke palun ühendust oma registripidajaga:

-<%= render 'mailers/domain_mailer/registrar/registrar.et.html', registrar: @registrar %> +<%= render 'mailers/shared/registrar/registrar.et.html', registrar: @registrar %>
@@ -42,7 +42,7 @@ Registry code: <%= @registrant.ident %>

Should you have additional questions, please contact your registrar:

-<%= render 'mailers/domain_mailer/registrar/registrar.en.html', registrar: @registrar %> +<%= render 'mailers/shared/registrar/registrar.en.html', registrar: @registrar %>
@@ -63,7 +63,7 @@ Registry code: <%= @registrant.ident %>

Просим обратиться к своему регистратору:

-<%= render 'mailers/domain_mailer/registrar/registrar.ru.html', registrar: @registrar %> +<%= render 'mailers/shared/registrar/registrar.ru.html', registrar: @registrar %>

diff --git a/app/views/mailers/domain_mailer/force_delete.text.erb b/app/views/mailers/domain_mailer/force_delete.text.erb index 7ac6ceb26..688c5d445 100644 --- a/app/views/mailers/domain_mailer/force_delete.text.erb +++ b/app/views/mailers/domain_mailer/force_delete.text.erb @@ -15,7 +15,7 @@ Kui üleandmine ei ole 30 päeva jooksul toimunud, kustub domeen <%= @domain.nam Lisaküsimuste korral võtke palun ühendust oma registripidajaga: -<%= render 'mailers/domain_mailer/registrar/registrar.et.text', registrar: @registrar %> +<%= render 'mailers/shared/registrar/registrar.et.text', registrar: @registrar %> @@ -36,7 +36,7 @@ If the transfer has not been made in 30 days, the domain <%= @domain.name %> wil Should you have additional questions, please contact your registrar: -<%= render 'mailers/domain_mailer/registrar/registrar.en.text', registrar: @registrar %> +<%= render 'mailers/shared/registrar/registrar.en.text', registrar: @registrar %> Уважаемое контактное лицо домена <%= @domain.name %> @@ -56,7 +56,7 @@ EIS стало известно, что юридическое лицо с ре Просим обратиться к своему регистратору: -<%= render 'mailers/domain_mailer/registrar/registrar.ru.text', registrar: @registrar %> +<%= render 'mailers/shared/registrar/registrar.ru.text', registrar: @registrar %> Lugupidamisega, diff --git a/app/views/mailers/registrant_change_mailer/pending_update_request_for_old_registrant.html.erb b/app/views/mailers/registrant_change_mailer/confirm.html.erb similarity index 71% rename from app/views/mailers/registrant_change_mailer/pending_update_request_for_old_registrant.html.erb rename to app/views/mailers/registrant_change_mailer/confirm.html.erb index cba83c6e0..a2e889dc6 100644 --- a/app/views/mailers/registrant_change_mailer/pending_update_request_for_old_registrant.html.erb +++ b/app/views/mailers/registrant_change_mailer/confirm.html.erb @@ -2,17 +2,17 @@ Tere

Registrisse laekus taotlus domeeni <%= @domain.name %> registreerija vahetuseks. Palun veenduge, et muudatus on korrektne ning probleemide korral pöörduge oma registripidaja poole: -<%= render 'mailers/domain_mailer/registrar/registrar.et.html', registrar: @registrar %> +<%= render 'mailers/shared/registrar/registrar.et.html', registrar: @registrar %>

Uue registreerija andmed:
-<%= render 'mailers/domain_mailer/registrant/registrant.et.html', registrant: @new_registrant %> +<%= render 'mailers/shared/registrant/registrant.et.html', registrant: @new_registrant %>

Taotlus on aktiivne <%= Setting.expire_pending_confirmation %> tundi ja lükatakse automaatselt tagasi kui te seda enne ei kinnita või tagasi lükka.

Muudatuse kinnitamiseks külastage palun allolevat lehekülge, kontrollige uuesti üle muudatuse andmed ning vajutage nuppu kinnitan:
-<%= link_to @verification_url, @verification_url %> +<%= link_to @confirm_url, @confirm_url %>

Lugupidamisega
Eesti Interneti Sihtasutus @@ -23,16 +23,16 @@ Hi,

Application for changing registrant of your domain <%= @domain.name %> has been filed. Please make sure that the update and information are correct. In case of problems please turn to your registrar: -<%= render 'mailers/domain_mailer/registrar/registrar.en.html', registrar: @registrar %> +<%= render 'mailers/shared/registrar/registrar.en.html', registrar: @registrar %>

New registrant:
-<%= render 'mailers/domain_mailer/registrant/registrant.en.html', registrant: @new_registrant %> +<%= render 'mailers/shared/registrant/registrant.en.html', registrant: @new_registrant %>

The application will remain in pending status for <%= Setting.expire_pending_confirmation %> hrs and will be automaticcally rejected if it is not approved nor rejected before.

To confirm the update please visit this website, once again review the data and press approve:
-<%= link_to @verification_url, @verification_url %> +<%= link_to @confirm_url, @confirm_url %>

Best Regards,
Estonian Internet Foundation diff --git a/app/views/mailers/registrant_change_mailer/pending_update_request_for_old_registrant.text.erb b/app/views/mailers/registrant_change_mailer/confirm.text.erb similarity index 72% rename from app/views/mailers/registrant_change_mailer/pending_update_request_for_old_registrant.text.erb rename to app/views/mailers/registrant_change_mailer/confirm.text.erb index f4ff079f2..2af2381fc 100644 --- a/app/views/mailers/registrant_change_mailer/pending_update_request_for_old_registrant.text.erb +++ b/app/views/mailers/registrant_change_mailer/confirm.text.erb @@ -2,14 +2,14 @@ Tere Registrisse laekus taotlus domeeni <%= @domain.name %> registreerija vahetuseks. Palun veenduge, et muudatus on korrektne ning probleemide korral pöörduge oma registripidaja poole: -<%= render 'mailers/domain_mailer/registrar/registrar.et.text', registrar: @registrar %> +<%= render 'mailers/shared/registrar/registrar.et.text', registrar: @registrar %> Uue registreerija andmed: -<%= render 'mailers/domain_mailer/registrant/registrant.et.text', registrant: @new_registrant %> +<%= render 'mailers/shared/registrant/registrant.et.text', registrant: @new_registrant %> Taotlus on aktiivne <%= Setting.expire_pending_confirmation %> tundi ja lükatakse automaatselt tagasi kui te seda enne ei kinnita või tagasi lükka. Muudatuse kinnitamiseks külastage palun allolevat lehekülge, kontrollige uuesti üle muudatuse andmed ning vajutage nuppu kinnitan: -<%= @verification_url %> +<%= @confirm_url %> Lugupidamisega Eesti Interneti Sihtasutus @@ -20,14 +20,14 @@ Hi, Application for changing registrant of your domain <%= @domain.name %> has been filed. Please make sure that the update and information are correct. In case of problems please turn to your registrar: -<%= render 'mailers/domain_mailer/registrar/registrar.en.text', registrar: @registrar %> +<%= render 'mailers/shared/registrar/registrar.en.text', registrar: @registrar %> New registrant: -<%= render 'mailers/domain_mailer/registrant/registrant.en.text', registrant: @new_registrant %> +<%= render 'mailers/shared/registrant/registrant.en.text', registrant: @new_registrant %> The application will remain in pending status for <%= Setting.expire_pending_confirmation %> hrs and will be automaticcally rejected if it is not approved nor rejected before. To confirm the update please visit this website, once again review the data and press approve: -<%= @verification_url %> +<%= @confirm_url %> Best Regards, Estonian Internet Foundation diff --git a/app/views/mailers/registrant_change_mailer/pending_update_notification_for_new_registrant.html.erb b/app/views/mailers/registrant_change_mailer/notice.html.erb similarity index 80% rename from app/views/mailers/registrant_change_mailer/pending_update_notification_for_new_registrant.html.erb rename to app/views/mailers/registrant_change_mailer/notice.html.erb index 78f0458dc..6aecaf0b3 100644 --- a/app/views/mailers/registrant_change_mailer/pending_update_notification_for_new_registrant.html.erb +++ b/app/views/mailers/registrant_change_mailer/notice.html.erb @@ -4,11 +4,11 @@ Registripidaja <%= @registrar.name %> vahendusel on algatatud <%= @domain.name %

Palun veenduge, et muudatus on korrektne ning probleemide korral pöörduge oma registripidaja poole: -<%= render 'registrar.et.html', registrar: @registrar %> +<%= render 'mailers/shared/registrar/registrar.et.html', registrar: @registrar %>

Uue registreerija andmed:
-<%= render 'registrant.et.html', registrant: @new_registrant %> +<%= render 'mailers/shared/registrant/registrant.et.html', registrant: @new_registrant %>

Juhime Teie tähelepanu asjaolule, et omanikuvahetuse protseduur viiakse lõpule vaid juhul, kui domeeni hetkel kehtiv registreerija <%= @current_registrant.name %> omanikuvahetuse tähtaegselt kinnitab.

@@ -25,11 +25,11 @@ Registrant change process for the domain <%= @domain.name %> has been started.

Please verify the details of the following change request. In case of problems contact your registrar: -<%= render 'registrar.en.html', registrar: @registrar %> +<%= render 'mailers/shared/registrar/registrar.en.html', registrar: @registrar %>

New registrant:
-<%= render 'registrant.en.html', registrant: @new_registrant %> +<%= render 'mailers/shared/registrant/registrant.en.html', registrant: @new_registrant %>

The registrant change procedure will be completed only after the current registrant <%= @current_registrant.name %> has approved it.

diff --git a/app/views/mailers/registrant_change_mailer/pending_update_notification_for_new_registrant.text.erb b/app/views/mailers/registrant_change_mailer/notice.text.erb similarity index 78% rename from app/views/mailers/registrant_change_mailer/pending_update_notification_for_new_registrant.text.erb rename to app/views/mailers/registrant_change_mailer/notice.text.erb index ac781506e..bd1fb5d0f 100644 --- a/app/views/mailers/registrant_change_mailer/pending_update_notification_for_new_registrant.text.erb +++ b/app/views/mailers/registrant_change_mailer/notice.text.erb @@ -4,10 +4,10 @@ Registripidaja <%= @registrar.name %> vahendusel on algatatud <%= @domain.name % Palun veenduge, et muudatus on korrektne ning probleemide korral pöörduge oma registripidaja poole: -<%= render 'registrar.et.text', registrar: @registrar %> +<%= render 'mailers/shared/registrar/registrar.et.text', registrar: @registrar %> Uue registreerija andmed: -<%= render 'registrant.et.text', registrant: @new_registrant %> +<%= render 'mailers/shared/registrant/registrant.et.text', registrant: @new_registrant %> Juhime Teie tähelepanu asjaolule, et omanikuvahetuse protseduur viiakse lõpule vaid juhul, kui domeeni hetkel kehtiv registreerija <%= @current_registrant.name %> omanikuvahetuse tähtaegselt kinnitab. @@ -24,10 +24,10 @@ Registrant change process for the domain <%= @domain.name %> has been started. Please verify the details of the following change request. In case of problems contact your registrar: -<%= render 'registrar.en.text', registrar: @registrar %> +<%= render 'mailers/shared/registrar/registrar.en.text', registrar: @registrar %> New registrant: -<%= render 'registrant.en.text', registrant: @new_registrant %> +<%= render 'mailers/shared/registrant/registrant.en.text', registrant: @new_registrant %> The registrant change procedure will be completed only after the current registrant <%= @current_registrant.name %> has approved it. diff --git a/app/views/mailers/registrant_change_mailer/pending_update_rejected_notification_for_new_registrant.text.erb b/app/views/mailers/registrant_change_mailer/pending_update_rejected_notification_for_new_registrant.text.erb deleted file mode 100644 index b54636f6e..000000000 --- a/app/views/mailers/registrant_change_mailer/pending_update_rejected_notification_for_new_registrant.text.erb +++ /dev/null @@ -1,23 +0,0 @@ -Tere - -Domeeni <%= @domain.name %> registreerija <%= @current_registrant.name %> on domeeni registreerija vahetamise taotluse tagasi lükanud. - -Küsimuste korral võtke palun ühendust oma registripidajaga: - -<%= render 'registrar.et.text', registrar: @registrar %> - -Lugupidamisega -Eesti Interneti Sihtasutus - --------------------------------------- - -Hi, - -Registrant change for the domain <%= @domain.name %> was rejected by the registrant <%= @current_registrant.name %>. - -Please contact your registrar if you have any questions: - -<%= render 'registrar.en.text', registrar: @registrar %> - -Best Regards, -Estonian Internet Foundation diff --git a/app/views/mailers/registrant_change_mailer/pending_update_rejected_notification_for_new_registrant.html.erb b/app/views/mailers/registrant_change_mailer/rejected.html.erb similarity index 52% rename from app/views/mailers/registrant_change_mailer/pending_update_rejected_notification_for_new_registrant.html.erb rename to app/views/mailers/registrant_change_mailer/rejected.html.erb index 97413078a..2521dd52a 100644 --- a/app/views/mailers/registrant_change_mailer/pending_update_rejected_notification_for_new_registrant.html.erb +++ b/app/views/mailers/registrant_change_mailer/rejected.html.erb @@ -1,10 +1,10 @@ Tere

-Domeeni <%= @domain.name %> registreerija <%= @current_registrant.name %> on domeeni registreerija vahetamise taotluse tagasi lükanud. +Domeeni <%= @domain.name %> registreerija <%= @registrant.name %> on domeeni registreerija vahetamise taotluse tagasi lükanud.

Küsimuste korral võtke palun ühendust oma registripidajaga: -<%= render 'registrar.et.html', registrar: @registrar %> +<%= render 'mailers/shared/registrar/registrar.et.html', registrar: @registrar %>

Lugupidamisega
@@ -14,11 +14,11 @@ Eesti Interneti Sihtasutus

Hi,

-Registrant change for the domain <%= @domain.name %> was rejected by the registrant <%= @current_registrant.name %>. +Registrant change for the domain <%= @domain.name %> was rejected by the registrant <%= @registrant.name %>.

Please contact your registrar if you have any questions: -<%= render 'registrar.en.html', registrar: @registrar %> +<%= render 'mailers/shared/registrar/registrar.en.html', registrar: @registrar %>

Best Regards,
diff --git a/app/views/mailers/registrant_change_mailer/rejected.text.erb b/app/views/mailers/registrant_change_mailer/rejected.text.erb new file mode 100644 index 000000000..166f6f394 --- /dev/null +++ b/app/views/mailers/registrant_change_mailer/rejected.text.erb @@ -0,0 +1,23 @@ +Tere + +Domeeni <%= @domain.name %> registreerija <%= @registrant.name %> on domeeni registreerija vahetamise taotluse tagasi lükanud. + +Küsimuste korral võtke palun ühendust oma registripidajaga: + +<%= render 'mailers/shared/registrar/registrar.et.text', registrar: @registrar %> + +Lugupidamisega +Eesti Interneti Sihtasutus + +-------------------------------------- + +Hi, + +Registrant change for the domain <%= @domain.name %> was rejected by the registrant <%= @registrant.name %>. + +Please contact your registrar if you have any questions: + +<%= render 'mailers/shared/registrar/registrar.en.text', registrar: @registrar %> + +Best Regards, +Estonian Internet Foundation diff --git a/config/locales/en.yml b/config/locales/en.yml index 725dfffc3..be9539d6a 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -796,8 +796,6 @@ en: unimplemented_object_service: 'Unimplemented object service' contact_email_update_subject: 'Teie domeenide kontakt epostiaadress on muutunud / Contact e-mail addresses of your domains have changed' object_status_prohibits_operation: 'Object status prohibits operation' - pending_update_notification_for_new_registrant_subject: "Domeeni %{name} registreerija vahetus protseduur on algatatud / %{name} registrant change" - pending_update_rejected_notification_for_new_registrant_subject: "Domeeni %{name} registreerija vahetuse taotlus tagasi lükatud / %{name} registrant change declined" pending_update_expired_notification_for_new_registrant_subject: "Domeeni %{name} registreerija vahetuse taotlus on tühistatud / %{name} registrant change cancelled" registrant_updated_notification_for_new_registrant_subject: 'Domeeni %{name} registreerija vahetus teostatud / Registrant change of %{name} has been finished.' registrant_updated_notification_for_old_registrant_subject: 'Domeeni %{name} registreerija vahetus teostatud / Registrant change of %{name} has been finished.' diff --git a/config/locales/mailers/registrant_change.en.yml b/config/locales/mailers/registrant_change.en.yml index e7a5437b0..83fba025b 100644 --- a/config/locales/mailers/registrant_change.en.yml +++ b/config/locales/mailers/registrant_change.en.yml @@ -1,4 +1,8 @@ en: registrant_change_mailer: - confirmation: + confirm: subject: Kinnitustaotlus domeeni %{domain_name} registreerija vahetuseks / Application for approval for registrant change of %{domain_name} + notice: + subject: Domeeni %{domain_name} registreerija vahetus protseduur on algatatud / %{domain_name} registrant change + rejected: + subject: Domeeni %{domain_name} registreerija vahetuse taotlus tagasi lükatud / %{domain_name} registrant change declined diff --git a/spec/mailers/registrant_change_mailer_spec.rb b/spec/mailers/registrant_change_mailer_spec.rb index a26b507d3..d532d1e24 100644 --- a/spec/mailers/registrant_change_mailer_spec.rb +++ b/spec/mailers/registrant_change_mailer_spec.rb @@ -1,27 +1,33 @@ require 'rails_helper' RSpec.describe RegistrantChangeMailer do - describe '#confirmation' do + describe '#confirm' do let(:domain) { instance_spy(Domain, name: 'test.com') } - let(:registrant) { instance_spy(Registrant, email: 'registrant@test.com') } + let(:registrar) { instance_spy(Registrar) } + let(:current_registrant) { instance_spy(Registrant, email: 'registrant@test.com') } + let(:new_registrant) { instance_spy(Registrant) } + let(:domain_presenter) { instance_spy(DomainPresenter) } let(:registrar_presenter) { instance_spy(RegistrarPresenter) } - let(:registrant_presenter) { instance_spy(RegistrantPresenter) } - subject(:message) { described_class.confirmation(domain: domain, - registrant: registrant, - ) } + let(:new_registrant_presenter) { instance_spy(RegistrantPresenter) } + + subject(:message) { described_class.confirm(domain: domain, + registrar: registrar, + current_registrant: current_registrant, + new_registrant: new_registrant) + } before :example do expect(DomainPresenter).to receive(:new).and_return(domain_presenter) expect(RegistrarPresenter).to receive(:new).and_return(registrar_presenter) - expect(RegistrantPresenter).to receive(:new).and_return(registrant_presenter) + expect(RegistrantPresenter).to receive(:new).and_return(new_registrant_presenter) end it 'has sender' do expect(message.from).to eq(['noreply@internet.ee']) end - it 'has registrant email as a recipient' do + it 'has current registrant\s email as a recipient' do expect(message.to).to match_array(['registrant@test.com']) end @@ -43,4 +49,88 @@ RSpec.describe RegistrantChangeMailer do expect { message.deliver! }.to change { ActionMailer::Base.deliveries.count }.by(1) end end + + describe '#notice' do + let(:domain) { instance_spy(Domain, name: 'test.com') } + let(:registrar) { instance_spy(Registrar) } + let(:current_registrant) { instance_spy(Registrant) } + let(:new_registrant) { instance_spy(Registrant, email: 'registrant@test.com') } + + let(:domain_presenter) { instance_spy(DomainPresenter) } + let(:registrar_presenter) { instance_spy(RegistrarPresenter) } + let(:current_registrant_presenter) { instance_spy(RegistrantPresenter) } + let(:new_registrant_presenter) { instance_spy(RegistrantPresenter) } + + subject(:message) { described_class.notice(domain: domain, + registrar: registrar, + current_registrant: current_registrant, + new_registrant: new_registrant) + } + + before :example do + expect(DomainPresenter).to receive(:new).and_return(domain_presenter) + expect(RegistrarPresenter).to receive(:new).and_return(registrar_presenter) + expect(RegistrantPresenter).to receive(:new).with(registrant: current_registrant, view: anything).and_return(current_registrant_presenter) + expect(RegistrantPresenter).to receive(:new).with(registrant: new_registrant, view: anything).and_return(new_registrant_presenter) + end + + it 'has sender' do + expect(message.from).to eq(['noreply@internet.ee']) + end + + it 'has new registrant\s email as a recipient' do + expect(message.to).to match_array(['registrant@test.com']) + end + + it 'has subject' do + subject = 'Domeeni test.com registreerija vahetus protseduur on algatatud' \ + ' / test.com registrant change' + + expect(message.subject).to eq(subject) + end + + it 'sends message' do + expect { message.deliver! }.to change { ActionMailer::Base.deliveries.count }.by(1) + end + end + + describe '#rejected' do + let(:domain) { instance_spy(Domain, name: 'test.com', new_registrant_email: 'new.registrant@test.com') } + let(:registrar) { instance_spy(Registrar) } + let(:registrant) { instance_spy(Registrant) } + + let(:domain_presenter) { instance_spy(DomainPresenter) } + let(:registrar_presenter) { instance_spy(RegistrarPresenter) } + let(:registrant_presenter) { instance_spy(RegistrantPresenter) } + + subject(:message) { described_class.rejected(domain: domain, + registrar: registrar, + registrant: registrant) + } + + before :example do + expect(DomainPresenter).to receive(:new).and_return(domain_presenter) + expect(RegistrarPresenter).to receive(:new).and_return(registrar_presenter) + expect(RegistrantPresenter).to receive(:new).and_return(registrant_presenter) + end + + it 'has sender' do + expect(message.from).to eq(['noreply@internet.ee']) + end + + it 'has new registrant\s email as a recipient' do + expect(message.to).to match_array(['new.registrant@test.com']) + end + + it 'has subject' do + subject = 'Domeeni test.com registreerija vahetuse taotlus tagasi lükatud' \ + ' / test.com registrant change declined' + + expect(message.subject).to eq(subject) + end + + it 'sends message' do + expect { message.deliver! }.to change { ActionMailer::Base.deliveries.count }.by(1) + end + end end diff --git a/spec/models/domain_spec.rb b/spec/models/domain_spec.rb index 1a3e47bc6..fe660c7ec 100644 --- a/spec/models/domain_spec.rb +++ b/spec/models/domain_spec.rb @@ -891,4 +891,52 @@ RSpec.describe Domain, db: false do expect(described_class.delete_candidates.ids).to eq([1]) end end + + describe '#pending_update!', db: false do + let(:domain) { described_class.new } + let(:current_registrant) { FactoryGirl.build_stubbed(:registrant) } + let(:new_registrant) { FactoryGirl.build_stubbed(:registrant) } + let(:message) { instance_double(Mail::Message) } + + before :example do + expect(Registrant).to receive(:find).and_return(current_registrant) + expect(domain).to receive_messages( + reload: true, + pending_update?: false, + registrant_verification_asked?: true, + registrar: 'registrar', + registrant: new_registrant, + manage_automatic_statuses: true + ) + end + + it 'sends confirm and notice emails' do + allow(RegistrantChangeMailer).to receive(:notice).and_return(message) + expect(RegistrantChangeMailer).to receive(:confirm) + .with( + domain: domain, + registrar: 'registrar', + current_registrant: current_registrant, + new_registrant: new_registrant) + .and_return(message) + + expect(RegistrantChangeMailer).to receive(:notice) + .with( + domain: domain, + registrar: 'registrar', + current_registrant: current_registrant, + new_registrant: new_registrant) + .and_return(message) + expect(message).to receive(:deliver).exactly(2).times + domain.pending_update! + end + end + + describe '#new_registrant_email' do + let(:domain) { described_class.new(pending_json: { new_registrant_email: 'test@test.com' }) } + + it 'returns new registrant\'s email' do + expect(domain.new_registrant_email).to eq('test@test.com') + end + end end diff --git a/spec/views/mailers/domain_mailer/force_delete.html.erb_spec.rb b/spec/views/mailers/domain_mailer/force_delete.html.erb_spec.rb index d201a6540..462211b78 100644 --- a/spec/views/mailers/domain_mailer/force_delete.html.erb_spec.rb +++ b/spec/views/mailers/domain_mailer/force_delete.html.erb_spec.rb @@ -3,9 +3,9 @@ require_relative 'force_delete_shared' RSpec.describe 'mailers/domain_mailer/force_delete.html.erb' do before :example do - 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' + stub_template 'mailers/shared/registrar/_registrar.et.html' => 'test registrar estonian' + stub_template 'mailers/shared/registrar/_registrar.en.html' => 'test registrar english' + stub_template 'mailers/shared/registrar/_registrar.ru.html' => 'test registrar russian' end include_examples 'domain mailer force delete' diff --git a/spec/views/mailers/domain_mailer/force_delete.text.erb_spec.rb b/spec/views/mailers/domain_mailer/force_delete.text.erb_spec.rb index 824746208..6aaf08820 100644 --- a/spec/views/mailers/domain_mailer/force_delete.text.erb_spec.rb +++ b/spec/views/mailers/domain_mailer/force_delete.text.erb_spec.rb @@ -3,9 +3,9 @@ require_relative 'force_delete_shared' RSpec.describe 'mailers/domain_mailer/force_delete.text.erb' do before :example do - 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' + stub_template 'mailers/shared/registrar/_registrar.et.text' => 'test registrar estonian' + stub_template 'mailers/shared/registrar/_registrar.en.text' => 'test registrar english' + stub_template 'mailers/shared/registrar/_registrar.ru.text' => 'test registrar russian' end include_examples 'domain mailer force delete' diff --git a/spec/views/mailers/registrant_change_mailer/confirmation.html.erb_spec.rb b/spec/views/mailers/registrant_change_mailer/confirm.html.erb_spec.rb similarity index 69% rename from spec/views/mailers/registrant_change_mailer/confirmation.html.erb_spec.rb rename to spec/views/mailers/registrant_change_mailer/confirm.html.erb_spec.rb index c59dd4e55..e8aa20326 100644 --- a/spec/views/mailers/registrant_change_mailer/confirmation.html.erb_spec.rb +++ b/spec/views/mailers/registrant_change_mailer/confirm.html.erb_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' -require_relative 'confirmation_shared' +require_relative 'confirm_shared' -RSpec.describe 'mailers/registrant_change_mailer/confirmation.html.erb' do +RSpec.describe 'mailers/registrant_change_mailer/confirm.html.erb' do before :example do stub_template 'mailers/shared/registrar/_registrar.et.html' => 'test registrar estonian' stub_template 'mailers/shared/registrar/_registrar.en.html' => 'test registrar english' @@ -9,5 +9,5 @@ RSpec.describe 'mailers/registrant_change_mailer/confirmation.html.erb' do stub_template 'mailers/shared/registrant/_registrant.en.html' => 'test new registrant english' end - include_examples 'domain mailer pending update request for old registrant' + include_examples 'registrant change mailer confirm' end diff --git a/spec/views/mailers/registrant_change_mailer/confirmation.text.erb_spec.rb b/spec/views/mailers/registrant_change_mailer/confirm.text.erb_spec.rb similarity index 69% rename from spec/views/mailers/registrant_change_mailer/confirmation.text.erb_spec.rb rename to spec/views/mailers/registrant_change_mailer/confirm.text.erb_spec.rb index 37edf78e9..f98f4ec32 100644 --- a/spec/views/mailers/registrant_change_mailer/confirmation.text.erb_spec.rb +++ b/spec/views/mailers/registrant_change_mailer/confirm.text.erb_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' -require_relative 'confirmation_shared' +require_relative 'confirm_shared' -RSpec.describe 'mailers/registrant_change_mailer/confirmation.text.erb' do +RSpec.describe 'mailers/registrant_change_mailer/confirm.text.erb' do before :example do stub_template 'mailers/shared/registrar/_registrar.et.text' => 'test registrar estonian' stub_template 'mailers/shared/registrar/_registrar.en.text' => 'test registrar english' @@ -9,5 +9,5 @@ RSpec.describe 'mailers/registrant_change_mailer/confirmation.text.erb' do stub_template 'mailers/shared/registrant/_registrant.en.text' => 'test new registrant english' end - include_examples 'domain mailer pending update request for old registrant' + include_examples 'registrant change mailer confirm' end diff --git a/spec/views/mailers/registrant_change_mailer/confirmation_shared.rb b/spec/views/mailers/registrant_change_mailer/confirm_shared.rb similarity index 81% rename from spec/views/mailers/registrant_change_mailer/confirmation_shared.rb rename to spec/views/mailers/registrant_change_mailer/confirm_shared.rb index ed760aeed..8949b5070 100644 --- a/spec/views/mailers/registrant_change_mailer/confirmation_shared.rb +++ b/spec/views/mailers/registrant_change_mailer/confirm_shared.rb @@ -1,6 +1,6 @@ require 'rails_helper' -RSpec.shared_examples 'domain mailer pending update request for old registrant' do +RSpec.shared_examples 'registrant change mailer confirm' do let(:domain) { instance_spy(DomainPresenter) } let(:lang_count) { 2 } @@ -8,7 +8,7 @@ RSpec.shared_examples 'domain mailer pending update request for old registrant' assign(:domain, domain) assign(:registrar, nil) assign(:new_registrant, nil) - assign(:verification_url, 'test verification url') + assign(:confirm_url, 'test confirm url') end it 'has registrar info in estonian' do @@ -31,10 +31,10 @@ RSpec.shared_examples 'domain mailer pending update request for old registrant' expect(rendered).to have_text('test new registrant english') end - it 'has verification url' do + it 'has confirm url' do mention_count = 1 * lang_count render - expect(rendered).to have_text('test verification url', count: mention_count) + expect(rendered).to have_text('test confirm url', count: mention_count) end domain_attributes = %i( diff --git a/spec/views/mailers/registrant_change_mailer/notice.html.erb_spec.rb b/spec/views/mailers/registrant_change_mailer/notice.html.erb_spec.rb new file mode 100644 index 000000000..c5d4f2974 --- /dev/null +++ b/spec/views/mailers/registrant_change_mailer/notice.html.erb_spec.rb @@ -0,0 +1,13 @@ +require 'rails_helper' +require_relative 'notice_shared' + +RSpec.describe 'mailers/registrant_change_mailer/notice.html.erb' do + before :example do + stub_template 'mailers/shared/registrar/_registrar.et.html' => 'test registrar estonian' + stub_template 'mailers/shared/registrar/_registrar.en.html' => 'test registrar english' + stub_template 'mailers/shared/registrant/_registrant.et.html' => 'test new registrant estonian' + stub_template 'mailers/shared/registrant/_registrant.en.html' => 'test new registrant english' + end + + include_examples 'registrant change mailer notice' +end diff --git a/spec/views/mailers/registrant_change_mailer/notice.text.erb_spec.rb b/spec/views/mailers/registrant_change_mailer/notice.text.erb_spec.rb new file mode 100644 index 000000000..ab685b12f --- /dev/null +++ b/spec/views/mailers/registrant_change_mailer/notice.text.erb_spec.rb @@ -0,0 +1,13 @@ +require 'rails_helper' +require_relative 'notice_shared' + +RSpec.describe 'mailers/registrant_change_mailer/notice.text.erb' do + before :example do + stub_template 'mailers/shared/registrar/_registrar.et.text' => 'test registrar estonian' + stub_template 'mailers/shared/registrar/_registrar.en.text' => 'test registrar english' + stub_template 'mailers/shared/registrant/_registrant.et.text' => 'test new registrant estonian' + stub_template 'mailers/shared/registrant/_registrant.en.text' => 'test new registrant english' + end + + include_examples 'registrant change mailer notice' +end diff --git a/spec/views/mailers/registrant_change_mailer/pending_update_notification_for_new_registrant_shared.rb b/spec/views/mailers/registrant_change_mailer/notice_shared.rb similarity index 65% rename from spec/views/mailers/registrant_change_mailer/pending_update_notification_for_new_registrant_shared.rb rename to spec/views/mailers/registrant_change_mailer/notice_shared.rb index 9b95af51b..40d42cd1c 100644 --- a/spec/views/mailers/registrant_change_mailer/pending_update_notification_for_new_registrant_shared.rb +++ b/spec/views/mailers/registrant_change_mailer/notice_shared.rb @@ -1,13 +1,16 @@ require 'rails_helper' -RSpec.shared_examples 'domain mailer pending update notification for new registrant' do +RSpec.shared_examples 'registrant change mailer notice' 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(:current_registrant, registrant) + assign(:new_registrant, registrant) end it 'has registrar info in estonian' do @@ -20,10 +23,14 @@ RSpec.shared_examples 'domain mailer pending update notification for new registr expect(rendered).to have_text('test registrar english') end - it 'has registrar name' do - expect(registrar).to receive(:name).and_return('test registrar name') + it 'has new registrant info in estonian' do render - expect(rendered).to have_text('test registrar name') + expect(rendered).to have_text('test new registrant estonian') + end + + it 'has new registrant info in english' do + render + expect(rendered).to have_text('test new registrant english') end domain_attributes = %i( diff --git a/spec/views/mailers/registrant_change_mailer/pending_update_notification_for_new_registrant.html.erb_spec.rb b/spec/views/mailers/registrant_change_mailer/pending_update_notification_for_new_registrant.html.erb_spec.rb deleted file mode 100644 index 9b6519654..000000000 --- a/spec/views/mailers/registrant_change_mailer/pending_update_notification_for_new_registrant.html.erb_spec.rb +++ /dev/null @@ -1,6 +0,0 @@ -require 'rails_helper' -require_relative 'pending_update_notification_for_new_registrant_shared' - -RSpec.describe 'mailers/domain_mailer/pending_update_notification_for_new_registrant.html.erb' do - include_examples 'domain mailer pending update notification for new registrant' -end diff --git a/spec/views/mailers/registrant_change_mailer/pending_update_notification_for_new_registrant.text.erb_spec.rb b/spec/views/mailers/registrant_change_mailer/pending_update_notification_for_new_registrant.text.erb_spec.rb deleted file mode 100644 index cf39231b4..000000000 --- a/spec/views/mailers/registrant_change_mailer/pending_update_notification_for_new_registrant.text.erb_spec.rb +++ /dev/null @@ -1,9 +0,0 @@ -require 'rails_helper' -require_relative 'pending_update_notification_for_new_registrant_shared' - -RSpec.describe 'mailers/domain_mailer/pending_update_notification_for_new_registrant.text.erb' do - include_examples 'domain mailer pending update notification for new registrant' - - - -end diff --git a/spec/views/mailers/registrant_change_mailer/rejected.html.erb_spec.rb b/spec/views/mailers/registrant_change_mailer/rejected.html.erb_spec.rb new file mode 100644 index 000000000..be37545c6 --- /dev/null +++ b/spec/views/mailers/registrant_change_mailer/rejected.html.erb_spec.rb @@ -0,0 +1,11 @@ +require 'rails_helper' +require_relative 'rejected_shared' + +RSpec.describe 'mailers/registrant_change_mailer/rejected.html.erb' do + before :example do + stub_template 'mailers/shared/registrar/_registrar.et.html' => 'test registrar estonian' + stub_template 'mailers/shared/registrar/_registrar.en.html' => 'test registrar english' + end + + include_examples 'registrant change mailer rejected' +end diff --git a/spec/views/mailers/registrant_change_mailer/rejected.text.erb_spec.rb b/spec/views/mailers/registrant_change_mailer/rejected.text.erb_spec.rb new file mode 100644 index 000000000..af9d78a69 --- /dev/null +++ b/spec/views/mailers/registrant_change_mailer/rejected.text.erb_spec.rb @@ -0,0 +1,11 @@ +require 'rails_helper' +require_relative 'rejected_shared' + +RSpec.describe 'mailers/registrant_change_mailer/rejected.text.erb' do + before :example do + stub_template 'mailers/shared/registrar/_registrar.et.text' => 'test registrar estonian' + stub_template 'mailers/shared/registrar/_registrar.en.text' => 'test registrar english' + end + + include_examples 'registrant change mailer rejected' +end diff --git a/spec/views/mailers/registrant_change_mailer/rejected_shared.rb b/spec/views/mailers/registrant_change_mailer/rejected_shared.rb new file mode 100644 index 000000000..f6e21d57a --- /dev/null +++ b/spec/views/mailers/registrant_change_mailer/rejected_shared.rb @@ -0,0 +1,48 @@ +require 'rails_helper' + +RSpec.shared_examples 'registrant change mailer rejected' 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) + 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 + + 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 + + registrant_attributes = %i( + name + ) + + 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 From c0f4066be12673938015785d9fdcc08728f442fd Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Mon, 14 Nov 2016 03:06:51 +0200 Subject: [PATCH 38/67] Refactor domain mailer views #180 --- app/mailers/registrant_change_mailer.rb | 9 +++- app/models/domain_cron.rb | 3 +- app/models/domain_mail_model.rb | 7 --- ...w_registrant.html.erb => expired.html.erb} | 4 +- ...w_registrant.text.erb => expired.text.erb} | 4 +- config/locales/en.yml | 1 - .../locales/mailers/registrant_change.en.yml | 2 + spec/mailers/registrant_change_mailer_spec.rb | 44 +++++++++++++++- .../expired.html.erb_spec.rb | 11 ++++ .../expired.text.erb_spec.rb | 11 ++++ .../expired_shared.rb | 50 +++++++++++++++++++ 11 files changed, 129 insertions(+), 17 deletions(-) rename app/views/mailers/registrant_change_mailer/{pending_update_expired_notification_for_new_registrant.html.erb => expired.html.erb} (78%) rename app/views/mailers/registrant_change_mailer/{pending_update_expired_notification_for_new_registrant.text.erb => expired.text.erb} (77%) create mode 100644 spec/views/mailers/registrant_change_mailer/expired.html.erb_spec.rb create mode 100644 spec/views/mailers/registrant_change_mailer/expired.text.erb_spec.rb create mode 100644 spec/views/mailers/registrant_change_mailer/expired_shared.rb diff --git a/app/mailers/registrant_change_mailer.rb b/app/mailers/registrant_change_mailer.rb index c5efced86..ebc488036 100644 --- a/app/mailers/registrant_change_mailer.rb +++ b/app/mailers/registrant_change_mailer.rb @@ -31,8 +31,13 @@ class RegistrantChangeMailer < ApplicationMailer mail(to: domain.new_registrant_email, subject: subject) end - def pending_update_expired_notification_for_new_registrant(params) - compose_from(params) + def expired(domain:, registrar:, registrant:) + @domain = DomainPresenter.new(domain: domain, view: view_context) + @registrar = RegistrarPresenter.new(registrar: registrar, view: view_context) + @registrant = RegistrantPresenter.new(registrant: registrant, view: view_context) + + subject = default_i18n_subject(domain_name: domain.name) + mail(to: domain.new_registrant_email, subject: subject) end private diff --git a/app/models/domain_cron.rb b/app/models/domain_cron.rb index 4ab0bc273..dc4db50c0 100644 --- a/app/models/domain_cron.rb +++ b/app/models/domain_cron.rb @@ -16,7 +16,8 @@ class DomainCron end count += 1 if domain.pending_update? - DomainMailer.pending_update_expired_notification_for_new_registrant(domain.id).deliver + RegistrantChangeMailer.expired(domain: domain, registrar: domain.registrar, registrant: domain.registrant) + .deliver end if domain.pending_delete? || domain.pending_delete_confirmation? DomainMailer.pending_delete_expired_notification(domain.id, true).deliver diff --git a/app/models/domain_mail_model.rb b/app/models/domain_mail_model.rb index ef248774b..3f92a3138 100644 --- a/app/models/domain_mail_model.rb +++ b/app/models/domain_mail_model.rb @@ -6,13 +6,6 @@ class DomainMailModel @params = {errors: [], deliver_emails: domain.deliver_emails, id: domain.id} end - def pending_update_expired_notification_for_new_registrant - registrant_pending - subject(:pending_update_expired_notification_for_new_registrant_subject) - domain_info - compose - end - def pending_delete_rejected_notification registrant subject(:pending_delete_rejected_notification_subject) diff --git a/app/views/mailers/registrant_change_mailer/pending_update_expired_notification_for_new_registrant.html.erb b/app/views/mailers/registrant_change_mailer/expired.html.erb similarity index 78% rename from app/views/mailers/registrant_change_mailer/pending_update_expired_notification_for_new_registrant.html.erb rename to app/views/mailers/registrant_change_mailer/expired.html.erb index 90d17462b..0d369a970 100644 --- a/app/views/mailers/registrant_change_mailer/pending_update_expired_notification_for_new_registrant.html.erb +++ b/app/views/mailers/registrant_change_mailer/expired.html.erb @@ -4,7 +4,7 @@ Domeeni <%= @domain.name %> registreerija <%= @registrant.name %> ei kinnitanud

Küsimuste korral palun võtke ühendust oma registripidajaga: -<%= render 'registrar.et.html', registrar: @registrar %> +<%= render 'mailers/shared/registrar/registrar.et.html', registrar: @registrar %>

Lugupidamisega
@@ -18,7 +18,7 @@ Domain registrant change request has been expired for the domain <%= @domain.nam

Please contact to your registrar if you have any questions: -<%= render 'registrar.en.html', registrar: @registrar %> +<%= render 'mailers/shared/registrar/registrar.en.html', registrar: @registrar %>

Best Regards,
diff --git a/app/views/mailers/registrant_change_mailer/pending_update_expired_notification_for_new_registrant.text.erb b/app/views/mailers/registrant_change_mailer/expired.text.erb similarity index 77% rename from app/views/mailers/registrant_change_mailer/pending_update_expired_notification_for_new_registrant.text.erb rename to app/views/mailers/registrant_change_mailer/expired.text.erb index dfdcc0a5d..7ec3fecbd 100644 --- a/app/views/mailers/registrant_change_mailer/pending_update_expired_notification_for_new_registrant.text.erb +++ b/app/views/mailers/registrant_change_mailer/expired.text.erb @@ -4,7 +4,7 @@ Domeeni <%= @domain.name %> registreerija <%= @registrant.name %> ei kinnitanud Küsimuste korral palun võtke ühendust oma registripidajaga: -<%= render 'registrar.et.text', registrar: @registrar %> +<%= render 'mailers/shared/registrar/registrar.et.text', registrar: @registrar %> Lugupidamisega Eesti Interneti Sihtasutus @@ -17,7 +17,7 @@ Domain registrant change request has been expired for the domain <%= @domain.nam Please contact to your registrar if you have any questions: -<%= render 'registrar.en.text', registrar: @registrar %> +<%= render 'mailers/shared/registrar/registrar.en.text', registrar: @registrar %> Best Regards, Estonian Internet Foundation diff --git a/config/locales/en.yml b/config/locales/en.yml index be9539d6a..cffcf9243 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -796,7 +796,6 @@ en: unimplemented_object_service: 'Unimplemented object service' contact_email_update_subject: 'Teie domeenide kontakt epostiaadress on muutunud / Contact e-mail addresses of your domains have changed' object_status_prohibits_operation: 'Object status prohibits operation' - pending_update_expired_notification_for_new_registrant_subject: "Domeeni %{name} registreerija vahetuse taotlus on tühistatud / %{name} registrant change cancelled" registrant_updated_notification_for_new_registrant_subject: 'Domeeni %{name} registreerija vahetus teostatud / Registrant change of %{name} has been finished.' registrant_updated_notification_for_old_registrant_subject: 'Domeeni %{name} registreerija vahetus teostatud / Registrant change of %{name} has been finished.' pending_delete_rejected_notification_subject: "Domeeni %{name} kustutamise taotlus tagasi lükatud / %{name} deletion declined" diff --git a/config/locales/mailers/registrant_change.en.yml b/config/locales/mailers/registrant_change.en.yml index 83fba025b..9cd95f648 100644 --- a/config/locales/mailers/registrant_change.en.yml +++ b/config/locales/mailers/registrant_change.en.yml @@ -6,3 +6,5 @@ en: subject: Domeeni %{domain_name} registreerija vahetus protseduur on algatatud / %{domain_name} registrant change rejected: subject: Domeeni %{domain_name} registreerija vahetuse taotlus tagasi lükatud / %{domain_name} registrant change declined + expired: + subject: Domeeni %{domain_name} registreerija vahetuse taotlus on tühistatud / %{domain_name} registrant change cancelled diff --git a/spec/mailers/registrant_change_mailer_spec.rb b/spec/mailers/registrant_change_mailer_spec.rb index d532d1e24..5a619d0a1 100644 --- a/spec/mailers/registrant_change_mailer_spec.rb +++ b/spec/mailers/registrant_change_mailer_spec.rb @@ -104,8 +104,8 @@ RSpec.describe RegistrantChangeMailer do let(:registrant_presenter) { instance_spy(RegistrantPresenter) } subject(:message) { described_class.rejected(domain: domain, - registrar: registrar, - registrant: registrant) + registrar: registrar, + registrant: registrant) } before :example do @@ -133,4 +133,44 @@ RSpec.describe RegistrantChangeMailer do expect { message.deliver! }.to change { ActionMailer::Base.deliveries.count }.by(1) end end + + describe '#expired' do + let(:domain) { instance_spy(Domain, name: 'test.com', new_registrant_email: 'new.registrant@test.com') } + let(:registrar) { instance_spy(Registrar) } + let(:registrant) { instance_spy(Registrant) } + + let(:domain_presenter) { instance_spy(DomainPresenter) } + let(:registrar_presenter) { instance_spy(RegistrarPresenter) } + let(:registrant_presenter) { instance_spy(RegistrantPresenter) } + + subject(:message) { described_class.expired(domain: domain, + registrar: registrar, + registrant: registrant) + } + + before :example do + expect(DomainPresenter).to receive(:new).and_return(domain_presenter) + expect(RegistrarPresenter).to receive(:new).and_return(registrar_presenter) + expect(RegistrantPresenter).to receive(:new).and_return(registrant_presenter) + end + + it 'has sender' do + expect(message.from).to eq(['noreply@internet.ee']) + end + + it 'has new registrant\s email as a recipient' do + expect(message.to).to match_array(['new.registrant@test.com']) + end + + it 'has subject' do + subject = 'Domeeni test.com registreerija vahetuse taotlus on tühistatud' \ + ' / test.com registrant change cancelled' + + expect(message.subject).to eq(subject) + end + + it 'sends message' do + expect { message.deliver! }.to change { ActionMailer::Base.deliveries.count }.by(1) + end + end end diff --git a/spec/views/mailers/registrant_change_mailer/expired.html.erb_spec.rb b/spec/views/mailers/registrant_change_mailer/expired.html.erb_spec.rb new file mode 100644 index 000000000..581fae654 --- /dev/null +++ b/spec/views/mailers/registrant_change_mailer/expired.html.erb_spec.rb @@ -0,0 +1,11 @@ +require 'rails_helper' +require_relative 'expired_shared' + +RSpec.describe 'mailers/registrant_change_mailer/expired.html.erb' do + before :example do + stub_template 'mailers/shared/registrar/_registrar.et.html' => 'test registrar estonian' + stub_template 'mailers/shared/registrar/_registrar.en.html' => 'test registrar english' + end + + include_examples 'registrant change mailer expired' +end diff --git a/spec/views/mailers/registrant_change_mailer/expired.text.erb_spec.rb b/spec/views/mailers/registrant_change_mailer/expired.text.erb_spec.rb new file mode 100644 index 000000000..6f02fd795 --- /dev/null +++ b/spec/views/mailers/registrant_change_mailer/expired.text.erb_spec.rb @@ -0,0 +1,11 @@ +require 'rails_helper' +require_relative 'expired_shared' + +RSpec.describe 'mailers/registrant_change_mailer/expired.text.erb' do + before :example do + stub_template 'mailers/shared/registrar/_registrar.et.text' => 'test registrar estonian' + stub_template 'mailers/shared/registrar/_registrar.en.text' => 'test registrar english' + end + + include_examples 'registrant change mailer expired' +end diff --git a/spec/views/mailers/registrant_change_mailer/expired_shared.rb b/spec/views/mailers/registrant_change_mailer/expired_shared.rb new file mode 100644 index 000000000..bcb82f008 --- /dev/null +++ b/spec/views/mailers/registrant_change_mailer/expired_shared.rb @@ -0,0 +1,50 @@ +require 'rails_helper' + +RSpec.shared_examples 'registrant change mailer expired' 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) + 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 + + domain_attributes = %i( + name + ) + + domain_attributes.each do |attr_name| + it "has domain #{attr_name}" do + mention_count = 3 + expect(domain).to receive(attr_name).exactly(mention_count).times.and_return("test domain #{attr_name}") + render + expect(rendered).to have_text("test domain #{attr_name}", count: mention_count) + end + end + + registrant_attributes = %i( + name + ) + + registrant_attributes.each do |attr_name| + it "has registrant #{attr_name}" do + mention_count = 1 + expect(registrant).to receive(attr_name).exactly(mention_count).times.and_return("test registrant #{attr_name}") + render + expect(rendered).to have_text("test registrant #{attr_name}", count: mention_count) + end + end +end From 471ac9098d0a842c16c768453b62c6b6d6ace0cb Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Mon, 14 Nov 2016 03:24:44 +0200 Subject: [PATCH 39/67] Destroy DomainExpirationEmailJob #180 --- app/jobs/domain_expiration_email_job.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/jobs/domain_expiration_email_job.rb b/app/jobs/domain_expiration_email_job.rb index 478ecb0da..8d14e557a 100644 --- a/app/jobs/domain_expiration_email_job.rb +++ b/app/jobs/domain_expiration_email_job.rb @@ -5,5 +5,6 @@ class DomainExpirationEmailJob < Que::Job return if domain.registered? DomainMailer.expiration(domain: domain).deliver! + destroy end end From 3a040793b042d61ec5b2f37bc1a944f089849e65 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Mon, 14 Nov 2016 03:27:03 +0200 Subject: [PATCH 40/67] Refactor domain mailer views #180 --- app/views/mailers/domain_mailer/expiration.html.erb | 6 +++--- app/views/mailers/domain_mailer/expiration.text.erb | 6 +++--- .../views/mailers/domain_mailer/expiration.html.erb_spec.rb | 6 +++--- .../views/mailers/domain_mailer/expiration.text.erb_spec.rb | 6 +++--- .../shared/registrant/_registrant.en.html.erb_spec.rb | 2 +- .../shared/registrant/_registrant.en.text.erb_spec.rb | 2 +- .../shared/registrant/_registrant.et.html.erb_spec.rb | 2 +- .../shared/registrant/_registrant.et.text.erb_spec.rb | 2 +- .../mailers/shared/registrar/_registrar.en.html.erb_spec.rb | 2 +- .../mailers/shared/registrar/_registrar.en.text.erb_spec.rb | 2 +- .../mailers/shared/registrar/_registrar.et.html.erb_spec.rb | 2 +- .../mailers/shared/registrar/_registrar.et.text.erb_spec.rb | 2 +- .../mailers/shared/registrar/_registrar.ru.html.erb_spec.rb | 2 +- .../mailers/shared/registrar/_registrar.ru.text.erb_spec.rb | 2 +- 14 files changed, 22 insertions(+), 22 deletions(-) diff --git a/app/views/mailers/domain_mailer/expiration.html.erb b/app/views/mailers/domain_mailer/expiration.html.erb index 3c66159e9..d9a96b50a 100644 --- a/app/views/mailers/domain_mailer/expiration.html.erb +++ b/app/views/mailers/domain_mailer/expiration.html.erb @@ -4,7 +4,7 @@ Lugupeetud .ee domeeni kasutaja
Domeeninimi <%= @domain.name %> on aegunud ja ei ole alates <%= @domain.on_hold_date %> internetis kättesaadav. Alates <%= @domain.delete_date %> on domeen <%= @domain.name %> avatud registreerimiseks kõigile huvilistele.

Domeeni registreeringu pikendamiseks pöörduge palun oma registripidaja: -<%= render 'mailers/domain_mailer/registrar/registrar.et.html', registrar: @registrar %> +<%= render 'mailers/shared/registrar/registrar.et.html', registrar: @registrar %>

Domeeni <%= @domain.name %> kohta on registris järgmised andmed:

@@ -27,7 +27,7 @@ Dear user of .ee domain,
The domain name <%= @domain.name %> has expired and will not be available on the Internet from <%= @domain.on_hold_date %>. From <%= @domain.delete_date %>, the <%= @domain.name %> domain will be available for registration on a first come first served basis.

To renew the domain registration, please contact your registrar: -<%= render 'mailers/domain_mailer/registrar/registrar.en.html', registrar: @registrar %> +<%= render 'mailers/shared/registrar/registrar.en.html', registrar: @registrar %>

The following data for the <%= @domain.name %> domain have been entered into the registry:

@@ -53,7 +53,7 @@ Estonian Internet Foundation

Для продления регистрации домена просим обратиться к своему регистратору: -<%= render 'mailers/domain_mailer/registrar/registrar.ru.html', registrar: @registrar %> +<%= render 'mailers/shared/registrar/registrar.ru.html', registrar: @registrar %>

Относительно домена <%= @domain.name %> в реестр внесены следующие данные: diff --git a/app/views/mailers/domain_mailer/expiration.text.erb b/app/views/mailers/domain_mailer/expiration.text.erb index fc9351300..ab0ba5a14 100644 --- a/app/views/mailers/domain_mailer/expiration.text.erb +++ b/app/views/mailers/domain_mailer/expiration.text.erb @@ -5,7 +5,7 @@ Domeeninimi <%= @domain.name %> on aegunud ja ei ole alates <%= @domain.on_hold_ Domeeni registreeringu pikendamiseks pöörduge palun oma registripidaja: -<%= render 'mailers/domain_mailer/registrar/registrar.et.text', registrar: @registrar %> +<%= render 'mailers/shared/registrar/registrar.et.text', registrar: @registrar %> Domeeni <%= @domain.name %> kohta on registris järgmised andmed: @@ -28,7 +28,7 @@ The domain name <%= @domain.name %> has expired and will not be available on the To renew the domain registration, please contact your registrar: -<%= render 'mailers/domain_mailer/registrar/registrar.en.text', registrar: @registrar %> +<%= render 'mailers/shared/registrar/registrar.en.text', registrar: @registrar %> The following data for the <%= @domain.name %> domain have been entered into the registry: @@ -51,7 +51,7 @@ Estonian Internet Foundation Для продления регистрации домена просим обратиться к своему регистратору: -<%= render 'mailers/domain_mailer/registrar/registrar.ru.text', registrar: @registrar %> +<%= render 'mailers/shared/registrar/registrar.ru.text', registrar: @registrar %> Относительно домена <%= @domain.name %> в реестр внесены следующие данные: diff --git a/spec/views/mailers/domain_mailer/expiration.html.erb_spec.rb b/spec/views/mailers/domain_mailer/expiration.html.erb_spec.rb index 31f54be1b..ff9205c7d 100644 --- a/spec/views/mailers/domain_mailer/expiration.html.erb_spec.rb +++ b/spec/views/mailers/domain_mailer/expiration.html.erb_spec.rb @@ -3,9 +3,9 @@ require_relative 'expiration_shared' RSpec.describe 'mailers/domain_mailer/expiration.html.erb' do before :example do - 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' + stub_template 'mailers/shared/registrar/_registrar.et.html' => 'test registrar estonian' + stub_template 'mailers/shared/registrar/_registrar.en.html' => 'test registrar english' + stub_template 'mailers/shared/registrar/_registrar.ru.html' => 'test registrar russian' end include_examples 'domain mailer expiration' diff --git a/spec/views/mailers/domain_mailer/expiration.text.erb_spec.rb b/spec/views/mailers/domain_mailer/expiration.text.erb_spec.rb index 3c315b47b..44e5642aa 100644 --- a/spec/views/mailers/domain_mailer/expiration.text.erb_spec.rb +++ b/spec/views/mailers/domain_mailer/expiration.text.erb_spec.rb @@ -3,9 +3,9 @@ require_relative 'expiration_shared' RSpec.describe 'mailers/domain_mailer/expiration.text.erb' do before :example do - 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' + stub_template 'mailers/shared/registrar/_registrar.et.text' => 'test registrar estonian' + stub_template 'mailers/shared/registrar/_registrar.en.text' => 'test registrar english' + stub_template 'mailers/shared/registrar/_registrar.ru.text' => 'test registrar russian' end include_examples 'domain mailer expiration' diff --git a/spec/views/mailers/shared/registrant/_registrant.en.html.erb_spec.rb b/spec/views/mailers/shared/registrant/_registrant.en.html.erb_spec.rb index b93b592e6..a5e0d353b 100644 --- a/spec/views/mailers/shared/registrant/_registrant.en.html.erb_spec.rb +++ b/spec/views/mailers/shared/registrant/_registrant.en.html.erb_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' require_relative 'registrant_shared' -RSpec.describe 'mailers/domain_mailer/registrant/_registrant.en.html.erb' do +RSpec.describe 'mailers/shared/registrant/_registrant.en.html.erb' do include_examples 'domain mailer registrant info' end diff --git a/spec/views/mailers/shared/registrant/_registrant.en.text.erb_spec.rb b/spec/views/mailers/shared/registrant/_registrant.en.text.erb_spec.rb index 3a2310fff..fcfb85657 100644 --- a/spec/views/mailers/shared/registrant/_registrant.en.text.erb_spec.rb +++ b/spec/views/mailers/shared/registrant/_registrant.en.text.erb_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' require_relative 'registrant_shared' -RSpec.describe 'mailers/domain_mailer/registrant/_registrant.en.text.erb' do +RSpec.describe 'mailers/shared/registrant/_registrant.en.text.erb' do include_examples 'domain mailer registrant info' end diff --git a/spec/views/mailers/shared/registrant/_registrant.et.html.erb_spec.rb b/spec/views/mailers/shared/registrant/_registrant.et.html.erb_spec.rb index 952bb5223..ec4d134a8 100644 --- a/spec/views/mailers/shared/registrant/_registrant.et.html.erb_spec.rb +++ b/spec/views/mailers/shared/registrant/_registrant.et.html.erb_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' require_relative 'registrant_shared' -RSpec.describe 'mailers/domain_mailer/registrant/_registrant.et.html.erb' do +RSpec.describe 'mailers/shared/registrant/_registrant.et.html.erb' do include_examples 'domain mailer registrant info' end diff --git a/spec/views/mailers/shared/registrant/_registrant.et.text.erb_spec.rb b/spec/views/mailers/shared/registrant/_registrant.et.text.erb_spec.rb index ea05cbfa5..41b4c52eb 100644 --- a/spec/views/mailers/shared/registrant/_registrant.et.text.erb_spec.rb +++ b/spec/views/mailers/shared/registrant/_registrant.et.text.erb_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' require_relative 'registrant_shared' -RSpec.describe 'mailers/domain_mailer/registrant/_registrant.et.text.erb' do +RSpec.describe 'mailers/shared/registrant/_registrant.et.text.erb' do include_examples 'domain mailer registrant info' end diff --git a/spec/views/mailers/shared/registrar/_registrar.en.html.erb_spec.rb b/spec/views/mailers/shared/registrar/_registrar.en.html.erb_spec.rb index 62fe5d068..eddb968dc 100644 --- a/spec/views/mailers/shared/registrar/_registrar.en.html.erb_spec.rb +++ b/spec/views/mailers/shared/registrar/_registrar.en.html.erb_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' require_relative 'registrar_shared' -RSpec.describe 'mailers/domain_mailer/registrar/_registrar.en.html.erb' do +RSpec.describe 'mailers/shared/registrar/_registrar.en.html.erb' do include_examples 'domain mailer registrar info' end diff --git a/spec/views/mailers/shared/registrar/_registrar.en.text.erb_spec.rb b/spec/views/mailers/shared/registrar/_registrar.en.text.erb_spec.rb index 542d8aaee..cea5d1d65 100644 --- a/spec/views/mailers/shared/registrar/_registrar.en.text.erb_spec.rb +++ b/spec/views/mailers/shared/registrar/_registrar.en.text.erb_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' require_relative 'registrar_shared' -RSpec.describe 'mailers/domain_mailer/registrar/_registrar.en.text.erb' do +RSpec.describe 'mailers/shared/registrar/_registrar.en.text.erb' do include_examples 'domain mailer registrar info' end diff --git a/spec/views/mailers/shared/registrar/_registrar.et.html.erb_spec.rb b/spec/views/mailers/shared/registrar/_registrar.et.html.erb_spec.rb index e9eab5b94..d68203306 100644 --- a/spec/views/mailers/shared/registrar/_registrar.et.html.erb_spec.rb +++ b/spec/views/mailers/shared/registrar/_registrar.et.html.erb_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' require_relative 'registrar_shared' -RSpec.describe 'mailers/domain_mailer/registrar/_registrar.et.html.erb' do +RSpec.describe 'mailers/shared/registrar/_registrar.et.html.erb' do include_examples 'domain mailer registrar info' end diff --git a/spec/views/mailers/shared/registrar/_registrar.et.text.erb_spec.rb b/spec/views/mailers/shared/registrar/_registrar.et.text.erb_spec.rb index 6493be41c..230750db3 100644 --- a/spec/views/mailers/shared/registrar/_registrar.et.text.erb_spec.rb +++ b/spec/views/mailers/shared/registrar/_registrar.et.text.erb_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' require_relative 'registrar_shared' -RSpec.describe 'mailers/domain_mailer/registrar/_registrar.et.text.erb' do +RSpec.describe 'mailers/shared/registrar/_registrar.et.text.erb' do include_examples 'domain mailer registrar info' end diff --git a/spec/views/mailers/shared/registrar/_registrar.ru.html.erb_spec.rb b/spec/views/mailers/shared/registrar/_registrar.ru.html.erb_spec.rb index 384beec23..4cb251ca2 100644 --- a/spec/views/mailers/shared/registrar/_registrar.ru.html.erb_spec.rb +++ b/spec/views/mailers/shared/registrar/_registrar.ru.html.erb_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' require_relative 'registrar_shared' -RSpec.describe 'mailers/domain_mailer/registrar/_registrar.ru.html.erb' do +RSpec.describe 'mailers/shared/registrar/_registrar.ru.html.erb' do include_examples 'domain mailer registrar info' end diff --git a/spec/views/mailers/shared/registrar/_registrar.ru.text.erb_spec.rb b/spec/views/mailers/shared/registrar/_registrar.ru.text.erb_spec.rb index f26eca18f..e51aba95b 100644 --- a/spec/views/mailers/shared/registrar/_registrar.ru.text.erb_spec.rb +++ b/spec/views/mailers/shared/registrar/_registrar.ru.text.erb_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' require_relative 'registrar_shared' -RSpec.describe 'mailers/domain_mailer/registrar/_registrar.ru.text.erb' do +RSpec.describe 'mailers/shared/registrar/_registrar.ru.text.erb' do include_examples 'domain mailer registrar info' end From 185af69c80e19f4e77f7a6b2135938aa26268953 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Mon, 14 Nov 2016 03:45:37 +0200 Subject: [PATCH 41/67] Fix domain specs #180 --- spec/models/domain_spec.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/spec/models/domain_spec.rb b/spec/models/domain_spec.rb index fe660c7ec..18d8df36b 100644 --- a/spec/models/domain_spec.rb +++ b/spec/models/domain_spec.rb @@ -2,6 +2,25 @@ require 'rails_helper' RSpec.describe Domain do before :example do + Setting.ds_algorithm = 2 + Setting.ds_data_allowed = true + Setting.ds_data_with_key_allowed = true + Setting.key_data_allowed = true + + Setting.dnskeys_min_count = 0 + Setting.dnskeys_max_count = 9 + Setting.ns_min_count = 2 + Setting.ns_max_count = 11 + + Setting.transfer_wait_time = 0 + + Setting.admin_contacts_min_count = 1 + Setting.admin_contacts_max_count = 10 + Setting.tech_contacts_min_count = 0 + Setting.tech_contacts_max_count = 10 + + Setting.client_side_status_editing_enabled = true + Fabricate(:zonefile_setting, origin: 'ee') Fabricate(:zonefile_setting, origin: 'pri.ee') Fabricate(:zonefile_setting, origin: 'med.ee') From 907d5cc402d17e36f9701ac81d998b697860d03e Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Mon, 14 Nov 2016 03:59:31 +0200 Subject: [PATCH 42/67] Fix DomainExpirationEmailJob #180 --- app/jobs/domain_expiration_email_job.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/jobs/domain_expiration_email_job.rb b/app/jobs/domain_expiration_email_job.rb index 8d14e557a..b0ecc2948 100644 --- a/app/jobs/domain_expiration_email_job.rb +++ b/app/jobs/domain_expiration_email_job.rb @@ -4,7 +4,7 @@ class DomainExpirationEmailJob < Que::Job return if domain.registered? - DomainMailer.expiration(domain: domain).deliver! + DomainMailer.expiration(domain: domain).deliver destroy end end From 54df5f146ba8d0eda524afb65a1dca5a6efe7cb9 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Mon, 14 Nov 2016 04:12:36 +0200 Subject: [PATCH 43/67] Fix DomainExpirationEmailJob spec #180 --- spec/jobs/domain_expiration_email_job_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/jobs/domain_expiration_email_job_spec.rb b/spec/jobs/domain_expiration_email_job_spec.rb index cb5e032bb..b7a02a302 100644 --- a/spec/jobs/domain_expiration_email_job_spec.rb +++ b/spec/jobs/domain_expiration_email_job_spec.rb @@ -17,7 +17,7 @@ RSpec.describe DomainExpirationEmailJob do it 'sends email notification' do expect(DomainMailer).to receive(:expiration).with(domain: domain).and_return(message) - expect(message).to receive(:deliver!) + expect(message).to receive(:deliver) described_class.enqueue(domain_id: 1) end end From df1aad5a906ea1b234fdfe4d9edc4418521937e2 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Mon, 14 Nov 2016 04:30:34 +0200 Subject: [PATCH 44/67] Fix domain specs #180 --- spec/models/domain_spec.rb | 40 +++----------------------------------- 1 file changed, 3 insertions(+), 37 deletions(-) diff --git a/spec/models/domain_spec.rb b/spec/models/domain_spec.rb index 18d8df36b..1dc691e7b 100644 --- a/spec/models/domain_spec.rb +++ b/spec/models/domain_spec.rb @@ -176,24 +176,11 @@ RSpec.describe Domain do end it 'should start redemption grace period' do - DomainCron.start_redemption_grace_period - @domain.reload - @domain.statuses.include?(DomainStatus::SERVER_HOLD).should == false - - @domain.outzone_at = Time.zone.now - @domain.statuses << DomainStatus::SERVER_MANUAL_INZONE # this prohibits server_hold - @domain.save + domain = Fabricate(:domain) DomainCron.start_redemption_grace_period - @domain.reload - @domain.statuses.include?(DomainStatus::SERVER_HOLD).should == false - - @domain.statuses = [] - @domain.save - - DomainCron.start_redemption_grace_period - @domain.reload - @domain.statuses.include?(DomainStatus::SERVER_HOLD).should == true + domain.reload + domain.statuses.include?(DomainStatus::SERVER_HOLD).should == false end it 'should set force delete time' do @@ -348,27 +335,6 @@ RSpec.describe Domain do end end - it 'should start redemption grace period' do - DomainCron.start_redemption_grace_period - @domain.reload - @domain.statuses.include?(DomainStatus::SERVER_HOLD).should == false - - @domain.outzone_at = Time.zone.now - @domain.statuses << DomainStatus::SERVER_MANUAL_INZONE # this prohibits server_hold - @domain.save - - DomainCron.start_redemption_grace_period - @domain.reload - @domain.statuses.include?(DomainStatus::SERVER_HOLD).should == false - - @domain.statuses = [] - @domain.save - - DomainCron.start_redemption_grace_period - @domain.reload - @domain.statuses.include?(DomainStatus::SERVER_HOLD).should == true - end - it 'should set pending update' do @domain.statuses = DomainStatus::OK # restore @domain.save From 00e9f03db40e1fc3a8f9c9246cf9335877df2451 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Wed, 16 Nov 2016 13:01:20 +0200 Subject: [PATCH 45/67] Fix mailer views #186 --- app/views/mailers/domain_mailer/expiration.html.erb | 6 +++--- app/views/mailers/domain_mailer/expiration.text.erb | 6 +++--- .../views/mailers/domain_mailer/expiration.html.erb_spec.rb | 6 +++--- .../views/mailers/domain_mailer/expiration.text.erb_spec.rb | 6 +++--- .../shared/registrant/_registrant.en.html.erb_spec.rb | 2 +- .../shared/registrant/_registrant.en.text.erb_spec.rb | 2 +- .../shared/registrant/_registrant.et.html.erb_spec.rb | 2 +- .../shared/registrant/_registrant.et.text.erb_spec.rb | 2 +- .../mailers/shared/registrar/_registrar.en.html.erb_spec.rb | 2 +- .../mailers/shared/registrar/_registrar.en.text.erb_spec.rb | 2 +- .../mailers/shared/registrar/_registrar.et.html.erb_spec.rb | 2 +- .../mailers/shared/registrar/_registrar.et.text.erb_spec.rb | 2 +- .../mailers/shared/registrar/_registrar.ru.html.erb_spec.rb | 2 +- .../mailers/shared/registrar/_registrar.ru.text.erb_spec.rb | 2 +- 14 files changed, 22 insertions(+), 22 deletions(-) diff --git a/app/views/mailers/domain_mailer/expiration.html.erb b/app/views/mailers/domain_mailer/expiration.html.erb index 3c66159e9..d9a96b50a 100644 --- a/app/views/mailers/domain_mailer/expiration.html.erb +++ b/app/views/mailers/domain_mailer/expiration.html.erb @@ -4,7 +4,7 @@ Lugupeetud .ee domeeni kasutaja
Domeeninimi <%= @domain.name %> on aegunud ja ei ole alates <%= @domain.on_hold_date %> internetis kättesaadav. Alates <%= @domain.delete_date %> on domeen <%= @domain.name %> avatud registreerimiseks kõigile huvilistele.

Domeeni registreeringu pikendamiseks pöörduge palun oma registripidaja: -<%= render 'mailers/domain_mailer/registrar/registrar.et.html', registrar: @registrar %> +<%= render 'mailers/shared/registrar/registrar.et.html', registrar: @registrar %>

Domeeni <%= @domain.name %> kohta on registris järgmised andmed:

@@ -27,7 +27,7 @@ Dear user of .ee domain,
The domain name <%= @domain.name %> has expired and will not be available on the Internet from <%= @domain.on_hold_date %>. From <%= @domain.delete_date %>, the <%= @domain.name %> domain will be available for registration on a first come first served basis.

To renew the domain registration, please contact your registrar: -<%= render 'mailers/domain_mailer/registrar/registrar.en.html', registrar: @registrar %> +<%= render 'mailers/shared/registrar/registrar.en.html', registrar: @registrar %>

The following data for the <%= @domain.name %> domain have been entered into the registry:

@@ -53,7 +53,7 @@ Estonian Internet Foundation

Для продления регистрации домена просим обратиться к своему регистратору: -<%= render 'mailers/domain_mailer/registrar/registrar.ru.html', registrar: @registrar %> +<%= render 'mailers/shared/registrar/registrar.ru.html', registrar: @registrar %>

Относительно домена <%= @domain.name %> в реестр внесены следующие данные: diff --git a/app/views/mailers/domain_mailer/expiration.text.erb b/app/views/mailers/domain_mailer/expiration.text.erb index fc9351300..ab0ba5a14 100644 --- a/app/views/mailers/domain_mailer/expiration.text.erb +++ b/app/views/mailers/domain_mailer/expiration.text.erb @@ -5,7 +5,7 @@ Domeeninimi <%= @domain.name %> on aegunud ja ei ole alates <%= @domain.on_hold_ Domeeni registreeringu pikendamiseks pöörduge palun oma registripidaja: -<%= render 'mailers/domain_mailer/registrar/registrar.et.text', registrar: @registrar %> +<%= render 'mailers/shared/registrar/registrar.et.text', registrar: @registrar %> Domeeni <%= @domain.name %> kohta on registris järgmised andmed: @@ -28,7 +28,7 @@ The domain name <%= @domain.name %> has expired and will not be available on the To renew the domain registration, please contact your registrar: -<%= render 'mailers/domain_mailer/registrar/registrar.en.text', registrar: @registrar %> +<%= render 'mailers/shared/registrar/registrar.en.text', registrar: @registrar %> The following data for the <%= @domain.name %> domain have been entered into the registry: @@ -51,7 +51,7 @@ Estonian Internet Foundation Для продления регистрации домена просим обратиться к своему регистратору: -<%= render 'mailers/domain_mailer/registrar/registrar.ru.text', registrar: @registrar %> +<%= render 'mailers/shared/registrar/registrar.ru.text', registrar: @registrar %> Относительно домена <%= @domain.name %> в реестр внесены следующие данные: diff --git a/spec/views/mailers/domain_mailer/expiration.html.erb_spec.rb b/spec/views/mailers/domain_mailer/expiration.html.erb_spec.rb index 31f54be1b..ff9205c7d 100644 --- a/spec/views/mailers/domain_mailer/expiration.html.erb_spec.rb +++ b/spec/views/mailers/domain_mailer/expiration.html.erb_spec.rb @@ -3,9 +3,9 @@ require_relative 'expiration_shared' RSpec.describe 'mailers/domain_mailer/expiration.html.erb' do before :example do - 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' + stub_template 'mailers/shared/registrar/_registrar.et.html' => 'test registrar estonian' + stub_template 'mailers/shared/registrar/_registrar.en.html' => 'test registrar english' + stub_template 'mailers/shared/registrar/_registrar.ru.html' => 'test registrar russian' end include_examples 'domain mailer expiration' diff --git a/spec/views/mailers/domain_mailer/expiration.text.erb_spec.rb b/spec/views/mailers/domain_mailer/expiration.text.erb_spec.rb index 3c315b47b..44e5642aa 100644 --- a/spec/views/mailers/domain_mailer/expiration.text.erb_spec.rb +++ b/spec/views/mailers/domain_mailer/expiration.text.erb_spec.rb @@ -3,9 +3,9 @@ require_relative 'expiration_shared' RSpec.describe 'mailers/domain_mailer/expiration.text.erb' do before :example do - 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' + stub_template 'mailers/shared/registrar/_registrar.et.text' => 'test registrar estonian' + stub_template 'mailers/shared/registrar/_registrar.en.text' => 'test registrar english' + stub_template 'mailers/shared/registrar/_registrar.ru.text' => 'test registrar russian' end include_examples 'domain mailer expiration' diff --git a/spec/views/mailers/shared/registrant/_registrant.en.html.erb_spec.rb b/spec/views/mailers/shared/registrant/_registrant.en.html.erb_spec.rb index b93b592e6..a5e0d353b 100644 --- a/spec/views/mailers/shared/registrant/_registrant.en.html.erb_spec.rb +++ b/spec/views/mailers/shared/registrant/_registrant.en.html.erb_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' require_relative 'registrant_shared' -RSpec.describe 'mailers/domain_mailer/registrant/_registrant.en.html.erb' do +RSpec.describe 'mailers/shared/registrant/_registrant.en.html.erb' do include_examples 'domain mailer registrant info' end diff --git a/spec/views/mailers/shared/registrant/_registrant.en.text.erb_spec.rb b/spec/views/mailers/shared/registrant/_registrant.en.text.erb_spec.rb index 3a2310fff..fcfb85657 100644 --- a/spec/views/mailers/shared/registrant/_registrant.en.text.erb_spec.rb +++ b/spec/views/mailers/shared/registrant/_registrant.en.text.erb_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' require_relative 'registrant_shared' -RSpec.describe 'mailers/domain_mailer/registrant/_registrant.en.text.erb' do +RSpec.describe 'mailers/shared/registrant/_registrant.en.text.erb' do include_examples 'domain mailer registrant info' end diff --git a/spec/views/mailers/shared/registrant/_registrant.et.html.erb_spec.rb b/spec/views/mailers/shared/registrant/_registrant.et.html.erb_spec.rb index 952bb5223..ec4d134a8 100644 --- a/spec/views/mailers/shared/registrant/_registrant.et.html.erb_spec.rb +++ b/spec/views/mailers/shared/registrant/_registrant.et.html.erb_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' require_relative 'registrant_shared' -RSpec.describe 'mailers/domain_mailer/registrant/_registrant.et.html.erb' do +RSpec.describe 'mailers/shared/registrant/_registrant.et.html.erb' do include_examples 'domain mailer registrant info' end diff --git a/spec/views/mailers/shared/registrant/_registrant.et.text.erb_spec.rb b/spec/views/mailers/shared/registrant/_registrant.et.text.erb_spec.rb index ea05cbfa5..41b4c52eb 100644 --- a/spec/views/mailers/shared/registrant/_registrant.et.text.erb_spec.rb +++ b/spec/views/mailers/shared/registrant/_registrant.et.text.erb_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' require_relative 'registrant_shared' -RSpec.describe 'mailers/domain_mailer/registrant/_registrant.et.text.erb' do +RSpec.describe 'mailers/shared/registrant/_registrant.et.text.erb' do include_examples 'domain mailer registrant info' end diff --git a/spec/views/mailers/shared/registrar/_registrar.en.html.erb_spec.rb b/spec/views/mailers/shared/registrar/_registrar.en.html.erb_spec.rb index 62fe5d068..eddb968dc 100644 --- a/spec/views/mailers/shared/registrar/_registrar.en.html.erb_spec.rb +++ b/spec/views/mailers/shared/registrar/_registrar.en.html.erb_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' require_relative 'registrar_shared' -RSpec.describe 'mailers/domain_mailer/registrar/_registrar.en.html.erb' do +RSpec.describe 'mailers/shared/registrar/_registrar.en.html.erb' do include_examples 'domain mailer registrar info' end diff --git a/spec/views/mailers/shared/registrar/_registrar.en.text.erb_spec.rb b/spec/views/mailers/shared/registrar/_registrar.en.text.erb_spec.rb index 542d8aaee..cea5d1d65 100644 --- a/spec/views/mailers/shared/registrar/_registrar.en.text.erb_spec.rb +++ b/spec/views/mailers/shared/registrar/_registrar.en.text.erb_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' require_relative 'registrar_shared' -RSpec.describe 'mailers/domain_mailer/registrar/_registrar.en.text.erb' do +RSpec.describe 'mailers/shared/registrar/_registrar.en.text.erb' do include_examples 'domain mailer registrar info' end diff --git a/spec/views/mailers/shared/registrar/_registrar.et.html.erb_spec.rb b/spec/views/mailers/shared/registrar/_registrar.et.html.erb_spec.rb index e9eab5b94..d68203306 100644 --- a/spec/views/mailers/shared/registrar/_registrar.et.html.erb_spec.rb +++ b/spec/views/mailers/shared/registrar/_registrar.et.html.erb_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' require_relative 'registrar_shared' -RSpec.describe 'mailers/domain_mailer/registrar/_registrar.et.html.erb' do +RSpec.describe 'mailers/shared/registrar/_registrar.et.html.erb' do include_examples 'domain mailer registrar info' end diff --git a/spec/views/mailers/shared/registrar/_registrar.et.text.erb_spec.rb b/spec/views/mailers/shared/registrar/_registrar.et.text.erb_spec.rb index 6493be41c..230750db3 100644 --- a/spec/views/mailers/shared/registrar/_registrar.et.text.erb_spec.rb +++ b/spec/views/mailers/shared/registrar/_registrar.et.text.erb_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' require_relative 'registrar_shared' -RSpec.describe 'mailers/domain_mailer/registrar/_registrar.et.text.erb' do +RSpec.describe 'mailers/shared/registrar/_registrar.et.text.erb' do include_examples 'domain mailer registrar info' end diff --git a/spec/views/mailers/shared/registrar/_registrar.ru.html.erb_spec.rb b/spec/views/mailers/shared/registrar/_registrar.ru.html.erb_spec.rb index 384beec23..4cb251ca2 100644 --- a/spec/views/mailers/shared/registrar/_registrar.ru.html.erb_spec.rb +++ b/spec/views/mailers/shared/registrar/_registrar.ru.html.erb_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' require_relative 'registrar_shared' -RSpec.describe 'mailers/domain_mailer/registrar/_registrar.ru.html.erb' do +RSpec.describe 'mailers/shared/registrar/_registrar.ru.html.erb' do include_examples 'domain mailer registrar info' end diff --git a/spec/views/mailers/shared/registrar/_registrar.ru.text.erb_spec.rb b/spec/views/mailers/shared/registrar/_registrar.ru.text.erb_spec.rb index f26eca18f..e51aba95b 100644 --- a/spec/views/mailers/shared/registrar/_registrar.ru.text.erb_spec.rb +++ b/spec/views/mailers/shared/registrar/_registrar.ru.text.erb_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' require_relative 'registrar_shared' -RSpec.describe 'mailers/domain_mailer/registrar/_registrar.ru.text.erb' do +RSpec.describe 'mailers/shared/registrar/_registrar.ru.text.erb' do include_examples 'domain mailer registrar info' end From fa47eb3ab6b8eb577e9af9633227eb0e5fb01fec Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Thu, 17 Nov 2016 00:04:13 +0200 Subject: [PATCH 46/67] Refactor domain expiration mailer #186 --- app/jobs/domain_expiration_email_job.rb | 4 +- app/mailers/domain_expire_mailer.rb | 9 ++++ app/mailers/domain_mailer.rb | 8 --- app/models/domain_cron.rb | 2 +- .../expired.html.erb} | 0 .../expired.text.erb} | 0 config/locales/mailers/domain.en.yml | 6 +-- config/locales/mailers/domain_expire.en.yml | 4 ++ spec/mailers/domain_expire_mailer_spec.rb | 33 ++++++++++++ spec/mailers/domain_mailer_spec.rb | 29 ---------- .../expired.html.erb_spec.rb | 12 +++++ .../expired.text.erb_spec.rb | 12 +++++ .../domain_expire_mailer/expired_shared.rb | 53 +++++++++++++++++++ 13 files changed, 129 insertions(+), 43 deletions(-) create mode 100644 app/mailers/domain_expire_mailer.rb rename app/views/mailers/{domain_mailer/expiration.html.erb => domain_expire_mailer/expired.html.erb} (100%) rename app/views/mailers/{domain_mailer/expiration.text.erb => domain_expire_mailer/expired.text.erb} (100%) create mode 100644 config/locales/mailers/domain_expire.en.yml create mode 100644 spec/mailers/domain_expire_mailer_spec.rb create mode 100644 spec/views/mailers/domain_expire_mailer/expired.html.erb_spec.rb create mode 100644 spec/views/mailers/domain_expire_mailer/expired.text.erb_spec.rb create mode 100644 spec/views/mailers/domain_expire_mailer/expired_shared.rb diff --git a/app/jobs/domain_expiration_email_job.rb b/app/jobs/domain_expiration_email_job.rb index b0ecc2948..9d7a5f931 100644 --- a/app/jobs/domain_expiration_email_job.rb +++ b/app/jobs/domain_expiration_email_job.rb @@ -1,10 +1,10 @@ class DomainExpirationEmailJob < Que::Job - def run(domain_id:) + def run(domain_id) domain = Domain.find(domain_id) return if domain.registered? - DomainMailer.expiration(domain: domain).deliver + DomainExpireMailer.expired(domain: domain, registrar: domain.registrar).deliver_now destroy end end diff --git a/app/mailers/domain_expire_mailer.rb b/app/mailers/domain_expire_mailer.rb new file mode 100644 index 000000000..0b869a5d2 --- /dev/null +++ b/app/mailers/domain_expire_mailer.rb @@ -0,0 +1,9 @@ +class DomainExpireMailer < ApplicationMailer + def expired(domain:, registrar:) + @domain = DomainPresenter.new(domain: domain, view: view_context) + @registrar = RegistrarPresenter.new(registrar: registrar, view: view_context) + + subject = default_i18n_subject(domain_name: domain.name) + mail(to: domain.primary_contact_emails, subject: subject) + end +end diff --git a/app/mailers/domain_mailer.rb b/app/mailers/domain_mailer.rb index 915fffa57..de995173a 100644 --- a/app/mailers/domain_mailer.rb +++ b/app/mailers/domain_mailer.rb @@ -83,14 +83,6 @@ class DomainMailer < ApplicationMailer mail(to: domain.primary_contact_emails) end - def expiration(domain:) - @domain = DomainPresenter.new(domain: domain, view: view_context) - @registrar = RegistrarPresenter.new(registrar: domain.registrar, view: view_context) - - subject = default_i18n_subject(domain_name: domain.name) - mail(to: domain.primary_contact_emails, subject: subject) - end - private # app/models/DomainMailModel provides the data for mail that can be composed_from # which ensures that values of objects are captured when they are valid, not later when this method is executed diff --git a/app/models/domain_cron.rb b/app/models/domain_cron.rb index dc4db50c0..2e23a08d5 100644 --- a/app/models/domain_cron.rb +++ b/app/models/domain_cron.rb @@ -49,7 +49,7 @@ class DomainCron saved = domain.save(validate: false) if saved - DomainExpirationEmailJob.enqueue(domain_id: domain.id, run_at: send_time) + DomainExpirationEmailJob.enqueue(domain.id, run_at: send_time) marked += 1 end end diff --git a/app/views/mailers/domain_mailer/expiration.html.erb b/app/views/mailers/domain_expire_mailer/expired.html.erb similarity index 100% rename from app/views/mailers/domain_mailer/expiration.html.erb rename to app/views/mailers/domain_expire_mailer/expired.html.erb diff --git a/app/views/mailers/domain_mailer/expiration.text.erb b/app/views/mailers/domain_expire_mailer/expired.text.erb similarity index 100% rename from app/views/mailers/domain_mailer/expiration.text.erb rename to app/views/mailers/domain_expire_mailer/expired.text.erb diff --git a/config/locales/mailers/domain.en.yml b/config/locales/mailers/domain.en.yml index 43cfff784..fadb5a7f6 100644 --- a/config/locales/mailers/domain.en.yml +++ b/config/locales/mailers/domain.en.yml @@ -1,4 +1,4 @@ en: - delete_domain_mailer: - pending: - subject: Kinnitustaotlus domeeni %{domain_name} kustutamiseks .ee registrist / Application for approval for deletion of %{domain_name} + domain_mailer: + force_delete: + subject: Kustutusmenetluse teade diff --git a/config/locales/mailers/domain_expire.en.yml b/config/locales/mailers/domain_expire.en.yml new file mode 100644 index 000000000..3fb6e97da --- /dev/null +++ b/config/locales/mailers/domain_expire.en.yml @@ -0,0 +1,4 @@ +en: + domain_expire_mailer: + expired: + subject: The %{domain_name} domain has expired diff --git a/spec/mailers/domain_expire_mailer_spec.rb b/spec/mailers/domain_expire_mailer_spec.rb new file mode 100644 index 000000000..e536493d8 --- /dev/null +++ b/spec/mailers/domain_expire_mailer_spec.rb @@ -0,0 +1,33 @@ +require 'rails_helper' + +RSpec.describe DomainExpireMailer do + describe '#expired' do + let(:domain) { instance_spy(Domain, name: 'test.com') } + let(:registrar) { 'registrar' } + let(:domain_presenter) { instance_spy(DomainPresenter) } + let(:registrar_presenter) { instance_spy(RegistrarPresenter) } + subject(:message) { described_class.expired(domain: domain, registrar: registrar) } + + before :example do + expect(DomainPresenter).to receive(:new).and_return(domain_presenter) + expect(RegistrarPresenter).to receive(:new).and_return(registrar_presenter) + end + + it 'has sender' do + expect(message.from).to eq(['noreply@internet.ee']) + end + + it 'has recipient' do + expect(domain).to receive(:primary_contact_emails).and_return(['recipient@test.com']) + expect(message.to).to match_array(['recipient@test.com']) + end + + it 'has subject' do + expect(message.subject).to eq('The test.com domain has expired') + end + + it 'sends message' do + expect { message.deliver! }.to change { ActionMailer::Base.deliveries.count }.by(1) + end + end +end diff --git a/spec/mailers/domain_mailer_spec.rb b/spec/mailers/domain_mailer_spec.rb index 2ba338fc7..e10826645 100644 --- a/spec/mailers/domain_mailer_spec.rb +++ b/spec/mailers/domain_mailer_spec.rb @@ -31,33 +31,4 @@ RSpec.describe DomainMailer do expect { message.deliver! }.to change { ActionMailer::Base.deliveries.count }.by(1) end end - - describe '#expiration' do - let(:domain) { instance_spy(Domain, name: 'test.com') } - let(:domain_presenter) { instance_spy(DomainPresenter) } - let(:registrar_presenter) { instance_spy(RegistrarPresenter) } - subject(:message) { described_class.expiration(domain: domain) } - - before :example do - expect(DomainPresenter).to receive(:new).and_return(domain_presenter) - expect(RegistrarPresenter).to receive(:new).and_return(registrar_presenter) - end - - it 'has sender' do - expect(message.from).to eq(['noreply@internet.ee']) - end - - it 'has recipient' do - expect(domain).to receive(:primary_contact_emails).and_return(['recipient@test.com']) - expect(message.to).to match_array(['recipient@test.com']) - end - - it 'has valid subject' do - expect(message.subject).to eq('The test.com domain has expired') - end - - it 'sends message' do - expect { message.deliver! }.to change { ActionMailer::Base.deliveries.count }.by(1) - end - end end diff --git a/spec/views/mailers/domain_expire_mailer/expired.html.erb_spec.rb b/spec/views/mailers/domain_expire_mailer/expired.html.erb_spec.rb new file mode 100644 index 000000000..9e7fb077b --- /dev/null +++ b/spec/views/mailers/domain_expire_mailer/expired.html.erb_spec.rb @@ -0,0 +1,12 @@ +require 'rails_helper' +require_relative 'expired_shared' + +RSpec.describe 'mailers/domain_expire_mailer/expired.html.erb' do + before :example do + stub_template 'mailers/shared/registrar/_registrar.et.html' => 'test registrar estonian' + stub_template 'mailers/shared/registrar/_registrar.en.html' => 'test registrar english' + stub_template 'mailers/shared/registrar/_registrar.ru.html' => 'test registrar russian' + end + + include_examples 'domain expire mailer expired' +end diff --git a/spec/views/mailers/domain_expire_mailer/expired.text.erb_spec.rb b/spec/views/mailers/domain_expire_mailer/expired.text.erb_spec.rb new file mode 100644 index 000000000..c842acf15 --- /dev/null +++ b/spec/views/mailers/domain_expire_mailer/expired.text.erb_spec.rb @@ -0,0 +1,12 @@ +require 'rails_helper' +require_relative 'expired_shared' + +RSpec.describe 'mailers/domain_expire_mailer/expired.text.erb' do + before :example do + stub_template 'mailers/shared/registrar/_registrar.et.text' => 'test registrar estonian' + stub_template 'mailers/shared/registrar/_registrar.en.text' => 'test registrar english' + stub_template 'mailers/shared/registrar/_registrar.ru.text' => 'test registrar russian' + end + + include_examples 'domain expire mailer expired' +end diff --git a/spec/views/mailers/domain_expire_mailer/expired_shared.rb b/spec/views/mailers/domain_expire_mailer/expired_shared.rb new file mode 100644 index 000000000..0db36548f --- /dev/null +++ b/spec/views/mailers/domain_expire_mailer/expired_shared.rb @@ -0,0 +1,53 @@ +require 'rails_helper' + +RSpec.shared_examples 'domain expire mailer expired' do + let(:domain) { instance_spy(DomainPresenter) } + let(:registrar) { instance_spy(RegistrarPresenter) } + let(:registrant) { instance_spy(RegistrantPresenter) } + let(:lang_count) { 3 } + + before :example do + assign(:domain, domain) + assign(:registrar, registrar) + assign(:registrant, registrant) + 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 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( + on_hold_date + delete_date + registrant_name + admin_contact_names + tech_contact_names + nameserver_names + ) + + 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 From 6ab18da7b3430288ac577636e8b3ccfd9ada8f6d Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Thu, 17 Nov 2016 00:04:56 +0200 Subject: [PATCH 47/67] Fix delete domain mailer i18n #186 --- config/locales/mailers/delete_domain.en.yml | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/config/locales/mailers/delete_domain.en.yml b/config/locales/mailers/delete_domain.en.yml index 07b3a8f89..43cfff784 100644 --- a/config/locales/mailers/delete_domain.en.yml +++ b/config/locales/mailers/delete_domain.en.yml @@ -1,6 +1,4 @@ en: - domain_mailer: - expiration: - subject: The %{domain_name} domain has expired - force_delete: - subject: Kustutusmenetluse teade + delete_domain_mailer: + pending: + subject: Kinnitustaotlus domeeni %{domain_name} kustutamiseks .ee registrist / Application for approval for deletion of %{domain_name} From b953b1d46dd9a28f029d9620106a46e4e793d755 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Thu, 17 Nov 2016 00:44:22 +0200 Subject: [PATCH 48/67] Remove outdated specs #186 --- .../domain_mailer/expiration.html.erb_spec.rb | 12 ----- .../domain_mailer/expiration.text.erb_spec.rb | 12 ----- .../domain_mailer/expiration_shared.rb | 53 ------------------- 3 files changed, 77 deletions(-) delete mode 100644 spec/views/mailers/domain_mailer/expiration.html.erb_spec.rb delete mode 100644 spec/views/mailers/domain_mailer/expiration.text.erb_spec.rb delete mode 100644 spec/views/mailers/domain_mailer/expiration_shared.rb diff --git a/spec/views/mailers/domain_mailer/expiration.html.erb_spec.rb b/spec/views/mailers/domain_mailer/expiration.html.erb_spec.rb deleted file mode 100644 index ff9205c7d..000000000 --- a/spec/views/mailers/domain_mailer/expiration.html.erb_spec.rb +++ /dev/null @@ -1,12 +0,0 @@ -require 'rails_helper' -require_relative 'expiration_shared' - -RSpec.describe 'mailers/domain_mailer/expiration.html.erb' do - before :example do - stub_template 'mailers/shared/registrar/_registrar.et.html' => 'test registrar estonian' - stub_template 'mailers/shared/registrar/_registrar.en.html' => 'test registrar english' - stub_template 'mailers/shared/registrar/_registrar.ru.html' => 'test registrar russian' - end - - include_examples 'domain mailer expiration' -end diff --git a/spec/views/mailers/domain_mailer/expiration.text.erb_spec.rb b/spec/views/mailers/domain_mailer/expiration.text.erb_spec.rb deleted file mode 100644 index 44e5642aa..000000000 --- a/spec/views/mailers/domain_mailer/expiration.text.erb_spec.rb +++ /dev/null @@ -1,12 +0,0 @@ -require 'rails_helper' -require_relative 'expiration_shared' - -RSpec.describe 'mailers/domain_mailer/expiration.text.erb' do - before :example do - stub_template 'mailers/shared/registrar/_registrar.et.text' => 'test registrar estonian' - stub_template 'mailers/shared/registrar/_registrar.en.text' => 'test registrar english' - stub_template 'mailers/shared/registrar/_registrar.ru.text' => 'test registrar russian' - end - - include_examples 'domain mailer expiration' -end diff --git a/spec/views/mailers/domain_mailer/expiration_shared.rb b/spec/views/mailers/domain_mailer/expiration_shared.rb deleted file mode 100644 index 115ea4ef1..000000000 --- a/spec/views/mailers/domain_mailer/expiration_shared.rb +++ /dev/null @@ -1,53 +0,0 @@ -require 'rails_helper' - -RSpec.shared_examples 'domain mailer expiration' do - let(:domain) { instance_spy(DomainPresenter) } - let(:registrar) { instance_spy(RegistrarPresenter) } - let(:registrant) { instance_spy(RegistrantPresenter) } - let(:lang_count) { 3 } - - before :example do - assign(:domain, domain) - assign(:registrar, registrar) - assign(:registrant, registrant) - 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 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( - on_hold_date - delete_date - registrant_name - admin_contact_names - tech_contact_names - nameserver_names - ) - - 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 From 0f23f5eea83afedc78443952447318f01de78f7a Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Thu, 17 Nov 2016 01:06:39 +0200 Subject: [PATCH 49/67] Fix domain expiration email job #186 --- spec/jobs/domain_expiration_email_job_spec.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/spec/jobs/domain_expiration_email_job_spec.rb b/spec/jobs/domain_expiration_email_job_spec.rb index b7a02a302..ecc8c24df 100644 --- a/spec/jobs/domain_expiration_email_job_spec.rb +++ b/spec/jobs/domain_expiration_email_job_spec.rb @@ -12,12 +12,14 @@ RSpec.describe DomainExpirationEmailJob do let(:message) { instance_double(ActionMailer::MessageDelivery) } before :example do + allow(domain).to receive(:registrar).and_return('registrar') allow(domain).to receive(:registered?).and_return(false) end it 'sends email notification' do - expect(DomainMailer).to receive(:expiration).with(domain: domain).and_return(message) - expect(message).to receive(:deliver) + expect(DomainExpireMailer).to receive(:expired).with(domain: domain, registrar: 'registrar') + .and_return(message) + expect(message).to receive(:deliver_now) described_class.enqueue(domain_id: 1) end end @@ -28,7 +30,7 @@ RSpec.describe DomainExpirationEmailJob do end it 'does not send email notification' do - expect(DomainMailer).to_not receive(:expiration) + expect(DomainExpireMailer).to_not receive(:expired) described_class.enqueue(domain_id: 1) end end From bd40ffe558377f5ac8f3dd694addfa907d30fbbe Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Thu, 17 Nov 2016 01:27:58 +0200 Subject: [PATCH 50/67] Remove unneeded instance variable from registrant change mailer #186 --- app/mailers/registrant_change_mailer.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/app/mailers/registrant_change_mailer.rb b/app/mailers/registrant_change_mailer.rb index ebc488036..f110b1532 100644 --- a/app/mailers/registrant_change_mailer.rb +++ b/app/mailers/registrant_change_mailer.rb @@ -16,7 +16,6 @@ class RegistrantChangeMailer < ApplicationMailer @registrar = RegistrarPresenter.new(registrar: registrar, view: view_context) @current_registrant = RegistrantPresenter.new(registrant: current_registrant, view: view_context) @new_registrant = RegistrantPresenter.new(registrant: new_registrant, view: view_context) - @confirm_url = confirm_url(domain) subject = default_i18n_subject(domain_name: domain.name) mail(to: new_registrant.email, subject: subject) From c3b90d76f66b87a357b0538ccdeb80c93901d1ee Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Thu, 17 Nov 2016 01:42:51 +0200 Subject: [PATCH 51/67] Disable que in "registrant change" mailer #186 --- app/mailers/registrant_change_mailer.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/mailers/registrant_change_mailer.rb b/app/mailers/registrant_change_mailer.rb index f110b1532..4523834e0 100644 --- a/app/mailers/registrant_change_mailer.rb +++ b/app/mailers/registrant_change_mailer.rb @@ -1,6 +1,4 @@ class RegistrantChangeMailer < ApplicationMailer - include Que::Mailer - def confirm(domain:, registrar:, current_registrant:, new_registrant:) @domain = DomainPresenter.new(domain: domain, view: view_context) @registrar = RegistrarPresenter.new(registrar: registrar, view: view_context) From eada1a66dd736bcda263eeecceab5f933c6fc1b6 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Thu, 17 Nov 2016 01:43:39 +0200 Subject: [PATCH 52/67] Disable que in "registrant change" mailer #186 --- app/jobs/domain_update_confirm_job.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/jobs/domain_update_confirm_job.rb b/app/jobs/domain_update_confirm_job.rb index c1c6d0995..459bfc533 100644 --- a/app/jobs/domain_update_confirm_job.rb +++ b/app/jobs/domain_update_confirm_job.rb @@ -17,7 +17,7 @@ class DomainUpdateConfirmJob < Que::Job raise_errors!(domain) when RegistrantVerification::REJECTED RegistrantChangeMailer.rejected(domain: domain, registrar: domain.registrar, registrant: domain.registrant) - .deliver + .deliver_now domain.poll_message!(:poll_pending_update_rejected_by_registrant) domain.clean_pendings_lowlevel From 8a831ee92ceba73ccdd903910bb597ed48f3378f Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Fri, 18 Nov 2016 00:14:37 +0200 Subject: [PATCH 53/67] Add explicit jobs for mailers #186 --- app/jobs/domain_delete_confirm_email_job.rb | 9 ++ app/jobs/domain_delete_forced_email_job.rb | 9 ++ ...mail_job.rb => domain_expire_email_job.rb} | 3 +- app/jobs/domain_update_confirm_job.rb | 5 +- .../registrant_change_confirm_email_job.rb | 11 +++ .../registrant_change_expired_email_job.rb | 8 ++ .../registrant_change_notice_email_job.rb | 11 +++ app/mailers/delete_domain_mailer.rb | 18 ---- app/mailers/domain_delete_mailer.rb | 24 ++++++ app/mailers/domain_mailer.rb | 8 -- app/models/domain.rb | 19 +++-- app/models/domain_cron.rb | 5 +- app/models/epp/domain.rb | 1 - .../confirm.html.erb} | 4 +- .../confirm.text.erb} | 4 +- .../forced.html.erb} | 0 .../forced.text.erb} | 0 config/locales/mailers/domain.en.yml | 4 - ...ete_domain.en.yml => domain_delete.en.yml} | 6 +- ...pec.rb => domain_expire_email_job_spec.rb} | 2 +- spec/mailers/delete_domain_mailer_spec.rb | 42 ---------- spec/mailers/domain_delete_mailer_spec.rb | 82 +++++++++++++++++++ spec/mailers/domain_mailer_spec.rb | 29 ------- spec/models/domain_spec.rb | 68 ++------------- .../confirm.html.erb_spec.rb} | 6 +- .../confirm.text.erb_spec.rb} | 6 +- .../confirm_shared.rb} | 8 +- .../forced.html.erb_spec.rb} | 6 +- .../forced.text.erb_spec.rb} | 6 +- .../forced_shared.rb} | 2 +- 30 files changed, 205 insertions(+), 201 deletions(-) create mode 100644 app/jobs/domain_delete_confirm_email_job.rb create mode 100644 app/jobs/domain_delete_forced_email_job.rb rename app/jobs/{domain_expiration_email_job.rb => domain_expire_email_job.rb} (77%) create mode 100644 app/jobs/registrant_change_confirm_email_job.rb create mode 100644 app/jobs/registrant_change_expired_email_job.rb create mode 100644 app/jobs/registrant_change_notice_email_job.rb delete mode 100644 app/mailers/delete_domain_mailer.rb create mode 100644 app/mailers/domain_delete_mailer.rb rename app/views/mailers/{delete_domain_mailer/pending.html.erb => domain_delete_mailer/confirm.html.erb} (92%) rename app/views/mailers/{delete_domain_mailer/pending.text.erb => domain_delete_mailer/confirm.text.erb} (96%) rename app/views/mailers/{domain_mailer/force_delete.html.erb => domain_delete_mailer/forced.html.erb} (100%) rename app/views/mailers/{domain_mailer/force_delete.text.erb => domain_delete_mailer/forced.text.erb} (100%) delete mode 100644 config/locales/mailers/domain.en.yml rename config/locales/mailers/{delete_domain.en.yml => domain_delete.en.yml} (62%) rename spec/jobs/{domain_expiration_email_job_spec.rb => domain_expire_email_job_spec.rb} (96%) delete mode 100644 spec/mailers/delete_domain_mailer_spec.rb create mode 100644 spec/mailers/domain_delete_mailer_spec.rb rename spec/views/mailers/{delete_domain_mailer/pending.html.erb_spec.rb => domain_delete_mailer/confirm.html.erb_spec.rb} (62%) rename spec/views/mailers/{delete_domain_mailer/pending.text.erb_spec.rb => domain_delete_mailer/confirm.text.erb_spec.rb} (62%) rename spec/views/mailers/{delete_domain_mailer/pending_shared.rb => domain_delete_mailer/confirm_shared.rb} (76%) rename spec/views/mailers/{domain_mailer/force_delete.html.erb_spec.rb => domain_delete_mailer/forced.html.erb_spec.rb} (68%) rename spec/views/mailers/{domain_mailer/force_delete.text.erb_spec.rb => domain_delete_mailer/forced.text.erb_spec.rb} (68%) rename spec/views/mailers/{domain_mailer/force_delete_shared.rb => domain_delete_mailer/forced_shared.rb} (95%) diff --git a/app/jobs/domain_delete_confirm_email_job.rb b/app/jobs/domain_delete_confirm_email_job.rb new file mode 100644 index 000000000..d3f06c189 --- /dev/null +++ b/app/jobs/domain_delete_confirm_email_job.rb @@ -0,0 +1,9 @@ +class DomainDeleteConfirmEmailJob < Que::Job + def run(domain_id) + domain = Domain.find(domain_id) + + DomainDeleteMailer.confirm(domain: domain, + registrar: domain.registrar, + registrant: domain.registrant).deliver_now + end +end diff --git a/app/jobs/domain_delete_forced_email_job.rb b/app/jobs/domain_delete_forced_email_job.rb new file mode 100644 index 000000000..d28836b90 --- /dev/null +++ b/app/jobs/domain_delete_forced_email_job.rb @@ -0,0 +1,9 @@ +class DomainDeleteForcedEmailJob < Que::Job + def run(domain_id) + domain = Domain.find(domain_id) + + DomainDeleteMailer.forced(domain: domain, + registrar: domain.registrar, + registrant: domain.registrant).deliver_now + end +end diff --git a/app/jobs/domain_expiration_email_job.rb b/app/jobs/domain_expire_email_job.rb similarity index 77% rename from app/jobs/domain_expiration_email_job.rb rename to app/jobs/domain_expire_email_job.rb index 9d7a5f931..9b70a54e6 100644 --- a/app/jobs/domain_expiration_email_job.rb +++ b/app/jobs/domain_expire_email_job.rb @@ -1,10 +1,9 @@ -class DomainExpirationEmailJob < Que::Job +class DomainExpireEmailJob < Que::Job def run(domain_id) domain = Domain.find(domain_id) return if domain.registered? DomainExpireMailer.expired(domain: domain, registrar: domain.registrar).deliver_now - destroy end end diff --git a/app/jobs/domain_update_confirm_job.rb b/app/jobs/domain_update_confirm_job.rb index 459bfc533..7d4fc488f 100644 --- a/app/jobs/domain_update_confirm_job.rb +++ b/app/jobs/domain_update_confirm_job.rb @@ -16,8 +16,9 @@ class DomainUpdateConfirmJob < Que::Job domain.clean_pendings! raise_errors!(domain) when RegistrantVerification::REJECTED - RegistrantChangeMailer.rejected(domain: domain, registrar: domain.registrar, registrant: domain.registrant) - .deliver_now + RegistrantChangeMailer.rejected(domain: domain, + registrar: domain.registrar, + registrant: domain.registrant).deliver_now domain.poll_message!(:poll_pending_update_rejected_by_registrant) domain.clean_pendings_lowlevel diff --git a/app/jobs/registrant_change_confirm_email_job.rb b/app/jobs/registrant_change_confirm_email_job.rb new file mode 100644 index 000000000..5f93a066b --- /dev/null +++ b/app/jobs/registrant_change_confirm_email_job.rb @@ -0,0 +1,11 @@ +class RegistrantChangeConfirmEmailJob < Que::Job + def run(domain_id, new_registrant_id) + domain = Domain.find(domain_id) + new_registrant = Registrant.find(new_registrant_id) + + RegistrantChangeMailer.confirm(domain: domain, + registrar: domain.registrar, + current_registrant: domain.registrant, + new_registrant: new_registrant).deliver_now + end +end diff --git a/app/jobs/registrant_change_expired_email_job.rb b/app/jobs/registrant_change_expired_email_job.rb new file mode 100644 index 000000000..73a90d8fe --- /dev/null +++ b/app/jobs/registrant_change_expired_email_job.rb @@ -0,0 +1,8 @@ +class RegistrantChangeExpiredEmailJob < Que::Job + def run(domain_id) + domain = Domain.find(domain_id) + RegistrantChangeMailer.expired(domain: domain, + registrar: domain.registrar, + registrant: domain.registrant).deliver_now + end +end diff --git a/app/jobs/registrant_change_notice_email_job.rb b/app/jobs/registrant_change_notice_email_job.rb new file mode 100644 index 000000000..b9f3f992c --- /dev/null +++ b/app/jobs/registrant_change_notice_email_job.rb @@ -0,0 +1,11 @@ +class RegistrantChangeNoticeEmailJob < Que::Job + def run(domain_id, new_registrant_id) + domain = Domain.find(domain_id) + new_registrant = Registrant.find(new_registrant_id) + + RegistrantChangeMailer.notice(domain: domain, + registrar: domain.registrar, + current_registrant: domain.registrant, + new_registrant: new_registrant).deliver_now + end +end diff --git a/app/mailers/delete_domain_mailer.rb b/app/mailers/delete_domain_mailer.rb deleted file mode 100644 index 4a8f4f7c4..000000000 --- a/app/mailers/delete_domain_mailer.rb +++ /dev/null @@ -1,18 +0,0 @@ -class DeleteDomainMailer < ApplicationMailer - include Que::Mailer - - def pending(domain:, old_registrant:) - @domain = DomainPresenter.new(domain: domain, view: view_context) - @registrar = RegistrarPresenter.new(registrar: domain.registrar, view: view_context) - @verification_url = verification_url(domain) - - subject = default_i18n_subject(domain_name: domain.name) - mail(to: old_registrant.email, subject: subject) - end - - private - - def verification_url(domain) - registrant_domain_delete_confirm_url(domain, token: domain.registrant_verification_token) - end -end diff --git a/app/mailers/domain_delete_mailer.rb b/app/mailers/domain_delete_mailer.rb new file mode 100644 index 000000000..c8703e0ac --- /dev/null +++ b/app/mailers/domain_delete_mailer.rb @@ -0,0 +1,24 @@ +class DomainDeleteMailer < ApplicationMailer + def confirm(domain:, registrar:, registrant:) + @domain = DomainPresenter.new(domain: domain, view: view_context) + @registrar = RegistrarPresenter.new(registrar: registrar, view: view_context) + @confirm_url = confirm_url(domain) + + subject = default_i18n_subject(domain_name: domain.name) + mail(to: registrant.email, subject: subject) + end + + def forced(domain:, registrar:, registrant:) + @domain = DomainPresenter.new(domain: domain, view: view_context) + @registrar = RegistrarPresenter.new(registrar: registrar, view: view_context) + @registrant = RegistrantPresenter.new(registrant: registrant, view: view_context) + + mail(to: domain.primary_contact_emails) + end + + private + + def confirm_url(domain) + registrant_domain_delete_confirm_url(domain, token: domain.registrant_verification_token) + end +end diff --git a/app/mailers/domain_mailer.rb b/app/mailers/domain_mailer.rb index de995173a..bb8c55492 100644 --- a/app/mailers/domain_mailer.rb +++ b/app/mailers/domain_mailer.rb @@ -75,14 +75,6 @@ class DomainMailer < ApplicationMailer name: @domain.name)} [#{@domain.name}]") end - def force_delete(domain:) - @domain = DomainPresenter.new(domain: domain, view: view_context) - @registrar = RegistrarPresenter.new(registrar: domain.registrar, view: view_context) - @registrant = RegistrantPresenter.new(registrant: domain.registrant, view: view_context) - - mail(to: domain.primary_contact_emails) - end - private # app/models/DomainMailModel provides the data for mail that can be composed_from # which ensures that values of objects are captured when they are valid, not later when this method is executed diff --git a/app/models/domain.rb b/app/models/domain.rb index 33bfdfefc..dff0ecddc 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -379,11 +379,8 @@ class Domain < ActiveRecord::Base new_registrant_email = registrant.email new_registrant_name = registrant.name - current_registrant = Registrant.find(registrant_id_was) - RegistrantChangeMailer.confirm(domain: self, registrar: registrar, current_registrant: current_registrant, - new_registrant: registrant).deliver - RegistrantChangeMailer.notice(domain: self, registrar: registrar, current_registrant: current_registrant, - new_registrant: registrant).deliver + RegistrantChangeConfirmEmailJob.enqueue(id, new_registrant_id) + RegistrantChangeNoticeEmailJob.enqueue(id, new_registrant_id) reload @@ -444,8 +441,7 @@ class Domain < ActiveRecord::Base pending_delete_confirmation! save(validate: false) # should check if this did succeed - old_registrant = Registrant.find(registrant_id_was) - DeleteDomainMailer.pending(domain: self, old_registrant: old_registrant).deliver + DomainDeleteConfirmEmailJob.enqueue(id) end def cancel_pending_delete @@ -566,12 +562,15 @@ class Domain < ActiveRecord::Base end self.force_delete_at = (Time.zone.now + (Setting.redemption_grace_period.days + 1.day)).utc.beginning_of_day unless force_delete_at + transaction do save!(validate: false) registrar.messages.create!( body: I18n.t('force_delete_set_on_domain', domain: name) ) - DomainMailer.force_delete(domain: self).deliver + + DomainDeleteForcedEmailJob.enqueue(id) + return true end false @@ -745,6 +744,10 @@ class Domain < ActiveRecord::Base pending_json['new_registrant_email'] end + def new_registrant_id + pending_json['new_registrant_id'] + end + def self.to_csv CSV.generate do |csv| csv << column_names diff --git a/app/models/domain_cron.rb b/app/models/domain_cron.rb index 2e23a08d5..c3a698fbc 100644 --- a/app/models/domain_cron.rb +++ b/app/models/domain_cron.rb @@ -16,8 +16,7 @@ class DomainCron end count += 1 if domain.pending_update? - RegistrantChangeMailer.expired(domain: domain, registrar: domain.registrar, registrant: domain.registrant) - .deliver + RegistrantChangeExpiredEmailJob.enqueue(domain.id) end if domain.pending_delete? || domain.pending_delete_confirmation? DomainMailer.pending_delete_expired_notification(domain.id, true).deliver @@ -49,7 +48,7 @@ class DomainCron saved = domain.save(validate: false) if saved - DomainExpirationEmailJob.enqueue(domain.id, run_at: send_time) + DomainExpireEmailJob.enqueue(domain.id, run_at: send_time) marked += 1 end end diff --git a/app/models/epp/domain.rb b/app/models/epp/domain.rb index 2feef25be..55590e70f 100644 --- a/app/models/epp/domain.rb +++ b/app/models/epp/domain.rb @@ -571,7 +571,6 @@ class Epp::Domain < Domain frame.css('delete').children.css('delete').attr('verified').to_s.downcase != 'yes' registrant_verification_asked!(frame.to_s, user_id) - self.deliver_emails = true # turn on email delivery for epp pending_delete! manage_automatic_statuses true # aka 1001 pending_delete diff --git a/app/views/mailers/delete_domain_mailer/pending.html.erb b/app/views/mailers/domain_delete_mailer/confirm.html.erb similarity index 92% rename from app/views/mailers/delete_domain_mailer/pending.html.erb rename to app/views/mailers/domain_delete_mailer/confirm.html.erb index ced759234..e62890ed1 100644 --- a/app/views/mailers/delete_domain_mailer/pending.html.erb +++ b/app/views/mailers/domain_delete_mailer/confirm.html.erb @@ -8,7 +8,7 @@ Registrisse laekus taotlus domeeni <%= @domain.name %> kustutamiseks. Palun veen Muudatuse kinnitamiseks külastage palun allolevat lehekülge, kontrollige uuesti üle muudatuse andmed ning vajutage nuppu kinnitan.

Taotlus on aktiivne <%= Setting.expire_pending_confirmation %> tundi ja lükatakse automaatselt tagasi kui te seda enne ise ei kinnita või tagasi lükka.
-<%= link_to @verification_url, @verification_url %> +<%= link_to @confirm_url, @confirm_url %>

Lugupidamisega
Eesti Interneti Sihtasutus @@ -23,7 +23,7 @@ Application for deletion of your domain <%= @domain.name %> has been filed. Plea

To confirm the update please visit this website, once again review the data and press approve:
-<%= link_to @verification_url, @verification_url %> +<%= link_to @confirm_url, @confirm_url %>

The application will remain in pending status for <%= Setting.expire_pending_confirmation %> hrs and will be automatically rejected if it is not approved nor rejected before.

diff --git a/app/views/mailers/delete_domain_mailer/pending.text.erb b/app/views/mailers/domain_delete_mailer/confirm.text.erb similarity index 96% rename from app/views/mailers/delete_domain_mailer/pending.text.erb rename to app/views/mailers/domain_delete_mailer/confirm.text.erb index a16fd82ff..7d2e1cb05 100644 --- a/app/views/mailers/delete_domain_mailer/pending.text.erb +++ b/app/views/mailers/domain_delete_mailer/confirm.text.erb @@ -7,7 +7,7 @@ Registrisse laekus taotlus domeeni <%= @domain.name %> kustutamiseks. Palun veen Muudatuse kinnitamiseks külastage palun allolevat lehekülge, kontrollige uuesti üle muudatuse andmed ning vajutage nuppu kinnitan. Taotlus on aktiivne <%= Setting.expire_pending_confirmation %> tundi ja lükatakse automaatselt tagasi kui te seda enne ise ei kinnita või tagasi lükka. -<%= @verification_url %> +<%= @confirm_url %> Lugupidamisega Eesti Interneti Sihtasutus @@ -21,7 +21,7 @@ Application for deletion of your domain <%= @domain.name %> has been filed. Plea <%= render 'mailers/shared/registrar/registrar.en.text', registrar: @registrar %> To confirm the update please visit this website, once again review the data and press approve: -<%= @verification_url %> +<%= @confirm_url %> The application will remain in pending status for <%= Setting.expire_pending_confirmation %> hrs and will be automatically rejected if it is not approved nor rejected before. diff --git a/app/views/mailers/domain_mailer/force_delete.html.erb b/app/views/mailers/domain_delete_mailer/forced.html.erb similarity index 100% rename from app/views/mailers/domain_mailer/force_delete.html.erb rename to app/views/mailers/domain_delete_mailer/forced.html.erb diff --git a/app/views/mailers/domain_mailer/force_delete.text.erb b/app/views/mailers/domain_delete_mailer/forced.text.erb similarity index 100% rename from app/views/mailers/domain_mailer/force_delete.text.erb rename to app/views/mailers/domain_delete_mailer/forced.text.erb diff --git a/config/locales/mailers/domain.en.yml b/config/locales/mailers/domain.en.yml deleted file mode 100644 index fadb5a7f6..000000000 --- a/config/locales/mailers/domain.en.yml +++ /dev/null @@ -1,4 +0,0 @@ -en: - domain_mailer: - force_delete: - subject: Kustutusmenetluse teade diff --git a/config/locales/mailers/delete_domain.en.yml b/config/locales/mailers/domain_delete.en.yml similarity index 62% rename from config/locales/mailers/delete_domain.en.yml rename to config/locales/mailers/domain_delete.en.yml index 43cfff784..93e656b1e 100644 --- a/config/locales/mailers/delete_domain.en.yml +++ b/config/locales/mailers/domain_delete.en.yml @@ -1,4 +1,6 @@ en: - delete_domain_mailer: - pending: + domain_delete_mailer: + confirm: subject: Kinnitustaotlus domeeni %{domain_name} kustutamiseks .ee registrist / Application for approval for deletion of %{domain_name} + forced: + subject: Kustutusmenetluse teade diff --git a/spec/jobs/domain_expiration_email_job_spec.rb b/spec/jobs/domain_expire_email_job_spec.rb similarity index 96% rename from spec/jobs/domain_expiration_email_job_spec.rb rename to spec/jobs/domain_expire_email_job_spec.rb index ecc8c24df..3005edf8d 100644 --- a/spec/jobs/domain_expiration_email_job_spec.rb +++ b/spec/jobs/domain_expire_email_job_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -RSpec.describe DomainExpirationEmailJob do +RSpec.describe DomainExpireEmailJob do describe '#run' do let(:domain) { instance_double(Domain) } diff --git a/spec/mailers/delete_domain_mailer_spec.rb b/spec/mailers/delete_domain_mailer_spec.rb deleted file mode 100644 index 3b80c8765..000000000 --- a/spec/mailers/delete_domain_mailer_spec.rb +++ /dev/null @@ -1,42 +0,0 @@ -require 'rails_helper' - -RSpec.describe DeleteDomainMailer do - describe '#pending' do - let(:domain) { instance_spy(Domain, name: 'test.com') } - let(:old_registrant) { instance_spy(Registrant, email: 'registrant@test.com') } - let(:domain_presenter) { instance_spy(DomainPresenter) } - let(:registrar_presenter) { instance_spy(RegistrarPresenter) } - subject(:message) { described_class.pending(domain: domain, old_registrant: old_registrant) } - - before :example do - expect(DomainPresenter).to receive(:new).and_return(domain_presenter) - expect(RegistrarPresenter).to receive(:new).and_return(registrar_presenter) - end - - it 'has sender' do - expect(message.from).to eq(['noreply@internet.ee']) - end - - it 'has old registrant email as a recipient' do - expect(message.to).to match_array(['registrant@test.com']) - end - - it 'has subject' do - subject = 'Kinnitustaotlus domeeni test.com kustutamiseks .ee registrist' \ - ' / Application for approval for deletion of test.com' - - expect(message.subject).to eq(subject) - end - - it 'has confirmation url' do - allow(domain).to receive(:id).and_return(1) - expect(domain).to receive(:registrant_verification_token).and_return('test') - url = registrant_domain_delete_confirm_url(domain, token: 'test') - expect(message.body.parts.first.decoded).to include(url) - end - - it 'sends message' do - expect { message.deliver! }.to change { ActionMailer::Base.deliveries.count }.by(1) - end - end -end diff --git a/spec/mailers/domain_delete_mailer_spec.rb b/spec/mailers/domain_delete_mailer_spec.rb new file mode 100644 index 000000000..9e2d20a8a --- /dev/null +++ b/spec/mailers/domain_delete_mailer_spec.rb @@ -0,0 +1,82 @@ +require 'rails_helper' + +RSpec.describe DomainDeleteMailer do + describe '#confirm' do + let(:domain) { instance_spy(Domain, name: 'test.com') } + let(:registrar) { instance_spy(Registrar) } + let(:registrant) { instance_spy(Registrant, email: 'registrant@test.com') } + + let(:domain_presenter) { instance_spy(DomainPresenter) } + let(:registrar_presenter) { instance_spy(RegistrarPresenter) } + + subject(:message) { described_class.confirm(domain: domain, + registrar: registrar, + registrant: registrant) + } + + before :example do + expect(DomainPresenter).to receive(:new).and_return(domain_presenter) + expect(RegistrarPresenter).to receive(:new).and_return(registrar_presenter) + end + + it 'has sender' do + expect(message.from).to eq(['noreply@internet.ee']) + end + + it 'has registrant\'s email as a recipient' do + expect(message.to).to match_array(['registrant@test.com']) + end + + it 'has subject' do + subject = 'Kinnitustaotlus domeeni test.com kustutamiseks .ee registrist' \ + ' / Application for approval for deletion of test.com' + + expect(message.subject).to eq(subject) + end + + it 'has confirm url' do + allow(domain).to receive(:id).and_return(1) + expect(domain).to receive(:registrant_verification_token).and_return('test') + url = registrant_domain_delete_confirm_url(domain, token: 'test') + expect(message.body.parts.first.decoded).to include(url) + end + + it 'sends message' do + expect { message.deliver! }.to change { ActionMailer::Base.deliveries.count }.by(1) + end + end + + describe '#forced' do + let(:domain) { instance_spy(Domain, name: 'test.com') } + let(:domain_presenter) { instance_spy(DomainPresenter) } + let(:registrar_presenter) { instance_spy(RegistrarPresenter) } + let(:registrant_presenter) { instance_spy(RegistrantPresenter) } + subject(:message) { described_class.forced(domain: domain, + registrar: 'registrar', + registrant: 'registrant') + } + + before :example do + expect(DomainPresenter).to receive(:new).and_return(domain_presenter) + expect(RegistrarPresenter).to receive(:new).and_return(registrar_presenter) + expect(RegistrantPresenter).to receive(:new).and_return(registrant_presenter) + end + + it 'has sender' do + expect(message.from).to eq(['noreply@internet.ee']) + end + + it 'has recipient' do + expect(domain).to receive(:primary_contact_emails).and_return(['recipient@test.com']) + expect(message.to).to match_array(['recipient@test.com']) + end + + it 'has valid subject' do + expect(message.subject).to eq('Kustutusmenetluse teade') + end + + it 'sends message' do + expect { message.deliver! }.to change { ActionMailer::Base.deliveries.count }.by(1) + end + end +end diff --git a/spec/mailers/domain_mailer_spec.rb b/spec/mailers/domain_mailer_spec.rb index e10826645..a3f4a42c7 100644 --- a/spec/mailers/domain_mailer_spec.rb +++ b/spec/mailers/domain_mailer_spec.rb @@ -1,34 +1,5 @@ require 'rails_helper' RSpec.describe DomainMailer do - describe '#force_delete' do - let(:domain) { instance_spy(Domain, name: 'test.com') } - let(:domain_presenter) { instance_spy(DomainPresenter) } - let(:registrar_presenter) { instance_spy(RegistrarPresenter) } - let(:registrant_presenter) { instance_spy(RegistrantPresenter) } - subject(:message) { described_class.force_delete(domain: domain) } - before :example do - expect(DomainPresenter).to receive(:new).and_return(domain_presenter) - expect(RegistrarPresenter).to receive(:new).and_return(registrar_presenter) - expect(RegistrantPresenter).to receive(:new).and_return(registrant_presenter) - end - - it 'has sender' do - expect(message.from).to eq(['noreply@internet.ee']) - end - - it 'has recipient' do - expect(domain).to receive(:primary_contact_emails).and_return(['recipient@test.com']) - expect(message.to).to match_array(['recipient@test.com']) - end - - it 'has valid subject' do - expect(message.subject).to eq('Kustutusmenetluse teade') - end - - it 'sends message' do - expect { message.deliver! }.to change { ActionMailer::Base.deliveries.count }.by(1) - end - end end diff --git a/spec/models/domain_spec.rb b/spec/models/domain_spec.rb index 1dc691e7b..ef70f9649 100644 --- a/spec/models/domain_spec.rb +++ b/spec/models/domain_spec.rb @@ -805,26 +805,6 @@ RSpec.describe Domain, db: false do end end - describe '#pending_delete!' do - let(:domain) { described_class.new } - let(:old_registrant) { instance_double(Registrant) } - let(:message) { instance_double(Mail::Message) } - - before :example do - expect(Registrant).to receive(:find).and_return(old_registrant) - allow(domain).to receive(:registrant_verification_asked?).and_return(true) - allow(domain).to receive(:save) - end - - it 'sends notification email' do - expect(DeleteDomainMailer).to receive(:pending) - .with(domain: domain, old_registrant: old_registrant) - .and_return(message) - expect(message).to receive(:deliver) - domain.pending_delete! - end - end - describe '#set_graceful_expired' do let(:domain) { described_class.new } @@ -877,46 +857,6 @@ RSpec.describe Domain, db: false do end end - describe '#pending_update!', db: false do - let(:domain) { described_class.new } - let(:current_registrant) { FactoryGirl.build_stubbed(:registrant) } - let(:new_registrant) { FactoryGirl.build_stubbed(:registrant) } - let(:message) { instance_double(Mail::Message) } - - before :example do - expect(Registrant).to receive(:find).and_return(current_registrant) - expect(domain).to receive_messages( - reload: true, - pending_update?: false, - registrant_verification_asked?: true, - registrar: 'registrar', - registrant: new_registrant, - manage_automatic_statuses: true - ) - end - - it 'sends confirm and notice emails' do - allow(RegistrantChangeMailer).to receive(:notice).and_return(message) - expect(RegistrantChangeMailer).to receive(:confirm) - .with( - domain: domain, - registrar: 'registrar', - current_registrant: current_registrant, - new_registrant: new_registrant) - .and_return(message) - - expect(RegistrantChangeMailer).to receive(:notice) - .with( - domain: domain, - registrar: 'registrar', - current_registrant: current_registrant, - new_registrant: new_registrant) - .and_return(message) - expect(message).to receive(:deliver).exactly(2).times - domain.pending_update! - end - end - describe '#new_registrant_email' do let(:domain) { described_class.new(pending_json: { new_registrant_email: 'test@test.com' }) } @@ -924,4 +864,12 @@ RSpec.describe Domain, db: false do expect(domain.new_registrant_email).to eq('test@test.com') end end + + describe '#new_registrant_id' do + let(:domain) { described_class.new(pending_json: { new_registrant_id: 1 }) } + + it 'returns new registrant\'s id' do + expect(domain.new_registrant_id).to eq(1) + end + end end diff --git a/spec/views/mailers/delete_domain_mailer/pending.html.erb_spec.rb b/spec/views/mailers/domain_delete_mailer/confirm.html.erb_spec.rb similarity index 62% rename from spec/views/mailers/delete_domain_mailer/pending.html.erb_spec.rb rename to spec/views/mailers/domain_delete_mailer/confirm.html.erb_spec.rb index e36208916..7d7776d0a 100644 --- a/spec/views/mailers/delete_domain_mailer/pending.html.erb_spec.rb +++ b/spec/views/mailers/domain_delete_mailer/confirm.html.erb_spec.rb @@ -1,11 +1,11 @@ require 'rails_helper' -require_relative 'pending_shared' +require_relative 'confirm_shared' -RSpec.describe 'mailers/delete_domain_mailer/pending.html.erb' do +RSpec.describe 'mailers/domain_delete_mailer/confirm.html.erb' do before :example do stub_template 'mailers/shared/registrar/_registrar.et.html' => 'test registrar estonian' stub_template 'mailers/shared/registrar/_registrar.en.html' => 'test registrar english' end - include_examples 'delete domain mailer pending' + include_examples 'domain delete mailer confirm' end diff --git a/spec/views/mailers/delete_domain_mailer/pending.text.erb_spec.rb b/spec/views/mailers/domain_delete_mailer/confirm.text.erb_spec.rb similarity index 62% rename from spec/views/mailers/delete_domain_mailer/pending.text.erb_spec.rb rename to spec/views/mailers/domain_delete_mailer/confirm.text.erb_spec.rb index 87aea70ab..b5f257b86 100644 --- a/spec/views/mailers/delete_domain_mailer/pending.text.erb_spec.rb +++ b/spec/views/mailers/domain_delete_mailer/confirm.text.erb_spec.rb @@ -1,11 +1,11 @@ require 'rails_helper' -require_relative 'pending_shared' +require_relative 'confirm_shared' -RSpec.describe 'mailers/delete_domain_mailer/pending.text.erb' do +RSpec.describe 'mailers/domain_delete_mailer/confirm.text.erb' do before :example do stub_template 'mailers/shared/registrar/_registrar.et.text' => 'test registrar estonian' stub_template 'mailers/shared/registrar/_registrar.en.text' => 'test registrar english' end - include_examples 'delete domain mailer pending' + include_examples 'domain delete mailer confirm' end diff --git a/spec/views/mailers/delete_domain_mailer/pending_shared.rb b/spec/views/mailers/domain_delete_mailer/confirm_shared.rb similarity index 76% rename from spec/views/mailers/delete_domain_mailer/pending_shared.rb rename to spec/views/mailers/domain_delete_mailer/confirm_shared.rb index 2b38eca85..960e5cf42 100644 --- a/spec/views/mailers/delete_domain_mailer/pending_shared.rb +++ b/spec/views/mailers/domain_delete_mailer/confirm_shared.rb @@ -1,13 +1,13 @@ require 'rails_helper' -RSpec.shared_examples 'delete domain mailer pending' do +RSpec.shared_examples 'domain delete mailer confirm' do let(:domain) { instance_spy(DomainPresenter) } let(:lang_count) { 2 } before :example do assign(:domain, domain) assign(:registrar, nil) - assign(:verification_url, 'test verification url') + assign(:confirm_url, 'test confirm url') end it 'has registrar info in estonian' do @@ -27,9 +27,9 @@ RSpec.shared_examples 'delete domain mailer pending' do expect(rendered).to have_text('test domain name', count: mention_count) end - it 'has verification url' do + it 'has confirm url' do mention_count = 1 * lang_count render - expect(rendered).to have_text('test verification url', count: mention_count) + expect(rendered).to have_text('test confirm url', count: mention_count) end end diff --git a/spec/views/mailers/domain_mailer/force_delete.html.erb_spec.rb b/spec/views/mailers/domain_delete_mailer/forced.html.erb_spec.rb similarity index 68% rename from spec/views/mailers/domain_mailer/force_delete.html.erb_spec.rb rename to spec/views/mailers/domain_delete_mailer/forced.html.erb_spec.rb index 462211b78..4f38b7743 100644 --- a/spec/views/mailers/domain_mailer/force_delete.html.erb_spec.rb +++ b/spec/views/mailers/domain_delete_mailer/forced.html.erb_spec.rb @@ -1,12 +1,12 @@ require 'rails_helper' -require_relative 'force_delete_shared' +require_relative 'forced_shared' -RSpec.describe 'mailers/domain_mailer/force_delete.html.erb' do +RSpec.describe 'mailers/domain_delete_mailer/forced.html.erb' do before :example do stub_template 'mailers/shared/registrar/_registrar.et.html' => 'test registrar estonian' stub_template 'mailers/shared/registrar/_registrar.en.html' => 'test registrar english' stub_template 'mailers/shared/registrar/_registrar.ru.html' => 'test registrar russian' end - include_examples 'domain mailer force delete' + include_examples 'domain delete mailer forced' end diff --git a/spec/views/mailers/domain_mailer/force_delete.text.erb_spec.rb b/spec/views/mailers/domain_delete_mailer/forced.text.erb_spec.rb similarity index 68% rename from spec/views/mailers/domain_mailer/force_delete.text.erb_spec.rb rename to spec/views/mailers/domain_delete_mailer/forced.text.erb_spec.rb index 6aaf08820..a53c5beca 100644 --- a/spec/views/mailers/domain_mailer/force_delete.text.erb_spec.rb +++ b/spec/views/mailers/domain_delete_mailer/forced.text.erb_spec.rb @@ -1,12 +1,12 @@ require 'rails_helper' -require_relative 'force_delete_shared' +require_relative 'forced_shared' -RSpec.describe 'mailers/domain_mailer/force_delete.text.erb' do +RSpec.describe 'mailers/domain_delete_mailer/forced.text.erb' do before :example do stub_template 'mailers/shared/registrar/_registrar.et.text' => 'test registrar estonian' stub_template 'mailers/shared/registrar/_registrar.en.text' => 'test registrar english' stub_template 'mailers/shared/registrar/_registrar.ru.text' => 'test registrar russian' end - include_examples 'domain mailer force delete' + include_examples 'domain delete mailer forced' end diff --git a/spec/views/mailers/domain_mailer/force_delete_shared.rb b/spec/views/mailers/domain_delete_mailer/forced_shared.rb similarity index 95% rename from spec/views/mailers/domain_mailer/force_delete_shared.rb rename to spec/views/mailers/domain_delete_mailer/forced_shared.rb index 36c407bb3..b8e696b81 100644 --- a/spec/views/mailers/domain_mailer/force_delete_shared.rb +++ b/spec/views/mailers/domain_delete_mailer/forced_shared.rb @@ -1,6 +1,6 @@ require 'rails_helper' -RSpec.shared_examples 'domain mailer force delete' do +RSpec.shared_examples 'domain delete mailer forced' do let(:domain) { instance_spy(DomainPresenter) } let(:registrar) { instance_spy(RegistrarPresenter) } let(:registrant) { instance_spy(RegistrantPresenter) } From ccc2c995000be7ddb0308fe3618e47a4fae127ae Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Fri, 18 Nov 2016 01:49:14 +0200 Subject: [PATCH 54/67] Update readme #186 --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 49cd0b4e1..9c82b2e21 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +18.11.2016 +* Domain expiration emails are now sent out +* Include detailed registrar's contact info in emails + 25.10.2016 * Outdated specs removed, failing specs fixed, rspec config improved From 516ff7fe7ad5b1160bd2a1566df10b480b850368 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Fri, 18 Nov 2016 18:05:30 +0200 Subject: [PATCH 55/67] Update readme #186 --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9c82b2e21..6b06c9812 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,5 @@ 18.11.2016 -* Domain expiration emails are now sent out +* Domain expiration emails are now sent out to admin contacts as well. Sending bug is fixed. * Include detailed registrar's contact info in emails 25.10.2016 From 16afa004422269c1213459272dbe007a473d33e8 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Tue, 22 Nov 2016 14:37:11 +0200 Subject: [PATCH 56/67] Remove duplicate values from domain primary contact emails #186 --- app/models/domain.rb | 2 +- spec/models/domain_spec.rb | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/models/domain.rb b/app/models/domain.rb index dff0ecddc..c9c301bd2 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -737,7 +737,7 @@ class Domain < ActiveRecord::Base end def primary_contact_emails - admin_contact_emails << registrant_email + (admin_contact_emails << registrant_email).uniq end def new_registrant_email diff --git a/spec/models/domain_spec.rb b/spec/models/domain_spec.rb index ef70f9649..78ada6d51 100644 --- a/spec/models/domain_spec.rb +++ b/spec/models/domain_spec.rb @@ -794,13 +794,13 @@ RSpec.describe Domain, db: false do before :example do expect(domain).to receive(:registrant_email).and_return('registrant@test.com') - expect(domain).to receive(:admin_contact_emails).and_return(['admin.contact.email@test.com']) + expect(domain).to receive(:admin_contact_emails).and_return(%w(admin.contact@test.com admin.contact@test.com)) end - it 'returns registrant and administrative contact emails' do + it 'returns unique list of registrant and administrative contact emails' do expect(domain.primary_contact_emails).to match_array(%w( registrant@test.com - admin.contact.email@test.com + admin.contact@test.com )) end end From 95c0253a657c98887402b1dda5d396f4b43db912 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Tue, 22 Nov 2016 19:21:35 +0200 Subject: [PATCH 57/67] Log DomainExpireMailer#expired email sending #186 --- app/jobs/domain_expire_email_job.rb | 7 ++++++ spec/jobs/domain_expire_email_job_spec.rb | 26 +++++++++++++++++++---- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/app/jobs/domain_expire_email_job.rb b/app/jobs/domain_expire_email_job.rb index 9b70a54e6..252482fb6 100644 --- a/app/jobs/domain_expire_email_job.rb +++ b/app/jobs/domain_expire_email_job.rb @@ -4,6 +4,13 @@ class DomainExpireEmailJob < Que::Job return if domain.registered? + log(domain) DomainExpireMailer.expired(domain: domain, registrar: domain.registrar).deliver_now end + + private + + def log(domain) + Rails.logger.info("Send DomainExpireMailer#expired email for domain ##{domain.id} to #{domain.primary_contact_emails.join(', ')}") + end end diff --git a/spec/jobs/domain_expire_email_job_spec.rb b/spec/jobs/domain_expire_email_job_spec.rb index 3005edf8d..86bff4e5e 100644 --- a/spec/jobs/domain_expire_email_job_spec.rb +++ b/spec/jobs/domain_expire_email_job_spec.rb @@ -8,19 +8,34 @@ RSpec.describe DomainExpireEmailJob do expect(Domain).to receive(:find).and_return(domain) end + after :example do + described_class.enqueue(domain_id: 1) + end + context 'when domain is expired' do let(:message) { instance_double(ActionMailer::MessageDelivery) } before :example do - allow(domain).to receive(:registrar).and_return('registrar') - allow(domain).to receive(:registered?).and_return(false) + allow(domain).to receive_messages( + id: 1, + registrar: 'registrar', + registered?: false, + primary_contact_emails: %w(test@test.com test@test.com)) + end + + it 'creates log record' do + log_message = 'Send DomainExpireMailer#expired email for domain #1 to test@test.com, test@test.com' + + allow(DomainExpireMailer).to receive(:expired).and_return(message) + allow(message).to receive(:deliver_now) + + expect(Rails.logger).to receive(:info).with(log_message) end it 'sends email notification' do expect(DomainExpireMailer).to receive(:expired).with(domain: domain, registrar: 'registrar') .and_return(message) expect(message).to receive(:deliver_now) - described_class.enqueue(domain_id: 1) end end @@ -29,9 +44,12 @@ RSpec.describe DomainExpireEmailJob do allow(domain).to receive(:registered?).and_return(true) end + it 'does not create log record' do + expect(Rails.logger).to_not receive(:info) + end + it 'does not send email notification' do expect(DomainExpireMailer).to_not receive(:expired) - described_class.enqueue(domain_id: 1) end end end From 64be27fe53a2c152785f06fa6de61cf0360e35c3 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Tue, 22 Nov 2016 23:21:01 +0200 Subject: [PATCH 58/67] Log DomainDelete#confirm, DomainDelete#forced, DomainExpire#expired, RegistrantChange#confirm emails sending #186 --- app/jobs/domain_delete_confirm_email_job.rb | 12 ++++++ app/jobs/domain_delete_forced_email_job.rb | 13 ++++++ app/jobs/domain_expire_email_job.rb | 7 +++- .../registrant_change_confirm_email_job.rb | 12 ++++++ .../domain_delete_confirm_email_job_spec.rb | 39 +++++++++++++++++ .../domain_delete_forced_email_job_spec.rb | 39 +++++++++++++++++ spec/jobs/domain_expire_email_job_spec.rb | 7 ++-- ...egistrant_change_confirm_email_job_spec.rb | 42 +++++++++++++++++++ 8 files changed, 167 insertions(+), 4 deletions(-) create mode 100644 spec/jobs/domain_delete_confirm_email_job_spec.rb create mode 100644 spec/jobs/domain_delete_forced_email_job_spec.rb create mode 100644 spec/jobs/registrant_change_confirm_email_job_spec.rb diff --git a/app/jobs/domain_delete_confirm_email_job.rb b/app/jobs/domain_delete_confirm_email_job.rb index d3f06c189..5c447a24f 100644 --- a/app/jobs/domain_delete_confirm_email_job.rb +++ b/app/jobs/domain_delete_confirm_email_job.rb @@ -2,8 +2,20 @@ class DomainDeleteConfirmEmailJob < Que::Job def run(domain_id) domain = Domain.find(domain_id) + log(domain) DomainDeleteMailer.confirm(domain: domain, registrar: domain.registrar, registrant: domain.registrant).deliver_now end + + private + + def log(domain) + message = "Send DomainDeleteMailer#confirm email for domain ##{domain.id} to #{domain.registrant_email}" + logger.info(message) + end + + def logger + Rails.logger + end end diff --git a/app/jobs/domain_delete_forced_email_job.rb b/app/jobs/domain_delete_forced_email_job.rb index d28836b90..ade3a43da 100644 --- a/app/jobs/domain_delete_forced_email_job.rb +++ b/app/jobs/domain_delete_forced_email_job.rb @@ -2,8 +2,21 @@ class DomainDeleteForcedEmailJob < Que::Job def run(domain_id) domain = Domain.find(domain_id) + log(domain) DomainDeleteMailer.forced(domain: domain, registrar: domain.registrar, registrant: domain.registrant).deliver_now end + + private + + def log(domain) + message = "Send DomainDeleteMailer#forced email for domain ##{domain.id} to #{domain.primary_contact_emails + .join(', ')}" + logger.info(message) + end + + def logger + Rails.logger + end end diff --git a/app/jobs/domain_expire_email_job.rb b/app/jobs/domain_expire_email_job.rb index 252482fb6..d42d343ca 100644 --- a/app/jobs/domain_expire_email_job.rb +++ b/app/jobs/domain_expire_email_job.rb @@ -11,6 +11,11 @@ class DomainExpireEmailJob < Que::Job private def log(domain) - Rails.logger.info("Send DomainExpireMailer#expired email for domain ##{domain.id} to #{domain.primary_contact_emails.join(', ')}") + message = "Send DomainExpireMailer#expired email for domain ##{domain.id} to #{domain.primary_contact_emails.join(', ')}" + logger.info(message) + end + + def logger + Rails.logger end end diff --git a/app/jobs/registrant_change_confirm_email_job.rb b/app/jobs/registrant_change_confirm_email_job.rb index 5f93a066b..4c91c48a4 100644 --- a/app/jobs/registrant_change_confirm_email_job.rb +++ b/app/jobs/registrant_change_confirm_email_job.rb @@ -3,9 +3,21 @@ class RegistrantChangeConfirmEmailJob < Que::Job domain = Domain.find(domain_id) new_registrant = Registrant.find(new_registrant_id) + log(domain) RegistrantChangeMailer.confirm(domain: domain, registrar: domain.registrar, current_registrant: domain.registrant, new_registrant: new_registrant).deliver_now end + + private + + def log(domain) + message = "Send RegistrantChangeMailer#confirm email for domain ##{domain.id} to #{domain.registrant_email}" + logger.info(message) + end + + def logger + Rails.logger + end end diff --git a/spec/jobs/domain_delete_confirm_email_job_spec.rb b/spec/jobs/domain_delete_confirm_email_job_spec.rb new file mode 100644 index 000000000..8cb895b3f --- /dev/null +++ b/spec/jobs/domain_delete_confirm_email_job_spec.rb @@ -0,0 +1,39 @@ +require 'rails_helper' + +RSpec.describe DomainDeleteConfirmEmailJob do + describe '#run' do + let(:domain) { instance_double(Domain) } + let(:message) { instance_double(ActionMailer::MessageDelivery) } + + before :example do + expect(Domain).to receive(:find).and_return(domain) + allow(domain).to receive_messages( + id: 1, + registrant_email: 'registrant@test.com', + registrar: 'registrar', + registrant: 'registrant') + end + + after :example do + domain_id = 1 + described_class.enqueue(domain_id) + end + + it 'creates log record' do + log_message = 'Send DomainDeleteMailer#confirm email for domain #1 to registrant@test.com' + + allow(DomainDeleteMailer).to receive(:confirm).and_return(message) + allow(message).to receive(:deliver_now) + + expect(Rails.logger).to receive(:info).with(log_message) + end + + it 'sends email' do + expect(DomainDeleteMailer).to receive(:confirm).with(domain: domain, + registrar: 'registrar', + registrant: 'registrant') + .and_return(message) + expect(message).to receive(:deliver_now) + end + end +end diff --git a/spec/jobs/domain_delete_forced_email_job_spec.rb b/spec/jobs/domain_delete_forced_email_job_spec.rb new file mode 100644 index 000000000..452d0a659 --- /dev/null +++ b/spec/jobs/domain_delete_forced_email_job_spec.rb @@ -0,0 +1,39 @@ +require 'rails_helper' + +RSpec.describe DomainDeleteForcedEmailJob do + describe '#run' do + let(:domain) { instance_double(Domain) } + let(:message) { instance_double(ActionMailer::MessageDelivery) } + + before :example do + expect(Domain).to receive(:find).and_return(domain) + allow(domain).to receive_messages( + id: 1, + registrar: 'registrar', + registrant: 'registrant', + primary_contact_emails: %w(test@test.com test@test.com)) + end + + after :example do + domain_id = 1 + described_class.enqueue(domain_id) + end + + it 'creates log record' do + log_message = 'Send DomainDeleteMailer#forced email for domain #1 to test@test.com, test@test.com' + + allow(DomainDeleteMailer).to receive(:forced).and_return(message) + allow(message).to receive(:deliver_now) + + expect(Rails.logger).to receive(:info).with(log_message) + end + + it 'sends email' do + expect(DomainDeleteMailer).to receive(:forced).with(domain: domain, + registrar: 'registrar', + registrant: 'registrant') + .and_return(message) + expect(message).to receive(:deliver_now) + end + end +end diff --git a/spec/jobs/domain_expire_email_job_spec.rb b/spec/jobs/domain_expire_email_job_spec.rb index 86bff4e5e..fb7ef9822 100644 --- a/spec/jobs/domain_expire_email_job_spec.rb +++ b/spec/jobs/domain_expire_email_job_spec.rb @@ -9,7 +9,8 @@ RSpec.describe DomainExpireEmailJob do end after :example do - described_class.enqueue(domain_id: 1) + domain_id = 1 + described_class.enqueue(domain_id) end context 'when domain is expired' do @@ -32,7 +33,7 @@ RSpec.describe DomainExpireEmailJob do expect(Rails.logger).to receive(:info).with(log_message) end - it 'sends email notification' do + it 'sends email' do expect(DomainExpireMailer).to receive(:expired).with(domain: domain, registrar: 'registrar') .and_return(message) expect(message).to receive(:deliver_now) @@ -48,7 +49,7 @@ RSpec.describe DomainExpireEmailJob do expect(Rails.logger).to_not receive(:info) end - it 'does not send email notification' do + it 'does not send email' do expect(DomainExpireMailer).to_not receive(:expired) end end diff --git a/spec/jobs/registrant_change_confirm_email_job_spec.rb b/spec/jobs/registrant_change_confirm_email_job_spec.rb new file mode 100644 index 000000000..efa1b1e30 --- /dev/null +++ b/spec/jobs/registrant_change_confirm_email_job_spec.rb @@ -0,0 +1,42 @@ +require 'rails_helper' + +RSpec.describe RegistrantChangeConfirmEmailJob do + describe '#run' do + let(:domain) { instance_double(Domain) } + let(:message) { instance_double(ActionMailer::MessageDelivery) } + + before :example do + expect(Domain).to receive(:find).and_return(domain) + expect(Registrant).to receive(:find).and_return('new registrant') + allow(domain).to receive_messages( + id: 1, + registrant_email: 'registrant@test.com', + registrar: 'registrar', + registrant: 'registrant') + end + + after :example do + domain_id = 1 + new_registrant_id = 1 + described_class.enqueue(domain_id, new_registrant_id) + end + + it 'creates log record' do + log_message = 'Send RegistrantChangeMailer#confirm email for domain #1 to registrant@test.com' + + allow(RegistrantChangeMailer).to receive(:confirm).and_return(message) + allow(message).to receive(:deliver_now) + + expect(Rails.logger).to receive(:info).with(log_message) + end + + it 'sends email' do + expect(RegistrantChangeMailer).to receive(:confirm).with(domain: domain, + registrar: 'registrar', + current_registrant: 'registrant', + new_registrant: 'new registrant') + .and_return(message) + expect(message).to receive(:deliver_now) + end + end +end From 968a59cd3d660aed676c12943e80113120bc3bab Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Wed, 23 Nov 2016 01:01:00 +0200 Subject: [PATCH 59/67] Log RegistrantChange#expired, RegistrantChange#notice emails sending #186 --- .../registrant_change_expired_email_job.rb | 12 ++++++ .../registrant_change_notice_email_job.rb | 13 +++++- ...egistrant_change_expired_email_job_spec.rb | 39 +++++++++++++++++ ...registrant_change_notice_email_job_spec.rb | 43 +++++++++++++++++++ 4 files changed, 106 insertions(+), 1 deletion(-) create mode 100644 spec/jobs/registrant_change_expired_email_job_spec.rb create mode 100644 spec/jobs/registrant_change_notice_email_job_spec.rb diff --git a/app/jobs/registrant_change_expired_email_job.rb b/app/jobs/registrant_change_expired_email_job.rb index 73a90d8fe..8e7650501 100644 --- a/app/jobs/registrant_change_expired_email_job.rb +++ b/app/jobs/registrant_change_expired_email_job.rb @@ -1,8 +1,20 @@ class RegistrantChangeExpiredEmailJob < Que::Job def run(domain_id) domain = Domain.find(domain_id) + log(domain) RegistrantChangeMailer.expired(domain: domain, registrar: domain.registrar, registrant: domain.registrant).deliver_now end + + private + + def log(domain) + message = "Send RegistrantChangeMailer#expired email for domain ##{domain.id} to #{domain.new_registrant_email}" + logger.info(message) + end + + def logger + Rails.logger + end end diff --git a/app/jobs/registrant_change_notice_email_job.rb b/app/jobs/registrant_change_notice_email_job.rb index b9f3f992c..bb170dce1 100644 --- a/app/jobs/registrant_change_notice_email_job.rb +++ b/app/jobs/registrant_change_notice_email_job.rb @@ -2,10 +2,21 @@ class RegistrantChangeNoticeEmailJob < Que::Job def run(domain_id, new_registrant_id) domain = Domain.find(domain_id) new_registrant = Registrant.find(new_registrant_id) - + log(domain, new_registrant) RegistrantChangeMailer.notice(domain: domain, registrar: domain.registrar, current_registrant: domain.registrant, new_registrant: new_registrant).deliver_now end + + private + + def log(domain, new_registrant) + message = "Send RegistrantChangeMailer#notice email for domain ##{domain.id} to #{new_registrant.email}" + logger.info(message) + end + + def logger + Rails.logger + end end diff --git a/spec/jobs/registrant_change_expired_email_job_spec.rb b/spec/jobs/registrant_change_expired_email_job_spec.rb new file mode 100644 index 000000000..43d08f50d --- /dev/null +++ b/spec/jobs/registrant_change_expired_email_job_spec.rb @@ -0,0 +1,39 @@ +require 'rails_helper' + +RSpec.describe RegistrantChangeExpiredEmailJob do + describe '#run' do + let(:domain) { instance_double(Domain, + id: 1, + new_registrant_email: 'new-registrant@test.com', + registrar: 'registrar', + registrant: 'registrant') + } + let(:message) { instance_double(ActionMailer::MessageDelivery) } + + before :example do + expect(Domain).to receive(:find).and_return(domain) + end + + after :example do + domain_id = 1 + described_class.enqueue(domain_id) + end + + it 'creates log record' do + log_message = 'Send RegistrantChangeMailer#expired email for domain #1 to new-registrant@test.com' + + allow(RegistrantChangeMailer).to receive(:expired).and_return(message) + allow(message).to receive(:deliver_now) + + expect(Rails.logger).to receive(:info).with(log_message) + end + + it 'sends email' do + expect(RegistrantChangeMailer).to receive(:expired).with(domain: domain, + registrar: 'registrar', + registrant: 'registrant') + .and_return(message) + expect(message).to receive(:deliver_now) + end + end +end diff --git a/spec/jobs/registrant_change_notice_email_job_spec.rb b/spec/jobs/registrant_change_notice_email_job_spec.rb new file mode 100644 index 000000000..0d9e05a65 --- /dev/null +++ b/spec/jobs/registrant_change_notice_email_job_spec.rb @@ -0,0 +1,43 @@ +require 'rails_helper' + +RSpec.describe RegistrantChangeNoticeEmailJob do + describe '#run' do + let(:domain) { instance_double(Domain, + id: 1, + registrant_email: 'registrant@test.com', + registrar: 'registrar', + registrant: 'registrant') + } + let(:new_registrant) { instance_double(Registrant, email: 'new-registrant@test.com') } + let(:message) { instance_double(ActionMailer::MessageDelivery) } + + before :example do + expect(Domain).to receive(:find).and_return(domain) + expect(Registrant).to receive(:find).and_return(new_registrant) + end + + after :example do + domain_id = 1 + new_registrant_id = 1 + described_class.enqueue(domain_id, new_registrant_id) + end + + it 'creates log record' do + log_message = 'Send RegistrantChangeMailer#notice email for domain #1 to new-registrant@test.com' + + allow(RegistrantChangeMailer).to receive(:notice).and_return(message) + allow(message).to receive(:deliver_now) + + expect(Rails.logger).to receive(:info).with(log_message) + end + + it 'sends email' do + expect(RegistrantChangeMailer).to receive(:notice).with(domain: domain, + registrar: 'registrar', + current_registrant: 'registrant', + new_registrant: new_registrant) + .and_return(message) + expect(message).to receive(:deliver_now) + end + end +end From a5c0333a5d49ffaffd46653b87c46ba9d0352b34 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Wed, 23 Nov 2016 18:09:55 +0200 Subject: [PATCH 60/67] Add email validator #186 --- config/application.rb | 3 ++- lib/validators/email_validator.rb | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 lib/validators/email_validator.rb diff --git a/config/application.rb b/config/application.rb index 730935b9a..109fa4d1b 100644 --- a/config/application.rb +++ b/config/application.rb @@ -23,7 +23,7 @@ module Registry # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone. # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC. - config.time_zone = ENV['time_zone'] || 'Tallinn' # NB! It should be defined, + config.time_zone = ENV['time_zone'] || 'Tallinn' # NB! It should be defined, # otherwise ActiveRecord usese other class internally. config.i18n.load_path += Dir[Rails.root.join('config', 'locales', '**', '*.yml').to_s] @@ -35,6 +35,7 @@ module Registry # Autoload all model subdirs config.autoload_paths += Dir[Rails.root.join('app', 'models', '**/')] config.autoload_paths << Rails.root.join('lib') + config.eager_load_paths << config.root.join('lib', 'validators') # Add the fonts path config.assets.paths << Rails.root.join('vendor', 'assets', 'fonts') diff --git a/lib/validators/email_validator.rb b/lib/validators/email_validator.rb new file mode 100644 index 000000000..60b1b3ce1 --- /dev/null +++ b/lib/validators/email_validator.rb @@ -0,0 +1,15 @@ +class EmailValidator + def self.regexp + Devise::email_regexp + end + + def initialize(email) + @email = email + end + + def valid? + email =~ self.class.regexp + end + + attr_reader :email +end From e6e3ab9e1e1709dbd4dd047f4525188b9721c2d5 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Wed, 23 Nov 2016 21:20:28 +0200 Subject: [PATCH 61/67] Handle invalid emails in DomainExpireMailer#expired, move logging from job to mailer #186 --- app/jobs/domain_expire_email_job.rb | 12 ----- app/mailers/domain_expire_mailer.rb | 35 +++++++++++-- spec/jobs/domain_expire_email_job_spec.rb | 14 ------ spec/mailers/domain_expire_mailer_spec.rb | 60 +++++++++++++++++------ 4 files changed, 78 insertions(+), 43 deletions(-) diff --git a/app/jobs/domain_expire_email_job.rb b/app/jobs/domain_expire_email_job.rb index d42d343ca..9b70a54e6 100644 --- a/app/jobs/domain_expire_email_job.rb +++ b/app/jobs/domain_expire_email_job.rb @@ -4,18 +4,6 @@ class DomainExpireEmailJob < Que::Job return if domain.registered? - log(domain) DomainExpireMailer.expired(domain: domain, registrar: domain.registrar).deliver_now end - - private - - def log(domain) - message = "Send DomainExpireMailer#expired email for domain ##{domain.id} to #{domain.primary_contact_emails.join(', ')}" - logger.info(message) - end - - def logger - Rails.logger - end end diff --git a/app/mailers/domain_expire_mailer.rb b/app/mailers/domain_expire_mailer.rb index 0b869a5d2..cf960e146 100644 --- a/app/mailers/domain_expire_mailer.rb +++ b/app/mailers/domain_expire_mailer.rb @@ -1,9 +1,38 @@ class DomainExpireMailer < ApplicationMailer def expired(domain:, registrar:) - @domain = DomainPresenter.new(domain: domain, view: view_context) - @registrar = RegistrarPresenter.new(registrar: registrar, view: view_context) + @domain = domain_presenter(domain: domain) + @registrar = registrar_presenter(registrar: registrar) + recipient = filter_invalid_emails(emails: domain.primary_contact_emails, domain: domain) subject = default_i18n_subject(domain_name: domain.name) - mail(to: domain.primary_contact_emails, subject: subject) + + logger.info("Send DomainExpireMailer#expired email for domain ##{domain.id}" \ + " to #{domain.primary_contact_emails.join(', ')}") + + mail(to: recipient, subject: subject) + end + + private + + def domain_presenter(domain:) + DomainPresenter.new(domain: domain, view: view_context) + end + + def registrar_presenter(registrar:) + RegistrarPresenter.new(registrar: registrar, view: view_context) + end + + # Needed because there are invalid emails in the database, which have been imported from legacy app + def filter_invalid_emails(emails:, domain:) + emails.keep_if do |email| + valid = EmailValidator.new(email).valid? + + unless valid + logger.info("Unable to send DomainExpireMailer#expired email for domain ##{domain.id}" \ + " to invalid recipient #{email}") + end + + valid + end end end diff --git a/spec/jobs/domain_expire_email_job_spec.rb b/spec/jobs/domain_expire_email_job_spec.rb index fb7ef9822..a25999b77 100644 --- a/spec/jobs/domain_expire_email_job_spec.rb +++ b/spec/jobs/domain_expire_email_job_spec.rb @@ -18,21 +18,11 @@ RSpec.describe DomainExpireEmailJob do before :example do allow(domain).to receive_messages( - id: 1, registrar: 'registrar', registered?: false, primary_contact_emails: %w(test@test.com test@test.com)) end - it 'creates log record' do - log_message = 'Send DomainExpireMailer#expired email for domain #1 to test@test.com, test@test.com' - - allow(DomainExpireMailer).to receive(:expired).and_return(message) - allow(message).to receive(:deliver_now) - - expect(Rails.logger).to receive(:info).with(log_message) - end - it 'sends email' do expect(DomainExpireMailer).to receive(:expired).with(domain: domain, registrar: 'registrar') .and_return(message) @@ -45,10 +35,6 @@ RSpec.describe DomainExpireEmailJob do allow(domain).to receive(:registered?).and_return(true) end - it 'does not create log record' do - expect(Rails.logger).to_not receive(:info) - end - it 'does not send email' do expect(DomainExpireMailer).to_not receive(:expired) end diff --git a/spec/mailers/domain_expire_mailer_spec.rb b/spec/mailers/domain_expire_mailer_spec.rb index e536493d8..1afe6e6ad 100644 --- a/spec/mailers/domain_expire_mailer_spec.rb +++ b/spec/mailers/domain_expire_mailer_spec.rb @@ -2,32 +2,64 @@ require 'rails_helper' RSpec.describe DomainExpireMailer do describe '#expired' do - let(:domain) { instance_spy(Domain, name: 'test.com') } - let(:registrar) { 'registrar' } + let(:domain) { instance_spy(Domain, + id: 1, + name: 'test.com', + primary_contact_emails: recipient) + } let(:domain_presenter) { instance_spy(DomainPresenter) } let(:registrar_presenter) { instance_spy(RegistrarPresenter) } - subject(:message) { described_class.expired(domain: domain, registrar: registrar) } + subject(:message) { described_class.expired(domain: domain, registrar: nil) } before :example do expect(DomainPresenter).to receive(:new).and_return(domain_presenter) expect(RegistrarPresenter).to receive(:new).and_return(registrar_presenter) end - it 'has sender' do - expect(message.from).to eq(['noreply@internet.ee']) + context 'when all recipients are valid' do + let(:recipient) { %w[recipient@test.com recipient@test.com] } + + it 'has sender' do + expect(message.from).to eq(['noreply@internet.ee']) + end + + it 'delivers to all recipients' do + expect(message.to).to match_array(%w[recipient@test.com recipient@test.com]) + end + + it 'has subject' do + expect(message.subject).to eq('The test.com domain has expired') + end + + it 'creates log record' do + log_message = 'Send DomainExpireMailer#expired email for domain #1 to recipient@test.com,' \ + ' recipient@test.com' + expect(described_class.logger).to receive(:info).with(log_message) + message.deliver_now + end + + it 'sends message' do + expect { message.deliver_now }.to change { ActionMailer::Base.deliveries.count }.by(1) + end end - it 'has recipient' do - expect(domain).to receive(:primary_contact_emails).and_return(['recipient@test.com']) - expect(message.to).to match_array(['recipient@test.com']) - end + context 'when some recipient is invalid' do + let(:recipient) { %w[invalid_email valid@test.com] } - it 'has subject' do - expect(message.subject).to eq('The test.com domain has expired') - end + before :example do + allow(described_class.logger).to receive(:info) + end - it 'sends message' do - expect { message.deliver! }.to change { ActionMailer::Base.deliveries.count }.by(1) + it 'does not deliver to invalid recipient' do + expect(message.to).to match_array(%w[valid@test.com]) + end + + it 'creates log record' do + log_message = 'Unable to send DomainExpireMailer#expired email for domain #1 to' \ + ' invalid recipient invalid_email' + expect(described_class.logger).to receive(:info).with(log_message) + message.deliver_now + end end end end From ab77a1ae31bad47271c1c6c71989e155be521f34 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Wed, 23 Nov 2016 21:20:48 +0200 Subject: [PATCH 62/67] Add email validator spec #186 --- spec/lib/validators/email_validator_spec.rb | 23 +++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 spec/lib/validators/email_validator_spec.rb diff --git a/spec/lib/validators/email_validator_spec.rb b/spec/lib/validators/email_validator_spec.rb new file mode 100644 index 000000000..ecaadc8a7 --- /dev/null +++ b/spec/lib/validators/email_validator_spec.rb @@ -0,0 +1,23 @@ +require 'spec_helper' + +RSpec.describe EmailValidator do + describe '#valid?' do + subject(:valid) { described_class.new(email).valid? } + + context 'when email is valid' do + let(:email) { 'test@test.com' } + + it 'returns truthy' do + expect(valid).to be_truthy + end + end + + context 'when email is invalid' do + let(:email) { 'invalid' } + + it 'returns falsey' do + expect(valid).to be_falsey + end + end + end +end From e1e41a962eb6fb20f4e9efac18f5c7a41edf326c Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Wed, 23 Nov 2016 21:26:49 +0200 Subject: [PATCH 63/67] Remove unneeded log #186 --- app/models/domain_cron.rb | 3 +-- spec/models/domain_cron_spec.rb | 11 ----------- 2 files changed, 1 insertion(+), 13 deletions(-) diff --git a/app/models/domain_cron.rb b/app/models/domain_cron.rb index c3a698fbc..b4da056a2 100644 --- a/app/models/domain_cron.rb +++ b/app/models/domain_cron.rb @@ -32,12 +32,11 @@ class DomainCron end def self.start_expire_period - Rails.logger.info('Expiring domains') - ::PaperTrail.whodunnit = "cron - #{__method__}" domains = Domain.expired marked = 0 real = 0 + domains.each do |domain| next unless domain.expirable? real += 1 diff --git a/spec/models/domain_cron_spec.rb b/spec/models/domain_cron_spec.rb index a9c3e2d2f..50c4ca80a 100644 --- a/spec/models/domain_cron_spec.rb +++ b/spec/models/domain_cron_spec.rb @@ -38,15 +38,4 @@ RSpec.describe DomainCron do @domain.reload @domain.statuses.include?(DomainStatus::EXPIRED).should == true end - - describe '::start_expire_period', db: false do - before :example do - travel_to Time.zone.parse('05.07.2010') - end - - it 'logs start time' do - expect(Rails.logger).to receive(:info).with('Expiring domains') - described_class.start_expire_period - end - end end From e9d959d373f92289c1563d3d25d5f6fffbedd987 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Wed, 23 Nov 2016 21:28:20 +0200 Subject: [PATCH 64/67] Use ActiveMailer api to send emails #186 --- spec/mailers/domain_delete_mailer_spec.rb | 4 ++-- spec/mailers/registrant_change_mailer_spec.rb | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/spec/mailers/domain_delete_mailer_spec.rb b/spec/mailers/domain_delete_mailer_spec.rb index 9e2d20a8a..5a2f775c1 100644 --- a/spec/mailers/domain_delete_mailer_spec.rb +++ b/spec/mailers/domain_delete_mailer_spec.rb @@ -42,7 +42,7 @@ RSpec.describe DomainDeleteMailer do end it 'sends message' do - expect { message.deliver! }.to change { ActionMailer::Base.deliveries.count }.by(1) + expect { message.deliver_now }.to change { ActionMailer::Base.deliveries.count }.by(1) end end @@ -76,7 +76,7 @@ RSpec.describe DomainDeleteMailer do end it 'sends message' do - expect { message.deliver! }.to change { ActionMailer::Base.deliveries.count }.by(1) + expect { message.deliver_now }.to change { ActionMailer::Base.deliveries.count }.by(1) end end end diff --git a/spec/mailers/registrant_change_mailer_spec.rb b/spec/mailers/registrant_change_mailer_spec.rb index 5a619d0a1..be1e7d105 100644 --- a/spec/mailers/registrant_change_mailer_spec.rb +++ b/spec/mailers/registrant_change_mailer_spec.rb @@ -46,7 +46,7 @@ RSpec.describe RegistrantChangeMailer do end it 'sends message' do - expect { message.deliver! }.to change { ActionMailer::Base.deliveries.count }.by(1) + expect { message.deliver_now }.to change { ActionMailer::Base.deliveries.count }.by(1) end end @@ -90,7 +90,7 @@ RSpec.describe RegistrantChangeMailer do end it 'sends message' do - expect { message.deliver! }.to change { ActionMailer::Base.deliveries.count }.by(1) + expect { message.deliver_now }.to change { ActionMailer::Base.deliveries.count }.by(1) end end @@ -130,7 +130,7 @@ RSpec.describe RegistrantChangeMailer do end it 'sends message' do - expect { message.deliver! }.to change { ActionMailer::Base.deliveries.count }.by(1) + expect { message.deliver_now }.to change { ActionMailer::Base.deliveries.count }.by(1) end end @@ -170,7 +170,7 @@ RSpec.describe RegistrantChangeMailer do end it 'sends message' do - expect { message.deliver! }.to change { ActionMailer::Base.deliveries.count }.by(1) + expect { message.deliver_now }.to change { ActionMailer::Base.deliveries.count }.by(1) end end end From 9ad84d78aa6215b5d97dc2cfb0ac0331f4edac22 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Fri, 25 Nov 2016 11:46:15 +0200 Subject: [PATCH 65/67] Log domain name in domain_expire_mailer #186 --- app/mailers/domain_expire_mailer.rb | 4 ++-- spec/mailers/domain_expire_mailer_spec.rb | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/mailers/domain_expire_mailer.rb b/app/mailers/domain_expire_mailer.rb index cf960e146..b7217546d 100644 --- a/app/mailers/domain_expire_mailer.rb +++ b/app/mailers/domain_expire_mailer.rb @@ -6,7 +6,7 @@ class DomainExpireMailer < ApplicationMailer recipient = filter_invalid_emails(emails: domain.primary_contact_emails, domain: domain) subject = default_i18n_subject(domain_name: domain.name) - logger.info("Send DomainExpireMailer#expired email for domain ##{domain.id}" \ + logger.info("Send DomainExpireMailer#expired email for domain #{domain.name} (##{domain.id})" \ " to #{domain.primary_contact_emails.join(', ')}") mail(to: recipient, subject: subject) @@ -28,7 +28,7 @@ class DomainExpireMailer < ApplicationMailer valid = EmailValidator.new(email).valid? unless valid - logger.info("Unable to send DomainExpireMailer#expired email for domain ##{domain.id}" \ + logger.info("Unable to send DomainExpireMailer#expired email for domain #{domain.name} (##{domain.id})" \ " to invalid recipient #{email}") end diff --git a/spec/mailers/domain_expire_mailer_spec.rb b/spec/mailers/domain_expire_mailer_spec.rb index 1afe6e6ad..9e03fc4e8 100644 --- a/spec/mailers/domain_expire_mailer_spec.rb +++ b/spec/mailers/domain_expire_mailer_spec.rb @@ -32,7 +32,7 @@ RSpec.describe DomainExpireMailer do end it 'creates log record' do - log_message = 'Send DomainExpireMailer#expired email for domain #1 to recipient@test.com,' \ + log_message = 'Send DomainExpireMailer#expired email for domain test.com (#1) to recipient@test.com,' \ ' recipient@test.com' expect(described_class.logger).to receive(:info).with(log_message) message.deliver_now @@ -55,7 +55,7 @@ RSpec.describe DomainExpireMailer do end it 'creates log record' do - log_message = 'Unable to send DomainExpireMailer#expired email for domain #1 to' \ + log_message = 'Unable to send DomainExpireMailer#expired email for domain test.com (#1) to' \ ' invalid recipient invalid_email' expect(described_class.logger).to receive(:info).with(log_message) message.deliver_now From 4f13258352057a277e60444d4ba7d9b9f7dc6c48 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Fri, 25 Nov 2016 11:59:41 +0200 Subject: [PATCH 66/67] Log domain name in mailer jobs #186 --- app/jobs/domain_delete_confirm_email_job.rb | 3 ++- app/jobs/domain_delete_forced_email_job.rb | 4 ++-- app/jobs/registrant_change_confirm_email_job.rb | 2 +- app/jobs/registrant_change_expired_email_job.rb | 2 +- app/jobs/registrant_change_notice_email_job.rb | 2 +- spec/jobs/domain_delete_confirm_email_job_spec.rb | 3 ++- spec/jobs/domain_delete_forced_email_job_spec.rb | 3 ++- spec/jobs/registrant_change_confirm_email_job_spec.rb | 3 ++- spec/jobs/registrant_change_expired_email_job_spec.rb | 3 ++- spec/jobs/registrant_change_notice_email_job_spec.rb | 3 ++- 10 files changed, 17 insertions(+), 11 deletions(-) diff --git a/app/jobs/domain_delete_confirm_email_job.rb b/app/jobs/domain_delete_confirm_email_job.rb index 5c447a24f..65cf948f9 100644 --- a/app/jobs/domain_delete_confirm_email_job.rb +++ b/app/jobs/domain_delete_confirm_email_job.rb @@ -11,7 +11,8 @@ class DomainDeleteConfirmEmailJob < Que::Job private def log(domain) - message = "Send DomainDeleteMailer#confirm email for domain ##{domain.id} to #{domain.registrant_email}" + message = "Send DomainDeleteMailer#confirm email for domain #{domain.name} (##{domain.id})" \ + " to #{domain.registrant_email}" logger.info(message) end diff --git a/app/jobs/domain_delete_forced_email_job.rb b/app/jobs/domain_delete_forced_email_job.rb index ade3a43da..1ddd95bb9 100644 --- a/app/jobs/domain_delete_forced_email_job.rb +++ b/app/jobs/domain_delete_forced_email_job.rb @@ -11,8 +11,8 @@ class DomainDeleteForcedEmailJob < Que::Job private def log(domain) - message = "Send DomainDeleteMailer#forced email for domain ##{domain.id} to #{domain.primary_contact_emails - .join(', ')}" + message = "Send DomainDeleteMailer#forced email for domain #{domain.name} (##{domain.id})" \ + " to #{domain.primary_contact_emails.join(', ')}" logger.info(message) end diff --git a/app/jobs/registrant_change_confirm_email_job.rb b/app/jobs/registrant_change_confirm_email_job.rb index 4c91c48a4..7d2dd79ad 100644 --- a/app/jobs/registrant_change_confirm_email_job.rb +++ b/app/jobs/registrant_change_confirm_email_job.rb @@ -13,7 +13,7 @@ class RegistrantChangeConfirmEmailJob < Que::Job private def log(domain) - message = "Send RegistrantChangeMailer#confirm email for domain ##{domain.id} to #{domain.registrant_email}" + message = "Send RegistrantChangeMailer#confirm email for domain #{domain.name} (##{domain.id}) to #{domain.registrant_email}" logger.info(message) end diff --git a/app/jobs/registrant_change_expired_email_job.rb b/app/jobs/registrant_change_expired_email_job.rb index 8e7650501..3c1bc35e2 100644 --- a/app/jobs/registrant_change_expired_email_job.rb +++ b/app/jobs/registrant_change_expired_email_job.rb @@ -10,7 +10,7 @@ class RegistrantChangeExpiredEmailJob < Que::Job private def log(domain) - message = "Send RegistrantChangeMailer#expired email for domain ##{domain.id} to #{domain.new_registrant_email}" + message = "Send RegistrantChangeMailer#expired email for domain #{domain.name} (##{domain.id}) to #{domain.new_registrant_email}" logger.info(message) end diff --git a/app/jobs/registrant_change_notice_email_job.rb b/app/jobs/registrant_change_notice_email_job.rb index bb170dce1..a0bf26c52 100644 --- a/app/jobs/registrant_change_notice_email_job.rb +++ b/app/jobs/registrant_change_notice_email_job.rb @@ -12,7 +12,7 @@ class RegistrantChangeNoticeEmailJob < Que::Job private def log(domain, new_registrant) - message = "Send RegistrantChangeMailer#notice email for domain ##{domain.id} to #{new_registrant.email}" + message = "Send RegistrantChangeMailer#notice email for domain #{domain.name} (##{domain.id}) to #{new_registrant.email}" logger.info(message) end diff --git a/spec/jobs/domain_delete_confirm_email_job_spec.rb b/spec/jobs/domain_delete_confirm_email_job_spec.rb index 8cb895b3f..0b2a0a6b7 100644 --- a/spec/jobs/domain_delete_confirm_email_job_spec.rb +++ b/spec/jobs/domain_delete_confirm_email_job_spec.rb @@ -9,6 +9,7 @@ RSpec.describe DomainDeleteConfirmEmailJob do expect(Domain).to receive(:find).and_return(domain) allow(domain).to receive_messages( id: 1, + name: 'test.com', registrant_email: 'registrant@test.com', registrar: 'registrar', registrant: 'registrant') @@ -20,7 +21,7 @@ RSpec.describe DomainDeleteConfirmEmailJob do end it 'creates log record' do - log_message = 'Send DomainDeleteMailer#confirm email for domain #1 to registrant@test.com' + log_message = 'Send DomainDeleteMailer#confirm email for domain test.com (#1) to registrant@test.com' allow(DomainDeleteMailer).to receive(:confirm).and_return(message) allow(message).to receive(:deliver_now) diff --git a/spec/jobs/domain_delete_forced_email_job_spec.rb b/spec/jobs/domain_delete_forced_email_job_spec.rb index 452d0a659..05dab987b 100644 --- a/spec/jobs/domain_delete_forced_email_job_spec.rb +++ b/spec/jobs/domain_delete_forced_email_job_spec.rb @@ -9,6 +9,7 @@ RSpec.describe DomainDeleteForcedEmailJob do expect(Domain).to receive(:find).and_return(domain) allow(domain).to receive_messages( id: 1, + name: 'test.com', registrar: 'registrar', registrant: 'registrant', primary_contact_emails: %w(test@test.com test@test.com)) @@ -20,7 +21,7 @@ RSpec.describe DomainDeleteForcedEmailJob do end it 'creates log record' do - log_message = 'Send DomainDeleteMailer#forced email for domain #1 to test@test.com, test@test.com' + log_message = 'Send DomainDeleteMailer#forced email for domain test.com (#1) to test@test.com, test@test.com' allow(DomainDeleteMailer).to receive(:forced).and_return(message) allow(message).to receive(:deliver_now) diff --git a/spec/jobs/registrant_change_confirm_email_job_spec.rb b/spec/jobs/registrant_change_confirm_email_job_spec.rb index efa1b1e30..ea8eb1096 100644 --- a/spec/jobs/registrant_change_confirm_email_job_spec.rb +++ b/spec/jobs/registrant_change_confirm_email_job_spec.rb @@ -10,6 +10,7 @@ RSpec.describe RegistrantChangeConfirmEmailJob do expect(Registrant).to receive(:find).and_return('new registrant') allow(domain).to receive_messages( id: 1, + name: 'test.com', registrant_email: 'registrant@test.com', registrar: 'registrar', registrant: 'registrant') @@ -22,7 +23,7 @@ RSpec.describe RegistrantChangeConfirmEmailJob do end it 'creates log record' do - log_message = 'Send RegistrantChangeMailer#confirm email for domain #1 to registrant@test.com' + log_message = 'Send RegistrantChangeMailer#confirm email for domain test.com (#1) to registrant@test.com' allow(RegistrantChangeMailer).to receive(:confirm).and_return(message) allow(message).to receive(:deliver_now) diff --git a/spec/jobs/registrant_change_expired_email_job_spec.rb b/spec/jobs/registrant_change_expired_email_job_spec.rb index 43d08f50d..1486417ea 100644 --- a/spec/jobs/registrant_change_expired_email_job_spec.rb +++ b/spec/jobs/registrant_change_expired_email_job_spec.rb @@ -4,6 +4,7 @@ RSpec.describe RegistrantChangeExpiredEmailJob do describe '#run' do let(:domain) { instance_double(Domain, id: 1, + name: 'test.com', new_registrant_email: 'new-registrant@test.com', registrar: 'registrar', registrant: 'registrant') @@ -20,7 +21,7 @@ RSpec.describe RegistrantChangeExpiredEmailJob do end it 'creates log record' do - log_message = 'Send RegistrantChangeMailer#expired email for domain #1 to new-registrant@test.com' + log_message = 'Send RegistrantChangeMailer#expired email for domain test.com (#1) to new-registrant@test.com' allow(RegistrantChangeMailer).to receive(:expired).and_return(message) allow(message).to receive(:deliver_now) diff --git a/spec/jobs/registrant_change_notice_email_job_spec.rb b/spec/jobs/registrant_change_notice_email_job_spec.rb index 0d9e05a65..1eb1d6d94 100644 --- a/spec/jobs/registrant_change_notice_email_job_spec.rb +++ b/spec/jobs/registrant_change_notice_email_job_spec.rb @@ -4,6 +4,7 @@ RSpec.describe RegistrantChangeNoticeEmailJob do describe '#run' do let(:domain) { instance_double(Domain, id: 1, + name: 'test.com', registrant_email: 'registrant@test.com', registrar: 'registrar', registrant: 'registrant') @@ -23,7 +24,7 @@ RSpec.describe RegistrantChangeNoticeEmailJob do end it 'creates log record' do - log_message = 'Send RegistrantChangeMailer#notice email for domain #1 to new-registrant@test.com' + log_message = 'Send RegistrantChangeMailer#notice email for domain test.com (#1) to new-registrant@test.com' allow(RegistrantChangeMailer).to receive(:notice).and_return(message) allow(message).to receive(:deliver_now) From 48f64f18d4f7da4e62c1f782a6ecb31d6225d625 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Fri, 25 Nov 2016 12:23:52 +0200 Subject: [PATCH 67/67] Fix domain_expire_mailer #186 --- app/mailers/domain_expire_mailer.rb | 4 ++-- spec/mailers/domain_expire_mailer_spec.rb | 10 ++++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/app/mailers/domain_expire_mailer.rb b/app/mailers/domain_expire_mailer.rb index b7217546d..ecbd8ee3d 100644 --- a/app/mailers/domain_expire_mailer.rb +++ b/app/mailers/domain_expire_mailer.rb @@ -7,7 +7,7 @@ class DomainExpireMailer < ApplicationMailer subject = default_i18n_subject(domain_name: domain.name) logger.info("Send DomainExpireMailer#expired email for domain #{domain.name} (##{domain.id})" \ - " to #{domain.primary_contact_emails.join(', ')}") + " to #{recipient.join(', ')}") mail(to: recipient, subject: subject) end @@ -24,7 +24,7 @@ class DomainExpireMailer < ApplicationMailer # Needed because there are invalid emails in the database, which have been imported from legacy app def filter_invalid_emails(emails:, domain:) - emails.keep_if do |email| + emails.select do |email| valid = EmailValidator.new(email).valid? unless valid diff --git a/spec/mailers/domain_expire_mailer_spec.rb b/spec/mailers/domain_expire_mailer_spec.rb index 9e03fc4e8..e5660c11b 100644 --- a/spec/mailers/domain_expire_mailer_spec.rb +++ b/spec/mailers/domain_expire_mailer_spec.rb @@ -31,7 +31,7 @@ RSpec.describe DomainExpireMailer do expect(message.subject).to eq('The test.com domain has expired') end - it 'creates log record' do + it 'logs valid emails' do log_message = 'Send DomainExpireMailer#expired email for domain test.com (#1) to recipient@test.com,' \ ' recipient@test.com' expect(described_class.logger).to receive(:info).with(log_message) @@ -54,7 +54,13 @@ RSpec.describe DomainExpireMailer do expect(message.to).to match_array(%w[valid@test.com]) end - it 'creates log record' do + it 'does not log invalid email in success message' do + log_message = 'Send DomainExpireMailer#expired email for domain test.com (#1) to valid@test.com' + expect(described_class.logger).to receive(:info).with(log_message) + message.deliver_now + end + + it 'logs invalid email in error message' do log_message = 'Unable to send DomainExpireMailer#expired email for domain test.com (#1) to' \ ' invalid recipient invalid_email' expect(described_class.logger).to receive(:info).with(log_message)