Add Mobile Phone validation to SpeakerProfile
This commit is contained in:
parent
867d2f4fab
commit
068ea45cbe
3
Gemfile
3
Gemfile
|
@ -21,6 +21,9 @@ gem 'devise-i18n'
|
|||
|
||||
gem 'simple_form'
|
||||
|
||||
# Phone validation
|
||||
gem 'phony_rails'
|
||||
|
||||
group :development do
|
||||
gem 'spring'
|
||||
gem 'spring-commands-rspec'
|
||||
|
|
|
@ -47,6 +47,9 @@ GEM
|
|||
coffee-script-source
|
||||
execjs
|
||||
coffee-script-source (1.7.1)
|
||||
countries (0.9.3)
|
||||
currencies (~> 0.4.2)
|
||||
currencies (0.4.2)
|
||||
devise (3.2.4)
|
||||
bcrypt (~> 3.0)
|
||||
orm_adapter (~> 0.1)
|
||||
|
@ -99,6 +102,11 @@ GEM
|
|||
mini_portile (= 0.6.0)
|
||||
orm_adapter (0.5.0)
|
||||
pg (0.17.1)
|
||||
phony (2.2.14)
|
||||
phony_rails (0.6.1)
|
||||
activesupport (>= 3.0)
|
||||
countries (>= 0.8.2)
|
||||
phony (~> 2.1)
|
||||
polyglot (0.3.5)
|
||||
pry (0.10.0)
|
||||
coderay (~> 1.1.0)
|
||||
|
@ -221,6 +229,7 @@ DEPENDENCIES
|
|||
guard-rspec
|
||||
jquery-rails
|
||||
pg
|
||||
phony_rails
|
||||
rails (= 4.1.4)
|
||||
rails-erd
|
||||
rails-i18n
|
||||
|
|
|
@ -4,6 +4,8 @@ class SpeakerProfile < ActiveRecord::Base
|
|||
validates :first_name, presence: true
|
||||
validates :last_name, presence: true
|
||||
validates :photo_url, presence: true
|
||||
validates :mobile_phone, presence: true
|
||||
validates :mobile_phone, phony_plausible: true, presence: true
|
||||
validates :biography, presence: true
|
||||
|
||||
phony_normalize :mobile_phone, default_country_code: 'BG'
|
||||
end
|
||||
|
|
|
@ -21,3 +21,6 @@
|
|||
|
||||
bg:
|
||||
hello: "Здравей, свят"
|
||||
errors:
|
||||
messages:
|
||||
improbable_phone: 'не е валиден телефонен номер'
|
|
@ -13,10 +13,25 @@ RSpec.describe SpeakerProfile, :type => :model do
|
|||
expect(build(:speaker_profile, photo_url: nil)).to have_error_on :photo_url
|
||||
end
|
||||
|
||||
it 'is invalid without a mobile phone' do
|
||||
describe 'mobile_phone' do
|
||||
it 'must be present' do
|
||||
expect(build(:speaker_profile, mobile_phone: nil)).to have_error_on :mobile_phone
|
||||
end
|
||||
|
||||
it 'must be a valid phone number' do
|
||||
expect(build(:speaker_profile, mobile_phone: 'abc')).to have_error_on :mobile_phone
|
||||
end
|
||||
|
||||
it 'is stored in a normalized form' do
|
||||
speaker_profile = create :speaker_profile, mobile_phone: '0883444555'
|
||||
expect(speaker_profile.mobile_phone).to eq '359883444555'
|
||||
|
||||
speaker_profile.mobile_phone = '+1883444555'
|
||||
speaker_profile.save
|
||||
expect(speaker_profile.mobile_phone).to eq '1883444555'
|
||||
end
|
||||
end
|
||||
|
||||
it 'is invalid without a bio' do
|
||||
expect(build(:speaker_profile, biography: nil)).to have_error_on :biography
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue