mirror of
https://github.com/internetee/registry.git
synced 2025-07-03 09:43:36 +02:00
commit
90bbe3d598
4 changed files with 54 additions and 65 deletions
|
@ -4,9 +4,12 @@
|
||||||
.row
|
.row
|
||||||
.col-md-8
|
.col-md-8
|
||||||
= render 'registrar/contacts/form_partials/general', f: f
|
= render 'registrar/contacts/form_partials/general', f: f
|
||||||
.row
|
|
||||||
.col-md-8
|
- if address_processing?
|
||||||
= render 'registrar/contacts/form_partials/address', f: f
|
.row
|
||||||
|
.col-md-8
|
||||||
|
= render 'registrar/contacts/form_partials/address', f: f
|
||||||
|
|
||||||
- if !@contact.persisted?
|
- if !@contact.persisted?
|
||||||
.row
|
.row
|
||||||
.col-md-8
|
.col-md-8
|
||||||
|
|
|
@ -4,21 +4,21 @@
|
||||||
.panel-body
|
.panel-body
|
||||||
.form-group
|
.form-group
|
||||||
.col-md-3.control-label
|
.col-md-3.control-label
|
||||||
= f.label :street, t(:street)
|
= f.label :street, t(:street) + '*'
|
||||||
.col-md-7
|
.col-md-7
|
||||||
= f.text_field :street, class: 'form-control', required: address_processing?
|
= f.text_field :street, class: 'form-control', required: true
|
||||||
|
|
||||||
.form-group
|
.form-group
|
||||||
.col-md-3.control-label
|
.col-md-3.control-label
|
||||||
= f.label :city, t(:city)
|
= f.label :city, t(:city) + '*'
|
||||||
.col-md-7
|
.col-md-7
|
||||||
= f.text_field :city, class: 'form-control', required: address_processing?
|
= f.text_field :city, class: 'form-control', required: true
|
||||||
|
|
||||||
.form-group
|
.form-group
|
||||||
.col-md-3.control-label
|
.col-md-3.control-label
|
||||||
= f.label :zip, t(:zip)
|
= f.label :zip, t(:zip) + '*'
|
||||||
.col-md-7
|
.col-md-7
|
||||||
= f.text_field :zip, class: 'form-control', required: address_processing?
|
= f.text_field :zip, class: 'form-control', required: true
|
||||||
|
|
||||||
.form-group
|
.form-group
|
||||||
.col-md-3.control-label
|
.col-md-3.control-label
|
||||||
|
@ -28,10 +28,9 @@
|
||||||
|
|
||||||
.form-group
|
.form-group
|
||||||
.col-md-3.control-label
|
.col-md-3.control-label
|
||||||
= f.label :country_code, t(:country)
|
= f.label :country_code, t(:country) + '*'
|
||||||
.col-md-7
|
.col-md-7
|
||||||
- country_selected = f.object.persisted? ? f.object.country_code : 'EE'
|
- country_selected = f.object.persisted? ? f.object.country_code : 'EE'
|
||||||
= f.select(:country_code,
|
= f.select(:country_code, SortedCountry.all_options(country_selected),
|
||||||
SortedCountry.all_options(country_selected),
|
{ include_blank: true }, required: true)
|
||||||
{ include_blank: true },
|
|
||||||
required: address_processing?)
|
|
||||||
|
|
38
spec/views/registrar/contacts/_form.haml_spec.rb
Normal file
38
spec/views/registrar/contacts/_form.haml_spec.rb
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
RSpec.describe 'registrar/contacts/_form' do
|
||||||
|
let(:contact) { instance_spy(Depp::Contact) }
|
||||||
|
|
||||||
|
before :example do
|
||||||
|
allow(view).to receive(:f).and_return(ActionView::Helpers::FormBuilder.new(:contact, contact, view, {}))
|
||||||
|
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' => ''
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when address processing is enabled' do
|
||||||
|
before do
|
||||||
|
allow(view).to receive(:address_processing?).and_return(true)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'has address' do
|
||||||
|
render
|
||||||
|
expect(rendered).to have_text('address info')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when address processing is disabled' do
|
||||||
|
before do
|
||||||
|
allow(view).to receive(:address_processing?).and_return(false)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'has no address' do
|
||||||
|
render
|
||||||
|
expect(rendered).to_not have_text('address info')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -1,51 +0,0 @@
|
||||||
require 'rails_helper'
|
|
||||||
|
|
||||||
module RequiredAddressFieldsHelper
|
|
||||||
def define_field_examples(attr_name)
|
|
||||||
describe "#{attr_name} field" do
|
|
||||||
let(:field) { page.find("[name='depp_contact[#{attr_name}]']") }
|
|
||||||
|
|
||||||
context 'when address processing is enabled' do
|
|
||||||
before do
|
|
||||||
allow(view).to receive(:address_processing?).and_return(true)
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'is required' do
|
|
||||||
render
|
|
||||||
expect(field[:required]).to eq('required')
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'when address processing is disabled' do
|
|
||||||
before do
|
|
||||||
allow(view).to receive(:address_processing?).and_return(false)
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'is optional' do
|
|
||||||
render
|
|
||||||
expect(field[:required]).to be_nil
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
RSpec.describe 'registrar/contacts/form_partials/_address' do
|
|
||||||
extend RequiredAddressFieldsHelper
|
|
||||||
let(:contact) { instance_spy(Depp::Contact) }
|
|
||||||
|
|
||||||
before do
|
|
||||||
allow(view).to receive(:f).and_return(ActionView::Helpers::FormBuilder.new(:depp_contact, contact, view, {}))
|
|
||||||
end
|
|
||||||
|
|
||||||
required_address_attributes = %i(
|
|
||||||
street
|
|
||||||
city
|
|
||||||
zip
|
|
||||||
country_code
|
|
||||||
)
|
|
||||||
|
|
||||||
required_address_attributes.each do |attr_name|
|
|
||||||
define_field_examples(attr_name)
|
|
||||||
end
|
|
||||||
end
|
|
Loading…
Add table
Add a link
Reference in a new issue