solidus_br_common 1.1.2 → 1.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e1a1c9f1cbc965f0e89c598f09cb2768d9d19d59
4
- data.tar.gz: 914cf27c94005ef27b1174b19d96b5122e6c035e
3
+ metadata.gz: 59064445995a3c758e8e9d7744504aeac0127565
4
+ data.tar.gz: 4eefd345f10455fa62eb379bc41a6e768a6c2334
5
5
  SHA512:
6
- metadata.gz: 05135c35c3cc34b3f1492480bcebe5e36f89021f453d338ea6c4e2c4b95edc3d31e576eb04439f6c2f84c6c873ce51eafc486be68a1e121aeed0964adde6153f
7
- data.tar.gz: a16498a56e9045bef9b273297cd5e5c0a51b0bf74346b376c7dbebd0ecf3641e5e6458313c192212aa802fdd810cd6da8759d057f2b6938fc400da18ed594d06
6
+ metadata.gz: af8e33de2576ebaf7b0d58e0a32e94b3f619cf450c3a33be4a39565e8ca96832f2a93e3a149df3a37e72fba10a5a4c31825bac11f98b9840abf654135f782d16
7
+ data.tar.gz: a7a805070f3659bb2e7b4b396ffe0fe80e40f7a7358850e703c183d1a150f36576ec92776b200c03f8cf8985d22982d7b2d64e115c1aad41bd571696282c6a80
@@ -3,4 +3,19 @@ Spree::Address.class_eval do
3
3
 
4
4
  validates :number, :numericality => {greater_than: 0}, :presence => true
5
5
  validates :district, length: { maximum: 150}, presence: true
6
+
7
+ before_validation :sanitize_phone
8
+
9
+ def phone_area_code
10
+ phone[0..1] if phone
11
+ end
12
+
13
+ def phone_number
14
+ phone[2..-1] if phone
15
+ end
16
+
17
+ private
18
+ def sanitize_phone
19
+ phone.gsub!(/[^\d]/, '')
20
+ end
6
21
  end
@@ -3,7 +3,7 @@ require 'validates_timeliness'
3
3
 
4
4
  Spree::User.class_eval do
5
5
 
6
- validates_presence_of :phone
6
+ validates_presence_of :phone, :cpf
7
7
  validates :date_of_birth,
8
8
  presence: true,
9
9
  timeliness: {
@@ -11,7 +11,6 @@ Spree::User.class_eval do
11
11
  on_or_after: lambda { 100.years.ago.at_midnight },
12
12
  type: :datetime
13
13
  }
14
- validates :cpf, presence: true
15
14
  validates :first_name, :last_name, presence: true, length: {maximum: 100}
16
15
  validates :phone, :alternative_phone, length: {maximum: 11}
17
16
  validate :valid_cpf
@@ -2,7 +2,7 @@
2
2
  Gem::Specification.new do |s|
3
3
  s.platform = Gem::Platform::RUBY
4
4
  s.name = 'solidus_br_common'
5
- s.version = '1.1.2'
5
+ s.version = '1.1.3'
6
6
  s.summary = 'Brazil commons aspects'
7
7
  s.description = 'This extension has goal to provide common aspects as cities, extras address information and some seeds to Brazil'
8
8
  s.required_ruby_version = '>= 2.0.0'
@@ -1,31 +1,77 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Spree::Address do
4
- let(:address) {build(:address)}
4
+ subject { build(:address, phone: '(11) 2334-4433') }
5
5
 
6
- it { is_expected.to validate_presence_of(:number) }
7
- it { is_expected.to validate_presence_of(:district) }
6
+ describe 'validations' do
7
+ it { is_expected.to validate_presence_of(:number) }
8
+ it { is_expected.to validate_presence_of(:district) }
8
9
 
9
- it 'should validate length of district' do
10
- address.district = string_with_length(151)
10
+ context 'phone' do
11
+ it 'validates length of district' do
12
+ subject.district = string_with_length(151)
11
13
 
