diff --git a/.reek b/.reek index d7d39a198..a511bdb43 100644 --- a/.reek +++ b/.reek @@ -289,7 +289,6 @@ DuplicateMethodCall: - Domain#renewable? - Domain#set_graceful_expired - DomainCron#self.clean_expired_pendings - - DomainCron#self.delete_legal_doc_duplicates - DomainCron#self.destroy_delete_candidates - DomainCron#self.start_expire_period - DomainCron#self.start_redemption_grace_period diff --git a/CHANGELOG.md b/CHANGELOG.md index 472c5545d..66e29f9f7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,12 @@ +03.04.2018 +* BUG: Fixed bug with sometimes failing bank-link payments [#642](https://github.com/internetee/registry/issues/642) +* EPP: Domain and associated objects are now validated on domain renew [#678](https://github.com/internetee/registry/issues/678) +* Admin: drop uniqueness requirement from registrar's registry number field [#776](https://github.com/internetee/registry/issues/776) +* Security: Loofah gem update to 2.2.2 [#783](https://github.com/internetee/registry/pull/783) +* Disabled spellcheck for browsers to cleanup UI [#759](https://github.com/internetee/registry/issues/759) +* Admin: refactored registrar management [#770](https://github.com/internetee/registry/pull/770) +* Fix structure.sql [#796](https://github.com/internetee/registry/pull/796) + 19.03.2018 * EPP transfer and REPP bulk transfer reuses contact objects [#746](https://github.com/internetee/registry/issues/746) * Gems: Rack (1.6.9) and Rack-protection (1.5.5) update [#768](https://github.com/internetee/registry/issues/768) diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..0c2c51e25 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,23 @@ +FROM ruby:2.2 +MAINTAINER maciej.szlosarczyk@internet.ee + +RUN apt-get update > /dev/null && apt-get install -y > /dev/null \ + build-essential \ + nodejs \ + imagemagick \ + postgresql-client + +RUN apt-get install -y > /dev/null \ + qt5-default \ + libqt5webkit5-dev \ + gstreamer1.0-plugins-base \ + gstreamer1.0-tools \ + qtdeclarative5-dev \ + gstreamer1.0-x + +RUN mkdir -p /opt/webapps/app/tmp/pids +WORKDIR /opt/webapps/app + +COPY Gemfile Gemfile.lock ./ +RUN gem install bundler && bundle install --jobs 20 --retry 5 +EXPOSE 3000 diff --git a/app/controllers/admin/bank_statements_controller.rb b/app/controllers/admin/bank_statements_controller.rb index d7b6edae2..a70387317 100644 --- a/app/controllers/admin/bank_statements_controller.rb +++ b/app/controllers/admin/bank_statements_controller.rb @@ -24,7 +24,7 @@ module Admin @invoice = Invoice.find_by(id: params[:invoice_id]) @bank_transaction = @bank_statement.bank_transactions.build( description: @invoice.to_s, - sum: @invoice.sum, + sum: @invoice.total, reference_no: @invoice.reference_no, paid_at: Time.zone.now.to_date, currency: 'EUR' diff --git a/app/controllers/admin/registrars_controller.rb b/app/controllers/admin/registrars_controller.rb index 82fa37be4..e919bdb25 100644 --- a/app/controllers/admin/registrars_controller.rb +++ b/app/controllers/admin/registrars_controller.rb @@ -61,7 +61,6 @@ module Admin def registrar_params params.require(:registrar).permit(:name, :reg_no, - :vat_no, :street, :city, :state, @@ -70,10 +69,12 @@ module Admin :email, :phone, :website, - :billing_email, :code, :test_registrar, + :vat_no, + :vat_rate, :accounting_customer_code, + :billing_email, :language) end end diff --git a/app/controllers/registrar/invoices_controller.rb b/app/controllers/registrar/invoices_controller.rb index ac762e712..735df91a3 100644 --- a/app/controllers/registrar/invoices_controller.rb +++ b/app/controllers/registrar/invoices_controller.rb @@ -55,8 +55,8 @@ class Registrar end def normalize_search_parameters - params[:q][:sum_cache_gteq].gsub!(',', '.') if params[:q][:sum_cache_gteq] - params[:q][:sum_cache_lteq].gsub!(',', '.') if params[:q][:sum_cache_lteq] + params[:q][:total_gteq].gsub!(',', '.') if params[:q][:total_gteq] + params[:q][:total_lteq].gsub!(',', '.') if params[:q][:total_lteq] ca_cache = params[:q][:due_date_lteq] begin diff --git a/app/models/bank_link.rb b/app/models/bank_link.rb index 24c94a771..e388a0f8b 100644 --- a/app/models/bank_link.rb +++ b/app/models/bank_link.rb @@ -29,7 +29,7 @@ class BankLink hash["VK_VERSION"] = "008" hash["VK_SND_ID"] = ENV["payments_#{type}_seller_account"] hash["VK_STAMP"] = invoice.number - hash["VK_AMOUNT"] = number_with_precision(invoice.sum_cache, :precision => 2, :separator => ".") + hash["VK_AMOUNT"] = number_with_precision(invoice.total, :precision => 2, :separator => ".") hash["VK_CURR"] = invoice.currency hash["VK_REF"] = "" hash["VK_MSG"] = invoice.order @@ -140,7 +140,7 @@ class BankLink def validate_amount source = number_with_precision(BigDecimal.new(params["VK_AMOUNT"].to_s), precision: 2, separator: ".") - target = number_with_precision(invoice.sum_cache, precision: 2, separator: ".") + target = number_with_precision(invoice.total, precision: 2, separator: ".") source == target end diff --git a/app/models/bank_transaction.rb b/app/models/bank_transaction.rb index daf6abc29..3749f92b5 100644 --- a/app/models/bank_transaction.rb +++ b/app/models/bank_transaction.rb @@ -47,7 +47,7 @@ class BankTransaction < ActiveRecord::Base return if invoice.binded? return if invoice.cancelled? - return if invoice.sum != sum + return if invoice.total != sum create_activity(registrar, invoice) end # rubocop: enable Metrics/PerceivedComplexity @@ -76,7 +76,7 @@ class BankTransaction < ActiveRecord::Base return end - if invoice.sum != sum + if invoice.total != sum errors.add(:base, I18n.t('invoice_and_transaction_sums_do_not_match')) return end @@ -88,7 +88,7 @@ class BankTransaction < ActiveRecord::Base create_account_activity( account: registrar.cash_account, invoice: invoice, - sum: invoice.sum_without_vat, + sum: invoice.subtotal, currency: currency, description: description, activity_type: AccountActivity::ADD_CREDIT diff --git a/app/models/directo.rb b/app/models/directo.rb index 62cf43804..9352c9356 100644 --- a/app/models/directo.rb +++ b/app/models/directo.rb @@ -3,7 +3,7 @@ class Directo < ActiveRecord::Base belongs_to :item, polymorphic: true def self.send_receipts - new_trans = Invoice.where(invoice_type: "DEB", in_directo: false).where(cancelled_at: nil) + new_trans = Invoice.where(in_directo: false).where(cancelled_at: nil) total = new_trans.count counter = 0 Rails.logger.info("[DIRECTO] Will try to send #{total} invoices") @@ -15,7 +15,7 @@ class Directo < ActiveRecord::Base group.each do |invoice| if invoice.account_activity.nil? || invoice.account_activity.bank_transaction.nil? || - invoice.account_activity.bank_transaction.sum.nil? || invoice.account_activity.bank_transaction.sum != invoice.sum_cache + invoice.account_activity.bank_transaction.sum.nil? || invoice.account_activity.bank_transaction.sum != invoice.total Rails.logger.info("[DIRECTO] Invoice #{invoice.number} has been skipped") next end @@ -29,12 +29,14 @@ class Directo < ActiveRecord::Base "InvoiceDate" => invoice.created_at.strftime("%Y-%m-%dT%H:%M:%S"), "PaymentTerm" => Setting.directo_receipt_payment_term, "Currency" => invoice.currency, - "CustomerCode"=> invoice.buyer.accounting_customer_code + "CustomerCode"=> invoice.buyer.accounting_customer_code, + 'TotalVAT' => ActionController::Base.helpers.number_with_precision(invoice.vat_amount, precision: 2, separator: '.') ){ xml.line( "ProductID" => Setting.directo_receipt_product_name, "Quantity" => 1, - "UnitPriceWoVAT" => ActionController::Base.helpers.number_with_precision(invoice.sum_cache/(1+invoice.vat_prc), precision: 2, separator: "."), + "UnitPriceWoVAT" => ActionController::Base.helpers.number_with_precision(invoice.subtotal, precision: 2, separator: '.'), + 'VATCode' => invoice.buyer_vat_no, "ProductName" => invoice.order ) } diff --git a/app/models/domain.rb b/app/models/domain.rb index d5c860913..55596aedf 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -209,28 +209,12 @@ class Domain < ActiveRecord::Base DomainCron.send(__method__) end - def self.start_delete_period - ActiveSupport::Deprecation.instance.deprecation_warning(DomainCron, __method__) - DomainCron.send(__method__) - end - def self.destroy_delete_candidates ActiveSupport::Deprecation.instance.deprecation_warning(DomainCron, __method__) DomainCron.send(__method__) end class << self - def included - includes( - :registrant, - :registrar, - :nameservers, - :whois_record, - { tech_contacts: :registrar }, - { admin_contacts: :registrar } - ) - end - def nameserver_required? Setting.nameserver_required end diff --git a/app/models/domain_cron.rb b/app/models/domain_cron.rb index dcd99328a..fb3b7644d 100644 --- a/app/models/domain_cron.rb +++ b/app/models/domain_cron.rb @@ -76,29 +76,6 @@ class DomainCron marked end - #doing nothing, deprecated - - def self.start_delete_period - # begin - # STDOUT << "#{Time.zone.now.utc} - Setting delete_candidate to domains\n" unless Rails.env.test? - # - # d = Domain.where('delete_at <= ?', Time.zone.now) - # marked = 0 - # real = 0 - # d.each do |domain| - # next unless domain.delete_candidateable? - # real += 1 - # domain.statuses << DomainStatus::DELETE_CANDIDATE - # STDOUT << "#{Time.zone.now.utc} DomainCron.start_delete_period: ##{domain.id} (#{domain.name})\n" unless Rails.env.test? - # ::PaperTrail.whodunnit = "cron - #{__method__}" - # domain.save(validate: false) and marked += 1 - # end - # ensure # the operator should see what was accomplished - # STDOUT << "#{Time.zone.now.utc} - Finished setting delete_candidate - #{marked} out of #{real} successfully set\n" unless Rails.env.test? - # end - # marked - end - def self.destroy_delete_candidates STDOUT << "#{Time.zone.now.utc} - Destroying domains\n" unless Rails.env.test? @@ -128,23 +105,4 @@ class DomainCron STDOUT << "#{Time.zone.now.utc} - Job destroy added for #{c} domains\n" unless Rails.env.test? end - - # rubocop: enable Metrics/AbcSize - # rubocop:enable Rails/FindEach - # rubocop: enable Metrics/LineLength - def self.destroy_with_message(domain) - domain.destroy - bye_bye = domain.versions.last - domain.registrar.messages.create!( - body: "#{I18n.t(:domain_deleted)}: #{domain.name}", - attached_obj_id: bye_bye.id, - attached_obj_type: bye_bye.class.to_s # DomainVersion - ) - end - - def self.delete_legal_doc_duplicates - Rake::Task['legal_doc:remove_duplicates'].reenable - Rake::Task['legal_doc:remove_duplicates'].invoke - end - end diff --git a/app/models/epp/domain.rb b/app/models/epp/domain.rb index 2ead51ea3..4e0e7d44c 100644 --- a/app/models/epp/domain.rb +++ b/app/models/epp/domain.rb @@ -18,7 +18,7 @@ class Epp::Domain < Domain after_validation :validate_contacts def validate_contacts - return true if is_renewal || is_transfer + return true if is_transfer ok = true active_admins = admin_domain_contacts.select { |x| !x.marked_for_destruction? } @@ -38,16 +38,6 @@ class Epp::Domain < Domain ok end - before_save :link_contacts - def link_contacts - #TODO: cleanup cache if we think to cache dynamic statuses - end - - after_destroy :unlink_contacts - def unlink_contacts - #TODO: cleanup cache if we think to cache dynamic statuses - end - class << self def new_from_epp(frame, current_user) domain = Epp::Domain.new diff --git a/app/models/invoice.rb b/app/models/invoice.rb index ad478443d..a2e469ca0 100644 --- a/app/models/invoice.rb +++ b/app/models/invoice.rb @@ -27,12 +27,18 @@ class Invoice < ActiveRecord::Base attr_accessor :billing_email validates :billing_email, email_format: { message: :invalid }, allow_blank: true - validates :invoice_type, :due_date, :currency, :seller_name, - :seller_iban, :buyer_name, :invoice_items, :vat_prc, presence: true + validates :due_date, :currency, :seller_name, + :seller_iban, :buyer_name, :invoice_items, presence: true + validates :vat_rate, numericality: { greater_than_or_equal_to: 0, less_than: 100 }, + allow_nil: true - before_create :set_invoice_number, :check_vat + before_create :set_invoice_number + before_create :apply_default_vat_rate, unless: :vat_rate? + before_create :calculate_total, unless: :total? + before_create :apply_default_buyer_vat_no, unless: :buyer_vat_no? - before_save :check_vat + attribute :vat_rate, ::Type::VATRate.new + attr_readonly :vat_rate def set_invoice_number last_no = Invoice.order(number: :desc).where('number IS NOT NULL').limit(1).pluck(:number).first @@ -50,14 +56,6 @@ class Invoice < ActiveRecord::Base false end - def check_vat - if buyer.country_code != 'EE' && buyer.vat_no.present? - self.vat_prc = 0 - end - end - - before_save -> { self.sum_cache = sum } - class << self def cancel_overdue_invoices STDOUT << "#{Time.zone.now.utc} - Cancelling overdue invoices\n" unless Rails.env.test? @@ -106,12 +104,12 @@ class Invoice < ActiveRecord::Base def buyer_country Country.new(buyer_country_code) end - + # order is used for directo/banklink description def order "Order nr. #{number}" end - + def pdf(html) kit = PDFKit.new(html) kit.to_pdf @@ -152,15 +150,31 @@ class Invoice < ActiveRecord::Base invoice_items end - def sum_without_vat - (items.map(&:item_sum_without_vat).sum).round(2) + def subtotal + invoice_items.map(&:item_sum_without_vat).reduce(:+) end - def vat - (sum_without_vat * vat_prc).round(2) + def vat_amount + return 0 unless vat_rate + subtotal * vat_rate / 100 end - def sum - (sum_without_vat + vat).round(2) + def total + calculate_total unless total? + read_attribute(:total) + end + + private + + def apply_default_vat_rate + self.vat_rate = buyer.effective_vat_rate + end + + def apply_default_buyer_vat_no + self.buyer_vat_no = buyer.vat_no + end + + def calculate_total + self.total = subtotal + vat_amount end end diff --git a/app/models/registrar.rb b/app/models/registrar.rb index 5fd0008b5..d539e01f2 100644 --- a/app/models/registrar.rb +++ b/app/models/registrar.rb @@ -19,6 +19,15 @@ class Registrar < ActiveRecord::Base validates :language, presence: true validate :forbid_special_code + validates :vat_rate, presence: true, if: 'foreign_vat_payer? && vat_no.blank?' + validates :vat_rate, absence: true, if: :home_vat_payer? + validates :vat_rate, absence: true, if: 'foreign_vat_payer? && vat_no?' + validates :vat_rate, numericality: { greater_than_or_equal_to: 0, less_than: 100 }, + allow_nil: true + + validate :forbid_special_code + + attribute :vat_rate, ::Type::VATRate.new after_initialize :set_defaults before_validation :generate_iso_11649_reference_no @@ -49,12 +58,10 @@ class Registrar < ActiveRecord::Base # rubocop:disable Metrics/AbcSize def issue_prepayment_invoice(amount, description = nil) invoices.create( - invoice_type: 'DEB', due_date: (Time.zone.now.to_date + Setting.days_to_keep_invoices_active.days).end_of_day, payment_term: 'prepayment', description: description, currency: 'EUR', - vat_prc: Setting.registry_vat_prc, seller_name: Setting.registry_juridical_name, seller_reg_no: Setting.registry_reg_no, seller_iban: Setting.registry_iban, @@ -70,7 +77,7 @@ class Registrar < ActiveRecord::Base seller_url: Setting.registry_url, seller_email: Setting.registry_email, seller_contact_name: Setting.registry_invoice_contact, - buyer_id: id, + buyer: self, buyer_name: name, buyer_reg_no: reg_no, buyer_country_code: country_code, @@ -105,11 +112,6 @@ class Registrar < ActiveRecord::Base cash_account.account_activities.create!(args) end - def credit!(args) - args[:currency] = 'EUR' - cash_account.account_activities.create!(args) - end - def address [street, city, state, zip].reject(&:blank?).compact.join(', ') end @@ -145,6 +147,14 @@ class Registrar < ActiveRecord::Base end end + def effective_vat_rate + if home_vat_payer? + Registry.instance.vat_rate + else + vat_rate + end + end + private def set_defaults @@ -175,4 +185,12 @@ class Registrar < ActiveRecord::Base break unless self.class.exists?(reference_no: reference_no) end end + + def home_vat_payer? + country == Registry.instance.legal_address_country + end + + def foreign_vat_payer? + !home_vat_payer? + end end diff --git a/app/models/registry.rb b/app/models/registry.rb new file mode 100644 index 000000000..5e5c8cd93 --- /dev/null +++ b/app/models/registry.rb @@ -0,0 +1,11 @@ +class Registry + include Singleton + + def vat_rate + Setting.registry_vat_prc.to_d * 100 + end + + def legal_address_country + Country.new(Setting.registry_country_code) + end +end diff --git a/app/models/type/vat_rate.rb b/app/models/type/vat_rate.rb new file mode 100644 index 000000000..5ee993211 --- /dev/null +++ b/app/models/type/vat_rate.rb @@ -0,0 +1,11 @@ +module Type + class VATRate < ActiveRecord::Type::Decimal + def type_cast_from_database(value) + super * 100 if value + end + + def type_cast_for_database(value) + super / 100.0 if value + end + end +end diff --git a/app/models/whois_record.rb b/app/models/whois_record.rb index bd16e0c99..e0ea4253d 100644 --- a/app/models/whois_record.rb +++ b/app/models/whois_record.rb @@ -9,20 +9,6 @@ class WhoisRecord < ActiveRecord::Base after_save :update_whois_server after_destroy :destroy_whois_record - class << self - def included - includes( - domain: [ - :registrant, - :registrar, - :nameservers, - { tech_contacts: :registrar }, - { admin_contacts: :registrar } - ] - ) - end - end - def self.find_by_name(name) WhoisRecord.where("lower(name) = ?", name.downcase) end diff --git a/app/views/admin/mail_templates/_form.haml b/app/views/admin/mail_templates/_form.haml index 739cce665..70873c22a 100644 --- a/app/views/admin/mail_templates/_form.haml +++ b/app/views/admin/mail_templates/_form.haml @@ -37,7 +37,7 @@ = f.email_field :bcc, class: 'form-control' .form-group .col-md-12 - = f.label :body, t(:html_body) + = f.label :body, t('admin.mail_templates.html_body') = liquid_help .col-md-12 = f.text_area(:body, class: 'form-control', size: '15x15') @@ -48,7 +48,7 @@ .col-md-12 = f.text_area(:text_body, class: 'form-control', size: '15x15') - %hr + %hr .row .col-md-12.text-right = button_tag(t(:save), class: 'btn btn-primary') diff --git a/app/views/admin/mail_templates/new.haml b/app/views/admin/mail_templates/new.haml index e5889e2b3..ecf2ea1e8 100644 --- a/app/views/admin/mail_templates/new.haml +++ b/app/views/admin/mail_templates/new.haml @@ -1,3 +1,3 @@ -= render 'shared/title', name: t(:new_mail_template) += render 'shared/title', name: t('admin.mail_templates.new_mail_template') = render 'form', mail_template: @mail_template diff --git a/app/views/admin/registrars/_billing.html.erb b/app/views/admin/registrars/_billing.html.erb index f3960233e..7a7e49fea 100644 --- a/app/views/admin/registrars/_billing.html.erb +++ b/app/views/admin/registrars/_billing.html.erb @@ -7,6 +7,9 @@
<%= Registrar.human_attribute_name :vat_no %>
<%= registrar.vat_no %>
+
<%= Registrar.human_attribute_name :vat_rate %>
+
<%= number_to_percentage(registrar.vat_rate, precision: 1) %>
+
<%= Registrar.human_attribute_name :accounting_customer_code %>
<%= registrar.accounting_customer_code %>
diff --git a/app/views/admin/registrars/form/_billing.html.erb b/app/views/admin/registrars/form/_billing.html.erb index a3adf1312..c87da8b6c 100644 --- a/app/views/admin/registrars/form/_billing.html.erb +++ b/app/views/admin/registrars/form/_billing.html.erb @@ -17,6 +17,19 @@ +
+
+ <%= f.label :vat_rate %> +
+
+
+ <%= f.number_field :vat_rate, min: 0, max: 99.9, step: 0.1, + class: 'form-control' %> +
%
+
+
+
+
<%= f.label :accounting_customer_code %> diff --git a/app/views/registrar/invoices/index.haml b/app/views/registrar/invoices/index.haml index b8c825c36..61d955708 100644 --- a/app/views/registrar/invoices/index.haml +++ b/app/views/registrar/invoices/index.haml @@ -33,11 +33,11 @@ .col-md-3 .form-group = f.label t(:minimum_total) - = f.search_field :sum_cache_gteq, class: 'form-control', placeholder: t(:minimum_total), autocomplete: 'off' + = f.search_field :total_gteq, class: 'form-control', placeholder: t(:minimum_total), autocomplete: 'off' .col-md-3 .form-group = f.label t(:maximum_total) - = f.search_field :sum_cache_lteq, class: 'form-control', placeholder: t(:maximum_total), autocomplete: 'off' + = f.search_field :total_lteq, class: 'form-control', placeholder: t(:maximum_total), autocomplete: 'off' .col-md-3{style: 'padding-top: 25px;'} %button.btn.btn-default   @@ -67,7 +67,7 @@ %td{class: 'text-danger'}= t(:unpaid) %td= l(x.due_date, format: :date_long) - %td= currency(x.sum) + %td= currency(x.total) .row .col-md-12 = paginate @invoices diff --git a/app/views/registrar/invoices/partials/_items.haml b/app/views/registrar/invoices/partials/_items.haml index 6ed5144a8..ebd94be53 100644 --- a/app/views/registrar/invoices/partials/_items.haml +++ b/app/views/registrar/invoices/partials/_items.haml @@ -20,13 +20,13 @@ %tfoot %tr %th{colspan: 3} - %th= t(:total_without_vat) - %td= currency(@invoice.sum_without_vat) + %th= Invoice.human_attribute_name :subtotal + %td= number_to_currency @invoice.subtotal %tr %th.no-border{colspan: 3} - %th= t('vat', vat_prc: (@invoice.vat_prc * 100).round) - %td= currency(@invoice.vat) + %th= "VAT #{number_to_percentage(@invoice.vat_rate, precision: 1)}" + %td= number_to_currency @invoice.vat_amount %tr %th.no-border{colspan: 3} %th= t(:total) - %td= currency(@invoice.sum) + %td= number_to_currency @invoice.total diff --git a/app/views/registrar/invoices/pdf.haml b/app/views/registrar/invoices/pdf.haml index c3f5fba75..3d6e111ef 100644 --- a/app/views/registrar/invoices/pdf.haml +++ b/app/views/registrar/invoices/pdf.haml @@ -238,16 +238,16 @@ %tfoot %tr %th{colspan: 3} - %th= t(:total_without_vat) - %td= "#{currency(@invoice.sum_without_vat)} #{@invoice.currency}" + %th= Invoice.human_attribute_name :subtotal + %td= number_to_currency @invoice.subtotal %tr %th.no-border{colspan: 3} - %th= t('vat', vat_prc: (@invoice.vat_prc * 100).round) - %td= "#{currency(@invoice.vat)} #{@invoice.currency}" + %th= "VAT #{number_to_percentage(@invoice.vat_rate, precision: 1)}" + %td= number_to_currency @invoice.vat_amount %tr %th.no-border{colspan: 3} %th= t(:total) - %td= "#{currency(@invoice.sum)} #{@invoice.currency}" + %td= number_to_currency @invoice.total #footer %hr diff --git a/config/application.rb b/config/application.rb index 57106c8ea..0d043fa5e 100644 --- a/config/application.rb +++ b/config/application.rb @@ -15,7 +15,13 @@ require 'rails/all' # you've limited to :test, :development, or :production. Bundler.require(*Rails.groups) -module Registry +# Add "db" to the list hosts on which you can run `rake db:setup:all` +# Only allow that in test and development. +if ['development', 'test'].include?(Rails.env) + ActiveRecord::Tasks::DatabaseTasks::LOCAL_HOSTS << "db" +end + +module DomainNameRegistry class Application < Rails::Application # Settings in config/environments/* take precedence over those specified here. # Application configuration should go into files in config/initializers diff --git a/config/database-example.yml b/config/database-example.yml index 8def2a36f..ca47a9979 100644 --- a/config/database-example.yml +++ b/config/database-example.yml @@ -4,14 +4,14 @@ # Registrant example is at database-example-registrant.yml file default: &default - host: localhost adapter: postgresql encoding: unicode - pool: 5 - username: registry - password: registry_pwd + pool: <%= ENV.fetch("APP_DB_MAX_THREADS") { 5 } %> + host: <%= ENV.fetch("APP_DBHOST") { "localhost" } %> + username: <%= ENV.fetch("APP_DBUSER") { "postgres" } %> + password: -# +# # Staging config For EPP, REPP, Admin, Registrar # @@ -27,7 +27,7 @@ api_log_staging: <<: *default database: registry_api_log_staging -# +# # Production config For EPP, REPP, Admin, Registrar # production: diff --git a/config/environments/test.rb b/config/environments/test.rb index df9ab2bbf..9b22ad426 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -43,6 +43,7 @@ Rails.application.configure do config.log_level = :debug config.active_job.queue_adapter = :test config.logger = ActiveSupport::Logger.new(nil) + config.active_support.test_order = :random # :random is the default in Rails 5 end # In this mode, any jobs you queue will be run in the same thread, synchronously diff --git a/config/initializers/eis_custom_active_record.rb b/config/initializers/eis_custom_active_record.rb deleted file mode 100644 index 60dcebeb9..000000000 --- a/config/initializers/eis_custom_active_record.rb +++ /dev/null @@ -1,8 +0,0 @@ -# Log all user issues raised by active record -# rubocop: disable Metrics/LineLength -class ActiveRecord::Base - after_validation do |m| - Rails.logger.info "USER MSG: ACTIVERECORD: #{m.class} ##{m.id} #{m.errors.full_messages} #{m.errors['epp_errors']}" if m.errors.present? - true - end -end diff --git a/config/locales/admin/mail_templates.en.yml b/config/locales/admin/mail_templates.en.yml new file mode 100644 index 000000000..2aa6ad52d --- /dev/null +++ b/config/locales/admin/mail_templates.en.yml @@ -0,0 +1,5 @@ +en: + admin: + mail_templates: + html_body: HTML body + new_mail_template: New mail template diff --git a/config/locales/admin/registrars.en.yml b/config/locales/admin/registrars.en.yml index 9acfca542..3586960b0 100644 --- a/config/locales/admin/registrars.en.yml +++ b/config/locales/admin/registrars.en.yml @@ -19,6 +19,12 @@ en: billing: header: Billing + edit: + header: Edit registrar + + billing: + header: Billing + create: created: Registrar has been successfully created diff --git a/config/locales/en.yml b/config/locales/en.yml index 1e65f7e29..4cdd5a41f 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -538,7 +538,6 @@ en: invoice_number: Invoice no. seller: 'Seller' prepayment: 'Prepayment' - vat: 'VAT (%{vat_prc}%)' unpaid: 'Unpaid' your_current_account_balance_is: 'Your current account balance is %{balance} %{currency}' billing: 'Billing' @@ -556,7 +555,6 @@ en: unit: 'Unit' price: 'Price' total: 'Total' - total_without_vat: 'Total without VAT' paid_at: 'Paid at' invoice: 'Invoice' bank_statements: 'Bank statements' @@ -731,7 +729,6 @@ en: is_registrant: 'Is registrant' force_delete_set_on_domain: 'Force delete set on domain %{domain_name}' mail_templates: Mail Templates - 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' welcome_to_eis_registrar_portal: 'Welcome to EIS Registrar portal' @@ -763,5 +760,6 @@ en: attributes: vat_no: VAT number + vat_rate: VAT rate ipv4: IPv4 ipv6: IPv6 diff --git a/config/schedule.rb b/config/schedule.rb index a136ba5c3..6413a9c56 100644 --- a/config/schedule.rb +++ b/config/schedule.rb @@ -46,10 +46,6 @@ if @cron_group == 'registry' runner 'DomainCron.start_expire_period' end - every 50.minutes do - runner 'DomainCron.start_delete_period' - end - every 52.minutes do runner 'DomainCron.start_redemption_grace_period' end diff --git a/db/migrate/20180228055259_add_registrars_vat_rate.rb b/db/migrate/20180228055259_add_registrars_vat_rate.rb new file mode 100644 index 000000000..5965b65cf --- /dev/null +++ b/db/migrate/20180228055259_add_registrars_vat_rate.rb @@ -0,0 +1,5 @@ +class AddRegistrarsVatRate < ActiveRecord::Migration + def change + add_column :registrars, :vat_rate, :decimal, precision: 4, scale: 3 + end +end diff --git a/db/migrate/20180228064342_rename_invoices_vat_prc_to_vat_rate.rb b/db/migrate/20180228064342_rename_invoices_vat_prc_to_vat_rate.rb new file mode 100644 index 000000000..89b4de724 --- /dev/null +++ b/db/migrate/20180228064342_rename_invoices_vat_prc_to_vat_rate.rb @@ -0,0 +1,5 @@ +class RenameInvoicesVatPrcToVatRate < ActiveRecord::Migration + def change + rename_column :invoices, :vat_prc, :vat_rate + end +end diff --git a/db/migrate/20180228070102_change_invoices_vat_rate_type.rb b/db/migrate/20180228070102_change_invoices_vat_rate_type.rb new file mode 100644 index 000000000..2c0790a18 --- /dev/null +++ b/db/migrate/20180228070102_change_invoices_vat_rate_type.rb @@ -0,0 +1,5 @@ +class ChangeInvoicesVatRateType < ActiveRecord::Migration + def change + change_column :invoices, :vat_rate, :decimal, precision: 4, scale: 3 + end +end diff --git a/db/migrate/20180228070431_change_invoice_vat_rate_to_null.rb b/db/migrate/20180228070431_change_invoice_vat_rate_to_null.rb new file mode 100644 index 000000000..37b8394b5 --- /dev/null +++ b/db/migrate/20180228070431_change_invoice_vat_rate_to_null.rb @@ -0,0 +1,5 @@ +class ChangeInvoiceVatRateToNull < ActiveRecord::Migration + def change + change_column_null :invoices, :vat_rate, true + end +end diff --git a/db/migrate/20180228074442_remove_registrars_vat.rb b/db/migrate/20180228074442_remove_registrars_vat.rb new file mode 100644 index 000000000..eb2bd44f1 --- /dev/null +++ b/db/migrate/20180228074442_remove_registrars_vat.rb @@ -0,0 +1,5 @@ +class RemoveRegistrarsVat < ActiveRecord::Migration + def change + remove_column :registrars, :vat, :boolean + end +end diff --git a/db/migrate/20180310142630_remove_invoices_invoice_type.rb b/db/migrate/20180310142630_remove_invoices_invoice_type.rb new file mode 100644 index 000000000..f8cddadf9 --- /dev/null +++ b/db/migrate/20180310142630_remove_invoices_invoice_type.rb @@ -0,0 +1,5 @@ +class RemoveInvoicesInvoiceType < ActiveRecord::Migration + def change + remove_column :invoices, :invoice_type, :string + end +end diff --git a/db/migrate/20180313090437_rename_invoices_sum_cache_to_total.rb b/db/migrate/20180313090437_rename_invoices_sum_cache_to_total.rb new file mode 100644 index 000000000..43e827dfc --- /dev/null +++ b/db/migrate/20180313090437_rename_invoices_sum_cache_to_total.rb @@ -0,0 +1,5 @@ +class RenameInvoicesSumCacheToTotal < ActiveRecord::Migration + def change + rename_column :invoices, :sum_cache, :total + end +end diff --git a/db/migrate/20180313124751_change_invoices_total_to_not_null.rb b/db/migrate/20180313124751_change_invoices_total_to_not_null.rb new file mode 100644 index 000000000..fb31f4084 --- /dev/null +++ b/db/migrate/20180313124751_change_invoices_total_to_not_null.rb @@ -0,0 +1,5 @@ +class ChangeInvoicesTotalToNotNull < ActiveRecord::Migration + def change + change_column_null :invoices, :total, false + end +end diff --git a/db/migrate/20180314122722_add_invoices_buyer_vat_no.rb b/db/migrate/20180314122722_add_invoices_buyer_vat_no.rb new file mode 100644 index 000000000..83f9f9abd --- /dev/null +++ b/db/migrate/20180314122722_add_invoices_buyer_vat_no.rb @@ -0,0 +1,5 @@ +class AddInvoicesBuyerVatNo < ActiveRecord::Migration + def change + add_column :invoices, :buyer_vat_no, :string + end +end diff --git a/db/structure.sql b/db/structure.sql index 1238d72f9..616a83c64 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -997,13 +997,12 @@ CREATE TABLE invoices ( id integer NOT NULL, created_at timestamp without time zone NOT NULL, updated_at timestamp without time zone NOT NULL, - invoice_type character varying NOT NULL, due_date timestamp without time zone NOT NULL, payment_term character varying, currency character varying NOT NULL, description character varying, reference_no character varying, - vat_prc numeric(10,2) NOT NULL, + vat_rate numeric(4,3), paid_at timestamp without time zone, seller_id integer, seller_name character varying NOT NULL, @@ -1036,8 +1035,9 @@ CREATE TABLE invoices ( updator_str character varying, number integer, cancelled_at timestamp without time zone, - sum_cache numeric(10,2), - in_directo boolean DEFAULT false + total numeric(10,2) NOT NULL, + in_directo boolean DEFAULT false, + buyer_vat_no character varying ); @@ -2153,11 +2153,11 @@ CREATE TABLE registrars ( code character varying NOT NULL, website character varying, accounting_customer_code character varying NOT NULL, - vat boolean, legacy_id integer, reference_no character varying, test_registrar boolean DEFAULT false, - language character varying NOT NULL + language character varying NOT NULL, + vat_rate numeric(4,3) ); @@ -4668,6 +4668,16 @@ INSERT INTO schema_migrations (version) VALUES ('20180214213743'); INSERT INTO schema_migrations (version) VALUES ('20180218004148'); +INSERT INTO schema_migrations (version) VALUES ('20180228055259'); + +INSERT INTO schema_migrations (version) VALUES ('20180228064342'); + +INSERT INTO schema_migrations (version) VALUES ('20180228070102'); + +INSERT INTO schema_migrations (version) VALUES ('20180228070431'); + +INSERT INTO schema_migrations (version) VALUES ('20180228074442'); + INSERT INTO schema_migrations (version) VALUES ('20180306180401'); INSERT INTO schema_migrations (version) VALUES ('20180306181538'); @@ -4694,5 +4704,13 @@ INSERT INTO schema_migrations (version) VALUES ('20180309053921'); INSERT INTO schema_migrations (version) VALUES ('20180309054510'); +INSERT INTO schema_migrations (version) VALUES ('20180310142630'); + +INSERT INTO schema_migrations (version) VALUES ('20180313090437'); + +INSERT INTO schema_migrations (version) VALUES ('20180313124751'); + +INSERT INTO schema_migrations (version) VALUES ('20180314122722'); + INSERT INTO schema_migrations (version) VALUES ('20180327151906'); diff --git a/doc/models_complete.svg b/doc/models_complete.svg index d014e0c8d..644822637 100644 --- a/doc/models_complete.svg +++ b/doc/models_complete.svg @@ -1488,7 +1488,6 @@ zip :string code :string url :string -vat :boolean legacy_id :integer reference_no :string @@ -1613,13 +1612,12 @@ id :integer created_at :datetime updated_at :datetime -invoice_type :string due_date :datetime payment_term :string currency :string description :string reference_no :string -vat_prc :decimal +vat_rate :decimal paid_at :datetime seller_id :integer seller_name :string @@ -1652,7 +1650,7 @@ updator_str :string number :integer cancelled_at :datetime -sum_cache :decimal +total :decimal Registrar->Invoice diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 000000000..5c5f523de --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,33 @@ +version: "3.2" + +services: + app: + tty: true + stdin_open: true + build: + context: . + dockerfile: Dockerfile + links: + - db + environment: + - APP_DBHOST=db + volumes: + - .:/opt/webapps/app + ports: + - "3000:3000" + command: bash -c "rm -f tmp/pids/server.pid && bundle exec rails server -p 3000 -b '0.0.0.0'" + + web: + image: nginx + volumes: + - ./docker/nginx.template:/etc/nginx/conf.d/nginx.template + ports: + - "80:80" + links: + - app + environment: + APP: 'app' + command: /bin/bash -c "envsubst '$$APP' < /etc/nginx/conf.d/nginx.template > /etc/nginx/conf.d/default.conf && nginx -g 'daemon off;'" + + db: + image: postgres:9.4 diff --git a/docker/docker_dev.sh b/docker/docker_dev.sh new file mode 100755 index 000000000..f5592517f --- /dev/null +++ b/docker/docker_dev.sh @@ -0,0 +1,6 @@ +# /bin/sh +docker-compose down +docker-compose build +docker-compose run app rake db:setup:all +docker-compose run app rake db:migrate +docker-compose run app rake dev:prime diff --git a/docker/docker_test.sh b/docker/docker_test.sh new file mode 100755 index 000000000..7239f78a9 --- /dev/null +++ b/docker/docker_test.sh @@ -0,0 +1,8 @@ +# /bin/sh +docker-compose down +docker-compose build + +# Setup test database +docker-compose run app rake db:setup:all test +# Finally run tests to check if everything is in order +docker-compose run app rspec diff --git a/docker/nginx.template b/docker/nginx.template new file mode 100644 index 000000000..50f6e8548 --- /dev/null +++ b/docker/nginx.template @@ -0,0 +1,29 @@ +log_format le_json '{ "time": "$time_iso8601", ' + '"remote_addr": "$remote_addr", ' + '"remote_user": "$remote_user", ' + '"body_bytes_sent": "$body_bytes_sent", ' + '"request_time": "$request_time", ' + '"status": "$status", ' + '"request": "$request", ' + '"request_method": "$request_method", ' + '"http_referrer": "$http_referer", ' + '"http_user_agent": "$http_user_agent" }'; + +upstream app { + server ${APP}:3000; +} + +server { + listen 80; + + access_log /var/log/nginx/access.log le_json; + + location / { + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header Host $http_host; + proxy_redirect off; + proxy_pass http://app; + break; + } +} diff --git a/lib/tasks/import.rake b/lib/tasks/import.rake index 3d334b554..d953c72c9 100644 --- a/lib/tasks/import.rake +++ b/lib/tasks/import.rake @@ -87,7 +87,6 @@ namespace :import do zip: x.postalcode.try(:strip), url: x.url.try(:strip), accounting_customer_code: x.directo_handle.try(:strip), - vat: x.vat, legacy_id: x.id, creator_str: user, updator_str: user, diff --git a/spec/factories/invoice.rb b/spec/factories/invoice.rb index 7eeed32b9..42ac54812 100644 --- a/spec/factories/invoice.rb +++ b/spec/factories/invoice.rb @@ -3,12 +3,11 @@ FactoryBot.define do buyer_name 'Registrar 1' currency { 'EUR' } due_date { Time.zone.now.to_date + 1.day } - invoice_type 'DEB' seller_iban { '123' } seller_name { 'EIS' } seller_city { 'Tallinn' } seller_street { 'Paldiski mnt. 123' } - vat_prc 0.2 + vat_rate 0.2 buyer { FactoryBot.create(:registrar) } after :build do |invoice| diff --git a/spec/models/invoice_spec.rb b/spec/models/invoice_spec.rb index 49d15310f..14747c9c1 100644 --- a/spec/models/invoice_spec.rb +++ b/spec/models/invoice_spec.rb @@ -13,10 +13,8 @@ describe Invoice do "Currency is missing", "Due date is missing", "Invoice items is missing", - "Invoice type is missing", "Seller iban is missing", "Seller name is missing", - "Vat prc is missing" ]) end @@ -52,20 +50,6 @@ describe Invoice do @invoice.seller_address.should == 'Paldiski mnt. 123, Tallinn' end - it 'should calculate sums correctly' do - @invoice = create(:invoice) - @invoice.vat_prc.should == BigDecimal.new('0.2') - @invoice.sum_without_vat.should == BigDecimal.new('300.0') - @invoice.vat.should == BigDecimal.new('60.0') - @invoice.sum.should == BigDecimal.new('360.0') - - ii = @invoice.items.first - ii.item_sum_without_vat.should == BigDecimal.new('150.0') - - ii = @invoice.items.last - ii.item_sum_without_vat.should == BigDecimal.new('150.0') - end - it 'should cancel overdue invoices' do create(:invoice, created_at: Time.zone.now - 35.days, due_date: Time.zone.now - 30.days) Invoice.cancel_overdue_invoices diff --git a/test/fixtures/billing/prices.yml b/test/fixtures/billing/prices.yml index ef2cd09a7..17e34d3f2 100644 --- a/test/fixtures/billing/prices.yml +++ b/test/fixtures/billing/prices.yml @@ -1,7 +1,31 @@ -cash: - duration: 1 year - price_cents: 500 +create_one_month: + duration: 1 month + price_cents: 100 operation_category: create valid_from: 2010-07-05 valid_to: 2010-07-05 zone: test + +renew_one_month: + duration: 1 month + price_cents: 100 + operation_category: renew + valid_from: 2010-07-05 + valid_to: 2010-07-05 + zone: test + +create_one_year: + duration: 1 year + price_cents: 1000 + operation_category: create + valid_from: 2010-07-05 + valid_to: 2010-07-05 + zone: test + +renew_one_year: + duration: 1 year + price_cents: 1000 + operation_category: renew + valid_from: 2010-07-05 + valid_to: 2010-07-05 + zone: test diff --git a/test/fixtures/domains.yml b/test/fixtures/domains.yml index b2b2a24b5..53de2837b 100644 --- a/test/fixtures/domains.yml +++ b/test/fixtures/domains.yml @@ -40,7 +40,7 @@ metro: invalid: name: invalid.test - transfer_code: any - valid_to: 2010-07-05 + transfer_code: 1438d6 + valid_to: <%= Time.zone.parse('2010-07-05').utc.to_s(:db) %> registrar: bestnames registrant: invalid diff --git a/test/fixtures/invoice_items.yml b/test/fixtures/invoice_items.yml index 417203a51..9c37ece9a 100644 --- a/test/fixtures/invoice_items.yml +++ b/test/fixtures/invoice_items.yml @@ -1,13 +1,13 @@ -DEFAULTS: &DEFAULTS +one: description: Acme services + price: 5 + amount: 1 + unit: pc + invoice: valid + +two: + description: Acme services + price: 5 amount: 2 unit: pc - price: 5 - -valid: - <<: *DEFAULTS - invoice: valid - -another: - <<: *DEFAULTS invoice: valid diff --git a/test/fixtures/invoices.yml b/test/fixtures/invoices.yml index 7a1c85dd1..c395da425 100644 --- a/test/fixtures/invoices.yml +++ b/test/fixtures/invoices.yml @@ -1,12 +1,13 @@ DEFAULTS: &DEFAULTS created_at: <%= Date.parse '2010-07-05' %> due_date: <%= Date.parse '2010-07-06' %> - invoice_type: DEB currency: EUR seller_name: John Doe seller_iban: 1234 + buyer: bestnames buyer_name: Jane Doe - vat_prc: 0.2 + vat_rate: 0.1 + total: 16.50 valid: <<: *DEFAULTS @@ -21,7 +22,7 @@ cancelled: paid: <<: *DEFAULTS - sum_cache: 1 + total: 1 outstanding: <<: *DEFAULTS diff --git a/test/fixtures/registrars.yml b/test/fixtures/registrars.yml index b0cc371a7..6ff6d2dc9 100644 --- a/test/fixtures/registrars.yml +++ b/test/fixtures/registrars.yml @@ -17,7 +17,8 @@ goodnames: reg_no: 12345 code: goodnames email: info@goodnames.test - country_code: US + country_code: DE + vat_no: DE123456789 accounting_customer_code: goodnames language: en @@ -29,3 +30,23 @@ not_in_use: country_code: US accounting_customer_code: any language: en + +complete: + name: Complete Names + reg_no: 123456 + code: completenames + email: completenames@example.com + country_code: US + accounting_customer_code: US0001 + language: en + vat_no: US12345 + vat_rate: 0.05 + +not_in_use: + name: any + reg_no: any + code: any + email: any@example.com + country_code: US + accounting_customer_code: any + language: en diff --git a/test/integration/admin/domains/force_delete_test.rb b/test/integration/admin/domains/force_delete_test.rb index 731de151b..0ef017c11 100644 --- a/test/integration/admin/domains/force_delete_test.rb +++ b/test/integration/admin/domains/force_delete_test.rb @@ -3,7 +3,7 @@ require 'test_helper' class AdminAreaDomainForceDeleteTest < ActionDispatch::IntegrationTest include ActionMailer::TestHelper - def setup + setup do login_as users(:admin) @domain = domains(:shop) ActionMailer::Base.deliveries.clear diff --git a/test/integration/admin/domains_test.rb b/test/integration/admin/domains_test.rb index 1dfb0dfd1..81261f017 100644 --- a/test/integration/admin/domains_test.rb +++ b/test/integration/admin/domains_test.rb @@ -1,7 +1,7 @@ require 'test_helper' class AdminDomainsTestTest < ActionDispatch::IntegrationTest - def setup + setup do login_as users(:admin) end diff --git a/test/integration/admin/mail_templates/new_test.rb b/test/integration/admin/mail_templates/new_test.rb new file mode 100644 index 000000000..42d50ef43 --- /dev/null +++ b/test/integration/admin/mail_templates/new_test.rb @@ -0,0 +1,14 @@ +require 'test_helper' + +class AdminAreaNewMailTemplateTest < ActionDispatch::IntegrationTest + setup do + login_as users(:admin) + end + + def test_new_mail_template_does_not_throw_template_error + visit admin_mail_templates_url + click_link_or_button 'New' + assert_text "HTML body" + assert_text "New mail template" + end +end diff --git a/test/integration/admin/registrars/delete_test.rb b/test/integration/admin/registrars/delete_test.rb index 34eb142bf..737c830c1 100644 --- a/test/integration/admin/registrars/delete_test.rb +++ b/test/integration/admin/registrars/delete_test.rb @@ -1,7 +1,7 @@ require 'test_helper' class AdminAreaDeleteRegistrarTest < ActionDispatch::IntegrationTest - def setup + setup do login_as users(:admin) end diff --git a/test/integration/admin/registrars/details_test.rb b/test/integration/admin/registrars/details_test.rb new file mode 100644 index 000000000..3c2f39072 --- /dev/null +++ b/test/integration/admin/registrars/details_test.rb @@ -0,0 +1,18 @@ +require 'test_helper' + +class AdminAreaRegistrarDetailsTest < ActionDispatch::IntegrationTest + include ActionView::Helpers::NumberHelper + + setup do + login_as users(:admin) + @registrar = registrars(:complete) + end + + def test_registrar_details + visit admin_registrar_path(@registrar) + assert_text 'Accounting customer code US0001' + assert_text 'VAT number US12345' + assert_text 'VAT rate 5.0%' + assert_text 'Language English' + end +end diff --git a/test/integration/admin/registrars/edit_test.rb b/test/integration/admin/registrars/edit_test.rb index af420b179..22b93657d 100644 --- a/test/integration/admin/registrars/edit_test.rb +++ b/test/integration/admin/registrars/edit_test.rb @@ -1,7 +1,7 @@ require 'test_helper' class AdminAreaEditRegistrarTest < ActionDispatch::IntegrationTest - def setup + setup do login_as users(:admin) @registrar = registrars(:bestnames) end diff --git a/test/integration/admin/registrars/new_test.rb b/test/integration/admin/registrars/new_test.rb index 61a7a43be..d2efc31a2 100644 --- a/test/integration/admin/registrars/new_test.rb +++ b/test/integration/admin/registrars/new_test.rb @@ -1,7 +1,7 @@ require 'test_helper' class AdminAreaNewRegistrarTest < ActionDispatch::IntegrationTest - def setup + setup do login_as users(:admin) end @@ -12,6 +12,7 @@ class AdminAreaNewRegistrarTest < ActionDispatch::IntegrationTest fill_in 'Name', with: 'Brand new names' fill_in 'Reg no', with: '55555555' fill_in 'Contact e-mail', with: 'test@example.com' + select 'United States', from: 'Country' fill_in 'Accounting customer code', with: 'test' fill_in 'Code', with: 'test' diff --git a/test/integration/admin/registrars/show_registrar_test.rb b/test/integration/admin/registrars/show_registrar_test.rb deleted file mode 100644 index cb310317c..000000000 --- a/test/integration/admin/registrars/show_registrar_test.rb +++ /dev/null @@ -1,19 +0,0 @@ -require 'test_helper' - -class ShowRegistrarTest < ActionDispatch::IntegrationTest - include ActionView::Helpers::NumberHelper - - def setup - login_as users(:admin) - @registrar = registrars(:bestnames) - visit admin_registrar_path(@registrar) - end - - def test_accounting_customer_code - assert_text 'bestnames' - end - - def test_language - assert_text 'Language English' - end -end diff --git a/test/integration/api/domain_transfers_test.rb b/test/integration/api/domain_transfers_test.rb index 08ce2e34c..04301e3e3 100644 --- a/test/integration/api/domain_transfers_test.rb +++ b/test/integration/api/domain_transfers_test.rb @@ -1,7 +1,7 @@ require 'test_helper' class APIDomainTransfersTest < ActionDispatch::IntegrationTest - def setup + setup do @domain = domains(:shop) @new_registrar = registrars(:goodnames) Setting.transfer_wait_time = 0 # Auto-approval diff --git a/test/integration/epp/domain/create/transfer_code_test.rb b/test/integration/epp/domain/create/transfer_code_test.rb index 276386851..60133cb35 100644 --- a/test/integration/epp/domain/create/transfer_code_test.rb +++ b/test/integration/epp/domain/create/transfer_code_test.rb @@ -1,7 +1,7 @@ require 'test_helper' class EppDomainCreateTransferCodeTest < ActionDispatch::IntegrationTest - def setup + setup do travel_to Time.zone.parse('2010-07-05') end diff --git a/test/integration/epp/domain/domain_renew_test.rb b/test/integration/epp/domain/domain_renew_test.rb new file mode 100644 index 000000000..338ecf766 --- /dev/null +++ b/test/integration/epp/domain/domain_renew_test.rb @@ -0,0 +1,32 @@ +require 'test_helper' + +class EppDomainRenewTest < ActionDispatch::IntegrationTest + self.use_transactional_fixtures = false + + setup do + travel_to Time.zone.parse('2010-07-05') + end + + def test_domain_cannot_be_renewed_when_invalid + request_xml = <<-XML + + + + + + invalid.test + 2010-07-05 + 1 + + + + + XML + + assert_no_changes -> { domains(:invalid).valid_to } do + post '/epp/command/renew', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames' + end + assert_equal '2304', Nokogiri::XML(response.body).at_css('result')[:code], + Nokogiri::XML(response.body).css('result').text + end +end diff --git a/test/integration/epp/domain/transfer/request_test.rb b/test/integration/epp/domain/transfer/request_test.rb index 508ec4334..f3ea644fc 100644 --- a/test/integration/epp/domain/transfer/request_test.rb +++ b/test/integration/epp/domain/transfer/request_test.rb @@ -1,7 +1,7 @@ require 'test_helper' class EppDomainTransferRequestTest < ActionDispatch::IntegrationTest - def setup + setup do @domain = domains(:shop) @new_registrar = registrars(:goodnames) Setting.transfer_wait_time = 0 diff --git a/test/integration/epp/login/session_limit_test.rb b/test/integration/epp/login/session_limit_test.rb index 513699415..b2fdfe88f 100644 --- a/test/integration/epp/login/session_limit_test.rb +++ b/test/integration/epp/login/session_limit_test.rb @@ -1,7 +1,7 @@ require 'test_helper' class EppLoginSessionLimitTest < ActionDispatch::IntegrationTest - def setup + setup do travel_to Time.zone.parse('2010-07-05') EppSession.delete_all end diff --git a/test/integration/registrant/domains_test.rb b/test/integration/registrant/domains_test.rb index 9b1151b84..db1acfeea 100644 --- a/test/integration/registrant/domains_test.rb +++ b/test/integration/registrant/domains_test.rb @@ -1,7 +1,7 @@ require 'test_helper' class RegistrantDomainsTest < ActionDispatch::IntegrationTest - def setup + setup do login_as users(:registrant) Setting.days_to_keep_business_registry_cache = 1 diff --git a/test/integration/registrar/billing/balance_top_up_test.rb b/test/integration/registrar/billing/balance_top_up_test.rb new file mode 100644 index 000000000..c77c9ff37 --- /dev/null +++ b/test/integration/registrar/billing/balance_top_up_test.rb @@ -0,0 +1,25 @@ +require 'test_helper' + +class BalanceTopUpTest < ActionDispatch::IntegrationTest + setup do + login_as users(:api_bestnames) + end + + def test_creates_new_invoice + Setting.registry_vat_prc = 0.1 + + visit registrar_invoices_url + click_link_or_button 'Add deposit' + fill_in 'Amount', with: '25.5' + + assert_difference 'Invoice.count' do + click_link_or_button 'Add' + end + + invoice = Invoice.last + + assert_equal BigDecimal(10), invoice.vat_rate + assert_equal BigDecimal('28.05'), invoice.total + assert_text 'Please pay the following invoice' + end +end diff --git a/test/integration/registrar/domain_transfers_test.rb b/test/integration/registrar/domain_transfers_test.rb index e29a11070..4cd6fc66c 100644 --- a/test/integration/registrar/domain_transfers_test.rb +++ b/test/integration/registrar/domain_transfers_test.rb @@ -1,7 +1,7 @@ require 'test_helper' class RegistrarDomainTransfersTest < ActionDispatch::IntegrationTest - def setup + setup do WebMock.reset! login_as users(:api_goodnames) end diff --git a/test/integration/registrar/domains_test.rb b/test/integration/registrar/domains_test.rb index f3936c578..35411815f 100644 --- a/test/integration/registrar/domains_test.rb +++ b/test/integration/registrar/domains_test.rb @@ -9,7 +9,7 @@ class RegistrarDomainsTest < ActionDispatch::IntegrationTest Domain,Transfer code,Registrant name,Registrant code,Date of expiry library.test,45118f5,Acme Ltd,acme-ltd-001,2010-07-05 shop.test,65078d5,John,john-001,2010-07-05 - invalid.test,any,any,any,2010-07-05 + invalid.test,1438d6,any,any,2010-07-05 airport.test,55438j5,John,john-001,2010-07-05 CSV diff --git a/test/integration/registrar/nameserver_replacement_test.rb b/test/integration/registrar/nameserver_replacement_test.rb index 9523d2bbd..8ed0f9419 100644 --- a/test/integration/registrar/nameserver_replacement_test.rb +++ b/test/integration/registrar/nameserver_replacement_test.rb @@ -1,7 +1,7 @@ require 'test_helper' class RegistrarNameserverReplacementTest < ActionDispatch::IntegrationTest - def setup + setup do WebMock.reset! login_as users(:api_goodnames) end diff --git a/test/models/contact/contact_test.rb b/test/models/contact/contact_test.rb index 286ded534..b2a7a02a8 100644 --- a/test/models/contact/contact_test.rb +++ b/test/models/contact/contact_test.rb @@ -1,7 +1,7 @@ require 'test_helper' class ContactTest < ActiveSupport::TestCase - def setup + setup do @contact = contacts(:john) end diff --git a/test/models/contact/identical_test.rb b/test/models/contact/identical_test.rb index 61d0946bc..61e960a7e 100644 --- a/test/models/contact/identical_test.rb +++ b/test/models/contact/identical_test.rb @@ -12,11 +12,16 @@ class ContactIdenticalTest < ActiveSupport::TestCase org_name ] - def setup + setup do + @original_address_processing = Setting.address_processing @contact = contacts(:william) @identical = contacts(:identical_to_william) end + teardown do + Setting.address_processing = @original_address_processing + end + def test_returns_identical assert_equal @identical, @contact.identical(@identical.registrar) end @@ -33,30 +38,24 @@ class ContactIdenticalTest < ActiveSupport::TestCase assert_nil @contact.identical(@identical.registrar) end - def test_takes_address_into_account_when_processing_enabled + def test_takes_address_into_account_when_address_processing_is_on + Setting.address_processing = true + Contact.address_attribute_names.each do |attribute| previous_value = @identical.public_send(attribute) @identical.update_attribute(attribute, 'other') - - Contact.stub :address_processing?, true do - assert_nil @contact.identical(@identical.registrar) - end - + assert_nil @contact.identical(@identical.registrar) @identical.update_attribute(attribute, previous_value) end end - def test_ignores_address_when_processing_disabled + def test_ignores_address_when_address_processing_is_off Setting.address_processing = false Contact.address_attribute_names.each do |attribute| previous_value = @identical.public_send(attribute) @identical.update_attribute(attribute, 'other') - - Contact.stub :address_processing?, false do - assert_equal @identical, @contact.identical(@identical.registrar) - end - + assert_equal @identical, @contact.identical(@identical.registrar) @identical.update_attribute(attribute, previous_value) end end diff --git a/test/models/contact/postal_address_test.rb b/test/models/contact/postal_address_test.rb index 645207a9f..baf06d9f4 100644 --- a/test/models/contact/postal_address_test.rb +++ b/test/models/contact/postal_address_test.rb @@ -1,10 +1,15 @@ require 'test_helper' class ContactPostalAddressTest < ActiveSupport::TestCase - def setup + setup do + @original_address_processing = Setting.address_processing @contact = contacts(:john) end + teardown do + Setting.address_processing = @original_address_processing + end + def test_invalid_if_country_code_is_invalid_and_address_processing_is_on Setting.address_processing = true @contact.country_code = 'invalid' diff --git a/test/models/contact/transfer_test.rb b/test/models/contact/transfer_test.rb index a695c112a..cc35cfdea 100644 --- a/test/models/contact/transfer_test.rb +++ b/test/models/contact/transfer_test.rb @@ -1,7 +1,7 @@ require 'test_helper' class ContactTransferTest < ActiveSupport::TestCase - def setup + setup do @contact = contacts(:john) @new_registrar = registrars(:goodnames) end diff --git a/test/models/domain/domain_test.rb b/test/models/domain/domain_test.rb index c67c8ee87..9be97a8ec 100644 --- a/test/models/domain/domain_test.rb +++ b/test/models/domain/domain_test.rb @@ -1,7 +1,7 @@ require 'test_helper' class DomainTest < ActiveSupport::TestCase - def setup + setup do @domain = domains(:shop) end diff --git a/test/models/domain/transferable_test.rb b/test/models/domain/transferable_test.rb index 35bf5f96b..56b2b21fb 100644 --- a/test/models/domain/transferable_test.rb +++ b/test/models/domain/transferable_test.rb @@ -1,7 +1,7 @@ require 'test_helper' class DomainTransferableTest < ActiveSupport::TestCase - def setup + setup do @domain = domains(:shop) @new_registrar = registrars(:goodnames) end diff --git a/test/models/domain_transfer_test.rb b/test/models/domain_transfer_test.rb index 7f11caf80..9dde09fa7 100644 --- a/test/models/domain_transfer_test.rb +++ b/test/models/domain_transfer_test.rb @@ -1,7 +1,7 @@ require 'test_helper' class DomainTransferTest < ActiveSupport::TestCase - def setup + setup do @domain_transfer = domain_transfers(:shop) end diff --git a/test/models/epp_session_test.rb b/test/models/epp_session_test.rb index fd795b23c..6f90e2445 100644 --- a/test/models/epp_session_test.rb +++ b/test/models/epp_session_test.rb @@ -1,7 +1,7 @@ require 'test_helper' class EppSessionTest < ActiveSupport::TestCase - def setup + setup do @epp_session = epp_sessions(:api_bestnames) end diff --git a/test/models/invoice_test.rb b/test/models/invoice_test.rb new file mode 100644 index 000000000..45ca57417 --- /dev/null +++ b/test/models/invoice_test.rb @@ -0,0 +1,109 @@ +require 'test_helper' + +class InvoiceTest < ActiveSupport::TestCase + setup do + @invoice = invoices(:valid) + end + + def test_valid + assert @invoice.valid? + end + + def test_optional_vat_rate + @invoice.vat_rate = nil + assert @invoice.valid? + end + + def test_vat_rate_validation + @invoice.vat_rate = -1 + assert @invoice.invalid? + + @invoice.vat_rate = 0 + assert @invoice.valid? + + @invoice.vat_rate = 99.9 + assert @invoice.valid? + + @invoice.vat_rate = 100 + assert @invoice.invalid? + end + + def test_serializes_and_deserializes_vat_rate + invoice = @invoice.dup + invoice.invoice_items = @invoice.invoice_items + invoice.vat_rate = BigDecimal('25.5') + invoice.save! + invoice.reload + assert_equal BigDecimal('25.5'), invoice.vat_rate + end + + def test_vat_rate_defaults_to_effective_vat_rate_of_a_registrar + registrar = registrars(:bestnames) + invoice = @invoice.dup + invoice.vat_rate = nil + invoice.buyer = registrar + invoice.invoice_items = @invoice.invoice_items + + registrar.stub(:effective_vat_rate, BigDecimal(55)) do + invoice.save! + end + + assert_equal BigDecimal(55), invoice.vat_rate + end + + def test_vat_rate_cannot_be_updated + @invoice.vat_rate = BigDecimal(21) + @invoice.save! + @invoice.reload + refute_equal BigDecimal(21), @invoice.vat_rate + end + + def test_calculates_vat_amount + assert_equal BigDecimal('1.5'), @invoice.vat_amount + end + + def test_vat_amount_is_zero_when_vat_rate_is_blank + @invoice.vat_rate = nil + assert_equal 0, @invoice.vat_amount + end + + def test_calculates_subtotal + line_item = InvoiceItem.new + invoice = Invoice.new(invoice_items: [line_item, line_item]) + + line_item.stub(:item_sum_without_vat, BigDecimal('2.5')) do + assert_equal BigDecimal(5), invoice.subtotal + end + end + + def test_returns_persisted_total + assert_equal BigDecimal('16.50'), @invoice.total + end + + def test_calculates_total + line_item = InvoiceItem.new + invoice = Invoice.new + invoice.vat_rate = 10 + invoice.invoice_items = [line_item, line_item] + + line_item.stub(:item_sum_without_vat, BigDecimal('2.5')) do + assert_equal BigDecimal('5.50'), invoice.total + end + end + + def test_valid_without_buyer_vat_no + @invoice.buyer_vat_no = '' + assert @invoice.valid? + end + + def test_buyer_vat_no_is_taken_from_registrar_by_default + registrar = registrars(:bestnames) + registrar.vat_no = 'US1234' + invoice = @invoice.dup + invoice.buyer_vat_no = nil + invoice.buyer = registrar + invoice.invoice_items = @invoice.invoice_items + invoice.save! + assert_equal 'US1234', invoice.buyer_vat_no + end +end diff --git a/test/models/message_test.rb b/test/models/message_test.rb index 1c7c7bad1..5c557150d 100644 --- a/test/models/message_test.rb +++ b/test/models/message_test.rb @@ -1,7 +1,7 @@ require 'test_helper' class MessageTest < ActiveSupport::TestCase - def setup + setup do @message = messages(:greeting) end diff --git a/test/models/nameserver/glue_record_test.rb b/test/models/nameserver/glue_record_test.rb index 7d5e39d8d..599f04ec6 100644 --- a/test/models/nameserver/glue_record_test.rb +++ b/test/models/nameserver/glue_record_test.rb @@ -1,7 +1,7 @@ require 'test_helper' class NameserverGlueRecordTest < ActiveSupport::TestCase - def setup + setup do @nameserver = nameservers(:shop_ns1) end diff --git a/test/models/nameserver_test.rb b/test/models/nameserver_test.rb index 5a552a7ee..8f2a07334 100644 --- a/test/models/nameserver_test.rb +++ b/test/models/nameserver_test.rb @@ -1,7 +1,7 @@ require 'test_helper' class NameserverTest < ActiveSupport::TestCase - def setup + setup do @nameserver = nameservers(:shop_ns1) end diff --git a/test/models/registrar/code_test.rb b/test/models/registrar/code_test.rb index 7b5188878..579e4d660 100644 --- a/test/models/registrar/code_test.rb +++ b/test/models/registrar/code_test.rb @@ -1,7 +1,7 @@ require 'test_helper' class RegistrarCodeTest < ActiveSupport::TestCase - def setup + setup do @registrar = registrars(:bestnames).dup end diff --git a/test/models/registrar/delete_test.rb b/test/models/registrar/delete_test.rb index 2020c76dc..e9cb20acf 100644 --- a/test/models/registrar/delete_test.rb +++ b/test/models/registrar/delete_test.rb @@ -1,7 +1,7 @@ require 'test_helper' class DeleteRegistrarTest < ActiveSupport::TestCase - def setup + setup do @registrar = registrars(:not_in_use) end diff --git a/test/models/registrar/vat_test.rb b/test/models/registrar/vat_test.rb new file mode 100644 index 000000000..2dc5de3ce --- /dev/null +++ b/test/models/registrar/vat_test.rb @@ -0,0 +1,97 @@ +require 'test_helper' + +class RegistrarVATTest < ActiveSupport::TestCase + setup do + @registrar = registrars(:bestnames) + end + + def test_optional_vat_no + @registrar.vat_no = '' + assert @registrar.valid? + + @registrar.vat_no = 'any' + assert @registrar.valid? + end + + def test_apply_vat_rate_from_registry_when_registrar_is_local_vat_payer + Setting.registry_country_code = 'US' + @registrar.country_code = 'US' + + Registry.instance.stub(:vat_rate, BigDecimal('5.5')) do + assert_equal BigDecimal('5.5'), @registrar.effective_vat_rate + end + end + + def test_require_no_vat_rate_when_registrar_is_local_vat_payer + @registrar.vat_rate = 1 + assert @registrar.invalid? + + @registrar.vat_rate = nil + assert @registrar.valid? + end + + def test_apply_vat_rate_from_registrar_when_registrar_is_foreign_vat_payer + Setting.registry_country_code = 'US' + @registrar.country_code = 'DE' + @registrar.vat_rate = BigDecimal('5.6') + assert_equal BigDecimal('5.6'), @registrar.effective_vat_rate + end + + def test_require_vat_rate_when_registrar_is_foreign_vat_payer_and_vat_no_is_absent + @registrar.country_code = 'DE' + @registrar.vat_no = '' + + @registrar.vat_rate = '' + assert @registrar.invalid? + assert @registrar.errors.added?(:vat_rate, :blank) + + @registrar.vat_rate = 5 + assert @registrar.valid? + end + + def test_require_no_vat_rate_when_registrar_is_foreign_vat_payer_and_vat_no_is_present + @registrar.country_code = 'DE' + @registrar.vat_no = 'valid' + + @registrar.vat_rate = 1 + assert @registrar.invalid? + + @registrar.vat_rate = nil + assert @registrar.valid? + end + + def test_vat_rate_validation + @registrar.country_code = 'DE' + @registrar.vat_no = '' + + @registrar.vat_rate = -1 + assert @registrar.invalid? + + @registrar.vat_rate = 0 + assert @registrar.valid? + + @registrar.vat_rate = 99.9 + assert @registrar.valid? + + @registrar.vat_rate = 100 + assert @registrar.invalid? + end + + def test_serializes_and_deserializes_vat_rate + @registrar.country_code = 'DE' + @registrar.vat_rate = BigDecimal('25.5') + @registrar.save! + @registrar.reload + assert_equal BigDecimal('25.5'), @registrar.vat_rate + end + + def test_parses_vat_rate_as_a_string + @registrar.vat_rate = '25.5' + assert_equal BigDecimal('25.5'), @registrar.vat_rate + end + + def test_treats_empty_vat_rate_as_nil + @registrar.vat_rate = '' + assert_nil @registrar.vat_rate + end +end diff --git a/test/models/registrar_test.rb b/test/models/registrar_test.rb index fda377d9b..756dabc83 100644 --- a/test/models/registrar_test.rb +++ b/test/models/registrar_test.rb @@ -1,7 +1,7 @@ require 'test_helper' class RegistrarTest < ActiveSupport::TestCase - def setup + setup do @registrar = registrars(:bestnames) end @@ -29,7 +29,7 @@ class RegistrarTest < ActiveSupport::TestCase assert @registrar.invalid? end - def test_requires_country_code + def test_invalid_without_country_code @registrar.country_code = '' assert @registrar.invalid? end diff --git a/test/models/registry_test.rb b/test/models/registry_test.rb new file mode 100644 index 000000000..90a603e15 --- /dev/null +++ b/test/models/registry_test.rb @@ -0,0 +1,16 @@ +require 'test_helper' + +class RegistryTest < ActiveSupport::TestCase + setup do + @registry = Registry.send(:new) + end + + def test_implements_singleton + assert_equal Registry.instance.object_id, Registry.instance.object_id + end + + def test_vat_rate + Setting.registry_vat_prc = 0.25 + assert_equal BigDecimal(25), @registry.vat_rate + end +end diff --git a/test/support/rails5_assetions.rb b/test/support/rails5_assetions.rb new file mode 100644 index 000000000..55a2e8dc6 --- /dev/null +++ b/test/support/rails5_assetions.rb @@ -0,0 +1,94 @@ +module ActiveSupport + module Testing + module Assertions + UNTRACKED = Object.new # :nodoc: + + # Assertion that the result of evaluating an expression is changed before + # and after invoking the passed in block. + # + # assert_changes 'Status.all_good?' do + # post :create, params: { status: { ok: false } } + # end + # + # You can pass the block as a string to be evaluated in the context of + # the block. A lambda can be passed for the block as well. + # + # assert_changes -> { Status.all_good? } do + # post :create, params: { status: { ok: false } } + # end + # + # The assertion is useful to test side effects. The passed block can be + # anything that can be converted to string with #to_s. + # + # assert_changes :@object do + # @object = 42 + # end + # + # The keyword arguments :from and :to can be given to specify the + # expected initial value and the expected value after the block was + # executed. + # + # assert_changes :@object, from: nil, to: :foo do + # @object = :foo + # end + # + # An error message can be specified. + # + # assert_changes -> { Status.all_good? }, 'Expected the status to be bad' do + # post :create, params: { status: { incident: true } } + # end + def assert_changes(expression, message = nil, from: UNTRACKED, to: UNTRACKED, &block) + exp = expression.respond_to?(:call) ? expression : -> { eval(expression.to_s, block.binding) } + + before = exp.call + retval = yield + + unless from == UNTRACKED + error = "#{expression.inspect} isn't #{from.inspect}" + error = "#{message}.\n#{error}" if message + assert from === before, error + end + + after = exp.call + + if to == UNTRACKED + error = "#{expression.inspect} didn't changed" + error = "#{message}.\n#{error}" if message + assert_not_equal before, after, error + else + error = "#{expression.inspect} didn't change to #{to}" + error = "#{message}.\n#{error}" if message + assert to === after, error + end + + retval + end + + # Assertion that the result of evaluating an expression is changed before + # and after invoking the passed in block. + # + # assert_no_changes 'Status.all_good?' do + # post :create, params: { status: { ok: true } } + # end + # + # An error message can be specified. + # + # assert_no_changes -> { Status.all_good? }, 'Expected the status to be good' do + # post :create, params: { status: { ok: false } } + # end + def assert_no_changes(expression, message = nil, &block) + exp = expression.respond_to?(:call) ? expression : -> { eval(expression.to_s, block.binding) } + + before = exp.call + retval = yield + after = exp.call + + error = "#{expression.inspect} did change to #{after}" + error = "#{message}.\n#{error}" if message + assert_equal before, after, error + + retval + end + end + end +end diff --git a/test/test_helper.rb b/test/test_helper.rb index 7bde0991d..e319656be 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -11,14 +11,20 @@ require 'minitest/mock' require 'capybara/rails' require 'capybara/minitest' require 'webmock/minitest' +require 'support/rails5_assetions' # Remove once upgraded to Rails 5 Setting.address_processing = false +Setting.registry_country_code = 'US' class ActiveSupport::TestCase include FactoryBot::Syntax::Methods ActiveRecord::Migration.check_pending! fixtures :all + + teardown do + travel_back + end end class ActionDispatch::IntegrationTest @@ -27,8 +33,9 @@ class ActionDispatch::IntegrationTest include Capybara::Minitest::Assertions include AbstractController::Translation - def teardown + teardown do Warden.test_reset! + WebMock.reset! Capybara.reset_sessions! Capybara.use_default_driver end