Skip to content

Commit

Permalink
Merge branch 'master' into registry-268
Browse files Browse the repository at this point in the history
  • Loading branch information
Artur Beljajev committed Mar 8, 2017
2 parents 0661ab0 + 5dd981d commit ba53ae9
Show file tree
Hide file tree
Showing 27 changed files with 164 additions and 80 deletions.
6 changes: 6 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,10 @@ def changing_css_class(version, *attrs)
version.object_changes.to_h.slice(*attrs).any? && css_class
end
end

def legal_document_types
types = LegalDocument::TYPES.dup
types.delete('ddoc')
".#{types.join(',.')}"
end
end
6 changes: 6 additions & 0 deletions app/helpers/default_form_builder.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class DefaultFormBuilder < ActionView::Helpers::FormBuilder
def legal_document_field(method, options = {})
self.multipart = true
@template.legal_document_field(@object_name, method, objectify_options(options))
end
end
8 changes: 8 additions & 0 deletions app/helpers/form_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module FormHelper
def legal_document_field(object_name, method, options = {})
options[:data] = { legal_document: true }
options[:accept] = legal_document_types unless options[:accept]

file_field(object_name, method, options)
end
end
8 changes: 8 additions & 0 deletions app/helpers/form_tag_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module FormTagHelper
def legal_document_field_tag(name, options = {})
options[:data] = { legal_document: true }
options[:accept] = legal_document_types unless options[:accept]

file_field_tag(name, options)
end
end
8 changes: 4 additions & 4 deletions app/views/registrar/contacts/_form.haml
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@
= f.hidden_field :password
.row
.col-md-8
= render 'registrar/contacts/form_partials/general', f: f
= render 'registrar/contacts/form/general', f: f

- if address_processing?
.row
.col-md-8
= render 'registrar/contacts/form_partials/address', f: f
= render 'registrar/contacts/form/address', f: f

- if [email protected]?
.row
.col-md-8
= render 'registrar/contacts/form_partials/code', f: f
= render 'registrar/contacts/form/code', f: f
.row
.col-md-8
= render 'registrar/contacts/form_partials/legal_document', f: f
= render 'registrar/contacts/form/legal_document', f: f

.row
.col-md-8.text-right
Expand Down
2 changes: 1 addition & 1 deletion app/views/registrar/contacts/delete.haml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

.row
.col-md-8
= render 'registrar/contacts/form_partials/legal_document', f: f
= render 'registrar/contacts/form/legal_document', f: f

%hr
.row
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
= f.label :legal_document, t(:legal_document)
%p.help-block= t(:legal_document_max_size)
.col-md-7
= f.file_field :legal_document, :value => '', data: {legal_document: true}
= f.legal_document_field :legal_document
41 changes: 0 additions & 41 deletions app/views/registrar/contacts/form_partials/_disclose.haml

This file was deleted.

10 changes: 0 additions & 10 deletions app/views/registrar/contacts/partials/_disclose.haml

This file was deleted.

2 changes: 1 addition & 1 deletion app/views/registrar/contacts/partials/_domains.haml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
%th{class: 'col-xs-3'}=custom_sort_link t(:domain_name), :name
%th{class: 'col-xs-3'}=custom_sort_link t(:registrar_name), :registrar_name
%th{class: 'col-xs-3'}=custom_sort_link t(:valid_to), :valid_to
%th{class: 'col-xs-3'}= t(:roles)
%th{class: 'col-xs-3'}= t('.roles')
%tbody
- domains.each do |x|
%tr
Expand Down
17 changes: 6 additions & 11 deletions app/views/registrar/domains/_form.haml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
.row
.col-md-8
#general-tab.tab-pane.active
= render 'registrar/domains/form_partials/general'
= render 'registrar/domains/form_partials/contacts'
= render 'registrar/domains/form_partials/nameservers'
= render 'registrar/domains/form_partials/dnskeys'
= render 'registrar/domains/form/general'
= render 'registrar/domains/form/contacts'
= render 'registrar/domains/form/nameservers'
= render 'registrar/domains/form/dnskeys'

.panel.panel-default
.panel-heading.clearfix
Expand All @@ -18,17 +18,12 @@
= label_tag 'domain[legal_document]', t(:legal_document), class: c
%p.help-block= t(:legal_document_max_size)
.col-md-7
= file_field_tag 'domain[legal_document]', required: fr, data: {legal_document: true}
= legal_document_field_tag 'domain[legal_document]', required: fr
.col-md-4
%p.domain-general-help= t(:domain_general_help).html_safe
%p.domain-admin-contact-help= t(:domain_admin_contact_help).html_safe
%p.domain-tech-contact-help= t(:domain_tech_contact_help).html_safe

.row
.col-md-8.text-right
= button_tag(t('shared.save'), class: 'btn btn-warning')

:javascript
$(function () {
$('#tabs a:first').tab('show')
})
= button_tag(t('.save_btn'), class: 'btn btn-warning')
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

.form-group
.col-md-3.control-label
= label_tag "domain_dnskeys_attributes_#{k}_flags", t(:flags)
= label_tag "domain_dnskeys_attributes_#{k}_flags", t('.flags')
.col-md-7
= select_tag "domain[dnskeys_attributes][#{k}][flags]",
options_for_select(Depp::Dnskey::FLAGS, v['flags']),
Expand All @@ -55,7 +55,7 @@

