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
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 1b084b052b4a0639e7874cc8156ec820262e4db6
|
4
|
+
data.tar.gz: a1c325860440697713771be07a69e50c40a7c92c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1d1eb57c77ac92baf4b5eb8a6961275039e991a6b90dce03c96e68f456d03048e86ffced341020310b95e26f0eb8224e0b21e4b12e8839f7e4aab10ebdd6c6ed
|
7
|
+
data.tar.gz: 485b2f7a4acd64a55fd476d2b41985fceb1a26292ecffa1d0be9676a8b3a4daab37ba201ead024b55d2fe93d7e9e16ab37dd39a679206a8202e0fa5229309221
|
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
spree_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: 31bcc215780b337025c8942a8545c0a95463812c5ba421fb2dcb4a61b17738cb
|
data/Gemfile
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
gem 'spree', github: 'spree/spree', branch: '3-0-stable'
|
4
|
+
# Provides basic authentication functionality for testing parts of your engine
|
5
|
+
gem 'spree_auth_devise', github: 'spree/spree_auth_devise', branch: '3-0-stable'
|
6
|
+
|
7
|
+
group :test do
|
8
|
+
gem 'rspec-activemodel-mocks', '~> 1.0.1'
|
9
|
+
gem 'rspec-collection_matchers', '~> 1.1.2'
|
10
|
+
gem 'capybara-webkit', '~> 1.5.1'
|
11
|
+
gem 'capybara-screenshot', '~> 1.0.9'
|
12
|
+
gem 'shoulda-matchers', '~> 2.8.0'
|
13
|
+
gem 'poltergeist', '~> 1.6.0'
|
14
|
+
gem 'codeclimate-test-reporter', require: nil
|
15
|
+
gem 'vcr', '~> 2.9.3'
|
16
|
+
gem 'webmock', '~> 1.21.0'
|
17
|
+
gem 'byebug'
|
18
|
+
end
|
19
|
+
|
20
|
+
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/spree_br_common.svg)](https://travis-ci.org/ddomingues/spree_br_common)
|
4
|
+
[![Code Climate](https://codeclimate.com/github/ddomingues/spree_br_common/badges/gpa.svg)](https://codeclimate.com/github/ddomingues/spree_br_common)
|
5
|
+
[![Test Coverage](https://codeclimate.com/github/ddomingues/spree_br_common/badges/coverage.svg)](https://codeclimate.com/github/ddomingues/spree_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 spree_br_common to your Gemfile:
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
gem 'spree_br_common'
|
30
|
+
```
|
31
|
+
|
32
|
+
Bundle your dependencies and run the installation generator:
|
33
|
+
|
34
|
+
```shell
|
35
|
+
bundle
|
36
|
+
bundle exec rails g spree_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 'spree_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'] = 'spree_br_common'
|
20
|
+
Rake::Task['extension:test_app'].invoke
|
21
|
+
end
|
@@ -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
|
+
});
|