mirror of
https://github.com/internetee/registry.git
synced 2025-06-12 15:44:45 +02:00
parent
7f2ad25ee6
commit
a5869e0eca
35 changed files with 471 additions and 427 deletions
|
@ -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,22 +36,15 @@ 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
|
||||
else
|
||||
flash.now[:alert] = I18n.t('failed_to_delete_registrar')
|
||||
render 'show'
|
||||
end
|
||||
@registrar.destroy!
|
||||
redirect_to admin_registrars_url, notice: t('.deleted')
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
@ -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,10 @@ class Registrar < ActiveRecord::Base
|
|||
validates :name, :reg_no, :reference_no, :code, uniqueness: true
|
||||
validates :accounting_customer_code, presence: true
|
||||
validates :language, presence: true
|
||||
validate :forbidden_codes
|
||||
validate :forbid_special_code
|
||||
|
||||
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 },
|
||||
|
@ -177,4 +150,29 @@ class Registrar < ActiveRecord::Base
|
|||
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
|
||||
end
|
||||
|
|
17
app/views/admin/registrars/_billing.html.erb
Normal file
17
app/views/admin/registrars/_billing.html.erb
Normal file
|
@ -0,0 +1,17 @@
|
|||
<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
<%= t '.header' %>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<dl class="dl-horizontal">
|
||||
<dt><%= Registrar.human_attribute_name :vat_no %></dt>
|
||||
<dd><%= registrar.vat_no %></dd>
|
||||
|
||||
<dt><%= Registrar.human_attribute_name :accounting_customer_code %></dt>
|
||||
<dd><%= registrar.accounting_customer_code %></dd>
|
||||
|
||||
<dt><%= Registrar.human_attribute_name :billing_email %></dt>
|
||||
<dd><%= registrar.billing_email %></dd>
|
||||
</dl>
|
||||
</div>
|
||||
</div>
|
|
@ -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 %>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-8">
|
||||
<div class="panel panel-default">
|
||||
|
@ -133,7 +134,9 @@
|
|||
<%= f.label :code %>
|
||||
</div>
|
||||
<div class="col-md-7">
|
||||
<%= 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' %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
|
@ -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}" %>
|
||||
<ol class="breadcrumb">
|
||||
<li><%= link_to t('admin.registrars.index.header'), admin_registrars_path %></li>
|
||||
<li><%= link_to @registrar.name, admin_registrar_path(@registrar) %></li>
|
||||
</ol>
|
||||
|
||||
<div class="page-header">
|
||||
<h1><%= t '.header' %></h1>
|
||||
</div>
|
||||
|
||||
<%= render 'form' %>
|
||||
|
|
|
@ -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) %>
|
||||
<div class="page-header">
|
||||
<div class="row">
|
||||
<div class="col-sm-10">
|
||||
<h1><%= t '.header' %></h1>
|
||||
</div>
|
||||
|
||||
<div class="col-sm-2 text-right">
|
||||
<%= link_to t('.new_btn'), new_admin_registrar_path, class: 'btn btn-primary' %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<div class="table-responsive">
|
||||
|
|
|
@ -1,2 +1,9 @@
|
|||
<%= render 'shared/title', name: t(:new_registrar) %>
|
||||
<ol class="breadcrumb">
|
||||
<li><%= link_to t('admin.registrars.index.header'), admin_registrars_path %></li>
|
||||
</ol>
|
||||
|
||||
<div class="page-header">
|
||||
<h1><%= t '.header' %></h1>
|
||||
</div>
|
||||
|
||||
<%= render 'form' %>
|
||||
|
|
|
@ -1,15 +1,31 @@
|
|||
<% 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? %>
|
||||
<span style="color: #c9302c;">(test)</span>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<%= render 'shared/title', name: @registrar.name %>
|
||||
|
||||
<ol class="breadcrumb">
|
||||
<li><%= link_to t('admin.registrars.index.header'), admin_registrars_path %></li>
|
||||
</ol>
|
||||
|
||||
<div class="page-header">
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
<h1>
|
||||
<%= @registrar.name %>
|
||||
<% if @registrar.test_registrar? %>
|
||||
<span class="text-danger"> (test)</span>
|
||||
<% end %>
|
||||
</h1>
|
||||
</div>
|
||||
|
||||
<div class="col-md-6 text-right">
|
||||
<%= link_to t('.edit_btn'), edit_admin_registrar_path(@registrar),
|
||||
class: 'btn btn-primary' %>
|
||||
<%= link_to t('.delete_btn'), admin_registrar_path(@registrar),
|
||||
method: :delete,
|
||||
data: { confirm: t('.delete_btn_confirm') },
|
||||
class: 'btn btn-default' %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<% if @registrar.errors.any? %>
|
||||
<% @registrar.errors.each do |attr, err| %>
|
||||
<%= err %>
|
||||
|
@ -41,12 +57,6 @@
|
|||
<dd>
|
||||
<%= @registrar.reg_no %>
|
||||
</dd>
|
||||
<dt>
|
||||
<%= t(:vat_no) %>
|
||||
</dt>
|
||||
<dd>
|
||||
<%= @registrar.vat_no %>
|
||||
</dd>
|
||||
<dt>
|
||||
<%= t(:reference_no) %>
|
||||
</dt>
|
||||
|
@ -71,12 +81,6 @@
|
|||
<dd>
|
||||
<%= @registrar.website %>
|
||||
</dd>
|
||||
<dt>
|
||||
<%= Registrar.human_attribute_name :accounting_customer_code %>
|
||||
</dt>
|
||||
<dd>
|
||||
<%= @registrar.accounting_customer_code %>
|
||||
</dd>
|
||||
</dl>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -120,21 +124,16 @@
|
|||
<dd>
|
||||
<%= @registrar.billing_address %>
|
||||
</dd>
|
||||
<dt>
|
||||
<%= t(:billing_email) %>
|
||||
</dt>
|
||||
<dd>
|
||||
<%= @registrar.billing_email %>
|
||||
</dd>
|
||||
</dl>
|
||||
</div>
|
||||
</div>
|
||||
<%= render 'billing', registrar: @registrar %>
|
||||
<%= render 'admin/registrars/show/preferences', registrar: registrar %>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<div class="panel panel-default" id="epp-users">
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading clearfix">
|
||||
<div class="pull-left">
|
||||
<%= t('.api_users') %>
|
||||
|
@ -174,7 +173,7 @@
|
|||
</div>
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<div class="panel panel-default" id="epp-users">
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading clearfix">
|
||||
<div class="pull-left">
|
||||
<%= t(:white_ips) %>
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
%dt= t(:reg_no)
|
||||
%dd= @registrar.reg_no
|
||||
|
||||
%dt= t(:vat_no)
|
||||
%dt= Registrar.human_attribute_name :vat_no
|
||||
%dd= @registrar.vat_no
|
||||
|
||||
%dt= t(:id)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -2,9 +2,16 @@ en:
|
|||
admin:
|
||||
registrars:
|
||||
index:
|
||||
header: Registrars
|
||||
new_btn: New registrar
|
||||
|
||||
new:
|
||||
header: New registrar
|
||||
|
||||
show:
|
||||
edit_btn: Edit
|
||||
delete_btn: Delete
|
||||
delete_btn_confirm: Are you sure you want delete registrar?
|
||||
new_api_use_btn: New API user
|
||||
active: Active
|
||||
api_users: API users
|
||||
|
@ -12,13 +19,20 @@ en:
|
|||
preferences:
|
||||
header: Preferences
|
||||
|
||||
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
|
||||
|
|
|
@ -199,7 +199,6 @@ en:
|
|||
alg: 'Algorithm'
|
||||
public_key: 'Public key'
|
||||
registrar:
|
||||
billing_email: 'Billing e-mail'
|
||||
phone: 'Contact phone'
|
||||
email: 'Contact e-mail'
|
||||
state: 'State / Province'
|
||||
|
@ -315,13 +314,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'
|
||||
|
@ -652,7 +645,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'
|
||||
|
@ -780,3 +772,6 @@ en:
|
|||
delimiter: " "
|
||||
precision: 2
|
||||
unit: €
|
||||
|
||||
attributes:
|
||||
vat_no: VAT number
|
||||
|
|
8
config/locales/registrars.en.yml
Normal file
8
config/locales/registrars.en.yml
Normal file
|
@ -0,0 +1,8 @@
|
|||
en:
|
||||
activerecord:
|
||||
errors:
|
||||
models:
|
||||
registrar:
|
||||
attributes:
|
||||
code:
|
||||
forbidden: is forbidden
|
|
@ -0,0 +1,19 @@
|
|||
class AddRegistrarsUniqueConstraints < ActiveRecord::Migration
|
||||
def up
|
||||
execute <<-SQL
|
||||
ALTER TABLE registrars ADD CONSTRAINT unique_name UNIQUE (name);
|
||||
ALTER TABLE registrars ADD CONSTRAINT unique_reg_no UNIQUE (reg_no);
|
||||
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_reg_no;
|
||||
ALTER TABLE registrars DROP CONSTRAINT unique_reference_no;
|
||||
ALTER TABLE registrars DROP CONSTRAINT unique_code;
|
||||
SQL
|
||||
end
|
||||
end
|
6
db/migrate/20180309053921_remove_registrars_indexes.rb
Normal file
6
db/migrate/20180309053921_remove_registrars_indexes.rb
Normal file
|
@ -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
|
|
@ -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
|
|
@ -2136,8 +2136,8 @@ 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,
|
||||
billing_address character varying,
|
||||
created_at timestamp without time zone,
|
||||
|
@ -2145,14 +2145,14 @@ CREATE TABLE registrars (
|
|||
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,
|
||||
|
@ -3244,6 +3244,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:
|
||||
--
|
||||
|
@ -3252,6 +3260,30 @@ 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_reg_no; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace:
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY registrars
|
||||
ADD CONSTRAINT unique_reg_no UNIQUE (reg_no);
|
||||
|
||||
|
||||
--
|
||||
-- Name: unique_session_id; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace:
|
||||
--
|
||||
|
@ -3854,20 +3886,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:
|
||||
--
|
||||
|
@ -4678,3 +4696,9 @@ INSERT INTO schema_migrations (version) VALUES ('20180306183540');
|
|||
|
||||
INSERT INTO schema_migrations (version) VALUES ('20180306183549');
|
||||
|
||||
INSERT INTO schema_migrations (version) VALUES ('20180309053424');
|
||||
|
||||
INSERT INTO schema_migrations (version) VALUES ('20180309053921');
|
||||
|
||||
INSERT INTO schema_migrations (version) VALUES ('20180309054510');
|
||||
|
||||
|
|
|
@ -101,7 +101,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
|
||||
|
||||
|
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
6
test/fixtures/accounts.yml
vendored
6
test/fixtures/accounts.yml
vendored
|
@ -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
|
||||
|
|
13
test/fixtures/registrars.yml
vendored
13
test/fixtures/registrars.yml
vendored
|
@ -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
|
||||
|
@ -16,3 +20,12 @@ goodnames:
|
|||
country_code: US
|
||||
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
|
||||
|
|
18
test/integration/admin/registrars/delete_test.rb
Normal file
18
test/integration/admin/registrars/delete_test.rb
Normal file
|
@ -0,0 +1,18 @@
|
|||
require 'test_helper'
|
||||
|
||||
class AdminAreaDeleteRegistrarTest < ActionDispatch::IntegrationTest
|
||||
def setup
|
||||
login_as users(:admin)
|
||||
end
|
||||
|
||||
def test_can_be_deleted_if_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
|
||||
end
|
|
@ -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
|
69
test/integration/admin/registrars/edit_test.rb
Normal file
69
test/integration/admin/registrars/edit_test.rb
Normal file
|
@ -0,0 +1,69 @@
|
|||
require 'test_helper'
|
||||
|
||||
class AdminAreaEditRegistrarTest < ActionDispatch::IntegrationTest
|
||||
def setup
|
||||
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
|
|
@ -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
|
49
test/integration/admin/registrars/new_test.rb
Normal file
49
test/integration/admin/registrars/new_test.rb
Normal file
|
@ -0,0 +1,49 @@
|
|||
require 'test_helper'
|
||||
|
||||
class AdminAreaNewRegistrarTest < ActionDispatch::IntegrationTest
|
||||
def setup
|
||||
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'
|
||||
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
|
29
test/models/registrar/code_test.rb
Normal file
29
test/models/registrar/code_test.rb
Normal file
|
@ -0,0 +1,29 @@
|
|||
require 'test_helper'
|
||||
|
||||
class RegistrarCodeTest < ActiveSupport::TestCase
|
||||
def setup
|
||||
@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
|
37
test/models/registrar/delete_test.rb
Normal file
37
test/models/registrar/delete_test.rb
Normal file
|
@ -0,0 +1,37 @@
|
|||
require 'test_helper'
|
||||
|
||||
class DeleteRegistrarTest < ActiveSupport::TestCase
|
||||
def setup
|
||||
@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
|
|
@ -9,21 +9,33 @@ class RegistrarTest < ActiveSupport::TestCase
|
|||
assert @registrar.valid?
|
||||
end
|
||||
|
||||
def test_invalid_without_name
|
||||
@registrar.name = ''
|
||||
assert @registrar.invalid?
|
||||
end
|
||||
|
||||
def test_invalid_without_reg_no
|
||||
@registrar.reg_no = ''
|
||||
assert @registrar.invalid?
|
||||
end
|
||||
|
||||
def test_invalid_without_email
|
||||
@registrar.email = ''
|
||||
assert @registrar.invalid?
|
||||
end
|
||||
|
||||
def test_rejects_absent_accounting_customer_code
|
||||
@registrar.accounting_customer_code = nil
|
||||
@registrar.validate
|
||||
assert @registrar.invalid?
|
||||
end
|
||||
|
||||
def test_requires_country_code
|
||||
@registrar.country_code = nil
|
||||
@registrar.validate
|
||||
assert @registrar.invalid?
|
||||
end
|
||||
|
||||
def test_requires_language
|
||||
@registrar.language = nil
|
||||
@registrar.validate
|
||||
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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue