diff --git a/.reek b/.reek index d0f2aaba3..a511bdb43 100644 --- a/.reek +++ b/.reek @@ -191,7 +191,6 @@ DuplicateMethodCall: - Registrant::SessionsController#mid_status - Registrant::WhoisController#index - Registrar::AccountActivitiesController#index - - Registrar::BaseController#check_ip - Registrar::ContactsController#download_list - Registrar::ContactsController#index - Registrar::ContactsController#normalize_search_parameters @@ -666,7 +665,6 @@ TooManyStatements: - Registrant::SessionsController#mid - Registrant::SessionsController#mid_status - Registrar::AccountActivitiesController#index - - Registrar::BaseController#check_ip - Registrar::ContactsController#download_list - Registrar::ContactsController#index - Registrar::ContactsController#normalize_search_parameters 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/Gemfile.lock b/Gemfile.lock index ed559f465..6d9105baf 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -160,6 +160,7 @@ GEM unicode_utils (~> 1.4) crack (0.4.3) safe_yaml (~> 1.0.0) + crass (1.0.3) daemons (1.2.4) daemons-rails (1.2.1) daemons @@ -247,7 +248,8 @@ GEM activesupport (>= 3.0.0) libxml-ruby (3.0.0) liquid (3.0.6) - loofah (2.0.3) + loofah (2.2.2) + crass (~> 1.0.2) nokogiri (>= 1.5.9) mail (2.6.6) mime-types (>= 1.16, < 4) diff --git a/app/assets/javascripts/admin-manifest.coffee b/app/assets/javascripts/admin-manifest.coffee index 909cd191c..dd99c1932 100644 --- a/app/assets/javascripts/admin-manifest.coffee +++ b/app/assets/javascripts/admin-manifest.coffee @@ -9,6 +9,7 @@ #= require select2 #= require jquery.doubleScroll #= require datepicker +#= require spell_check #= require admin/application #= require admin/app #= require_tree ./admin diff --git a/app/assets/javascripts/registrant-manifest.coffee b/app/assets/javascripts/registrant-manifest.coffee index eb7577e02..84f95374a 100644 --- a/app/assets/javascripts/registrant-manifest.coffee +++ b/app/assets/javascripts/registrant-manifest.coffee @@ -4,4 +4,5 @@ #= require jquery-ui/datepicker #= require select2 #= require datepicker +#= require spell_check #= require shared/general diff --git a/app/assets/javascripts/registrar-manifest.coffee b/app/assets/javascripts/registrar-manifest.coffee index 656b5cb18..5c4a58df6 100644 --- a/app/assets/javascripts/registrar-manifest.coffee +++ b/app/assets/javascripts/registrar-manifest.coffee @@ -6,6 +6,7 @@ #= require jquery-ui/datepicker #= require select2 #= require datepicker +#= require spell_check #= require shared/general #= require registrar/autocomplete #= require registrar/application diff --git a/app/assets/javascripts/spell_check.js b/app/assets/javascripts/spell_check.js new file mode 100644 index 000000000..7c04ab071 --- /dev/null +++ b/app/assets/javascripts/spell_check.js @@ -0,0 +1,12 @@ +(function() { + function disableSpellCheck() { + let selector = 'input[type=text], textarea'; + let textFields = document.querySelectorAll(selector); + + for (let field of textFields) { + field.spellcheck = false; + } + } + + disableSpellCheck(); +})(); 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 8d020787b..e919bdb25 100644 --- a/app/controllers/admin/registrars_controller.rb +++ b/app/controllers/admin/registrars_controller.rb @@ -19,17 +19,15 @@ module Admin def create @registrar = Registrar.new(registrar_params) - begin + if @registrar.valid? @registrar.transaction do @registrar.save! @registrar.accounts.create!(account_type: Account::CASH, currency: 'EUR') end - flash[:notice] = t('.created') - redirect_to [:admin, @registrar] - rescue ActiveRecord::RecordInvalid - flash.now[:alert] = t('.not_created') - render 'new' + redirect_to [:admin, @registrar], notice: t('.created') + else + render :new end end @@ -38,21 +36,19 @@ module Admin def update if @registrar.update(registrar_params) - flash[:notice] = t('.updated') - redirect_to [:admin, @registrar] + redirect_to [:admin, @registrar], notice: t('.updated') else - flash.now[:alert] = t('.not_updated') - render 'edit' + render :edit end end def destroy if @registrar.destroy - flash[:notice] = I18n.t('registrar_deleted') - redirect_to admin_registrars_path + flash[:notice] = t('.deleted') + redirect_to admin_registrars_url else - flash.now[:alert] = I18n.t('failed_to_delete_registrar') - render 'show' + flash[:alert] = @registrar.errors.full_messages.first + redirect_to admin_registrar_url(@registrar) end end @@ -65,7 +61,6 @@ module Admin def registrar_params params.require(:registrar).permit(:name, :reg_no, - :vat_no, :street, :city, :state, @@ -74,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/controllers/registrar/payments_controller.rb b/app/controllers/registrar/payments_controller.rb index 696dbbc7e..18c892ea7 100644 --- a/app/controllers/registrar/payments_controller.rb +++ b/app/controllers/registrar/payments_controller.rb @@ -3,7 +3,7 @@ class Registrar protect_from_forgery except: :back skip_authorization_check # actually anyone can pay, no problems at all - skip_before_action :authenticate_user!, :check_ip, only: [:back] + skip_before_action :authenticate_user!, :check_ip_restriction, only: [:back] before_action :check_bank # to handle existing model we should 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/epp/domain.rb b/app/models/epp/domain.rb index fb01fe38a..249f90a98 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? } 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 2aa9ea3e4..d539e01f2 100644 --- a/app/models/registrar.rb +++ b/app/models/registrar.rb @@ -6,7 +6,7 @@ class Registrar < ActiveRecord::Base has_many :api_users, dependent: :restrict_with_error has_many :messages has_many :invoices, foreign_key: 'buyer_id' - has_many :accounts + has_many :accounts, dependent: :destroy has_many :nameservers, through: :domains has_many :whois_records has_many :white_ips, dependent: :destroy @@ -17,37 +17,19 @@ class Registrar < ActiveRecord::Base validates :name, :reference_no, :code, uniqueness: true validates :accounting_customer_code, presence: true validates :language, presence: true - validate :forbidden_codes + 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 - - def forbidden_codes - return true unless ['CID'].include? code - errors.add(:code, I18n.t(:forbidden_code)) - false - end - before_validation :generate_iso_11649_reference_no - def generate_iso_11649_reference_no - return if reference_no.present? - - loop do - base = nil - loop do - base = SecureRandom.random_number.to_s.last(8) - break if base.to_i != 0 && base.length == 8 - end - - control_base = (base + '2715' + '00').to_i - reminder = control_base % 97 - check_digits = 98 - reminder - - check_digits = check_digits < 10 ? "0#{check_digits}" : check_digits.to_s - - self.reference_no = "RF#{check_digits}#{base}" - break unless self.class.exists?(reference_no: reference_no) - end - end validates :email, :billing_email, email_format: { message: :invalid }, @@ -76,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, @@ -97,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, @@ -132,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 @@ -172,9 +147,50 @@ 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 self.language = Setting.default_language unless language end + + def forbid_special_code + errors.add(:code, :forbidden) if code == 'CID' + end + + def generate_iso_11649_reference_no + return if reference_no.present? + + loop do + base = nil + loop do + base = SecureRandom.random_number.to_s.last(8) + break if base.to_i != 0 && base.length == 8 + end + + control_base = (base + '2715' + '00').to_i + reminder = control_base % 97 + check_digits = 98 - reminder + + check_digits = check_digits < 10 ? "0#{check_digits}" : check_digits.to_s + + self.reference_no = "RF#{check_digits}#{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/views/admin/bank_transactions/show.haml b/app/views/admin/bank_transactions/show.haml index 4133386e5..60515200a 100644 --- a/app/views/admin/bank_transactions/show.haml +++ b/app/views/admin/bank_transactions/show.haml @@ -41,7 +41,7 @@ %dt= t(:currency) %dd= @bank_transaction.currency - %dt= t(:reference_no) + %dt= BankTransaction.human_attribute_name :reference_no %dd= @bank_transaction.reference_no %dt= t(:paid_at) 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 new file mode 100644 index 000000000..7a7e49fea --- /dev/null +++ b/app/views/admin/registrars/_billing.html.erb @@ -0,0 +1,20 @@ +
+
+ <%= t '.header' %> +
+
+
+
<%= 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 %>
+ +
<%= Registrar.human_attribute_name :billing_email %>
+
<%= registrar.billing_email %>
+
+
+
diff --git a/app/views/admin/registrars/_contacts.html.erb b/app/views/admin/registrars/_contacts.html.erb new file mode 100644 index 000000000..190e48458 --- /dev/null +++ b/app/views/admin/registrars/_contacts.html.erb @@ -0,0 +1,24 @@ +
+
+ <%= t '.header' %> +
+ +
+
+
<%= t(:country) %>
+
<%= @registrar.country %>
+ +
<%= t(:address) %>
+
<%= @registrar.address %>
+ +
<%= t(:contact_phone) %>
+
<%= @registrar.phone %>
+ +
<%= t(:contact_email) %>
+
<%= @registrar.email %>
+ +
<%= Registrar.human_attribute_name :billing_email %>
+
<%= @registrar.billing_email %>
+
+
+
diff --git a/app/views/admin/registrars/_details.html.erb b/app/views/admin/registrars/_details.html.erb new file mode 100644 index 000000000..c640075ba --- /dev/null +++ b/app/views/admin/registrars/_details.html.erb @@ -0,0 +1,27 @@ +
+
+ <%= t '.header' %> +
+ +
+
+
<%= Registrar.human_attribute_name :name %>
+
<%= registrar.name %>
+ +
<%= Registrar.human_attribute_name :reg_no %>
+
<%= registrar.reg_no %>
+ +
<%= Registrar.human_attribute_name :reference_no %>
+
<%= registrar.reference_no %>
+ +
<%= Registrar.human_attribute_name :code %>
+
<%= registrar.code %>
+ +
<%= Registrar.human_attribute_name :balance %>
+
<%= registrar.balance %>
+ +
<%= Registrar.human_attribute_name :website %>
+
<%= registrar.website %>
+
+
+
diff --git a/app/views/admin/registrars/_form.html.erb b/app/views/admin/registrars/_form.html.erb index 65a5351ad..71c4fb68f 100644 --- a/app/views/admin/registrars/_form.html.erb +++ b/app/views/admin/registrars/_form.html.erb @@ -1,5 +1,6 @@ <%= form_for([:admin, @registrar], html: { class: 'form-horizontal' }) do |f| %> - <%= render 'shared/full_errors', object: @registrar %> + <%= render 'form_errors', target: @registrar %> +
@@ -133,7 +134,9 @@ <%= f.label :code %>
- <%= f.text_field :code, required: f.object.new_record?, class: 'form-control', disabled: !f.object.new_record? %> + <%= f.text_field :code, required: f.object.new_record?, + disabled: f.object.persisted?, + class: 'form-control' %>
diff --git a/app/views/admin/registrars/show/_preferences.html.erb b/app/views/admin/registrars/_preferences.html.erb similarity index 100% rename from app/views/admin/registrars/show/_preferences.html.erb rename to app/views/admin/registrars/_preferences.html.erb diff --git a/app/views/admin/registrars/_users.html.erb b/app/views/admin/registrars/_users.html.erb new file mode 100644 index 000000000..f182e4615 --- /dev/null +++ b/app/views/admin/registrars/_users.html.erb @@ -0,0 +1,28 @@ +
+
+ <%= t '.header' %> +
+ + + + + + + + + + + <% registrar.api_users.each do |user| %> + + + + + <% end %> + +
<%= ApiUser.human_attribute_name :username %><%= ApiUser.human_attribute_name :active %>
<%= link_to(user, [:admin, user]) %><%= user.active %>
+ + +
diff --git a/app/views/admin/registrars/_white_ips.html.erb b/app/views/admin/registrars/_white_ips.html.erb new file mode 100644 index 000000000..c86c85eb9 --- /dev/null +++ b/app/views/admin/registrars/_white_ips.html.erb @@ -0,0 +1,38 @@ +
+
+ <%= t '.header' %> +
+ + + + + + + + + + + + <% registrar.white_ips.each do |white_ip| %> + + + + + + <% end %> + +
<%= WhiteIp.human_attribute_name :ipv4 %><%= WhiteIp.human_attribute_name :ipv6 %><%= WhiteIp.human_attribute_name :interfaces %>
+ <% if white_ip.ipv4.present? %> + <%= link_to(white_ip.ipv4, [:admin, registrar, white_ip]) %> + <% end %> + + <% if white_ip.ipv6.present? %> + <%= link_to(white_ip.ipv6, [:admin, registrar, white_ip]) %> + <% end %> + <%= white_ip.interfaces.join(', ').upcase %>
+ + +
diff --git a/app/views/admin/registrars/edit.html.erb b/app/views/admin/registrars/edit.html.erb index 71d6bd882..205ba6b28 100644 --- a/app/views/admin/registrars/edit.html.erb +++ b/app/views/admin/registrars/edit.html.erb @@ -1,5 +1,10 @@ -<% content_for :actions do %> - <%= link_to(t(:back_to_registrar), [:admin, @registrar], class: 'btn btn-default') %> -<% end %> -<%= render 'shared/title', name: "#{t(:edit)}: #{@registrar.name}" %> + + + + <%= render 'form' %> 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/admin/registrars/index.html.erb b/app/views/admin/registrars/index.html.erb index 5533a6f07..a66816568 100644 --- a/app/views/admin/registrars/index.html.erb +++ b/app/views/admin/registrars/index.html.erb @@ -1,7 +1,15 @@ -<% content_for :actions do %> - <%= link_to(t('.new_btn'), new_admin_registrar_path, class: 'btn btn-primary') %> -<% end %> -<%= render 'shared/title', name: t(:registrars) %> + +
@@ -12,10 +20,10 @@ <%= sort_link(@q, 'name') %> - <%= sort_link(@q, 'reg_no', t(:reg_no)) %> + <%= sort_link(@q, 'reg_no', Registrar.human_attribute_name(:reg_no)) %> - <%= t(:credit_balance) %> + <%= Registrar.human_attribute_name :balance %> <%= t(:test_registrar) %> diff --git a/app/views/admin/registrars/new.html.erb b/app/views/admin/registrars/new.html.erb index 70154d217..e813bdd57 100644 --- a/app/views/admin/registrars/new.html.erb +++ b/app/views/admin/registrars/new.html.erb @@ -1,2 +1,9 @@ -<%= render 'shared/title', name: t(:new_registrar) %> + + + + <%= render 'form' %> diff --git a/app/views/admin/registrars/show.html.erb b/app/views/admin/registrars/show.html.erb index a6f2240a9..65435ef77 100644 --- a/app/views/admin/registrars/show.html.erb +++ b/app/views/admin/registrars/show.html.erb @@ -1,218 +1,50 @@ <% registrar = RegistrarPresenter.new(registrar: @registrar, view: self) %> -<% content_for :actions do %> - <%= link_to(t(:edit), edit_admin_registrar_path(@registrar), class: 'btn btn-primary') %> - <%= link_to(t(:delete), admin_registrar_path(@registrar), method: :delete, data: { confirm: t(:are_you_sure) }, class: 'btn btn-danger') %> -<% end %> -<% content_for :page_name do %> - <%= @registrar.name %> - <% if @registrar.test_registrar? %> - (test) - <% end %> -<% end %> -<%= render 'shared/title', name: @registrar.name %> -<% if @registrar.errors.any? %> - <% @registrar.errors.each do |attr, err| %> - <%= err %> -
- <% end %> -<% end %> -<% if @registrar.errors.any? %> -
-<% end %> + + + + +
-
-
-