.form-group
.col-md-3.control-label
= label_tag "domain_dnskeys_attributes_#{k}_alg", t(:alg)
= label_tag "domain_dnskeys_attributes_#{k}_alg", t('.alg')
.col-md-7
= select_tag "domain[dnskeys_attributes][#{k}][alg]",
options_for_select(Depp::Dnskey::ALGORITHMS, v['alg']), { class: 'form-control' }
Expand Down
6 changes: 3 additions & 3 deletions app/views/registrar/domains/partials/_general.haml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
%dt= t(:registrant)
%dd= "#{registrant.name} (#{@data.css('registrant').text})"

%dt= t(:registered)
%dt= t('.registered')
%dd= @data.css('crDate').text

%dt= t(:valid_to)
%dd= @data.css('exDate').text

%dt= t(:created)
%dt= t('.created')
%dd= @data.css('crDate').text

%dt= t(:updated)
%dt= t('.updated')
%dd= @data.css('upDate').text
2 changes: 2 additions & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ class Application < Rails::Application
domain: ENV['smtp_domain'],
openssl_verify_mode: ENV['smtp_openssl_verify_mode']
}

config.action_view.default_form_builder = 'DefaultFormBuilder'
end
end

Expand Down
6 changes: 6 additions & 0 deletions config/locales/registrar/contacts.en.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
en:
registrar:
contacts:
partials:
domains:
roles: Roles
12 changes: 12 additions & 0 deletions config/locales/registrar/domains.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,15 @@ en:
registrant_name: Registrant name
registrant_code: Registrant code
expire_time: Date of expiry

form:
save_btn: Save
dnskeys:
flags: Flags
alg: Algorithm

partials:
general:
registered: Registered
created: Created
updated: Updated
9 changes: 7 additions & 2 deletions spec/factories/api_user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,13 @@
end

factory :api_user_with_unlimited_balance do
after :build do |api_user|
api_user.registrar = create(:registrar_with_unlimited_balance)
transient do
registrar false
end

after :build do |api_user, evaluator|
registrar = (evaluator.registrar || create(:registrar_with_unlimited_balance))
api_user.registrar = registrar
end
end
end
Expand Down
52 changes: 52 additions & 0 deletions spec/features/registrar/contacts/delete_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
require 'rails_helper'

class FakeDeppContact
include ActiveModel::Model

def id
'test'
end

def name
'test'
end

def persisted?
true
end

def password
'test'
end

def delete
true
end
end

RSpec.feature 'Contact deletion in registrar area' do
given!(:registrar) { create(:registrar) }
given!(:contact) { create(:contact, registrar: registrar) }

background do
allow(Depp::Contact).to receive(:find_by_id).and_return(FakeDeppContact.new)
allow(Depp::Contact).to receive(:new).and_return(FakeDeppContact.new)
Setting.api_ip_whitelist_enabled = false
Setting.registrar_ip_whitelist_enabled = false
sign_in_to_registrar_area(user: create(:api_user_with_unlimited_balance, registrar: registrar))
end

it 'deletes contact' do
visit registrar_contacts_url
click_link_or_button 'Delete'
confirm

expect(page).to have_text('Destroyed')
end

private

def confirm
click_link_or_button 'Delete'
end
end
8 changes: 4 additions & 4 deletions spec/views/registrar/contacts/_form.haml_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
assign(:contact, contact)

stub_template 'registrar/shared/_error_messages' => ''
stub_template 'registrar/contacts/form_partials/_general' => ''
stub_template 'registrar/contacts/form_partials/_address' => 'address info'
stub_template 'registrar/contacts/form_partials/_code' => ''
stub_template 'registrar/contacts/form_partials/_legal_document' => ''
stub_template 'registrar/contacts/form/_general' => ''
stub_template 'registrar/contacts/form/_address' => 'address info'
stub_template 'registrar/contacts/form/_code' => ''
stub_template 'registrar/contacts/form/_legal_document' => ''
end

context 'when address processing is enabled' do
Expand Down
15 changes: 15 additions & 0 deletions spec/views/registrar/contacts/form/_legal_document.haml_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
require 'rails_helper'

RSpec.describe 'registrar/contacts/form/_legal_document' do
let(:contact) { instance_spy(Depp::Contact) }

before :example do
allow(view).to receive(:f).and_return(DefaultFormBuilder.new(:depp_contact, contact, view, {}))
assign(:contact, contact)
end

it 'has legal document' do
render
expect(rendered).to have_css('[name="depp_contact[legal_document]"]')
end
end
20 changes: 20 additions & 0 deletions spec/views/registrar/domains/_form.haml_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
require 'rails_helper'

RSpec.describe 'registrar/domains/_form' do
let(:domain) { instance_spy(Depp::Domain) }

before :example do
allow(view).to receive(:f).and_return(DefaultFormBuilder.new(:domain, domain, view, {}))
assign(:domain, domain)

stub_template 'registrar/domains/form/_general' => ''
stub_template 'registrar/domains/form/_contacts' => ''
stub_template 'registrar/domains/form/_nameservers' => ''
stub_template 'registrar/domains/form/_dnskeys' => ''
end

it 'has legal document' do
render
expect(rendered).to have_css('[name="domain[legal_document]"]')
end
end

0 comments on commit ba53ae9

Please sign in to comment.