spree_br_common 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/.rspec +1 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +14 -0
- data/Gemfile +20 -0
- data/LICENSE +26 -0
- data/README.md +55 -0
- data/Rakefile +21 -0
- data/app/assets/javascripts/spree/backend/spree_br_common.js +2 -0
- data/app/assets/javascripts/spree/frontend/address.js +119 -0
- data/app/assets/javascripts/spree/frontend/mask.js +21 -0
- data/app/assets/javascripts/spree/frontend/plugins/jquery.mask.extension.js +4 -0
- data/app/assets/javascripts/spree/frontend/plugins/jquery.mask.js +395 -0
- data/app/assets/javascripts/spree/frontend/routes.js.erb +4 -0
- data/app/assets/javascripts/spree/frontend/spree_br_common.js +1 -0
- data/app/assets/stylesheets/spree/backend/spree_br_common.css +4 -0
- data/app/assets/stylesheets/spree/frontend/spree_br_common.css +4 -0
- data/app/controllers/spree/addresses_controller.rb +24 -0
- data/app/controllers/spree/api/cities_controller.rb +38 -0
- data/app/controllers/spree/user_registrations_controller_decorator.rb +13 -0
- data/app/helpers/spree/api/api_helpers_decorator.rb +13 -0
- data/app/helpers/spree/base_helper_decorator.rb +5 -0
- data/app/models/spree/ability_decorator.rb +21 -0
- data/app/models/spree/address_decorator.rb +6 -0
- data/app/models/spree/city.rb +7 -0
- data/app/models/spree/permitted_attributes_decorator.rb +8 -0
- data/app/models/spree/state_decorator.rb +3 -0
- data/app/models/spree/user_decorator.rb +52 -0
- data/app/overrides/spree/address/_form/add_district.html.erb.deface +5 -0
- data/app/overrides/spree/address/_form/add_number.html.erb.deface +5 -0
- data/app/overrides/spree/address/_form/hide_country.html.erb.deface +4 -0
- data/app/overrides/spree/address/_form/move_city_to_after_state.deface +2 -0
- data/app/overrides/spree/address/_form/move_zipcode_after_last_name.deface +2 -0
- data/app/overrides/spree/address/_form/replace_city_input_text_by_select.html.erb.deface +18 -0
- data/app/overrides/spree/address/_form/set_data_uf_to_state.html.erb.deface +15 -0
- data/app/overrides/spree/admin/users/_form/add_extras_fields.html.erb.deface +39 -0
- data/app/overrides/spree/shared/_user_form/add_extra_fields.html.erb.deface +19 -0
- data/app/overrides/spree/users/show/add_details.html.erb.deface +13 -0
- data/app/views/spree/api/cities/index.v1.rabl +11 -0
- data/app/views/spree/api/cities/show.v1.rabl +2 -0
- data/bin/rails +7 -0
- data/config/locales/en.yml +11 -0
- data/config/locales/pt-BR.yml +14 -0
- data/config/routes.rb +7 -0
- data/db/default/country.rb +3 -0
- data/db/default/shipping_categories.rb +1 -0
- data/db/default/shipping_zones.rb +3 -0
- data/db/default/states.rb +31 -0
- data/db/default/states_cities_of_acre.rb +26 -0
- data/db/default/states_cities_of_alagoas.rb +107 -0
- data/db/default/states_cities_of_amapa.rb +20 -0
- data/db/default/states_cities_of_amazonas.rb +67 -0
- data/db/default/states_cities_of_bahia.rb +421 -0
- data/db/default/states_cities_of_ceara.rb +188 -0
- data/db/default/states_cities_of_distrito_federal.rb +5 -0
- data/db/default/states_cities_of_espirito_santo.rb +82 -0
- data/db/default/states_cities_of_goias.rb +250 -0
- data/db/default/states_cities_of_maranhao.rb +221 -0
- data/db/default/states_cities_of_mato_grosso.rb +145 -0
- data/db/default/states_cities_of_mato_grosso_do_sul.rb +82 -0
- data/db/default/states_cities_of_minas_gerais.rb +857 -0
- data/db/default/states_cities_of_para.rb +147 -0
- data/db/default/states_cities_of_paraiba.rb +227 -0
- data/db/default/states_cities_of_parana.rb +403 -0
- data/db/default/states_cities_of_pernambuco.rb +189 -0
- data/db/default/states_cities_of_piaui.rb +227 -0
- data/db/default/states_cities_of_rio_de_janeiro.rb +96 -0
- data/db/default/states_cities_of_rio_grande_do_norte.rb +171 -0
- data/db/default/states_cities_of_rio_grande_do_sul.rb +500 -0
- data/db/default/states_cities_of_rondonia.rb +56 -0
- data/db/default/states_cities_of_roraima.rb +19 -0
- data/db/default/states_cities_of_santa_catarina.rb +297 -0
- data/db/default/states_cities_of_sao_paulo.rb +649 -0
- data/db/default/states_cities_of_sergipe.rb +79 -0
- data/db/default/states_cities_of_tocantins.rb +144 -0
- data/db/default/stock.rb +1 -0
- data/db/default/tax_categories.rb +1 -0
- data/db/default/user.rb +100 -0
- data/db/migrate/20150503011715_create_spree_cities.rb +13 -0
- data/db/migrate/20150504004509_remove_city_from_spree_address.rb +5 -0
- data/db/migrate/20150504004648_add_city_to_spree_address.rb +5 -0
- data/db/migrate/20150505020218_add_number_and_district_to_spree_address.rb +6 -0
- data/db/migrate/20150505031019_add_details_to_spree_user.rb +10 -0
- data/db/seeds.rb +5 -0
- data/lib/generators/spree_br_common/install/install_generator.rb +31 -0
- data/lib/spree_br_common/engine.rb +20 -0
- data/lib/spree_br_common/factories/address_factory.rb +7 -0
- data/lib/spree_br_common/factories/city_factory.rb +8 -0
- data/lib/spree_br_common/factories/user_factory.rb +12 -0
- data/lib/spree_br_common/factories.rb +3 -0
- data/lib/spree_br_common.rb +2 -0
- data/spec/controllers/features/address_checkout_spec.rb +89 -0
- data/spec/controllers/features/user_account_spec.rb +46 -0
- data/spec/controllers/features/user_signup_spec.rb +24 -0
- data/spec/controllers/spree/addresses_controller_spec.rb +27 -0
- data/spec/controllers/spree/api/cities_controller_spec.rb +86 -0
- data/spec/fixtures/vcr_cassettes/Checkout/visitor_makes_checkout_as_guest_without_registration/full_checkout/does_not_break_the_per-item_shipping_method_calculator.yml +49 -0
- data/spec/fixtures/vcr_cassettes/Checkout/visitor_makes_checkout_as_guest_without_registration/full_checkout/in_Brazil/should_autocomplete_zipcode.yml +46 -0
- data/spec/fixtures/vcr_cassettes/Spree_AddressesController/_show/does_not_find_an_incorrect_cep.yml +38 -0
- data/spec/fixtures/vcr_cassettes/Spree_AddressesController/_show/shows_the_correct_address.yml +46 -0
- data/spec/models/spree/address_spec.rb +32 -0
- data/spec/models/spree/city_spec.rb +7 -0
- data/spec/models/spree/user_spec.rb +88 -0
- data/spec/spec_helper.rb +94 -0
- data/spec/support/controller_hacks.rb +33 -0
- data/spec/support/shared_context/checkout_setup.rb +9 -0
- data/spec/support/vcr.rb +8 -0
- data/spree_br_common.gemspec +33 -0
- metadata +351 -0
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Spree::AddressesController, :type => :controller do
|
4
|
+
context '#show', :vcr do
|
5
|
+
it 'shows the correct address' do
|
6
|
+
api_get :show, {cep: '04089000'}
|
7
|
+
|
8
|
+
expect(json_response['cep']).to eq('04089000')
|
9
|
+
expect(json_response['bairro']).to eq('Indianópolis')
|
10
|
+
expect(json_response['logradouro']).to eq('Alameda dos Maracatins')
|
11
|
+
expect(json_response['estado']).to eq('SP')
|
12
|
+
expect(json_response['cidade']).to eq('São Paulo')
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'does not find an incorrect cep' do
|
16
|
+
api_get :show, {cep: '00000000'}
|
17
|
+
|
18
|
+
expect(response.status).to eq 404
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'requires :cep parameter' do
|
22
|
+
expect {
|
23
|
+
api_get :show
|
24
|
+
}.to raise_exception
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Spree::Api::CitiesController, :type => :controller do
|
4
|
+
render_views
|
5
|
+
|
6
|
+
let!(:city) { create(:city) }
|
7
|
+
let(:attributes) { Spree::Api::ApiHelpers.city_attributes }
|
8
|
+
|
9
|
+
before do
|
10
|
+
stub_authentication!
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'gets all cities' do
|
14
|
+
api_get :index
|
15
|
+
|
16
|
+
expect(json_response['cities'].first).to include(*attributes)
|
17
|
+
expect(json_response['cities'].first['name']).to eq(city.name)
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'gets all the cities for a particular state' do
|
21
|
+
api_get :index, :state_id => city.state.id
|
22
|
+
|
23
|
+
expect(json_response['cities'].first).to include(*attributes)
|
24
|
+
expect(json_response['cities'].first['name']).to eq(city.name)
|
25
|
+
end
|
26
|
+
|
27
|
+
context 'pagination' do
|
28
|
+
|
29
|
+
before do
|
30
|
+
allow(Spree::City).to receive(:accessible_by).and_return(@scope = double)
|
31
|
+
allow(@scope).to receive_message_chain(:ransack, :result, :includes, :order).and_return(@scope)
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'does not paginate cities results when asked not to do so' do
|
35
|
+
expect(@scope).to_not receive(:page)
|
36
|
+
expect(@scope).to_not receive(:per)
|
37
|
+
api_get :index
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'paginates when page parameter is passed through' do
|
41
|
+
expect(@scope).to receive(:page).with(1).and_return(@scope)
|
42
|
+
expect(@scope).to receive(:per).with(nil)
|
43
|
+
api_get :index, :page => 1
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'paginates when per_page parameter is passed through' do
|
47
|
+
expect(@scope).to receive(:page).with(nil).and_return(@scope)
|
48
|
+
expect(@scope).to receive(:per).with(25)
|
49
|
+
api_get :index, :per_page => 25
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
|
54
|
+
context 'with two cities' do
|
55
|
+
before { create(:city, :name => 'Attalla') }
|
56
|
+
|
57
|
+
it 'gets all cities for a state' do
|
58
|
+
state = create(:state, name: 'Amazonas', abbr: 'AM')
|
59
|
+
city.state = state
|
60
|
+
city.save
|
61
|
+
|
62
|
+
api_get :index, :state_id => state.id
|
63
|
+
|
64
|
+
expect(json_response['cities'].first).to include(*attributes)
|
65
|
+
expect(json_response['cities'].count).to eq 1
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'can view all cities' do
|
69
|
+
api_get :index
|
70
|
+
|
71
|
+
expect(json_response['cities'].first).to include(*attributes)
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'can query the results through a parameter' do
|
75
|
+
api_get :index, :q => { :name_cont => 'Ash' }
|
76
|
+
|
77
|
+
expect(json_response['cities'].first['name']).to eq('Ashville')
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
it 'can view a city' do
|
82
|
+
api_get :show, :id => city.id
|
83
|
+
|
84
|
+
expect(json_response).to include(*attributes)
|
85
|
+
end
|
86
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: http://api.postmon.com.br/v1/cep/12345
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
Accept:
|
11
|
+
- "*/*; q=0.5, application/xml"
|
12
|
+
Accept-Encoding:
|
13
|
+
- gzip, deflate
|
14
|
+
User-Agent:
|
15
|
+
- Ruby
|
16
|
+
response:
|
17
|
+
status:
|
18
|
+
code: 404
|
19
|
+
message: Not Found
|
20
|
+
headers:
|
21
|
+
Server:
|
22
|
+
- nginx/1.1.19
|
23
|
+
Date:
|
24
|
+
- Tue, 12 May 2015 05:46:09 GMT
|
25
|
+
Content-Type:
|
26
|
+
- text/html; charset=UTF-8
|
27
|
+
Content-Length:
|
28
|
+
- '368'
|
29
|
+
Connection:
|
30
|
+
- keep-alive
|
31
|
+
Vary:
|
32
|
+
- Accept-Encoding
|
33
|
+
Content-Encoding:
|
34
|
+
- gzip
|
35
|
+
body:
|
36
|
+
encoding: ASCII-8BIT
|
37
|
+
string: !binary |-
|
38
|
+
H4sIAAAAAAAAA3VSTU/CQBC9+ytGSDyJ2/KRYFt7EEokQSRaDh6X7pQ2lu66
|
39
|
+
uxga439325pAi+xpZ+fNmzfz9grM8a6nL5PwfRXAU/i8gNX6cTGfQKdHyDwI
|
40
|
+
Z4RMw2md6d9ZhATLjn9VlSV6l9XXOkTKjmH1pFOdoR9IyaUDQ2sIS65hxvc5
|
41
|
+
80ida+KVLjIEXQh86Gg8aBIp1WliAMq28L2h0cdWllS9iGclfxcRXYh5rnsx
|
42
|
+
3aVZ4YCiuXJ/WvUbzop/6+M4dk1WMjSRLQ6geJYy6DLG3BZHfQRlLM23BjwS
|
43
|
+
Bxd2VG7T/C9qdxUSL4u+0PTY4JzRI9WyTvZPmgZ45Zyt/Sb2BTNMookU/huX
|
44
|
+
srgFnSBI/Nyj0shg/bowrmr/pmsN7t1Ea+EQkvGIZglX2hlbY4t82SRCQez+
|
45
|
+
YDiqccZs3XYRIrpXhpHmgJUkj4i2Bol+qTEuNTpQc51zl7CTLRzHNmNVP/QX
|
46
|
+
8ak9XOUCAAA=
|
47
|
+
http_version:
|
48
|
+
recorded_at: Tue, 12 May 2015 05:37:46 GMT
|
49
|
+
recorded_with: VCR 2.9.3
|
@@ -0,0 +1,46 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: http://api.postmon.com.br/v1/cep/04089000
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
Accept:
|
11
|
+
- "*/*; q=0.5, application/xml"
|
12
|
+
Accept-Encoding:
|
13
|
+
- gzip, deflate
|
14
|
+
User-Agent:
|
15
|
+
- Ruby
|
16
|
+
response:
|
17
|
+
status:
|
18
|
+
code: 200
|
19
|
+
message: OK
|
20
|
+
headers:
|
21
|
+
Server:
|
22
|
+
- nginx/1.1.19
|
23
|
+
Date:
|
24
|
+
- Tue, 12 May 2015 05:51:31 GMT
|
25
|
+
Content-Type:
|
26
|
+
- application/json
|
27
|
+
Content-Length:
|
28
|
+
- '334'
|
29
|
+
Connection:
|
30
|
+
- keep-alive
|
31
|
+
Access-Control-Allow-Origin:
|
32
|
+
- "*"
|
33
|
+
Cache-Control:
|
34
|
+
- public, max-age=2592000
|
35
|
+
X-Cache:
|
36
|
+
- HIT
|
37
|
+
body:
|
38
|
+
encoding: UTF-8
|
39
|
+
string: '{"complemento": "at\u00e9 470 - lado par", "bairro": "Indian\u00f3polis",
|
40
|
+
"cidade": "S\u00e3o Paulo", "logradouro": "Alameda dos Maracatins", "estado_info":
|
41
|
+
{"area_km2": "248.222,362", "codigo_ibge": "35", "nome": "S\u00e3o Paulo"},
|
42
|
+
"cep": "04089000", "cidade_info": {"area_km2": "1521,101", "codigo_ibge":
|
43
|
+
"3550308"}, "estado": "SP"}'
|
44
|
+
http_version:
|
45
|
+
recorded_at: Tue, 12 May 2015 05:43:08 GMT
|
46
|
+
recorded_with: VCR 2.9.3
|
data/spec/fixtures/vcr_cassettes/Spree_AddressesController/_show/does_not_find_an_incorrect_cep.yml
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: http://api.postmon.com.br/v1/cep/00000000
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
Accept:
|
11
|
+
- "*/*; q=0.5, application/xml"
|
12
|
+
Accept-Encoding:
|
13
|
+
- gzip, deflate
|
14
|
+
User-Agent:
|
15
|
+
- Ruby
|
16
|
+
response:
|
17
|
+
status:
|
18
|
+
code: 404
|
19
|
+
message: CEP 00000000 nao encontrado
|
20
|
+
headers:
|
21
|
+
Server:
|
22
|
+
- nginx/1.1.19
|
23
|
+
Date:
|
24
|
+
- Fri, 08 May 2015 02:39:13 GMT
|
25
|
+
Content-Type:
|
26
|
+
- application/json
|
27
|
+
Content-Length:
|
28
|
+
- '0'
|
29
|
+
Connection:
|
30
|
+
- keep-alive
|
31
|
+
Access-Control-Allow-Origin:
|
32
|
+
- "*"
|
33
|
+
body:
|
34
|
+
encoding: UTF-8
|
35
|
+
string: ''
|
36
|
+
http_version:
|
37
|
+
recorded_at: Fri, 08 May 2015 02:30:57 GMT
|
38
|
+
recorded_with: VCR 2.9.3
|
data/spec/fixtures/vcr_cassettes/Spree_AddressesController/_show/shows_the_correct_address.yml
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: http://api.postmon.com.br/v1/cep/04089000
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
Accept:
|
11
|
+
- "*/*; q=0.5, application/xml"
|
12
|
+
Accept-Encoding:
|
13
|
+
- gzip, deflate
|
14
|
+
User-Agent:
|
15
|
+
- Ruby
|
16
|
+
response:
|
17
|
+
status:
|
18
|
+
code: 200
|
19
|
+
message: OK
|
20
|
+
headers:
|
21
|
+
Server:
|
22
|
+
- nginx/1.1.19
|
23
|
+
Date:
|
24
|
+
- Fri, 08 May 2015 02:39:13 GMT
|
25
|
+
Content-Type:
|
26
|
+
- application/json
|
27
|
+
Content-Length:
|
28
|
+
- '334'
|
29
|
+
Connection:
|
30
|
+
- keep-alive
|
31
|
+
Access-Control-Allow-Origin:
|
32
|
+
- "*"
|
33
|
+
Cache-Control:
|
34
|
+
- public, max-age=2592000
|
35
|
+
X-Cache:
|
36
|
+
- MISS
|
37
|
+
body:
|
38
|
+
encoding: UTF-8
|
39
|
+
string: '{"complemento": "at\u00e9 470 - lado par", "bairro": "Indian\u00f3polis",
|
40
|
+
"cidade": "S\u00e3o Paulo", "logradouro": "Alameda dos Maracatins", "estado_info":
|
41
|
+
{"area_km2": "248.222,801", "codigo_ibge": "35", "nome": "S\u00e3o Paulo"},
|
42
|
+
"cep": "04089000", "cidade_info": {"area_km2": "1521,101", "codigo_ibge":
|
43
|
+
"3550308"}, "estado": "SP"}'
|
44
|
+
http_version:
|
45
|
+
recorded_at: Fri, 08 May 2015 02:30:57 GMT
|
46
|
+
recorded_with: VCR 2.9.3
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Spree::Address do
|
4
|
+
let(:address) {build(:address)}
|
5
|
+
|
6
|
+
it { is_expected.to validate_presence_of(:number) }
|
7
|
+
it { is_expected.to validate_presence_of(:district) }
|
8
|
+
|
9
|
+
it 'should validate length of district' do
|
10
|
+
address.district = string_with_length(151)
|
11
|
+
|
12
|
+
expect(address).to_not be_valid
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'should validate number negative' do
|
16
|
+
address.number = -1
|
17
|
+
|
18
|
+
expect(address).to_not be_valid
|
19
|
+
end
|
20
|
+
|
21
|
+
context '#save' do
|
22
|
+
subject { address }
|
23
|
+
|
24
|
+
before { address.save! }
|
25
|
+
|
26
|
+
it { is_expected.to be_persisted }
|
27
|
+
end
|
28
|
+
|
29
|
+
def string_with_length(length)
|
30
|
+
(1..length).map { (65 + rand(26)).chr }.join
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Spree::User do
|
4
|
+
def string_with_length(length)
|
5
|
+
(1..length).map { (65 + rand(26)).chr }.join
|
6
|
+
end
|
7
|
+
|
8
|
+
let(:user) { build(:user) }
|
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
|
+
}
|
17
|
+
|
18
|
+
context '#full_name' do
|
19
|
+
it 'should return first_name + last_name' do
|
20
|
+
full_name = "#{user.first_name} #{user.last_name}"
|
21
|
+
|
22
|
+
expect(user.full_name).to eq(full_name)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context '#cpf_formatted' do
|
27
|
+
it 'should return cpf formatted' do
|
28
|
+
user.cpf = '12345678910'
|
29
|
+
|
30
|
+
expect(user.cpf_formatted).to eql('123.456.789-10')
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'should respond to extra properties' do
|
35
|
+
expect(user).to respond_to :first_name, :last_name, :cpf, :date_of_birth, :phone, :alternative_phone
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'should save user with success' do
|
39
|
+
expect(user.save!).to be_truthy
|
40
|
+
end
|
41
|
+
|
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)
|
46
|
+
|
47
|
+
user.save!
|
48
|
+
|
49
|
+
expect(user.cpf).to eq(cpf.stripped)
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'should save user with sanitize phone' do
|
53
|
+
user.phone = '(011) 3882-8877'
|
54
|
+
user.save!
|
55
|
+
|
56
|
+
expect(user.phone).to eq('01138828877')
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'should validate cpf' do
|
60
|
+
expect(user).to be_valid
|
61
|
+
|
62
|
+
user.cpf = '123456789'
|
63
|
+
|
64
|
+
expect(user).to_not be_valid
|
65
|
+
|
66
|
+
user.cpf = '12345678910'
|
67
|
+
|
68
|
+
expect(user).to_not be_valid
|
69
|
+
end
|
70
|
+
|
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
|
76
|
+
|
77
|
+
it 'should validate length of last_name' do
|
78
|
+
user.last_name = string_with_length(101)
|
79
|
+
|
80
|
+
expect(user).to_not be_valid
|
81
|
+
end
|
82
|
+
|
83
|
+
it 'should validate date_of_birth is greater or equal to 18 years' do
|
84
|
+
user.date_of_birth = 17.years.ago
|
85
|
+
|
86
|
+
expect(user).to_not be_valid
|
87
|
+
end
|
88
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
# Run Coverage report
|
2
|
+
require 'codeclimate-test-reporter'
|
3
|
+
CodeClimate::TestReporter.start
|
4
|
+
|
5
|
+
# Configure Rails Environment
|
6
|
+
ENV['RAILS_ENV'] = 'test'
|
7
|
+
|
8
|
+
require File.expand_path('../dummy/config/environment.rb', __FILE__)
|
9
|
+
|
10
|
+
require 'rspec/rails'
|
11
|
+
require 'database_cleaner'
|
12
|
+
require 'ffaker'
|
13
|
+
|
14
|
+
require 'capybara/rspec'
|
15
|
+
require 'capybara-screenshot/rspec'
|
16
|
+
|
17
|
+
if ENV['WEBDRIVER'] == 'accessible'
|
18
|
+
require 'capybara/accessible'
|
19
|
+
Capybara.javascript_driver = :accessible
|
20
|
+
else
|
21
|
+
require 'capybara/poltergeist'
|
22
|
+
Capybara.javascript_driver = :poltergeist
|
23
|
+
end
|
24
|
+
|
25
|
+
# Requires supporting ruby files with custom matchers and macros, etc,
|
26
|
+
# in spec/support/ and its subdirectories.
|
27
|
+
Dir[File.join(File.dirname(__FILE__), 'support/**/*.rb')].each { |f| require f }
|
28
|
+
|
29
|
+
# Requires factories and other useful helpers defined in spree_core.
|
30
|
+
require 'spree/testing_support/authorization_helpers'
|
31
|
+
require 'spree/testing_support/capybara_ext'
|
32
|
+
require 'spree/testing_support/controller_requests'
|
33
|
+
require 'spree/testing_support/factories'
|
34
|
+
require 'spree/testing_support/url_helpers'
|
35
|
+
|
36
|
+
require 'spree/api/testing_support/helpers'
|
37
|
+
|
38
|
+
# Requires factories defined in lib/spree_br_common/factories.rb
|
39
|
+
require 'spree_br_common/factories'
|
40
|
+
|
41
|
+
RSpec.configure do |config|
|
42
|
+
config.include FactoryGirl::Syntax::Methods
|
43
|
+
|
44
|
+
# Infer an example group's spec type from the file location.
|
45
|
+
config.infer_spec_type_from_file_location!
|
46
|
+
|
47
|
+
# == URL Helpers
|
48
|
+
#
|
49
|
+
# Allows access to Spree's routes in specs:
|
50
|
+
#
|
51
|
+
# visit spree.admin_path
|
52
|
+
# current_path.should eql(spree.products_path)
|
53
|
+
config.include Spree::TestingSupport::UrlHelpers
|
54
|
+
|
55
|
+
config.include Spree::Api::TestingSupport::Helpers
|
56
|
+
|
57
|
+
# == Mock Framework
|
58
|
+
#
|
59
|
+
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
|
60
|
+
#
|
61
|
+
# config.mock_with :mocha
|
62
|
+
# config.mock_with :flexmock
|
63
|
+
# config.mock_with :rr
|
64
|
+
config.mock_with :rspec
|
65
|
+
config.color = true
|
66
|
+
|
67
|
+
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
|
68
|
+
config.fixture_path = "#{::Rails.root}/spec/fixtures"
|
69
|
+
|
70
|
+
# Capybara javascript drivers require transactional fixtures set to false, and we use DatabaseCleaner
|
71
|
+
# to cleanup after each test instead. Without transactional fixtures set to false the records created
|
72
|
+
# to setup a test will be unavailable to the browser, which runs under a separate server instance.
|
73
|
+
config.use_transactional_fixtures = false
|
74
|
+
|
75
|
+
# Ensure Suite is set to use transactions for speed.
|
76
|
+
config.before :suite do
|
77
|
+
DatabaseCleaner.strategy = :transaction
|
78
|
+
DatabaseCleaner.clean_with :truncation
|
79
|
+
end
|
80
|
+
|
81
|
+
# Before each spec check if it is a Javascript test and switch between using database transactions or not where necessary.
|
82
|
+
config.before :each do
|
83
|
+
DatabaseCleaner.strategy = RSpec.current_example.metadata[:js] ? :truncation : :transaction
|
84
|
+
DatabaseCleaner.start
|
85
|
+
end
|
86
|
+
|
87
|
+
# After each spec clean the database.
|
88
|
+
config.after :each do
|
89
|
+
DatabaseCleaner.clean
|
90
|
+
end
|
91
|
+
|
92
|
+
config.fail_fast = ENV['FAIL_FAST'] || false
|
93
|
+
config.order = 'random'
|
94
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'active_support/all'
|
2
|
+
module ControllerHacks
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
routes { Spree::Core::Engine.routes }
|
7
|
+
end
|
8
|
+
|
9
|
+
def api_get(action, params={}, session=nil, flash=nil)
|
10
|
+
api_process(action, params, session, flash, "GET")
|
11
|
+
end
|
12
|
+
|
13
|
+
def api_post(action, params={}, session=nil, flash=nil)
|
14
|
+
api_process(action, params, session, flash, "POST")
|
15
|
+
end
|
16
|
+
|
17
|
+
def api_put(action, params={}, session=nil, flash=nil)
|
18
|
+
api_process(action, params, session, flash, "PUT")
|
19
|
+
end
|
20
|
+
|
21
|
+
def api_delete(action, params={}, session=nil, flash=nil)
|
22
|
+
api_process(action, params, session, flash, "DELETE")
|
23
|
+
end
|
24
|
+
|
25
|
+
def api_process(action, params={}, session=nil, flash=nil, method="get")
|
26
|
+
scoping = respond_to?(:resource_scoping) ? resource_scoping : {}
|
27
|
+
process(action, method, params.merge(scoping).reverse_merge!(:format => :json), session, flash)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
RSpec.configure do |config|
|
32
|
+
config.include ControllerHacks, type: :controller
|
33
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
shared_context 'checkout setup' do
|
2
|
+
let!(:country) { create(:country, states_required: true) }
|
3
|
+
let!(:state) { create(:state, country: country) }
|
4
|
+
let!(:shipping_method) { create(:shipping_method) }
|
5
|
+
let!(:stock_location) { create(:stock_location) }
|
6
|
+
let!(:mug) { create(:product, name: "RoR Mug") }
|
7
|
+
let!(:payment_method) { create(:check_payment_method) }
|
8
|
+
let!(:zone) { create(:zone) }
|
9
|
+
end
|
data/spec/support/vcr.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
Gem::Specification.new do |s|
|
3
|
+
s.platform = Gem::Platform::RUBY
|
4
|
+
s.name = 'spree_br_common'
|
5
|
+
s.version = '3.0.0'
|
6
|
+
s.summary = 'Brazil common aspects'
|
7
|
+
s.description = 'This extension has goal to provide common aspects as cities, extras address informations and some seeds to Brazil'
|
8
|
+
s.required_ruby_version = '>= 2.0.0'
|
9
|
+
|
10
|
+
s.author = 'Diego Domingues'
|
11
|
+
s.email = 'diego.domingues16@gmail.com'
|
12
|
+
s.homepage = 'https://github.com/ddomingues/spree_br-common'
|
13
|
+
|
14
|
+
s.files = `git ls-files`.split("\n")
|
15
|
+
s.test_files = `git ls-files -- spec/*`.split("\n")
|
16
|
+
s.require_path = 'lib'
|
17
|
+
s.requirements << 'none'
|
18
|
+
|
19
|
+
s.add_dependency 'spree_core', '~> 3.0.0'
|
20
|
+
s.add_dependency 'cpf_cnpj', '~> 0.2.1'
|
21
|
+
s.add_dependency 'jc-validates_timeliness', '~> 3.1.1'
|
22
|
+
s.add_dependency 'rest-client', '~> 1.8.0'
|
23
|
+
|
24
|
+
s.add_development_dependency 'capybara', '~> 2.4'
|
25
|
+
s.add_development_dependency 'coffee-rails'
|
26
|
+
s.add_development_dependency 'database_cleaner'
|
27
|
+
s.add_development_dependency 'factory_girl', '~> 4.5'
|
28
|
+
s.add_development_dependency 'ffaker'
|
29
|
+
s.add_development_dependency 'rspec-rails', '~> 3.1'
|
30
|
+
s.add_development_dependency 'sass-rails', '~> 5.0.0.beta1'
|
31
|
+
s.add_development_dependency 'selenium-webdriver'
|
32
|
+
s.add_development_dependency 'sqlite3'
|
33
|
+
end
|