diff --git a/app/controllers/admin/registrars_controller.rb b/app/controllers/admin/registrars_controller.rb index de8d099d2..119abf85b 100644 --- a/app/controllers/admin/registrars_controller.rb +++ b/app/controllers/admin/registrars_controller.rb @@ -78,7 +78,8 @@ module Admin :billing_email, :code, :test_registrar, - :accounting_customer_code) + :accounting_customer_code, + :language) end end end diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index fac9d29f4..ff1e8eb26 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -16,6 +16,8 @@ class ApplicationController < ActionController::Base end helper_method :registrant_request?, :registrar_request?, :admin_request?, :current_root_url + helper_method :available_languages + def registrant_request? request.path.match(/^\/registrant/) end @@ -79,4 +81,10 @@ class ApplicationController < ActionController::Base return if params[parent_key][key].blank? params[parent_key][key].sub!(/,/, '.') end + + private + + def available_languages + { en: 'English', et: 'Estonian' }.invert + end end diff --git a/app/helpers/default_form_builder.rb b/app/helpers/default_form_builder.rb index 406893109..02f98e69d 100644 --- a/app/helpers/default_form_builder.rb +++ b/app/helpers/default_form_builder.rb @@ -7,4 +7,11 @@ class DefaultFormBuilder < ActionView::Helpers::FormBuilder def money_field(method, options = {}) @template.money_field(@object_name, method, objectify_options(options)) end + + def language_select(method, choices = nil, options = {}, html_options = {}, &block) + options[:selected] = @object.send(method) unless options[:selected] + @template.language_select(@object_name, method, choices, objectify_options(options), + @default_options.merge(html_options), + &block) + end end diff --git a/app/helpers/form_helper.rb b/app/helpers/form_helper.rb index aa25fbaea..f82fee682 100644 --- a/app/helpers/form_helper.rb +++ b/app/helpers/form_helper.rb @@ -12,4 +12,9 @@ module FormHelper text_field(object_name, method, options) end + + def language_select(object, method, choices = nil, options = {}, html_options = {}, &block) + choices = options_for_select(available_languages, options[:selected]) + select(object, method, choices, options, html_options, &block) + end end diff --git a/app/models/registrar.rb b/app/models/registrar.rb index b410a1c76..418277b8a 100644 --- a/app/models/registrar.rb +++ b/app/models/registrar.rb @@ -16,8 +16,11 @@ class Registrar < ActiveRecord::Base validates :name, :reg_no, :country_code, :email, :code, presence: true validates :name, :reg_no, :reference_no, :code, uniqueness: true validates :accounting_customer_code, presence: true + validates :language, presence: true validate :forbidden_codes + after_initialize :set_defaults + def forbidden_codes return true unless ['CID'].include? code errors.add(:code, I18n.t(:forbidden_code)) @@ -163,4 +166,10 @@ class Registrar < ActiveRecord::Base return true unless Setting.api_ip_whitelist_enabled white_ips.api.pluck(:ipv4, :ipv6).flatten.include?(ip) end + + private + + def set_defaults + self.language = Setting.default_language unless language + end end diff --git a/app/presenters/registrar_presenter.rb b/app/presenters/registrar_presenter.rb index 57c130faa..40d26f063 100644 --- a/app/presenters/registrar_presenter.rb +++ b/app/presenters/registrar_presenter.rb @@ -20,6 +20,10 @@ class RegistrarPresenter registrar.website end + def language + view.available_languages.key(registrar.language.to_sym) + end + private attr_reader :registrar diff --git a/app/views/admin/registrars/_form.haml b/app/views/admin/registrars/_form.haml deleted file mode 100644 index 2a80e7357..000000000 --- a/app/views/admin/registrars/_form.haml +++ /dev/null @@ -1,105 +0,0 @@ -= form_for([:admin, @registrar], html: {class: 'form-horizontal'}) do |f| - = render 'shared/full_errors', object: @registrar - - .row - .col-md-8 - .panel.panel-default - .panel-heading.clearfix - .pull-left= t(:general) - .panel-body - .form-group - .col-md-4.control-label - = f.label :name - .col-md-7 - = f.text_field(:name, class: 'form-control') - .form-group - .col-md-4.control-label - = f.label :reg_no - .col-md-7 - = f.text_field(:reg_no, class: 'form-control') - .form-group - .col-md-4.control-label - = f.label :vat_no - .col-md-7 - = f.text_field(:vat_no, class: 'form-control') - .form-group - .col-md-4.control-label - = f.label :phone - .col-md-7 - = f.text_field(:phone, class: 'form-control') - .form-group - .col-md-4.control-label - = f.label :website - .col-md-7 - = f.url_field :website, class: 'form-control' - .form-group - .col-md-4.control-label - = f.label :email - .col-md-7 - = f.email_field :email, class: 'form-control' - .form-group - .col-md-4.control-label - = f.label :billing_email - .col-md-7 - = f.email_field :billing_email, class: 'form-control' - - .form-group - .col-md-4.control-label - = f.label :accounting_customer_code - .col-md-7 - = f.text_field :accounting_customer_code, class: 'form-control', required: true - - .row - .col-md-8 - .panel.panel-default - .panel-heading.clearfix - .pull-left= t(:address) - .panel-body - .form-group - .col-md-4.control-label - = f.label :street - .col-md-7 - = f.text_field(:street, class: 'form-control') - .form-group - .col-md-4.control-label - = f.label :city - .col-md-7 - = f.text_field(:city, class: 'form-control') - .form-group - .col-md-4.control-label - = f.label :state - .col-md-7 - = f.text_field(:state, class: 'form-control') - .form-group - .col-md-4.control-label - = f.label :zip - .col-md-7 - = f.text_field(:zip, class: 'form-control') - .form-group - .col-md-4.control-label - = f.label :country_code, t(:country) - .col-md-7 - = f.select(:country_code, - SortedCountry.all_options(f.object.country_code), {}, class: 'form-control') - - .row - .col-md-8 - .panel.panel-default - .panel-heading.clearfix - .pull-left= t('.misc') - .panel-body - .form-group - .col-md-4.control-label - = f.label :code - .col-md-7 - = f.text_field(:code, class: 'form-control', disabled: !f.object.new_record?) - .form-group - .col-md-4.control-label - = f.label :test_registrar - .col-md-7 - = f.check_box :test_registrar, class: 'form-control' - - %hr - .row - .col-md-8.text-right - = button_tag(t(".#{f.object.new_record? ? 'create' : 'update'}_btn"), class: 'btn btn-success') diff --git a/app/views/admin/registrars/_form.html.erb b/app/views/admin/registrars/_form.html.erb new file mode 100644 index 000000000..65a5351ad --- /dev/null +++ b/app/views/admin/registrars/_form.html.erb @@ -0,0 +1,165 @@ +<%= form_for([:admin, @registrar], html: { class: 'form-horizontal' }) do |f| %> + <%= render 'shared/full_errors', object: @registrar %> +
+
+
+
+
+ <%= t(:general) %> +
+
+
+
+
+ <%= f.label :name %> +
+
+ <%= f.text_field :name, required: true, autofocus: true, class: 'form-control' %> +
+
+ +
+
+ <%= f.label :reg_no %> +
+
+ <%= f.text_field :reg_no, required: true, class: 'form-control' %> +
+
+ +
+
+ <%= f.label :phone %> +
+
+ <%= f.text_field(:phone, class: 'form-control') %> +
+
+ +
+
+ <%= f.label :website %> +
+
+ <%= f.url_field :website, class: 'form-control' %> +
+
+ +
+
+ <%= f.label :email %> +
+
+ <%= f.email_field :email, required: true, class: 'form-control' %> +
+
+
+
+
+
+ +
+
+
+
+
+ <%= t(:address) %> +
+
+
+
+
+ <%= f.label :street %> +
+
+ <%= f.text_field(:street, class: 'form-control') %> +
+
+ +
+
+ <%= f.label :city %> +
+
+ <%= f.text_field(:city, class: 'form-control') %> +
+
+ +
+
+ <%= f.label :state %> +
+
+ <%= f.text_field(:state, class: 'form-control') %> +
+
+ +
+
+ <%= f.label :zip %> +
+
+ <%= f.text_field(:zip, class: 'form-control') %> +
+
+ +
+
+ <%= f.label :country_code, t(:country) %> +
+
+ <%= f.select(:country_code, SortedCountry.all_options(f.object.country_code), {}, class: 'form-control') %> +
+
+
+
+
+
+ + <%= render 'admin/registrars/form/billing', f: f %> + +
+
+
+
+
+ <%= t('.misc') %> +
+
+ +
+
+
+ <%= f.label :code %> +
+
+ <%= f.text_field :code, required: f.object.new_record?, class: 'form-control', disabled: !f.object.new_record? %> +
+
+ +
+
+ <%= f.label :test_registrar %> +
+
+ <%= f.check_box :test_registrar, class: 'form-control' %> +
+
+
+
+
+
+ +
+
+ <%= render 'admin/registrars/form/preferences', f: f %> +
+
+ +
+
+
+ <%= button_tag(t(".#{f.object.new_record? ? 'create' : 'update'}_btn"), class: 'btn btn-success') %> +
+
+<% end %> diff --git a/app/views/admin/registrars/edit.haml b/app/views/admin/registrars/edit.haml deleted file mode 100644 index 0fb8a88c6..000000000 --- a/app/views/admin/registrars/edit.haml +++ /dev/null @@ -1,5 +0,0 @@ -- content_for :actions do - = link_to(t(:back_to_registrar), [:admin, @registrar], class: 'btn btn-default') -= render 'shared/title', name: "#{t(:edit)}: #{@registrar.name}" - -= render 'form' diff --git a/app/views/admin/registrars/edit.html.erb b/app/views/admin/registrars/edit.html.erb new file mode 100644 index 000000000..71d6bd882 --- /dev/null +++ b/app/views/admin/registrars/edit.html.erb @@ -0,0 +1,5 @@ +<% 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 new file mode 100644 index 000000000..a3adf1312 --- /dev/null +++ b/app/views/admin/registrars/form/_billing.html.erb @@ -0,0 +1,40 @@ +
+
+
+
+
+ <%= t '.header' %> +
+
+ +
+
+
+ <%= f.label :vat_no %> +
+
+ <%= f.text_field :vat_no, class: 'form-control' %> +
+
+ +
+
+ <%= f.label :accounting_customer_code %> +
+
+ <%= f.text_field :accounting_customer_code, class: 'form-control', required: true %> +
+
+ +
+
+ <%= f.label :billing_email %> +
+
+ <%= f.email_field :billing_email, class: 'form-control' %> +
+
+
+
+
+
diff --git a/app/views/admin/registrars/form/_preferences.html.erb b/app/views/admin/registrars/form/_preferences.html.erb new file mode 100644 index 000000000..0626c21ef --- /dev/null +++ b/app/views/admin/registrars/form/_preferences.html.erb @@ -0,0 +1,16 @@ +
+
+ <%= t '.header' %> +
+ +
+
+
+ <%= f.label :language %> +
+
+ <%= f.language_select :language, nil, {}, required: true, class: 'form-control' %> +
+
+
+
diff --git a/app/views/admin/registrars/index.haml b/app/views/admin/registrars/index.haml deleted file mode 100644 index ea9f7b312..000000000 --- a/app/views/admin/registrars/index.haml +++ /dev/null @@ -1,28 +0,0 @@ -- content_for :actions do - = link_to(t('.new_btn'), new_admin_registrar_path, class: 'btn btn-primary') -= render 'shared/title', name: t(:registrars) - -.row - .col-md-12 - .table-responsive - %table.table.table-hover.table-bordered.table-condensed - %thead - %tr - %th{class: 'col-xs-4'} - = sort_link(@q, 'name') - %th{class: 'col-xs-4'} - = sort_link(@q, 'reg_no', t(:reg_no)) - %th{class: 'col-xs-4'} - = t(:credit_balance) - %th{class: 'col-xs-4'} - = t(:test_registrar) - %tbody - - @registrars.each do |x| - %tr - %td= link_to(x, [:admin, x]) - %td= x.reg_no - %td= "#{x.balance}" - %td= "#{x.test_registrar}" -.row - .col-md-12 - = paginate @registrars diff --git a/app/views/admin/registrars/index.html.erb b/app/views/admin/registrars/index.html.erb new file mode 100644 index 000000000..5533a6f07 --- /dev/null +++ b/app/views/admin/registrars/index.html.erb @@ -0,0 +1,51 @@ +<% content_for :actions do %> + <%= link_to(t('.new_btn'), new_admin_registrar_path, class: 'btn btn-primary') %> +<% end %> +<%= render 'shared/title', name: t(:registrars) %> +
+
+
+ + + + + + + + + + + <% @registrars.each do |x| %> + + + + + + + <% end %> + +
+ <%= sort_link(@q, 'name') %> + + <%= sort_link(@q, 'reg_no', t(:reg_no)) %> + + <%= t(:credit_balance) %> + + <%= t(:test_registrar) %> +
+ <%= link_to(x, [:admin, x]) %> + + <%= x.reg_no %> + + <%= "#{x.balance}" %> + + <%= "#{x.test_registrar}" %> +
+
+
+
+
+
+ <%= paginate @registrars %> +
+
diff --git a/app/views/admin/registrars/new.haml b/app/views/admin/registrars/new.haml deleted file mode 100644 index 5f651835a..000000000 --- a/app/views/admin/registrars/new.haml +++ /dev/null @@ -1,3 +0,0 @@ -= render 'shared/title', name: t(:new_registrar) - -= render 'form' diff --git a/app/views/admin/registrars/new.html.erb b/app/views/admin/registrars/new.html.erb new file mode 100644 index 000000000..70154d217 --- /dev/null +++ b/app/views/admin/registrars/new.html.erb @@ -0,0 +1,2 @@ +<%= render 'shared/title', name: t(:new_registrar) %> +<%= render 'form' %> diff --git a/app/views/admin/registrars/show.haml b/app/views/admin/registrars/show.haml deleted file mode 100644 index 7bd49f058..000000000 --- a/app/views/admin/registrars/show.haml +++ /dev/null @@ -1,118 +0,0 @@ -- 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') -- content_for :page_name do - = @registrar.name - - if @registrar.test_registrar? - %span{style: "color: #c9302c;"} (test) -= render 'shared/title', name: @registrar.name - -- if @registrar.errors.any? - - @registrar.errors.each do |attr, err| - = err - %br -- if @registrar.errors.any? - %hr -.row - .col-md-6 - .panel.panel-default - .panel-heading - %h3.panel-title= t(:general) - .panel-body - %dl.dl-horizontal - %dt= t(:name) - %dd= @registrar.name - - %dt= t(:reg_no) - %dd= @registrar.reg_no - - %dt= t(:vat_no) - %dd= @registrar.vat_no - - %dt= t(:reference_no) - %dd= @registrar.reference_no - - %dt= t(:id) - %dd= @registrar.code - - %dt= t(:credit_balance) - %dd= @registrar.balance - - %dt= Registrar.human_attribute_name :website - %dd= @registrar.website - - %dt= Registrar.human_attribute_name :accounting_customer_code - %dd= @registrar.accounting_customer_code - - .col-md-6 - .panel.panel-default - .panel-heading - %h3.panel-title= t(:contact) - .panel-body - %dl.dl-horizontal - %dt= t(:country) - %dd= @registrar.country - - %dt= t(:address) - %dd= @registrar.address - - %dt= t(:contact_phone) - %dd= @registrar.phone - - %dt= t(:contact_email) - %dd= @registrar.email - - %dt= t(:billing_address) - %dd= @registrar.billing_address - - %dt= t(:billing_email) - %dd= @registrar.billing_email - -.row - .col-md-12 - #epp-users.panel.panel-default - .panel-heading.clearfix - .pull-left - = t('.api_users') - .pull-right - = link_to(t('.new_api_use_btn'), new_admin_registrar_api_user_path(@registrar), class: 'btn btn-default btn-xs') - - .table-responsive - %table.table.table-hover.table-bordered.table-condensed - %thead - %tr - %th{class: 'col-xs-6'}= t(:username) - %th{class: 'col-xs-6'}= t('.active') - %tbody - - @registrar.api_users.each do |x| - %tr - %td= link_to(x, [:admin, x]) - %td= x.active - -.row - .col-md-12 - #epp-users.panel.panel-default - .panel-heading.clearfix - .pull-left - = t(:white_ips) - .pull-right - = link_to(t(:create_new_white_ip), new_admin_registrar_white_ip_path(@registrar), class: 'btn btn-default btn-xs') - - .table-responsive - %table.table.table-hover.table-bordered.table-condensed - %thead - %tr - %th{class: 'col-xs-4'}= t(:ipv4) - %th{class: 'col-xs-6'}= t(:ipv6) - %th{class: 'col-xs-2'}= t(:interfaces) - %tbody - - @registrar.white_ips.each do |x| - %tr - %td - - if x.ipv4.present? - = link_to(x.ipv4, [:admin, @registrar, x]) - %td - - if x.ipv6.present? - = link_to(x.ipv6, [:admin, @registrar, x]) - %td= x.interfaces.join(', ').upcase diff --git a/app/views/admin/registrars/show.html.erb b/app/views/admin/registrars/show.html.erb new file mode 100644 index 000000000..c09602985 --- /dev/null +++ b/app/views/admin/registrars/show.html.erb @@ -0,0 +1,224 @@ +<% 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 %> +
+
+
+
+
+
+
+
+

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

