Validate iban

This commit is contained in:
Artur Beljajev 2019-05-20 13:25:26 +03:00
parent ca317ace45
commit da191e14e6
4 changed files with 18 additions and 1 deletions

View file

@ -3,6 +3,7 @@ module Admin
load_and_authorize_resource
before_action :set_registrar, only: [:show, :edit, :update, :destroy]
helper_method :registry_vat_rate
helper_method :iban_max_length
def index
@q = Registrar.joins(:accounts).ordered.search(params[:q])
@ -80,5 +81,9 @@ module Admin
def registry_vat_rate
Registry.current.vat_rate
end
def iban_max_length
Iban.max_length
end
end
end

5
app/models/iban.rb Normal file
View file

@ -0,0 +1,5 @@
class Iban
def self.max_length
34
end
end

View file

@ -73,7 +73,7 @@
<%= f.label :iban %>
</div>
<div class="col-md-7">
<%= f.text_field :iban, class: 'form-control' %>
<%= f.text_field :iban, maxlength: iban_max_length, class: 'form-control' %>
</div>
</div>
</div>

7
test/models/iban_test.rb Normal file
View file

@ -0,0 +1,7 @@
require 'test_helper'
class IbanTest < ActiveSupport::TestCase
def test_returns_max_length
assert_equal 34, Iban.max_length
end
end