- <%= t(:general) %> -

-
-
-
-
- <%= t(:name) %> -
-
- <%= @registrar.name %> -
-
- <%= t(:reg_no) %> -
-
- <%= @registrar.reg_no %> -
-
- <%= t(:vat_no) %> -
-
- <%= @registrar.vat_no %> -
-
- <%= t(:reference_no) %> -
-
- <%= @registrar.reference_no %> -
-
- <%= t(:id) %> -
-
- <%= @registrar.code %> -
-
- <%= t(:credit_balance) %> -
-
- <%= @registrar.balance %> -
-
- <%= Registrar.human_attribute_name :website %> -
-
- <%= @registrar.website %> -
-
- <%= Registrar.human_attribute_name :accounting_customer_code %> -
-
- <%= @registrar.accounting_customer_code %> -
-
-
-
+ <%= render 'details', registrar: @registrar %>
-
-
-

- <%= t(:contact) %> -

-
-
-
-
- <%= t(:country) %> -
-
- <%= @registrar.country %> -
-
- <%= t(:address) %> -
-
- <%= @registrar.address %> -
-
- <%= t(:contact_phone) %> -
-
- <%= @registrar.phone %> -
-
- <%= t(:contact_email) %> -
-
- <%= @registrar.email %> -
-
- <%= t(:billing_email) %> -
-
- <%= @registrar.billing_email %> -
-
-
-
- <%= render 'admin/registrars/show/preferences', registrar: registrar %> + <%= render 'contacts', registrar: @registrar %> + <%= render 'billing', registrar: @registrar %> + <%= render 'preferences', registrar: registrar %>
+
-
-
-
- <%= t('.api_users') %> -
-
- <%= link_to(t('.new_api_use_btn'), new_admin_registrar_api_user_path(@registrar), class: 'btn btn-default btn-xs') %> -
-
-
- - - - - - - - - <% @registrar.api_users.each do |x| %> - - - - - <% end %> - -
- <%= t(:username) %> - - <%= t('.active') %> -
- <%= link_to(x, [:admin, x]) %> - - <%= x.active %> -
-
-
+ <%= render 'users', registrar: @registrar %>
+
-
-
-
- <%= t(:white_ips) %> -
-
- <%= link_to(t(:create_new_white_ip), new_admin_registrar_white_ip_path(@registrar), class: 'btn btn-default btn-xs') %> -
-
-
- - - - - - - - - - <% @registrar.white_ips.each do |x| %> - - - - - - <% end %> - -
- <%= t(:ipv4) %> - - <%= t(:ipv6) %> - - <%= t(:interfaces) %> -
- <% if x.ipv4.present? %> - <%= link_to(x.ipv4, [:admin, @registrar, x]) %> - <% end %> - - <% if x.ipv6.present? %> - <%= link_to(x.ipv6, [:admin, @registrar, x]) %> - <% end %> - - <%= x.interfaces.join(', ').upcase %> -
-
-
+ <%= render 'white_ips', registrar: @registrar %>
diff --git a/app/views/admin/white_ips/new.haml b/app/views/admin/white_ips/new.haml index 99150a871..220599d2a 100644 --- a/app/views/admin/white_ips/new.haml +++ b/app/views/admin/white_ips/new.haml @@ -1,5 +1,5 @@ - content_for :actions do = link_to(t(:back_to_registrar), admin_registrar_path(@registrar), class: 'btn btn-default') -= render 'shared/title', name: t(:create_new_white_ip) += render 'shared/title', name: t('.header') = render 'form' diff --git a/app/views/admin/white_ips/show.haml b/app/views/admin/white_ips/show.haml index 33688d9fe..2ec354aa4 100644 --- a/app/views/admin/white_ips/show.haml +++ b/app/views/admin/white_ips/show.haml @@ -14,11 +14,11 @@ %dt= t(:registrar_name) %dd= link_to(@registrar, [:admin, @registrar]) - %dt= t(:ipv4) + %dt= WhiteIp.human_attribute_name :ipv4 %dd= @white_ip.ipv4 - %dt= t(:ipv6) + %dt= WhiteIp.human_attribute_name :ipv6 %dd= @white_ip.ipv6 - %dt= t(:interfaces) + %dt= WhiteIp.human_attribute_name :interfaces %dd= @white_ip.interfaces.join(', ').upcase diff --git a/app/views/registrant/registrars/index.haml b/app/views/registrant/registrars/index.haml index 0489bcf52..03bd5a02a 100644 --- a/app/views/registrant/registrars/index.haml +++ b/app/views/registrant/registrars/index.haml @@ -10,7 +10,7 @@ %th{class: 'col-xs-6'} = sort_link(@q, 'name') %th{class: 'col-xs-6'} - = sort_link(@q, 'reg_no', t(:reg_no)) + = sort_link(@q, 'reg_no', Registrar.human_attribute_name(:reg_no)) %tbody - @registrars.each do |x| %tr diff --git a/app/views/registrant/registrars/show.haml b/app/views/registrant/registrars/show.haml index e0da73ee3..678e387de 100644 --- a/app/views/registrant/registrars/show.haml +++ b/app/views/registrant/registrars/show.haml @@ -16,10 +16,10 @@ %dt= t(:name) %dd= @registrar.name - %dt= t(:reg_no) + %dt= Registrar.human_attribute_name :reg_no %dd= @registrar.reg_no - %dt= t(:vat_no) + %dt= Registrar.human_attribute_name :vat_no %dd= @registrar.vat_no %dt= t(:id) 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/_details.haml b/app/views/registrar/invoices/partials/_details.haml index 1375c76f8..69248b457 100644 --- a/app/views/registrar/invoices/partials/_details.haml +++ b/app/views/registrar/invoices/partials/_details.haml @@ -32,5 +32,5 @@ %dt= t(:description) %dd=@invoice.description - %dt= t(:reference_no) + %dt= Invoice.human_attribute_name :reference_no %dd= @invoice.reference_no 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/partials/_seller.haml b/app/views/registrar/invoices/partials/_seller.haml index 0008c2f13..30f27bcef 100644 --- a/app/views/registrar/invoices/partials/_seller.haml +++ b/app/views/registrar/invoices/partials/_seller.haml @@ -4,7 +4,7 @@ %dt= t(:name) %dd= @invoice.seller_name - %dt= t(:reg_no) + %dt= Registrar.human_attribute_name :reg_no %dd= @invoice.seller_reg_no %dt= t(:iban) @@ -16,7 +16,7 @@ %dt= t(:swift) %dd= @invoice.seller_swift - %dt= t(:vat_no) + %dt= Registrar.human_attribute_name :vat_no %dd= @invoice.seller_vat_no %dt= t(:address) diff --git a/app/views/registrar/invoices/pdf.haml b/app/views/registrar/invoices/pdf.haml index a74254a2a..3d6e111ef 100644 --- a/app/views/registrar/invoices/pdf.haml +++ b/app/views/registrar/invoices/pdf.haml @@ -182,7 +182,7 @@ %dt= t(:description) %dd=@invoice.description - %dt= t(:reference_no) + %dt= Invoice.human_attribute_name :reference_no %dd= @invoice.reference_no .col-md-6.right @@ -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 @@ -261,7 +261,7 @@ %br = "#{t('reg_no')} #{@invoice.seller_reg_no}" %br - = "#{t('vat_no')} #{@invoice.seller_vat_no}" + = "#{Registrar.human_attribute_name :vat_no} #{@invoice.seller_vat_no}" .col-md-3.left = @invoice.seller_phone diff --git a/app/views/registrar/registrar_nameservers/_form.html.erb b/app/views/registrar/registrar_nameservers/_form.html.erb index cb872a91a..3aca3e0e1 100644 --- a/app/views/registrar/registrar_nameservers/_form.html.erb +++ b/app/views/registrar/registrar_nameservers/_form.html.erb @@ -7,7 +7,6 @@
<%= text_field_tag :old_hostname, params[:old_hostname], autofocus: true, required: true, - spellcheck: false, class: 'form-control' %>
@@ -19,7 +18,6 @@
<%= text_field_tag :new_hostname, params[:new_hostname], required: true, - spellcheck: false, class: 'form-control' %>
@@ -30,7 +28,7 @@
- <%= text_area_tag :ipv4, params[:ipv4], spellcheck: false, class: 'form-control' %> + <%= text_area_tag :ipv4, params[:ipv4], class: 'form-control' %>
@@ -40,7 +38,7 @@
- <%= text_area_tag :ipv6, params[:ipv6], spellcheck: false, class: 'form-control' %> + <%= text_area_tag :ipv6, params[:ipv6], class: 'form-control' %> <%= t '.ip_hint' %>
diff --git a/config/application.rb b/config/application.rb index 57106c8ea..04d697f55 100644 --- a/config/application.rb +++ b/config/application.rb @@ -15,7 +15,7 @@ require 'rails/all' # you've limited to :test, :development, or :production. Bundler.require(*Rails.groups) -module Registry +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/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/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 3d269f64b..3586960b0 100644 --- a/config/locales/admin/registrars.en.yml +++ b/config/locales/admin/registrars.en.yml @@ -2,23 +2,37 @@ en: admin: registrars: index: + header: Registrars new_btn: New registrar - show: - new_api_use_btn: New API user - active: Active - api_users: API users + new: + header: New registrar - preferences: - header: Preferences + show: + edit_btn: Edit + delete_btn: Delete + delete_btn_confirm: Are you sure you want delete registrar? + + edit: + header: Edit registrar + + billing: + header: Billing + + edit: + header: Edit registrar + + billing: + header: Billing create: created: Registrar has been successfully created - not_created: Unable to create registrar update: updated: Registrar has been successfully updated - not_updated: Unable to update registrar + + destroy: + deleted: Registrar has been successfully deleted form: misc: Miscellaneous @@ -30,3 +44,20 @@ en: preferences: header: Preferences + + details: + header: Details + + contacts: + header: Contacts + + preferences: + header: Preferences + + users: + header: API Users + new_btn: New API user + + white_ips: + header: Whitelisted IPs + new_btn: New whitelisted IP diff --git a/config/locales/admin/white_ips.en.yml b/config/locales/admin/white_ips.en.yml new file mode 100644 index 000000000..b42db4cff --- /dev/null +++ b/config/locales/admin/white_ips.en.yml @@ -0,0 +1,5 @@ +en: + admin: + white_ips: + new: + header: New whitelisted IP diff --git a/config/locales/en.yml b/config/locales/en.yml index 6366faca0..4cdd5a41f 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -197,15 +197,11 @@ en: alg: 'Algorithm' public_key: 'Public key' registrar: - billing_email: 'Billing e-mail' phone: 'Contact phone' email: 'Contact e-mail' state: 'State / Province' deposit: amount: 'Amount' - white_ip: - ipv4: 'IPv4' - ipv6: 'IPv6' errors: messages: @@ -302,7 +298,6 @@ en: reg_no: 'Reg. no' status: 'Status' contact: 'Contact' - credit_balance: 'Credit balance' starting_balance: 'Starting balance' destroyed: 'Destroyed' @@ -313,13 +308,7 @@ en: edit_statuses: 'Edit statuses' history: 'History' - new_registrar: 'New registrar' - registrar_details: 'Registrar details' - vat_no: 'VAT no' - edit_registrar: 'Edit registrar' back_to_registrar: 'Back to registrar' - registrar_deleted: 'Registrar deleted' - failed_to_delete_registrar: 'Failed to delete registrar' users: 'Users' user_details: 'User details' @@ -393,7 +382,6 @@ en: choose: 'Choose...' created_before: 'Created before' created_after: 'Created after' - billing_email: 'Billing e-mail' contact_phone: 'Contact phone' contact_email: 'Contact e-mail' address_help: 'Street name, house no - apartment no, city, county, country, zip' @@ -550,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' @@ -568,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' @@ -584,7 +570,6 @@ en: queried_at: 'Queried at' import_file_path: 'Import file path' bank_code: 'Bank code' - reference_no: 'Reference no' currency: 'Currency' buyer_name: 'Buyer name' buyer_iban: 'Buyer IBAN' @@ -649,7 +634,6 @@ en: due_date_until: 'Due date until' minimum_total: 'Minimum total' maximum_total: 'Maximum total' - forbidden_code: 'is forbidden to use' 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' @@ -662,8 +646,6 @@ en: not_valid_domain_verification_body: This could mean your verification has been expired or done already.