12
- expect(address).to_not be_valid
13
- end
14
+ expect(subject).to_not be_valid
15
+ end
14
16
 
15
- it 'should validate number negative' do
16
- address.number = -1
17
+ it 'validates number negative' do
18
+ subject.number = -1
17
19
 
18
- expect(address).to_not be_valid
20
+ expect(subject).to_not be_valid
21
+ end
22
+ end
19
23
  end
20
24
 
21
25
  context '#save' do
22
- subject { address }
23
-
24
- before { address.save! }
26
+ before { subject.save! }
25
27
 
26
28
  it { is_expected.to be_persisted }
27
29
  end
28
30
 
31
+ context '#phone_area_code' do
32
+ context 'when there is phone' do
33
+ before { subject.valid? }
34
+
35
+ it 'returns only the phone area code' do
36
+ expect(subject.phone_area_code).to eq('11')
37
+ end
38
+ end
39
+
40
+ context 'when there is not phone' do
41
+ before { subject.phone = nil }
42
+
43
+ it 'returns nil' do
44
+ expect(subject.phone_area_code).to be_nil
45
+ end
46
+ end
47
+ end
48
+
49
+ context '#phone_number' do
50
+ context 'when there is phone' do
51
+ before { subject.valid? }
52
+
53
+ it 'returns only the phone number' do
54
+ expect(subject.phone_number).to eq('23344433')
55
+ end
56
+ end
57
+
58
+ context 'when there is not phone' do
59
+ before { subject.phone = nil }
60
+
61
+ it 'returns nil' do
62
+ expect(subject.phone_number).to be_nil
63
+ end
64
+ end
65
+ end
66
+
67
+ context 'sanitize_phone' do
68
+ it 'keeps only numbers' do
69
+ subject.valid?
70
+
71
+ expect(subject.phone).to eq('1123344433')
72
+ end
73
+ end
74
+
29
75
  def string_with_length(length)
30
76
  (1..length).map { (65 + rand(26)).chr }.join
31
77
  end
@@ -5,15 +5,57 @@ describe Spree::User do
5
5
  (1..length).map { (65 + rand(26)).chr }.join
6
6
  end
7
7
 
8
- let(:user) { build(:user) }
8
+ subject(:user) { build(:user, phone: '(11) 2334-4433') }
9
9
 
10
- it {
11
- is_expected.to validate_presence_of(:cpf)
12
- is_expected.to validate_presence_of(:first_name)
13
- is_expected.to validate_presence_of(:last_name)
14
- is_expected.to validate_presence_of(:date_of_birth)
15
- is_expected.to validate_presence_of(:phone)
16
- }
10
+ context 'validations' do
11
+ it { is_expected.to validate_presence_of(:cpf)}
12
+ it { is_expected.to validate_presence_of(:first_name)}
13
+ it { is_expected.to validate_presence_of(:last_name)}
14
+ it { is_expected.to validate_presence_of(:date_of_birth)}
15
+ it { is_expected.to validate_presence_of(:phone)}
16
+
17
+ context 'cpf' do
18
+ it 'returns valid' do
19
+ user.cpf = CPF.generate(true)
20
+
21
+ expect(user).to be_valid
22
+ end
23
+
24
+ context 'when the length is incorrect' do
25
+ it 'returns invalid' do
26
+ user.cpf = '123456789'
27
+
28
+ expect(user).to_not be_valid
29
+ end
30
+ end
31
+
32
+ context 'when the number is incorrect' do
33
+ it 'returns invalid' do
34
+ user.cpf = '12345678910'
35
+
36
+ expect(user).to_not be_valid
37
+ end
38
+ end
39
+ end
40
+
41
+ it 'validates length of first_name' do
42
+ user.first_name = string_with_length(101)
43
+
44
+ expect(user).to_not be_valid
45
+ end
46
+
47
+ it 'validates length of last_name' do
48
+ user.last_name = string_with_length(101)
49
+
50
+ expect(user).to_not be_valid
51
+ end
52
+
53
+ it 'validates date_of_birth is greater or equal to 18 years' do
54
+ user.date_of_birth = 17.years.ago
55
+
56
+ expect(user).to_not be_valid
57
+ end
58
+ end
17
59
 