+
+
+
+
+ <%= t(:country) %> +
+
+ <%= @registrar.country %> +
+
+ <%= t(:address) %> +
+
+ <%= @registrar.address %> +
+
+ <%= t(:contact_phone) %> +
+
+ <%= @registrar.phone %> +
+
+ <%= t(:contact_email) %> +
+
+ <%= @registrar.email %> +
+
+ <%= t(:billing_address) %> +
+
+ <%= @registrar.billing_address %> +
+
+ <%= t(:billing_email) %> +
+
+ <%= @registrar.billing_email %> +
+
+
+
+ <%= render 'admin/registrars/show/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 %> +
+
+
+
+
+
+
+
+
+
+ <%= 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 %> +
+
+
+
+
diff --git a/app/views/admin/registrars/show/_preferences.html.erb b/app/views/admin/registrars/show/_preferences.html.erb new file mode 100644 index 000000000..7b492962e --- /dev/null +++ b/app/views/admin/registrars/show/_preferences.html.erb @@ -0,0 +1,12 @@ +
+
+ <%= t '.header' %> +
+ +
+
+
<%= Registrar.human_attribute_name :language %>
+
<%= registrar.language %>
+
+
+
diff --git a/app/views/admin/settings/index.haml b/app/views/admin/settings/index.haml index 94d0a2657..c41f5cd6b 100644 --- a/app/views/admin/settings/index.haml +++ b/app/views/admin/settings/index.haml @@ -50,6 +50,13 @@ = render 'setting_row', var: :request_confirmation_on_domain_deletion_enabled = render 'setting_row', var: :address_processing + %tr + %td.col-md-6= label_tag :default_language + %td.col-md-6 + = select_tag '[settings][default_language]', + options_for_select(available_languages, Setting.default_language), + class: 'form-control' + .panel.panel-default .panel-heading = t('.billing') diff --git a/config/initializers/initial_settings.rb b/config/initializers/initial_settings.rb index 922d96bc9..94ff1dc7e 100644 --- a/config/initializers/initial_settings.rb +++ b/config/initializers/initial_settings.rb @@ -27,6 +27,7 @@ if con.present? && con.table_exists?('settings') Setting.save_default(:request_confrimation_on_registrant_change_enabled, true) Setting.save_default(:request_confirmation_on_domain_deletion_enabled, true) Setting.save_default(:address_processing, true) + Setting.save_default(:default_language, 'en') Setting.save_default(:nameserver_required, false) Setting.save_default(:client_side_status_editing_enabled, false) diff --git a/config/locales/admin/registrars.en.yml b/config/locales/admin/registrars.en.yml index b30ad456e..3d269f64b 100644 --- a/config/locales/admin/registrars.en.yml +++ b/config/locales/admin/registrars.en.yml @@ -9,6 +9,9 @@ en: active: Active api_users: API users + preferences: + header: Preferences + create: created: Registrar has been successfully created not_created: Unable to create registrar @@ -21,3 +24,9 @@ en: misc: Miscellaneous create_btn: Create registrar update_btn: Update registrar + + billing: + header: Billing + + preferences: + header: Preferences diff --git a/db/migrate/20171121233843_add_registrar_language.rb b/db/migrate/20171121233843_add_registrar_language.rb new file mode 100644 index 000000000..ac3500b4a --- /dev/null +++ b/db/migrate/20171121233843_add_registrar_language.rb @@ -0,0 +1,5 @@ +class AddRegistrarLanguage < ActiveRecord::Migration + def change + add_column :registrars, :language, :string + end +end diff --git a/db/migrate/20171123035941_change_registrar_language_to_not_null.rb b/db/migrate/20171123035941_change_registrar_language_to_not_null.rb new file mode 100644 index 000000000..583e17bf4 --- /dev/null +++ b/db/migrate/20171123035941_change_registrar_language_to_not_null.rb @@ -0,0 +1,5 @@ +class ChangeRegistrarLanguageToNotNull < ActiveRecord::Migration + def change + change_column_null :registrars, :language, false, 'et' + end +end diff --git a/db/structure.sql b/db/structure.sql index 860a85530..30df2f3cf 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -2477,7 +2477,8 @@ CREATE TABLE registrars ( vat boolean, legacy_id integer, reference_no character varying, - test_registrar boolean DEFAULT false + test_registrar boolean DEFAULT false, + language character varying NOT NULL ); @@ -5057,3 +5058,7 @@ INSERT INTO schema_migrations (version) VALUES ('20171025113808'); INSERT INTO schema_migrations (version) VALUES ('20171025153841'); +INSERT INTO schema_migrations (version) VALUES ('20171121233843'); + +INSERT INTO schema_migrations (version) VALUES ('20171123035941'); + diff --git a/spec/views/admin/registrars/_form.haml_spec.rb b/spec/views/admin/registrars/_form.html.erb_spec.rb similarity index 73% rename from spec/views/admin/registrars/_form.haml_spec.rb rename to spec/views/admin/registrars/_form.html.erb_spec.rb index 98021d93a..83b727a30 100644 --- a/spec/views/admin/registrars/_form.haml_spec.rb +++ b/spec/views/admin/registrars/_form.html.erb_spec.rb @@ -6,6 +6,10 @@ RSpec.describe 'admin/registrars/_form' do 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 diff --git a/spec/views/admin/registrars/show.haml_spec.rb b/spec/views/admin/registrars/show.haml_spec.rb index 6ec9cab14..4def10e8c 100644 --- a/spec/views/admin/registrars/show.haml_spec.rb +++ b/spec/views/admin/registrars/show.haml_spec.rb @@ -6,6 +6,10 @@ RSpec.describe 'admin/registrars/show' do 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 diff --git a/test/controllers/admin/registrars/create_test.rb b/test/controllers/admin/registrars/create_test.rb deleted file mode 100644 index e7ee57011..000000000 --- a/test/controllers/admin/registrars/create_test.rb +++ /dev/null @@ -1,18 +0,0 @@ -require 'test_helper' - -class RegistrarsControllerTest < ActionDispatch::IntegrationTest - def setup - login_as create(:admin_user) - end - - def test_creates_new_registrar - assert_difference -> { Registrar.count } do - post admin_registrars_path, registrar: attributes_for(:registrar) - end - end - - def test_redirects_to_newly_created_registrar - post admin_registrars_path, registrar: attributes_for(:registrar) - assert_redirected_to admin_registrar_path(Registrar.first) - end -end diff --git a/test/controllers/admin/registrars/show_test.rb b/test/controllers/admin/registrars/show_test.rb deleted file mode 100644 index a3868dded..000000000 --- a/test/controllers/admin/registrars/show_test.rb +++ /dev/null @@ -1,13 +0,0 @@ -require 'test_helper' - -class RegistrarsControllerTest < ActionDispatch::IntegrationTest - def setup - login_as create(:admin_user) - end - - def test_accounting_customer_code - registrar = create(:registrar, accounting_customer_code: 'test accounting customer code') - visit admin_registrar_path(registrar) - assert_text 'test accounting customer code' - end -end diff --git a/test/controllers/admin/registrars/update_test.rb b/test/controllers/admin/registrars/update_test.rb index bf79aca65..ae695f3c3 100644 --- a/test/controllers/admin/registrars/update_test.rb +++ b/test/controllers/admin/registrars/update_test.rb @@ -2,39 +2,29 @@ require 'test_helper' class RegistrarsControllerTest < ActionDispatch::IntegrationTest def setup - login_as create(:admin_user) + login_as users(:admin) + @registrar = registrars(:valid) end def test_updates_website - registrar = create(:registrar, website: 'test') + patch admin_registrar_path(@registrar), registrar: @registrar.attributes.merge(website: 'new.example.com') + @registrar.reload - patch admin_registrar_path(registrar), registrar: attributes_for(:registrar, website: 'new-website') - registrar.reload - - assert_equal 'new-website', registrar.website + assert_equal 'new.example.com', @registrar.website end def test_updates_email - registrar = create(:registrar, email: 'test@test.com') + patch admin_registrar_path(@registrar), registrar: @registrar.attributes.merge(email: 'new@example.com') + @registrar.reload - patch admin_registrar_path(registrar), registrar: attributes_for(:registrar, email: 'new-test@test.com') - registrar.reload - - assert_equal 'new-test@test.com', registrar.email + assert_equal 'new@example.com', @registrar.email end def test_updates_billing_email - registrar = create(:registrar, billing_email: 'test@test.com') + patch admin_registrar_path(@registrar), + registrar: @registrar.attributes.merge(billing_email: 'new-billing@example.com') + @registrar.reload - patch admin_registrar_path(registrar), registrar: attributes_for(:registrar, billing_email: 'new-test@test.com') - registrar.reload - - assert_equal 'new-test@test.com', registrar.billing_email - end - - def test_redirects_to_registrar - registrar = create(:registrar) - patch admin_registrar_path(registrar), registrar: attributes_for(:registrar) - assert_redirected_to admin_registrar_path(registrar) + assert_equal 'new-billing@example.com', @registrar.billing_email end end diff --git a/test/fixtures/registrars.yml b/test/fixtures/registrars.yml new file mode 100644 index 000000000..52b2bbc00 --- /dev/null +++ b/test/fixtures/registrars.yml @@ -0,0 +1,21 @@ +DEFAULTS: &DEFAULTS + name: Acme Ltd + reg_no: 1234 + country_code: US + email: acme@example.com + code: 1234 + accounting_customer_code: ACCOUNT001 + language: en + +valid: + <<: *DEFAULTS + +complete: + <<: *DEFAULTS + name: 2 + reg_no: 2 + code: 2 + website: example.com + email: info@example.com + billing_email: billing@example.com + vat_no: US12345 diff --git a/test/fixtures/users.yml b/test/fixtures/users.yml new file mode 100644 index 000000000..860f06c13 --- /dev/null +++ b/test/fixtures/users.yml @@ -0,0 +1,16 @@ +DEFAULTS: &DEFAULTS + username: test + +api: + <<: *DEFAULTS + type: ApiUser + registrar: valid + roles: + - super + +admin: + <<: *DEFAULTS + type: AdminUser + country_code: US + roles: + - admin diff --git a/test/integration/admin/registrars/edit_registrar_test.rb b/test/integration/admin/registrars/edit_registrar_test.rb index 6965cfd02..b21488306 100644 --- a/test/integration/admin/registrars/edit_registrar_test.rb +++ b/test/integration/admin/registrars/edit_registrar_test.rb @@ -2,16 +2,16 @@ require 'test_helper' class EditRegistrarTest < ActionDispatch::IntegrationTest def setup - login_as create(:admin_user) + login_as users(:admin) + @registrar = registrars(:valid) end def test_updates_registrar - registrar = create(:registrar) - - visit admin_registrar_path(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/new_registrar_test.rb b/test/integration/admin/registrars/new_registrar_test.rb index c0087e5e2..33deea9e8 100644 --- a/test/integration/admin/registrars/new_registrar_test.rb +++ b/test/integration/admin/registrars/new_registrar_test.rb @@ -2,20 +2,22 @@ require 'test_helper' class NewRegistrarTest < ActionDispatch::IntegrationTest def setup - login_as create(:admin_user) + login_as users(:admin) end def test_creates_registrar visit admin_registrars_path click_link_or_button 'New registrar' - fill_in 'registrar[name]', with: 'test' + 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/show_registrar_test.rb b/test/integration/admin/registrars/show_registrar_test.rb new file mode 100644 index 000000000..b56c3a74f --- /dev/null +++ b/test/integration/admin/registrars/show_registrar_test.rb @@ -0,0 +1,19 @@ +require 'test_helper' + +class ShowRegistrarTest < ActionDispatch::IntegrationTest + include ActionView::Helpers::NumberHelper + + def setup + login_as users(:admin) + @registrar = registrars(:complete) + visit admin_registrar_path(@registrar) + end + + def test_accounting_customer_code + assert_text 'ACCOUNT001' + end + + def test_language + assert_text 'Language English' + end +end diff --git a/test/models/registrar_test.rb b/test/models/registrar_test.rb index f5012b099..6c92bbff9 100644 --- a/test/models/registrar_test.rb +++ b/test/models/registrar_test.rb @@ -1,9 +1,41 @@ require 'test_helper' class RegistrarTest < ActiveSupport::TestCase + def setup + @registrar = registrars(:valid) + end + + def test_valid + assert @registrar.valid? + end + def test_rejects_absent_accounting_customer_code - registrar = Registrar.new(accounting_customer_code: nil) - registrar.validate - assert registrar.errors.added?(:accounting_customer_code, :blank) + @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 + assert @registrar.invalid? + end + + def test_has_default_language + Setting.default_language = 'en' + registrar = Registrar.new + assert_equal 'en', registrar.language + end + + def test_overrides_default_language + Setting.default_language = 'en' + registrar = Registrar.new(language: 'de') + assert_equal 'de', registrar.language end end