Please contact us if you think something is wrong. upload_crt: 'Upload CRT' crt_or_csr_must_be_present: 'CRT or CSR must be present' - white_ips: 'White IP-s' - create_new_white_ip: 'Create new white IP' ipv4_or_ipv6_must_be_present: 'IPv4 or IPv6 must be present' white_ip: 'White IP' edit_white_ip: 'Edit white IP' @@ -747,11 +729,9 @@ 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' - interfaces: 'Interfaces' next: 'Next' previous: 'Previous' personal_domain_verification_url: 'Personal domain verification url' @@ -777,3 +757,9 @@ en: delimiter: " " precision: 2 unit: € + + attributes: + vat_no: VAT number + vat_rate: VAT rate + ipv4: IPv4 + ipv6: IPv6 diff --git a/config/locales/registrars.en.yml b/config/locales/registrars.en.yml new file mode 100644 index 000000000..60cb9d5c5 --- /dev/null +++ b/config/locales/registrars.en.yml @@ -0,0 +1,8 @@ +en: + activerecord: + errors: + models: + registrar: + attributes: + code: + forbidden: is forbidden diff --git a/config/routes.rb b/config/routes.rb index 77f856c8f..9caeef4a2 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -97,7 +97,6 @@ Rails.application.routes.draw do get 'pay/go/:bank' => 'payments#pay', as: 'payment_with' end - # REGISTRANT ROUTES namespace :registrant do root 'domains#index' @@ -111,17 +110,6 @@ Rails.application.routes.draw do end end - # resources :invoices do - # member do - # get 'download_pdf' - # match 'forward', via: [:post, :get] - # patch 'cancel' - # end - # end - - # resources :deposits - # resources :account_activities - resources :domain_update_confirms resources :domain_delete_confirms @@ -150,8 +138,6 @@ Rails.application.routes.draw do end resources :registrars do - resources :api_users - resources :white_ips collection do get :search 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/20180309053424_add_registrars_unique_constraints.rb b/db/migrate/20180309053424_add_registrars_unique_constraints.rb new file mode 100644 index 000000000..fb3455896 --- /dev/null +++ b/db/migrate/20180309053424_add_registrars_unique_constraints.rb @@ -0,0 +1,17 @@ +class AddRegistrarsUniqueConstraints < ActiveRecord::Migration + def up + execute <<-SQL + ALTER TABLE registrars ADD CONSTRAINT unique_name UNIQUE (name); + ALTER TABLE registrars ADD CONSTRAINT unique_reference_no UNIQUE (reference_no); + ALTER TABLE registrars ADD CONSTRAINT unique_code UNIQUE (code); + SQL + end + + def down + execute <<-SQL + ALTER TABLE registrars DROP CONSTRAINT unique_name; + ALTER TABLE registrars DROP CONSTRAINT unique_reference_no; + ALTER TABLE registrars DROP CONSTRAINT unique_code; + SQL + end +end diff --git a/db/migrate/20180309053921_remove_registrars_indexes.rb b/db/migrate/20180309053921_remove_registrars_indexes.rb new file mode 100644 index 000000000..0613d9fc6 --- /dev/null +++ b/db/migrate/20180309053921_remove_registrars_indexes.rb @@ -0,0 +1,6 @@ +class RemoveRegistrarsIndexes < ActiveRecord::Migration + def change + remove_index :registrars, name: :index_registrars_on_code + remove_index :registrars, name: :index_registrars_on_legacy_id + end +end diff --git a/db/migrate/20180309054510_add_registrars_not_null_constraints.rb b/db/migrate/20180309054510_add_registrars_not_null_constraints.rb new file mode 100644 index 000000000..33d464356 --- /dev/null +++ b/db/migrate/20180309054510_add_registrars_not_null_constraints.rb @@ -0,0 +1,9 @@ +class AddRegistrarsNotNullConstraints < ActiveRecord::Migration + def change + change_column_null :registrars, :name, false + change_column_null :registrars, :reg_no, false + change_column_null :registrars, :country_code, false + change_column_null :registrars, :email, false + change_column_null :registrars, :code, false + 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 a9257ffa3..4c7dbd70d 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -998,13 +998,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, @@ -1037,8 +1036,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 ); @@ -2136,29 +2136,29 @@ ALTER SEQUENCE registrant_verifications_id_seq OWNED BY registrant_verifications CREATE TABLE registrars ( id integer NOT NULL, - name character varying, - reg_no character varying, + name character varying NOT NULL, + reg_no character varying NOT NULL, vat_no character varying, created_at timestamp without time zone, updated_at timestamp without time zone, creator_str character varying, updator_str character varying, phone character varying, - email character varying, + email character varying NOT NULL, billing_email character varying, - country_code character varying, + country_code character varying NOT NULL, state character varying, city character varying, street character varying, zip character varying, - code character varying, + 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) ); @@ -3243,6 +3243,14 @@ ALTER TABLE ONLY settings ADD CONSTRAINT settings_pkey PRIMARY KEY (id); +-- +-- Name: unique_code; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: +-- + +ALTER TABLE ONLY registrars + ADD CONSTRAINT unique_code UNIQUE (code); + + -- -- Name: unique_contact_code; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: -- @@ -3251,6 +3259,22 @@ ALTER TABLE ONLY contacts ADD CONSTRAINT unique_contact_code UNIQUE (code); +-- +-- Name: unique_name; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: +-- + +ALTER TABLE ONLY registrars + ADD CONSTRAINT unique_name UNIQUE (name); + + +-- +-- Name: unique_reference_no; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: +-- + +ALTER TABLE ONLY registrars + ADD CONSTRAINT unique_reference_no UNIQUE (reference_no); + + -- -- Name: unique_session_id; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: -- @@ -3853,20 +3877,6 @@ CREATE INDEX index_registrant_verifications_on_created_at ON registrant_verifica CREATE INDEX index_registrant_verifications_on_domain_id ON registrant_verifications USING btree (domain_id); --- --- Name: index_registrars_on_code; Type: INDEX; Schema: public; Owner: -; Tablespace: --- - -CREATE INDEX index_registrars_on_code ON registrars USING btree (code); - - --- --- Name: index_registrars_on_legacy_id; Type: INDEX; Schema: public; Owner: -; Tablespace: --- - -CREATE INDEX index_registrars_on_legacy_id ON registrars USING btree (legacy_id); - - -- -- Name: index_settings_on_thing_type_and_thing_id_and_var; Type: INDEX; Schema: public; Owner: -; Tablespace: -- @@ -4659,6 +4669,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'); @@ -4679,3 +4699,17 @@ INSERT INTO schema_migrations (version) VALUES ('20180306183549'); INSERT INTO schema_migrations (version) VALUES ('20180308123240'); +INSERT INTO schema_migrations (version) VALUES ('20180309053424'); + +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'); + diff --git a/doc/controllers_complete.svg b/doc/controllers_complete.svg index 765d4a08b..dcf736019 100644 --- a/doc/controllers_complete.svg +++ b/doc/controllers_complete.svg @@ -492,7 +492,6 @@ _layout -check_ip role_base_root_url diff --git a/doc/models_complete.svg b/doc/models_complete.svg index 296d20c67..235aa433b 100644 --- a/doc/models_complete.svg +++ b/doc/models_complete.svg @@ -1489,7 +1489,6 @@ zip :string code :string url :string -vat :boolean legacy_id :integer reference_no :string @@ -1614,13 +1613,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 @@ -1653,7 +1651,7 @@ updator_str :string number :integer cancelled_at :datetime -sum_cache :decimal +total :decimal Registrar->Invoice diff --git a/lib/tasks/import.rake b/lib/tasks/import.rake index f26ad252f..c5f84160d 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, @@ -100,7 +99,7 @@ namespace :import do puts "-----> Generating reference numbers" Registrar.all.each do |x| - x.generate_iso_11649_reference_no + x.send(:generate_iso_11649_reference_no) x.save(validate: false) end 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/spec/models/registrar_spec.rb b/spec/models/registrar_spec.rb deleted file mode 100644 index 4a8110d45..000000000 --- a/spec/models/registrar_spec.rb +++ /dev/null @@ -1,118 +0,0 @@ -require 'rails_helper' - -describe Registrar do - context 'with invalid attribute' do - before :all do - @registrar = Registrar.new - end - - it 'is not valid' do - @registrar.valid? - @registrar.errors.full_messages.should include(*[ - 'Contact e-mail is missing', - 'Country code is missing', - 'Name is missing', - 'Reg no is missing', - 'Code is missing' - ]) - end - - it 'returns an error with invalid email' do - @registrar.email = 'bla' - @registrar.billing_email = 'bla' - - @registrar.valid? - @registrar.errors[:email].should == ['is invalid'] - @registrar.errors[:billing_email].should == ['is invalid'] - end - - it 'should not have valid code' do - @registrar.code.should == nil - end - - it 'should generate reference number' do - @registrar.generate_iso_11649_reference_no - @registrar.reference_no.should_not be_blank - @registrar.reference_no.last(10).to_i.should_not == 0 - end - end - - context 'with valid attributes' do - before :all do - @registrar = create(:registrar) - end - - it 'should be valid' do - @registrar.valid? - @registrar.errors.full_messages.should match_array([]) - end - - it 'should be valid twice' do - @registrar = create(:registrar) - @registrar.valid? - @registrar.errors.full_messages.should match_array([]) - end - - it 'should remove blank from code' do - registrar = build(:registrar, code: 'with blank') - registrar.valid? - registrar.errors.full_messages.should match_array([ - ]) - registrar.code.should == 'WITHBLANK' - end - - it 'should remove colon from code' do - registrar = build(:registrar, code: 'with colon:and:blank') - registrar.valid? - registrar.errors.full_messages.should match_array([ - ]) - registrar.code.should == 'WITHCOLONANDBLANK' - end - - it 'should allow dot in code' do - registrar = build(:registrar, code: 'with.dot') - registrar.valid? - registrar.errors.full_messages.should match_array([ - ]) - registrar.code.should == 'WITH.DOT' - end - - it 'should have one version' do - with_versioning do - @registrar.versions.should == [] - @registrar.name = 'New name' - @registrar.save - @registrar.errors.full_messages.should match_array([]) - @registrar.versions.size.should == 1 - end - end - - it 'should return full address' do - registrar = described_class.new(street: 'Street 999', city: 'Town', state: 'County', zip: 'Postal') - registrar.address.should == 'Street 999, Town, County, Postal' - end - - it 'should not be able to change code' do - registrar = create(:registrar, code: 'TEST') - registrar.code = 'new-code' - expect(registrar.code).to eq('TEST') - end - - it 'should be able to issue a prepayment invoice' do - Setting.days_to_keep_invoices_active = 30 - create(:registrar, name: 'EIS', reg_no: '90010019') - @registrar.issue_prepayment_invoice(200, 'add some money') - @registrar.invoices.count.should == 1 - i = @registrar.invoices.first - i.sum.should == BigDecimal.new('240.0') - i.due_date.should be_within(0.1).of((Time.zone.now + 30.days).end_of_day) - i.description.should == 'add some money' - end - - it 'should not allaw to use CID as code for leagcy reasons' do - registrar = build(:registrar, code: 'CID') - registrar.valid? - registrar.errors.full_messages.should == ['Code is forbidden to use'] - end - end -end diff --git a/spec/requests/admin/registrars/update_spec.rb b/spec/requests/admin/registrars/update_spec.rb deleted file mode 100644 index 7bffb99d0..000000000 --- a/spec/requests/admin/registrars/update_spec.rb +++ /dev/null @@ -1,42 +0,0 @@ -require 'rails_helper' - -RSpec.describe 'admin registrar update' do - before :example do - sign_in_to_admin_area - end - - it 'updates website' do - registrar = create(:registrar, website: 'test') - - patch admin_registrar_path(registrar), registrar: attributes_for(:registrar, website: 'new-website') - registrar.reload - - expect(registrar.website).to eq('new-website') - end - - it 'updates email' do - registrar = create(:registrar, email: 'test@test.com') - - patch admin_registrar_path(registrar), registrar: attributes_for(:registrar, email: 'new-test@test.com') - registrar.reload - - expect(registrar.email).to eq('new-test@test.com') - end - - it 'updates billing email' do - registrar = create(:registrar, billing_email: 'test@test.com') - - patch admin_registrar_path(registrar), registrar: attributes_for(:registrar, billing_email: 'new-test@test.com') - registrar.reload - - expect(registrar.billing_email).to eq('new-test@test.com') - end - - it 'redirects to :show' do - registrar = create(:registrar) - - patch admin_registrar_path(registrar), { registrar: attributes_for(:registrar) } - - expect(response).to redirect_to admin_registrar_path(registrar) - end -end diff --git a/spec/routing/admin/registrars_routing_spec.rb b/spec/routing/admin/registrars_routing_spec.rb deleted file mode 100644 index 14ec765e9..000000000 --- a/spec/routing/admin/registrars_routing_spec.rb +++ /dev/null @@ -1,33 +0,0 @@ -require 'rails_helper' - -RSpec.describe Admin::RegistrarsController do - describe 'routing' do - it 'routes to #index' do - expect(get: '/admin/registrars').to route_to('admin/registrars#index') - end - - it 'routes to #new' do - expect(get: '/admin/registrars/new').to route_to('admin/registrars#new') - end - - it 'routes to #show' do - expect(get: '/admin/registrars/1').to route_to('admin/registrars#show', id: '1') - end - - it 'routes to #edit' do - expect(get: '/admin/registrars/1/edit').to route_to('admin/registrars#edit', id: '1') - end - - it 'routes to #create' do - expect(post: '/admin/registrars').to route_to('admin/registrars#create') - end - - it 'routes to #update' do - expect(patch: '/admin/registrars/1').to route_to('admin/registrars#update', id: '1') - end - - it 'routes to #destroy' do - expect(delete: '/admin/registrars/1').to route_to('admin/registrars#destroy', id: '1') - end - end -end diff --git a/spec/views/admin/registrars/_form.html.erb_spec.rb b/spec/views/admin/registrars/_form.html.erb_spec.rb deleted file mode 100644 index 83b727a30..000000000 --- a/spec/views/admin/registrars/_form.html.erb_spec.rb +++ /dev/null @@ -1,19 +0,0 @@ -require 'rails_helper' - -RSpec.describe 'admin/registrars/_form' do - let(:registrar) { build_stubbed(:registrar) } - - before :example do - assign(:registrar, registrar) - stub_template 'shared/_full_errors' => '' - - without_partial_double_verification do - allow(view).to receive(:available_languages).and_return({}) - end - end - - it 'has website' do - render - expect(rendered).to have_css('[name="registrar[website]"]') - end -end diff --git a/spec/views/admin/registrars/show.haml_spec.rb b/spec/views/admin/registrars/show.haml_spec.rb deleted file mode 100644 index 4def10e8c..000000000 --- a/spec/views/admin/registrars/show.haml_spec.rb +++ /dev/null @@ -1,19 +0,0 @@ -require 'rails_helper' - -RSpec.describe 'admin/registrars/show' do - let(:registrar) { build_stubbed(:registrar, website: 'test website') } - - before :example do - assign(:registrar, registrar) - stub_template 'shared/_title' => '' - - without_partial_double_verification do - allow(view).to receive(:available_languages).and_return({}) - end - end - - it 'has website' do - render - expect(rendered).to have_text('test website') - end -end diff --git a/test/controllers/admin/registrars/update_test.rb b/test/controllers/admin/registrars/update_test.rb deleted file mode 100644 index 2c996ef44..000000000 --- a/test/controllers/admin/registrars/update_test.rb +++ /dev/null @@ -1,30 +0,0 @@ -require 'test_helper' - -class RegistrarsControllerTest < ActionDispatch::IntegrationTest - def setup - login_as users(:admin) - @registrar = registrars(:bestnames) - end - - def test_updates_website - patch admin_registrar_path(@registrar), registrar: @registrar.attributes.merge(website: 'new.example.com') - @registrar.reload - - assert_equal 'new.example.com', @registrar.website - end - - def test_updates_email - patch admin_registrar_path(@registrar), registrar: @registrar.attributes.merge(email: 'new@example.com') - @registrar.reload - - assert_equal 'new@example.com', @registrar.email - end - - def test_updates_billing_email - patch admin_registrar_path(@registrar), - registrar: @registrar.attributes.merge(billing_email: 'new-billing@example.com') - @registrar.reload - - assert_equal 'new-billing@example.com', @registrar.billing_email - end -end diff --git a/test/fixtures/accounts.yml b/test/fixtures/accounts.yml index ea51ff7eb..a7060c249 100644 --- a/test/fixtures/accounts.yml +++ b/test/fixtures/accounts.yml @@ -3,3 +3,9 @@ cash: balance: 100 currency: EUR registrar: bestnames + +not_in_use_cash: + account_type: cash + balance: 0 + currency: EUR + registrar: not_in_use 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 0026f323b..6ff6d2dc9 100644 --- a/test/fixtures/registrars.yml +++ b/test/fixtures/registrars.yml @@ -3,6 +3,10 @@ bestnames: reg_no: 1234 code: bestnames email: info@bestnames.test + street: Main Street + zip: 12345 + city: New York + state: New York country_code: US accounting_customer_code: bestnames language: en @@ -13,6 +17,36 @@ 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 + +not_in_use: + name: any + reg_no: any + code: any + email: any@example.com + 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 new file mode 100644 index 000000000..737c830c1 --- /dev/null +++ b/test/integration/admin/registrars/delete_test.rb @@ -0,0 +1,30 @@ +require 'test_helper' + +class AdminAreaDeleteRegistrarTest < ActionDispatch::IntegrationTest + setup do + login_as users(:admin) + end + + def test_can_be_deleted_when_not_in_use + visit admin_registrar_url(registrars(:not_in_use)) + + assert_difference 'Registrar.count', -1 do + click_link_or_button 'Delete' + end + + assert_current_path admin_registrars_path + assert_text 'Registrar has been successfully deleted' + end + + def test_cannot_be_deleted_when_in_use + registrar = registrars(:bestnames) + visit admin_registrar_url(registrar) + + assert_no_difference 'Registrar.count' do + click_link_or_button 'Delete' + end + + assert_current_path admin_registrar_path(registrar) + assert_text 'Cannot delete record because dependent domains exist' + end +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_registrar_test.rb b/test/integration/admin/registrars/edit_registrar_test.rb deleted file mode 100644 index ada794032..000000000 --- a/test/integration/admin/registrars/edit_registrar_test.rb +++ /dev/null @@ -1,17 +0,0 @@ -require 'test_helper' - -class EditRegistrarTest < ActionDispatch::IntegrationTest - def setup - login_as users(:admin) - @registrar = registrars(:bestnames) - end - - def test_updates_registrar - visit admin_registrar_path(@registrar) - click_link_or_button 'Edit' - click_link_or_button 'Update registrar' - - assert_current_path admin_registrar_path(@registrar) - assert_text 'Registrar has been successfully updated' - end -end diff --git a/test/integration/admin/registrars/edit_test.rb b/test/integration/admin/registrars/edit_test.rb new file mode 100644 index 000000000..22b93657d --- /dev/null +++ b/test/integration/admin/registrars/edit_test.rb @@ -0,0 +1,69 @@ +require 'test_helper' + +class AdminAreaEditRegistrarTest < ActionDispatch::IntegrationTest + setup do + login_as users(:admin) + @registrar = registrars(:bestnames) + end + + def test_attributes_update + visit admin_registrar_path(@registrar) + click_link_or_button 'Edit' + + fill_in 'Name', with: 'new name' + fill_in 'Reg no', with: '4727673' + fill_in 'Contact phone', with: '2570937' + fill_in 'Website', with: 'http://new.example.com' + fill_in 'Contact e-mail', with: 'new@example.com' + + fill_in 'Street', with: 'new street' + fill_in 'Zip', with: 'new zip' + fill_in 'City', with: 'new city' + fill_in 'State / Province', with: 'new state' + select 'Germany', from: 'Country' + + fill_in 'VAT number', with: '2386449' + fill_in 'Accounting customer code', with: '866477' + fill_in 'Billing email', with: 'new-billing@example.com' + + select 'Estonian', from: 'Language' + click_link_or_button 'Update registrar' + + @registrar.reload + assert_equal 'new name', @registrar.name + assert_equal '4727673', @registrar.reg_no + assert_equal '2570937', @registrar.phone + assert_equal 'http://new.example.com', @registrar.website + assert_equal 'new@example.com', @registrar.email + + assert_equal 'new street', @registrar.street + assert_equal 'new zip', @registrar.zip + assert_equal 'new city', @registrar.city + assert_equal 'new state', @registrar.state + assert_equal Country.new('DE'), @registrar.country + + assert_equal '2386449', @registrar.vat_no + assert_equal '866477', @registrar.accounting_customer_code + assert_equal 'new-billing@example.com', @registrar.billing_email + + assert_equal 'et', @registrar.language + assert_current_path admin_registrar_path(@registrar) + assert_text 'Registrar has been successfully updated' + end + + def test_code_cannot_be_changed + visit admin_registrar_path(@registrar) + click_link_or_button 'Edit' + assert_no_field 'Code' + end + + def test_fails_gracefully + visit admin_registrar_path(@registrar) + click_link_or_button 'Edit' + fill_in 'Name', with: 'Good Names' + click_link_or_button 'Update registrar' + + assert_field 'Name', with: 'Good Names' + assert_text 'Name has already been taken' + end +end diff --git a/test/integration/admin/registrars/new_registrar_test.rb b/test/integration/admin/registrars/new_registrar_test.rb deleted file mode 100644 index 33deea9e8..000000000 --- a/test/integration/admin/registrars/new_registrar_test.rb +++ /dev/null @@ -1,23 +0,0 @@ -require 'test_helper' - -class NewRegistrarTest < ActionDispatch::IntegrationTest - def setup - login_as users(:admin) - end - - def test_creates_registrar - visit admin_registrars_path - click_link_or_button 'New registrar' - - fill_in 'registrar[name]', with: 'John Doe' - fill_in 'registrar[reg_no]', with: '1234567' - fill_in 'registrar[email]', with: 'test@test.com' - fill_in 'registrar[code]', with: 'test' - fill_in 'registrar[accounting_customer_code]', with: 'test' - click_link_or_button 'Create registrar' - - assert_current_path admin_registrar_path(Registrar.last) - assert_text 'Registrar has been successfully created' - assert_text 'John Doe' - end -end diff --git a/test/integration/admin/registrars/new_test.rb b/test/integration/admin/registrars/new_test.rb new file mode 100644 index 000000000..d2efc31a2 --- /dev/null +++ b/test/integration/admin/registrars/new_test.rb @@ -0,0 +1,50 @@ +require 'test_helper' + +class AdminAreaNewRegistrarTest < ActionDispatch::IntegrationTest + setup do + login_as users(:admin) + end + + def test_new_registrar_creation_with_required_params + visit admin_registrars_url + click_link_or_button 'New registrar' + + 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' + + assert_difference 'Registrar.count' do + click_link_or_button 'Create registrar' + end + + assert_current_path admin_registrar_path(Registrar.last) + assert_text 'Registrar has been successfully created' + end + + def test_fails_gracefully + visit admin_registrars_url + click_link_or_button 'New registrar' + + fill_in 'Name', with: 'Best Names' + fill_in 'Reg no', with: '55555555' + fill_in 'Contact e-mail', with: 'test@example.com' + fill_in 'Accounting customer code', with: 'test' + fill_in 'Code', with: 'test' + + assert_no_difference 'Registrar.count' do + click_link_or_button 'Create registrar' + end + assert_field 'Name', with: 'Best Names' + assert_text 'Name has already been taken' + end + + def test_pre_populated_default_language + Setting.default_language = 'en' + visit admin_registrars_url + click_link_or_button 'New registrar' + assert_field 'Language', with: 'en' + end +end 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 new file mode 100644 index 000000000..579e4d660 --- /dev/null +++ b/test/models/registrar/code_test.rb @@ -0,0 +1,29 @@ +require 'test_helper' + +class RegistrarCodeTest < ActiveSupport::TestCase + setup do + @registrar = registrars(:bestnames).dup + end + + def test_registrar_is_invalid_without_code + @registrar.code = '' + assert @registrar.invalid? + end + + def test_special_code_validation + @registrar.code = 'CID' + assert @registrar.invalid? + assert_includes @registrar.errors.full_messages, 'Code is forbidden' + end + + def test_cannot_be_changed_once_registrar_is_created + registrar = registrars(:bestnames) + registrar.update!(code: 'new-code') + refute_equal 'new-code', registrar.code + end + + def test_normalization + @registrar.code = 'with spaces:and:colon.' + assert_equal 'WITHSPACESANDCOLON.', @registrar.code + end +end diff --git a/test/models/registrar/delete_test.rb b/test/models/registrar/delete_test.rb new file mode 100644 index 000000000..e9cb20acf --- /dev/null +++ b/test/models/registrar/delete_test.rb @@ -0,0 +1,37 @@ +require 'test_helper' + +class DeleteRegistrarTest < ActiveSupport::TestCase + setup do + @registrar = registrars(:not_in_use) + end + + def test_can_be_deleted_if_not_in_use + assert_difference 'Registrar.count', -1 do + @registrar.destroy + end + end + + def test_cannot_be_deleted_if_has_at_least_one_user + users(:api_bestnames).update!(registrar: @registrar) + + assert_no_difference 'Registrar.count' do + @registrar.destroy + end + end + + def test_cannot_be_deleted_if_has_at_least_one_contact + contacts(:john).update!(registrar: @registrar) + + assert_no_difference 'Registrar.count' do + @registrar.destroy + end + end + + def test_cannot_be_deleted_if_has_at_least_one_domain + domains(:shop).update!(registrar: @registrar) + + assert_no_difference 'Registrar.count' do + @registrar.destroy + end + end +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 58a06b0ae..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 @@ -9,21 +9,33 @@ class RegistrarTest < ActiveSupport::TestCase assert @registrar.valid? end - def test_rejects_absent_accounting_customer_code - @registrar.accounting_customer_code = nil - @registrar.validate + def test_invalid_without_name + @registrar.name = '' assert @registrar.invalid? end - def test_requires_country_code - @registrar.country_code = nil - @registrar.validate + def test_invalid_without_reg_no + @registrar.reg_no = '' assert @registrar.invalid? end - def test_requires_language - @registrar.language = nil - @registrar.validate + def test_invalid_without_email + @registrar.email = '' + assert @registrar.invalid? + end + + def test_invalid_without_accounting_customer_code + @registrar.accounting_customer_code = '' + assert @registrar.invalid? + end + + def test_invalid_without_country_code + @registrar.country_code = '' + assert @registrar.invalid? + end + + def test_invalid_without_language + @registrar.language = '' assert @registrar.invalid? end @@ -38,4 +50,13 @@ class RegistrarTest < ActiveSupport::TestCase registrar = Registrar.new(language: 'de') assert_equal 'de', registrar.language end + + def test_full_address + assert_equal 'Main Street, New York, New York, 12345', @registrar.address + end + + def test_reference_number_generation + @registrar.validate + refute_empty @registrar.reference_no + end 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