solidus_br_common 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (113) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +14 -0
  3. data/.rspec +1 -0
  4. data/.ruby-gemset +1 -0
  5. data/.ruby-version +1 -0
  6. data/.travis.yml +14 -0
  7. data/Gemfile +19 -0
  8. data/LICENSE +26 -0
  9. data/README.md +55 -0
  10. data/Rakefile +21 -0
  11. data/app/assets/javascripts/spree/backend/solidus_br_common.js +2 -0
  12. data/app/assets/javascripts/spree/frontend/address.js +119 -0
  13. data/app/assets/javascripts/spree/frontend/mask.js +21 -0
  14. data/app/assets/javascripts/spree/frontend/plugins/jquery.mask.extension.js +4 -0
  15. data/app/assets/javascripts/spree/frontend/plugins/jquery.mask.js +395 -0
  16. data/app/assets/javascripts/spree/frontend/routes.js.erb +4 -0
  17. data/app/assets/javascripts/spree/frontend/solidus_br_common.js +1 -0
  18. data/app/assets/stylesheets/spree/backend/solidus_br_common.css +4 -0
  19. data/app/assets/stylesheets/spree/frontend/solidus_br_common.css +4 -0
  20. data/app/controllers/spree/addresses_controller.rb +24 -0
  21. data/app/controllers/spree/api/cities_controller.rb +33 -0
  22. data/app/controllers/spree/user_registrations_controller_decorator.rb +13 -0
  23. data/app/helpers/spree/api/api_helpers_decorator.rb +9 -0
  24. data/app/helpers/spree/base_helper_decorator.rb +5 -0
  25. data/app/models/spree/ability_decorator.rb +21 -0
  26. data/app/models/spree/address_decorator.rb +6 -0
  27. data/app/models/spree/city.rb +7 -0
  28. data/app/models/spree/permitted_attributes_decorator.rb +8 -0
  29. data/app/models/spree/state_decorator.rb +3 -0
  30. data/app/models/spree/user_decorator.rb +52 -0
  31. data/app/overrides/spree/address/_form/add_district.html.erb.deface +5 -0
  32. data/app/overrides/spree/address/_form/add_number.html.erb.deface +5 -0
  33. data/app/overrides/spree/address/_form/hide_country.html.erb.deface +4 -0
  34. data/app/overrides/spree/address/_form/move_city_to_after_state.deface +2 -0
  35. data/app/overrides/spree/address/_form/move_zipcode_after_last_name.deface +2 -0
  36. data/app/overrides/spree/address/_form/replace_city_input_text_by_select.html.erb.deface +18 -0
  37. data/app/overrides/spree/address/_form/set_data_uf_to_state.html.erb.deface +15 -0
  38. data/app/overrides/spree/admin/users/_form/add_extras_fields.html.erb.deface +39 -0
  39. data/app/overrides/spree/shared/_user_form/add_extra_fields.html.erb.deface +19 -0
  40. data/app/overrides/spree/users/show/add_details.html.erb.deface +13 -0
  41. data/app/views/spree/api/cities/index.v1.rabl +11 -0
  42. data/app/views/spree/api/cities/show.v1.rabl +2 -0
  43. data/bin/rails +7 -0
  44. data/config/locales/en.yml +11 -0
  45. data/config/locales/pt-BR.yml +14 -0
  46. data/config/routes.rb +7 -0
  47. data/db/default/country.rb +3 -0
  48. data/db/default/shipping_categories.rb +1 -0
  49. data/db/default/shipping_zones.rb +3 -0
  50. data/db/default/states.rb +31 -0
  51. data/db/default/states_cities_of_acre.rb +26 -0
  52. data/db/default/states_cities_of_alagoas.rb +107 -0
  53. data/db/default/states_cities_of_amapa.rb +20 -0
  54. data/db/default/states_cities_of_amazonas.rb +67 -0
  55. data/db/default/states_cities_of_bahia.rb +421 -0
  56. data/db/default/states_cities_of_ceara.rb +188 -0
  57. data/db/default/states_cities_of_distrito_federal.rb +5 -0
  58. data/db/default/states_cities_of_espirito_santo.rb +82 -0
  59. data/db/default/states_cities_of_goias.rb +250 -0
  60. data/db/default/states_cities_of_maranhao.rb +221 -0
  61. data/db/default/states_cities_of_mato_grosso.rb +145 -0
  62. data/db/default/states_cities_of_mato_grosso_do_sul.rb +82 -0
  63. data/db/default/states_cities_of_minas_gerais.rb +857 -0
  64. data/db/default/states_cities_of_para.rb +147 -0
  65. data/db/default/states_cities_of_paraiba.rb +227 -0
  66. data/db/default/states_cities_of_parana.rb +403 -0
  67. data/db/default/states_cities_of_pernambuco.rb +189 -0
  68. data/db/default/states_cities_of_piaui.rb +227 -0
  69. data/db/default/states_cities_of_rio_de_janeiro.rb +96 -0
  70. data/db/default/states_cities_of_rio_grande_do_norte.rb +171 -0
  71. data/db/default/states_cities_of_rio_grande_do_sul.rb +500 -0
  72. data/db/default/states_cities_of_rondonia.rb +56 -0
  73. data/db/default/states_cities_of_roraima.rb +19 -0
  74. data/db/default/states_cities_of_santa_catarina.rb +297 -0
  75. data/db/default/states_cities_of_sao_paulo.rb +649 -0
  76. data/db/default/states_cities_of_sergipe.rb +79 -0
  77. data/db/default/states_cities_of_tocantins.rb +144 -0
  78. data/db/default/stock.rb +1 -0
  79. data/db/default/tax_categories.rb +1 -0
  80. data/db/default/user.rb +100 -0
  81. data/db/migrate/20150503011715_create_spree_cities.rb +13 -0
  82. data/db/migrate/20150504004509_remove_city_from_spree_address.rb +5 -0
  83. data/db/migrate/20150504004648_add_city_to_spree_address.rb +5 -0
  84. data/db/migrate/20150505020218_add_number_and_district_to_spree_address.rb +6 -0
  85. data/db/migrate/20150505031019_add_details_to_spree_user.rb +10 -0
  86. data/db/seeds.rb +5 -0
  87. data/lib/generators/solidus_br_common/install/install_generator.rb +31 -0
  88. data/lib/solidus_br_common/engine.rb +20 -0
  89. data/lib/solidus_br_common/factories/address_factory.rb +7 -0
  90. data/lib/solidus_br_common/factories/city_factory.rb +8 -0
  91. data/lib/solidus_br_common/factories/user_factory.rb +12 -0
  92. data/lib/solidus_br_common/factories.rb +3 -0
  93. data/lib/solidus_br_common.rb +2 -0
  94. data/solidus_br_common.gemspec +33 -0
  95. data/spec/controllers/spree/addresses_controller_spec.rb +27 -0
  96. data/spec/controllers/spree/api/cities_controller_spec.rb +91 -0
  97. data/spec/features/address_checkout_spec.rb +89 -0
  98. data/spec/features/user_account_spec.rb +46 -0
  99. data/spec/features/user_signup_spec.rb +24 -0
  100. 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
  101. data/spec/fixtures/vcr_cassettes/Checkout/visitor_makes_checkout_as_guest_without_registration/full_checkout/in_Brazil/should_autocomplete_zipcode.yml +46 -0
  102. data/spec/fixtures/vcr_cassettes/Spree_AddressesController/_show/does_not_find_an_incorrect_cep.yml +38 -0
  103. data/spec/fixtures/vcr_cassettes/Spree_AddressesController/_show/shows_the_correct_address.yml +46 -0
  104. data/spec/models/spree/address_spec.rb +32 -0
  105. data/spec/models/spree/city_spec.rb +7 -0
  106. data/spec/models/spree/user_spec.rb +88 -0
  107. data/spec/spec_helper.rb +61 -0
  108. data/spec/support/controller_hacks.rb +33 -0
  109. data/spec/support/database_cleaner.rb +24 -0
  110. data/spec/support/shared_context/checkout_setup.rb +9 -0
  111. data/spec/support/shoulda_matchers.rb +6 -0
  112. data/spec/support/vcr.rb +8 -0
  113. metadata +385 -0