18
60
  context '#full_name' do
19
61
  it 'should return first_name + last_name' do
@@ -31,58 +73,69 @@ describe Spree::User do
31
73
  end
32
74
  end
33
75
 
34
- it 'should respond to extra properties' do
76
+ it 'responds to extra properties' do
35
77
  expect(user).to respond_to :first_name, :last_name, :cpf, :date_of_birth, :phone, :alternative_phone
36
78
  end
37
79
 
38
- it 'should save user with success' do
80
+ it 'saves user with success' do
39
81
  expect(user.save!).to be_truthy
40
82
  end
41
83
 
42
- it 'should save user with sanitize cpf' do
43
- cpf_formatted = CPF.generate(true)
44
- user.cpf = cpf_formatted
45
- cpf = CPF.new(cpf_formatted)
84
+ context '#phone_area_code' do
85
+ context 'when there is phone' do
86
+ before { subject.valid? }
46
87
 
47
- user.save!
48
-
49
- expect(user.cpf).to eq(cpf.stripped)
50
- end
88
+ it 'returns only the phone area code' do
89
+ expect(subject.phone_area_code).to eq('11')
90
+ end
91
+ end
51
92
 
52
- it 'should save user with sanitize phone' do
53
- user.phone = '(011) 3882-8877'
54
- user.save!
93
+ context 'when there is not phone' do
94
+ before { subject.phone = nil }
55
95
 
56
- expect(user.phone).to eq('01138828877')
96
+ it 'returns nil' do
97
+ expect(subject.phone_area_code).to be_nil
98
+ end
99
+ end
57
100
  end
58
101
 
59
- it 'should validate cpf' do
60
- expect(user).to be_valid
61
-
62
- user.cpf = '123456789'
102
+ context '#phone_number' do
103
+ context 'when there is phone' do
104
+ before { subject.valid? }
63
105
 
64
- expect(user).to_not be_valid
106
+ it 'returns only the phone number' do
107
+ expect(subject.phone_number).to eq('23344433')
108
+ end
109
+ end
65
110
 
66
- user.cpf = '12345678910'
111
+ context 'when there is not phone' do
112
+ before { subject.phone = nil }
67
113
 
68
- expect(user).to_not be_valid
114
+ it 'returns nil' do
115
+ expect(subject.phone_number).to be_nil
116
+ end
117
+ end
69
118
  end
70
119
 
71
- it 'should validate length of first_name' do
72
- user.first_name = string_with_length(101)
73
-
74
- expect(user).to_not be_valid
75
- end
120
+ context 'sanitize' do
121
+ context 'phone' do
122
+ it 'keeps only numbers' do
123
+ subject.valid?
76
124
 
77
- it 'should validate length of last_name' do
78
- user.last_name = string_with_length(101)
125
+ expect(subject.phone).to eq('1123344433')
126
+ end
127
+ end
79
128
 
80
- expect(user).to_not be_valid
81
- end
129
+ context 'cpf' do
130
+ it 'keeps only number' do
131
+ cpf_formatted = CPF.generate(true)
132
+ user.cpf = cpf_formatted
133
+ cpf = CPF.new(cpf_formatted)
82
134
 
83
- it 'should validate date_of_birth is greater or equal to 18 years' do
84
- user.date_of_birth = 17.years.ago
135
+ user.valid?
85
136
 
86
- expect(user).to_not be_valid
137
+ expect(user.cpf).to eq(cpf.stripped)
138
+ end
139
+ end
87
140
  end
88
141
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: solidus_br_common
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 1.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Diego Domingues
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-29 00:00:00.000000000 Z
11
+ date: 2016-01-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: solidus_core