solidus_br_common 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
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
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9b0c10dced182787ee316101915a0a147cbff419
4
+ data.tar.gz: 35170c6022fcc61906d3b8797ae816574c321502
5
+ SHA512:
6
+ metadata.gz: 44ff2360905131ede86e3630b34292986ed90aaae45517444db1381cfd9fe0c44c5e57a3cdb26d89e0b65e92a48f4eff6a807f33413e00cf8e333a4921f8405e
7
+ data.tar.gz: 8c826ac445da5fa6507229afc0d8bf20921cde2510af73084fcd3648f74a54e9d5b135aff2c189b5eb12f5999aad666d8342ed10d2e0b317412a85c2393e1c6d
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ \#*
2
+ *~
3
+ .#*
4
+ .DS_Store
5
+ .idea
6
+ .project
7
+ .sass-cache
8
+ coverage
9
+ Gemfile.lock
10
+ tmp
11
+ nbproject
12
+ pkg
13
+ *.swp
14
+ spec/dummy
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ solidus_br_common
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-2.1.5
data/.travis.yml ADDED
@@ -0,0 +1,14 @@
1
+ language: ruby
2
+ before_script:
3
+ - sh -e /etc/init.d/xvfb start
4
+ - export DISPLAY=:99.0
5
+ script:
6
+ - bundle exec rake
7
+ notifications:
8
+ email:
9
+ - diego.domingues16@gmail.com
10
+ rvm:
11
+ - 2.1.5
12
+ addons:
13
+ code_climate:
14
+ repo_token: 94cd0b0ff03ee6eb48b3f115a84ee3432cfbf594064a38fa1c5e7946c669d38b
data/Gemfile ADDED
@@ -0,0 +1,19 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'solidus', '~> 1.1'
4
+ gem 'solidus_auth_devise', '~> 1.2', '>= 1.2.3'
5
+
6
+ group :test do
7
+ gem 'rspec-activemodel-mocks', '~> 1.0.2'
8
+ gem 'rspec-collection_matchers', '~> 1.1.2'
9
+ gem 'capybara-webkit', '~> 1.7', '>= 1.7.1'
10
+ gem 'capybara-screenshot', '~> 1.0', '>= 1.0.11'
11
+ gem 'shoulda-matchers', '~> 3.0', '>= 3.0.1'
12
+ gem 'poltergeist', '~> 1.8', '>= 1.8.1'
13
+ gem 'codeclimate-test-reporter', require: nil
14
+ gem 'vcr', '~> 3.0', '>= 3.0.1'
15
+ gem 'webmock', '~> 1.22', '>= 1.22.3'
16
+ gem 'byebug'
17
+ end
18
+
19
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,26 @@
1
+ Copyright (c) 2015 [name of plugin creator]
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without modification,
5
+ are permitted provided that the following conditions are met:
6
+
7
+ * Redistributions of source code must retain the above copyright notice,
8
+ this list of conditions and the following disclaimer.
9
+ * Redistributions in binary form must reproduce the above copyright notice,
10
+ this list of conditions and the following disclaimer in the documentation
11
+ and/or other materials provided with the distribution.
12
+ * Neither the name Spree nor the names of its contributors may be used to
13
+ endorse or promote products derived from this software without specific
14
+ prior written permission.
15
+
16
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
20
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
23
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
24
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
25
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README.md ADDED
@@ -0,0 +1,55 @@
1
+ # SpreeBrCommon
2
+
3
+ [![Build Status](https://travis-ci.org/ddomingues/solidus_br_common.svg)](https://travis-ci.org/ddomingues/solidus_br_common)
4
+ [![Code Climate](https://codeclimate.com/github/ddomingues/solidus_br_common/badges/gpa.svg)](https://codeclimate.com/github/ddomingues/solidus_br_common)
5
+ [![Test Coverage](https://codeclimate.com/github/ddomingues/solidus_br_common/badges/coverage.svg)](https://codeclimate.com/github/ddomingues/solidus_br_common)
6
+
7
+ This extension has goal to provide common aspects as cities, extras address informations and some seeds to Brazil.
8
+
9
+ ## New Features
10
+ > * Address attributes:
11
+ * district
12
+ * number
13
+ * City entity
14
+ * User attributes:
15
+ * first name
16
+ * last name
17
+ * cpf
18
+ * phone
19
+ * alternative phone
20
+ * date of birth
21
+ * Cep Autocomplete: using the [Postmon](http://postmon.com.br/) REST API
22
+ * Default Seeds to Brazil
23
+
24
+ # Installation
25
+
26
+ Add solidus_br_common to your Gemfile:
27
+
28
+ ```ruby
29
+ gem 'solidus_br_common'
30
+ ```
31
+
32
+ Bundle your dependencies and run the installation generator:
33
+
34
+ ```shell
35
+ bundle
36
+ bundle exec rails g solidus_br_common:install
37
+ ```
38
+
39
+ # Testing
40
+
41
+ First bundle your dependencies, then run `rake`. `rake` will default to building the dummy app if it does not exist, then it will run specs. The dummy app can be regenerated by using `rake test_app`.
42
+
43
+ ```shell
44
+ bundle
45
+ bundle exec rake
46
+ ```
47
+
48
+ When testing your applications integration with this extension you may use it's factories.
49
+ Simply add this require statement to your spec_helper:
50
+
51
+ ```ruby
52
+ require 'solidus_br_common/factories'
53
+ ```
54
+
55
+ Copyright (c) 2015 Diego Domingues, released under the New BSD License
data/Rakefile ADDED
@@ -0,0 +1,21 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require 'rspec/core/rake_task'
5
+ require 'spree/testing_support/extension_rake'
6
+
7
+ RSpec::Core::RakeTask.new
8
+
9
+ task :default do
10
+ if Dir["spec/dummy"].empty?
11
+ Rake::Task[:test_app].invoke
12
+ Dir.chdir("../../")
13
+ end
14
+ Rake::Task[:spec].invoke
15
+ end
16
+
17
+ desc 'Generates a dummy app for testing'
18
+ task :test_app do
19
+ ENV['LIB_NAME'] = 'solidus_br_common'
20
+ Rake::Task['extension:test_app'].invoke
21
+ end
@@ -0,0 +1,2 @@
1
+ // Placeholder manifest file.
2
+ // the installer will append this file to the app vendored assets here: vendor/assets/javascripts/spree/backend/all.js'
@@ -0,0 +1,119 @@
1
+ Spree.ready(function ($) {
2
+ 'use strict';
3
+
4
+ function _in(region) {
5
+ return {
6
+ find: function (selector) {
7
+ return $('#' + region + selector);
8
+ }
9
+ }
10
+ }
11
+
12
+ function isPresent(value) {
13
+ return $.trim(value).length
14
+ }
15
+
16
+ var $checkoutFormAddress = $('#checkout_form_address');
17
+
18
+ if ($checkoutFormAddress.is('*')) {
19
+ var citiesCallbacks = [];
20
+
21
+ $checkoutFormAddress.validate();
22
+
23
+ Spree.fillAddress = function (region, zipcode) {
24
+
25
+ $('.ajax-loading').attr({disabled: true});
26
+
27
+ Spree.ajax(Spree.routes.address_show(zipcode))
28
+ .done(function (data) {
29
+ if (isPresent(data.estado)) {
30
+
31
+ if (isPresent(data.cidade))
32
+ citiesCallbacks.push(function () {
33
+ var $city = _in(region).find('city select');
34
+ var idCity = $city.find('option:contains("' + data.cidade + '")').val();
35
+ $city.val(idCity);
36
+ });
37
+
38
+ var $state = _in(region).find('state select');
39
+ var idState = $state.find('option[data-uf="' + data.estado + '"]').val();
40
+ $state.val(idState).trigger('change');
41
+ }
42
+
43
+ _in(region).find('address1 input').val(data.logradouro);
44
+ _in(region).find('district input').val(data.bairro);
45
+ })
46
+ .fail(function () {
47
+ alert('Não foi possível encontrar o CEP especificado, por favor, verifique ou preencha manualmente o cadastro');
48
+ })
49
+ .always(function () {
50
+ $('.ajax-loading').attr({disabled: false});
51
+ });
52
+ };
53
+
54
+ Spree.getStateId = function (region) {
55
+ return _in(region).find('state select').val();
56
+ };
57
+
58
+ Spree.updateCity = function (region) {
59
+ var stateId = Spree.getStateId(region);
60
+ if (stateId !== '') {
61
+ if (!Spree.Checkout[stateId] || !Spree.Checkout[stateId].cities) {
62
+ return Spree.ajax(
63
+ Spree.routes.cities_search,
64
+ {
65
+ data: {state_id: stateId},
66
+ success: function (data) {
67
+ Spree.Checkout[stateId] = data;
68
+ Spree.fillCities(Spree.Checkout[stateId].cities, region);
69
+ }
70
+ }
71
+ );
72
+ } else {
73
+ return Spree.fillCities(Spree.Checkout[stateId].cities, region);
74
+ }
75
+ }
76
+ };
77
+
78
+ Spree.fillCities = function (cities, region) {
79
+ var selected,
80
+ optionsCities = [],
81
+ citySelect = _in(region).find('city select');
82
+
83
+ citySelect.html('');
84
+
85
+ if (cities.length > 0) {
86
+ selected = parseInt(citySelect.val());
87
+
88
+ $.each(cities, function (idx, city) {
89
+
90
+ var $option = $('<option />').attr('value', city.id).html(city.name);
91
+
92
+ if (selected === city.id)
93
+ $option.prop('selected', true);
94
+
95
+ optionsCities.push($option);
96
+ });
97
+
98
+ citySelect.append(optionsCities);
99
+
100
+ while (citiesCallbacks.length) {
101
+ citiesCallbacks.pop()();
102
+ }
103
+ }
104
+ };
105
+
106
+ $(['b', 's']).each(function (i, region) {
107
+ function onChangeUpdateAddress() {
108
+ return Spree.fillAddress(region, $(this).cleanVal());
109
+ }
110
+
111
+ function onChangeUpdateCity() {
112
+ return Spree.updateCity(region);
113
+ }
114
+
115
+ _in(region).find('state select').on('change', onChangeUpdateCity);
116
+ _in(region).find('zipcode input').on('change', onChangeUpdateAddress);
117
+ });
118
+ }
119
+ });
@@ -0,0 +1,21 @@
1
+ Spree.ready(function() {
2
+ 'use strict';
3
+
4
+ $('input[id$="zipcode"]').each(function() {
5
+ $(this).mask('00000-000');
6
+ });
7
+
8
+ $('*[data-mask]').each(function() {
9
+ var input = $(this);
10
+ input.mask(input.attr('data-mask'));
11
+ });
12
+
13
+ $('*[type="tel"]').mask(
14
+ PhoneMaskBehavior,
15
+ {
16
+ onKeyPress: function(val, e, field, options) {
17
+ field.mask(PhoneMaskBehavior(val, e, field, options), options);
18
+ }
19
+ }
20
+ );
21
+ });
@@ -0,0 +1,4 @@
1
+ function PhoneMaskBehavior (val, e, field, options) {
2
+ var masks = ['(00) 00000-0000', '(00) 0000-00009'];
3
+ return val.length > 14 ? masks[0] : masks[1];
4
+ };