@@ -0,0 +1,89 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Checkout', type: :feature, inaccessible: true do
4
+ include_context 'checkout setup'
5
+
6
+ let!(:city) { create(:city, state: Spree::State.first!) }
7
+
8
+ context 'visitor makes checkout as guest without registration' do
9
+ before(:each) do
10
+ stock_location.stock_items.update_all(count_on_hand: 1)
11
+ end
12
+
13
+ context 'full checkout', :vcr do
14
+ before do
15
+ shipping_method.calculator.update!(preferred_amount: 10)
16
+ mug.shipping_category = shipping_method.shipping_categories.first
17
+ mug.save!
18
+ end
19
+
20
+ it 'does not break the per-item shipping method calculator', :js => true do
21
+ add_mug_to_cart
22
+ click_button 'Checkout'
23
+
24
+ fill_in 'order_email', :with => 'test@example.com'
25
+ click_button 'Continue'
26
+
27
+ fill_in_address
28
+ click_button 'Save and Continue'
29
+
30
+ expect(page).not_to have_content("undefined method `promotion'")
31
+ click_button 'Save and Continue'
32
+ expect(page).to have_content('Shipping total: $10.00')
33
+ end
34
+
35
+ context 'in Brazil' do
36
+ before do
37
+ brazil = create(:country, name: 'Brasil')
38
+ minas_gerais_state = create(:state, abbr: 'MG', name: 'Minas Gerais', country: brazil)
39
+ minas_gerais_city = create(:city, name: 'Minas Gerais', state: minas_gerais_state)
40
+ @sao_paulo_state = create(:state, abbr: 'SP', name: 'São Paulo', country: brazil)
41
+ @sao_paulo_city = create(:city, name: 'São Paulo', state: @sao_paulo_state)
42
+
43
+ Spree::Config[:default_country_id] = brazil.id
44
+ end
45
+
46
+ it 'should autocomplete zipcode', :js => true do
47
+ add_mug_to_cart
48
+ click_button 'Checkout'
49
+
50
+ fill_in 'order_email', :with => 'test@example.com'
51
+ click_button 'Continue'
52
+
53
+ address = 'order_bill_address_attributes'
54
+ fill_in "#{address}_zipcode", with: '04089000'
55
+
56
+ wait_for_ajax
57
+
58
+ expect(find_by_id("#{address}_address1").value).to eq('Alameda dos Maracatins')
59
+ expect(find_by_id("#{address}_district").value).to eq('Indianópolis')
60
+ expect(find_by_id("#{address}_state_id").value).to eq(@sao_paulo_state.id.to_s)
61
+ expect(find_by_id("#{address}_city_id").value).to eq(@sao_paulo_city.id.to_s)
62
+ end
63
+
64
+ after do
65
+ Spree::Config[:default_country_id] = nil
66
+ end
67
+ end
68
+ end
69
+ end
70
+
71
+ def fill_in_address
72
+ address = 'order_bill_address_attributes'
73
+ fill_in "#{address}_firstname", with: 'Ryan'
74
+ fill_in "#{address}_lastname", with: 'Bigg'
75
+ fill_in "#{address}_address1", with: 'Swan Street'
76
+ fill_in "#{address}_number", with: '143'
77
+ fill_in "#{address}_district", with: 'Carville'
78
+ select 'Alabama', from: "#{address}_state_id"
79
+ select city.name, from: "#{address}_city_id"
80
+ fill_in "#{address}_zipcode", with: '12345'
81
+ fill_in "#{address}_phone", with: '(555) 555-5555'
82
+ end
83
+
84
+ def add_mug_to_cart
85
+ visit spree.root_path
86
+ click_link mug.name
87
+ click_button 'add-to-cart-button'
88
+ end
89
+ end
@@ -0,0 +1,46 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Accounts', type: :feature, inaccessible: true, js: true do
4
+ def login_as(user)
5
+ visit spree.login_path
6
+ fill_in 'Email', with: user.email
7
+ fill_in 'Password', with: user.password
8
+ click_button 'Login'
9
+ end
10
+
11
+ let(:user) { create(:user) }
12
+
13
+ before do
14
+ login_as(user)
15
+ end
16
+
17
+ context 'editing' do
18
+ scenario 'should rename user with success' do
19
+ Spree::Auth::Config.set(signout_after_password_change: false)
20
+ click_link 'My Account'
21
+
22
+ expect(page).to have_text user.email
23
+ click_link 'Edit'
24
+ fill_in 'First Name', with: 'Diego'
25
+ fill_in 'Last Name', with: 'Domingues'
26
+ fill_in Spree.t(:date_of_birth), with: 19.years.ago.strftime(Spree.t('date_picker.format', default: '%Y/%m/%d'))
27
+ click_button 'Update'
28
+
29
+ expect(page).to have_text 'Diego Domingues'
30
+ expect(page).to have_text 'Account updated'
31
+ end
32
+ end
33
+
34
+ context 'showing' do
35
+ scenario 'should show details of user' do
36
+ click_link 'My Account'
37
+
38
+ expect(page).to have_text user.full_name
39
+ expect(page).to have_text user.cpf_formatted
40
+ expect(page).to have_text user.phone
41
+ expect(page).to have_text user.alternative_phone if user.alternative_phone.present?
42
+ expect(page).to have_text user.date_of_birth.to_date
43
+ expect(page).to have_text user.email
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Sign Up', type: :feature, inaccessible: true do
4
+ context 'with valid data' do
5
+ scenario 'create a user with success', js: true do
6
+ visit spree.signup_path
7
+
8
+ fill_in Spree.t(:first_name), with: 'Carlos'
9
+ fill_in Spree.t(:last_name), with: 'Andrade'
10
+ fill_in Spree.t(:cpf), with: '53229124367'
11
+ fill_in Spree.t(:date_of_birth), with: 18.years.ago.strftime(Spree.t('date_picker.format', default: '%Y/%m/%d'))
12
+ fill_in Spree.t(:email), with: 'email@person.com'
13
+ fill_in Spree.t(:phone), with: '11 12211221'
14
+ fill_in Spree.t(:alternative_phone), with: '11 12211221'
15
+ fill_in Spree.t(:password), with: 'password'
16
+ fill_in 'Password Confirmation', with: 'password'
17
+
18
+ click_button 'Create'
19
+
20
+ expect(page).to have_text 'You have signed up successfully.'
21
+ expect(Spree::User.count).to eq(1)
22
+ end
23
+ end
24
+ 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
@@ -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
@@ -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,7 @@
1
+ require 'spec_helper'
2
+
3
+ describe Spree::City do
4
+ it { is_expected.to validate_presence_of(:state) }
5
+ it { is_expected.to validate_presence_of(:name) }
6
+ it { is_expected.to validate_presence_of(:ibge_code) }
7
+ 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
@@ -0,0 +1,61 @@
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/solidus_br_common/factories.rb
39
+ require 'solidus_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
+ config.include Spree::Api::TestingSupport::Helpers
55
+
56
+ config.mock_with :rspec
57
+ config.color = true
58
+ config.fixture_path = "#{::Rails.root}/spec/fixtures"
59
+ config.fail_fast = ENV['FAIL_FAST'] || false
60
+ config.order = 'random'
61
+ 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,24 @@
1
+ RSpec.configure do |config|
2
+ # Capybara javascript drivers require transactional fixtures set to false, and we use DatabaseCleaner
3
+ # to cleanup after each test instead. Without transactional fixtures set to false the records created
4
+ # to setup a test will be unavailable to the browser, which runs under a separate server instance.
5
+ config.use_transactional_fixtures = false
6
+
7
+ config.before(:suite) do
8
+ DatabaseCleaner.strategy = :transaction
9
+ DatabaseCleaner.clean_with(:truncation)
10
+ end
11
+
12
+ # Before each spec check if it is a Javascript test and switch between using database transactions or not where necessary.
13
+ config.before(:each) do
14
+ DatabaseCleaner.strategy = RSpec.current_example.metadata[:js] ? :truncation : :transaction
15
+ end
16
+
17
+ config.before(:each) do
18
+ DatabaseCleaner.start
19
+ end
20
+
21
+ config.after(:each) do
22
+ DatabaseCleaner.clean
23
+ end
24
+ 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
@@ -0,0 +1,6 @@
1
+ Shoulda::Matchers.configure do |config|
2
+ config.integrate do |with|
3
+ with.test_framework :rspec
4
+ with.library :rails
5
+ end
6
+ end
@@ -0,0 +1,8 @@
1
+ require 'vcr'
2
+
3
+ VCR.configure do |c|
4
+ c.cassette_library_dir = 'spec/fixtures/vcr_cassettes'
5
+ c.hook_into :webmock
6
+ c.configure_rspec_metadata!
7
+ c.ignore_hosts '127.0.0.1', 'localhost', 'codeclimate.com'
8
+ end