spree_cpf 2.1.2
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.
- checksums.yaml +7 -0
- data/.gitignore +28 -0
- data/.rspec +2 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +24 -0
- data/Gemfile +17 -0
- data/LICENSE +26 -0
- data/README.md +52 -0
- data/Rakefile +15 -0
- data/Versionfile +12 -0
- data/app/assets/javascripts/admin/spree_cpf.js +1 -0
- data/app/assets/javascripts/store/spree_cpf.js +1 -0
- data/app/assets/stylesheets/admin/spree_cpf.css +3 -0
- data/app/assets/stylesheets/store/spree_cpf.css +3 -0
- data/app/lib/spree/permitted_attributes_decorator.rb +5 -0
- data/app/models/spree/order_decorator.rb +3 -0
- data/app/overrides/spree/address/_form/add_cpf_to_address_form.html.erb.deface +8 -0
- data/app/overrides/spree/admin/shared/_address_form/add_cpf_to_admin_address_form.html.erb.deface +7 -0
- data/app/validators/cpf_validator.rb +33 -0
- data/config/locales/en.yml +5 -0
- data/config/routes.rb +3 -0
- data/db/migrate/20131108001124_add_cpf_to_address.rb +9 -0
- data/lib/generators/spree_cpf/install/install_generator.rb +31 -0
- data/lib/spree_cpf/engine.rb +28 -0
- data/lib/spree_cpf/factories.rb +26 -0
- data/lib/spree_cpf.rb +2 -0
- data/script/rails +7 -0
- data/spec/features/admin/orders/customer_detail_spec.rb +39 -0
- data/spec/features/frontend/checkout_spec.rb +89 -0
- data/spec/spec_helper.rb +73 -0
- data/spec/support/capybara_ext.rb +3 -0
- data/spec/validators/cpf_validator_spec.rb +46 -0
- data/spree_cpf.gemspec +34 -0
- metadata +259 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a9499d41ab1723e226628658a7f70af90c213dea
|
4
|
+
data.tar.gz: c0914647748a8ceb4363d59fa27cda768c35122a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0fa1097663f78dc2cf5226f22deb18b686f3eade61f00437a7a77c57a46541d56a984bdb7b80c85ba7b9c3c72178ff527eb7ec598789bae56e4afae46d62d13f
|
7
|
+
data.tar.gz: f37452438c251da99c5c0a353394339cbd5fa9c7bb0eaf5fb26ef2d8e3b5ef24194a3a4352cfd53b1ad1c7135162b99f7f313d4f9195492d2e0c154380825f37
|
data/.gitignore
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# YARD artifacts
|
2
|
+
*.gem
|
3
|
+
*.rbc
|
4
|
+
*.swp
|
5
|
+
*~
|
6
|
+
.#*
|
7
|
+
.bundle
|
8
|
+
.config
|
9
|
+
.DS_Store
|
10
|
+
.idea
|
11
|
+
.project
|
12
|
+
.sass-cache
|
13
|
+
.yardoc
|
14
|
+
\#*
|
15
|
+
_yardoc
|
16
|
+
coverage
|
17
|
+
doc/
|
18
|
+
Gemfile.lock
|
19
|
+
InstalledFiles
|
20
|
+
lib/bundler/man
|
21
|
+
nbproject
|
22
|
+
pkg
|
23
|
+
rdoc
|
24
|
+
spec/dummy
|
25
|
+
spec/reports
|
26
|
+
test/tmp
|
27
|
+
test/version_tmp
|
28
|
+
tmp
|
data/.rspec
ADDED
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
spree_cpf
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.0.0-p247
|
data/.travis.yml
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
language: ruby
|
2
|
+
before_script:
|
3
|
+
- sh -e /etc/init.d/xvfb start
|
4
|
+
- export DISPLAY=:99.0
|
5
|
+
- bundle exec rake test_app
|
6
|
+
script:
|
7
|
+
- bundle exec rspec spec
|
8
|
+
notifications:
|
9
|
+
email:
|
10
|
+
- tiagocis@gmail.com
|
11
|
+
rvm:
|
12
|
+
- 1.9.3
|
13
|
+
- 2.0.0
|
14
|
+
- jruby-19mode
|
15
|
+
matrix:
|
16
|
+
allow_failures:
|
17
|
+
- rvm: jruby-19mode
|
18
|
+
env:
|
19
|
+
- DB=sqlite
|
20
|
+
- DB=mysql
|
21
|
+
- DB=postgres
|
22
|
+
branches:
|
23
|
+
only:
|
24
|
+
- 2-1-stable
|
data/Gemfile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
gem 'spree', github: 'spree/spree', branch: 'master'
|
4
|
+
|
5
|
+
platforms :jruby do
|
6
|
+
gem 'activerecord-jdbcsqlite3-adapter'
|
7
|
+
gem 'activerecord-jdbcpostgresql-adapter'
|
8
|
+
gem 'activerecord-jdbcmysql-adapter', '~> 1.3.2'
|
9
|
+
end
|
10
|
+
|
11
|
+
platforms :ruby do
|
12
|
+
gem 'sqlite3'
|
13
|
+
gem 'pg'
|
14
|
+
gem 'mysql2'
|
15
|
+
end
|
16
|
+
|
17
|
+
gemspec
|
data/LICENSE
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
Copyright (c) 2013 Tiago Amaro
|
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,52 @@
|
|
1
|
+
SpreeCpf
|
2
|
+
========
|
3
|
+
|
4
|
+
[](https://travis-ci.org/tiagoamaro/spree_cpf)
|
5
|
+
[](https://coveralls.io/r/tiagoamaro/spree_cpf?branch=2-1-stable)
|
6
|
+
[](https://gemnasium.com/tiagoamaro/spree_cpf)
|
7
|
+
|
8
|
+
Spree Extension that adds CPF field in an order
|
9
|
+
|
10
|
+
Installation
|
11
|
+
------------
|
12
|
+
|
13
|
+
Add spree_cpf to your Gemfile:
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
gem 'spree_cpf'
|
17
|
+
```
|
18
|
+
|
19
|
+
Bundle your dependencies and run the installation generator:
|
20
|
+
|
21
|
+
```shell
|
22
|
+
bundle
|
23
|
+
bundle exec rails g spree_cpf:install
|
24
|
+
```
|
25
|
+
|
26
|
+
Set the preference in an initializer such as config/initializers/spree.rb:
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
Spree.config do |config|
|
30
|
+
config.add_cpf_to_ship_address = true # Default is false
|
31
|
+
end
|
32
|
+
```
|
33
|
+
|
34
|
+
Testing
|
35
|
+
-------
|
36
|
+
|
37
|
+
Be sure to bundle your dependencies and then create a dummy test app for the specs to run against.
|
38
|
+
|
39
|
+
```shell
|
40
|
+
bundle
|
41
|
+
bundle exec rake test_app
|
42
|
+
bundle exec rspec spec
|
43
|
+
```
|
44
|
+
|
45
|
+
When testing your applications integration with this extension you may use it's factories.
|
46
|
+
Simply add this require statement to your spec_helper:
|
47
|
+
|
48
|
+
```ruby
|
49
|
+
require 'spree_cpf/factories'
|
50
|
+
```
|
51
|
+
|
52
|
+
Copyright (c) 2013 Tiago Amaro, released under the MIT License
|
data/Rakefile
ADDED
@@ -0,0 +1,15 @@
|
|
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 => [:spec]
|
10
|
+
|
11
|
+
desc 'Generates a dummy app for testing'
|
12
|
+
task :test_app do
|
13
|
+
ENV['LIB_NAME'] = 'spree_cpf'
|
14
|
+
Rake::Task['extension:test_app'].invoke
|
15
|
+
end
|
data/Versionfile
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
# This file is used to designate compatibilty with different versions of Spree
|
2
|
+
# Please see http://spreecommerce.com/documentation/extensions.html#versionfile for details
|
3
|
+
|
4
|
+
# Examples
|
5
|
+
#
|
6
|
+
# '1.2.x' => { :branch => 'master' }
|
7
|
+
# '1.1.x' => { :branch => '1-1-stable' }
|
8
|
+
# '1.0.x' => { :branch => '1-0-stable' }
|
9
|
+
# '0.70.x' => { :branch => '0-70-stable' }
|
10
|
+
# '0.40.x' => { :tag => 'v1.0.0', :version => '1.0.0' }
|
11
|
+
|
12
|
+
"2.1.x" => { :branch => "2-1-stable" }
|
@@ -0,0 +1 @@
|
|
1
|
+
//= require admin/spree_backend
|
@@ -0,0 +1 @@
|
|
1
|
+
//= require store/spree_frontend
|
@@ -0,0 +1,8 @@
|
|
1
|
+
<!-- insert_before "erb[silent]:contains('Spree::Config[:company]')" -->
|
2
|
+
<% if address_type == 'billing' || Spree::Config[:ship_address_has_cpf] %>
|
3
|
+
<p class="field" id=<%="#{address_id}cpf" %>>
|
4
|
+
<%= form.label :cpf, Spree.t(:cpf) %>
|
5
|
+
<span class="required">*</span> <br />
|
6
|
+
<%= form.text_field :cpf, :class => 'required' %>
|
7
|
+
</p>
|
8
|
+
<% end %>
|
data/app/overrides/spree/admin/shared/_address_form/add_cpf_to_admin_address_form.html.erb.deface
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
<!-- insert_before "erb[silent]:contains('Spree::Config[:company]')" -->
|
2
|
+
<% if type == 'billing' || Spree::Config[:ship_address_has_cpf] %>
|
3
|
+
<div class="field <%= "#{type}-row" %>">
|
4
|
+
<%= f.label :cpf, Spree.t(:cpf) %>
|
5
|
+
<%= f.text_field :cpf, :class => 'fullwidth' %>
|
6
|
+
</div>
|
7
|
+
<% end %>
|
@@ -0,0 +1,33 @@
|
|
1
|
+
class CpfValidator < ActiveModel::Validator
|
2
|
+
NIL_CPFS = %w(12345678909 11111111111 22222222222 33333333333 44444444444 55555555555 66666666666 77777777777 88888888888 99999999999 00000000000)
|
3
|
+
|
4
|
+
def validate(order)
|
5
|
+
ship_address_cpf = order.ship_address.try(:cpf)
|
6
|
+
bill_address_cpf = order.bill_address.try(:cpf)
|
7
|
+
|
8
|
+
order.errors.add(:ship_address, :cpf_invalid) if ship_address_cpf && !valid_cpf?(ship_address_cpf) && Spree::Config[:ship_address_has_cpf]
|
9
|
+
order.errors.add(:bill_address, :cpf_invalid) if bill_address_cpf && !valid_cpf?(bill_address_cpf)
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def valid_cpf?(cpf)
|
15
|
+
value = cpf.scan /[0-9]/
|
16
|
+
if value.length == 11
|
17
|
+
unless NIL_CPFS.member?(value.join)
|
18
|
+
value = value.collect{|x| x.to_i}
|
19
|
+
sum = 10*value[0]+9*value[1]+8*value[2]+7*value[3]+6*value[4]+5*value[5]+4*value[6]+3*value[7]+2*value[8]
|
20
|
+
sum = sum - (11 * (sum/11))
|
21
|
+
result1 = (sum == 0 or sum == 1) ? 0 : 11 - sum
|
22
|
+
if result1 == value[9]
|
23
|
+
sum = value[0]*11+value[1]*10+value[2]*9+value[3]*8+value[4]*7+value[5]*6+value[6]*5+value[7]*4+value[8]*3+value[9]*2
|
24
|
+
sum = sum - (11 * (sum/11))
|
25
|
+
result2 = (sum == 0 or sum == 1) ? 0 : 11 - sum
|
26
|
+
return true if result2 == value[10] # valid CPF
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
false
|
32
|
+
end
|
33
|
+
end
|
data/config/routes.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
module SpreeCpf
|
2
|
+
module Generators
|
3
|
+
class InstallGenerator < Rails::Generators::Base
|
4
|
+
|
5
|
+
class_option :auto_run_migrations, :type => :boolean, :default => false
|
6
|
+
|
7
|
+
def add_javascripts
|
8
|
+
# append_file 'app/assets/javascripts/store/all.js', "//= require store/spree_cpf\n"
|
9
|
+
# append_file 'app/assets/javascripts/admin/all.js', "//= require admin/spree_cpf\n"
|
10
|
+
end
|
11
|
+
|
12
|
+
def add_stylesheets
|
13
|
+
# inject_into_file 'app/assets/stylesheets/store/all.css', " *= require store/spree_cpf\n", :before => /\*\//, :verbose => true
|
14
|
+
# inject_into_file 'app/assets/stylesheets/admin/all.css', " *= require admin/spree_cpf\n", :before => /\*\//, :verbose => true
|
15
|
+
end
|
16
|
+
|
17
|
+
def add_migrations
|
18
|
+
run 'bundle exec rake railties:install:migrations FROM=spree_cpf'
|
19
|
+
end
|
20
|
+
|
21
|
+
def run_migrations
|
22
|
+
run_migrations = options[:auto_run_migrations] || ['', 'y', 'Y'].include?(ask 'Would you like to run the migrations now? [Y/n]')
|
23
|
+
if run_migrations
|
24
|
+
run 'bundle exec rake db:migrate'
|
25
|
+
else
|
26
|
+
puts 'Skipping rake db:migrate, don\'t forget to run it!'
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module SpreeCpf
|
2
|
+
class Engine < Rails::Engine
|
3
|
+
require 'spree/core'
|
4
|
+
isolate_namespace Spree
|
5
|
+
engine_name 'spree_cpf'
|
6
|
+
|
7
|
+
config.autoload_paths += %W(#{config.root}/lib)
|
8
|
+
|
9
|
+
# use rspec for tests
|
10
|
+
config.generators do |g|
|
11
|
+
g.test_framework :rspec
|
12
|
+
end
|
13
|
+
|
14
|
+
initializer "spree.spree_cpf.preferences", :before => :load_config_initializers do |app|
|
15
|
+
Spree::AppConfiguration.class_eval do
|
16
|
+
preference :ship_address_has_cpf, :boolean, default: false
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.activate
|
21
|
+
Dir.glob(File.join(File.dirname(__FILE__), '../../app/**/*_decorator*.rb')) do |c|
|
22
|
+
Rails.configuration.cache_classes ? require(c) : load(c)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
config.to_prepare &method(:activate).to_proc
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
FactoryGirl.define do
|
2
|
+
# Define your Spree extensions Factories within this file to enable applications, and other extensions to use and override them.
|
3
|
+
#
|
4
|
+
# Example adding this to your spec_helper will load these Factories for use:
|
5
|
+
# require 'spree_cpf/factories'
|
6
|
+
|
7
|
+
factory :address_with_cpf, class: Spree::Address do
|
8
|
+
firstname 'John'
|
9
|
+
lastname 'Doe'
|
10
|
+
company 'Company'
|
11
|
+
address1 '10 Lovely Street'
|
12
|
+
address2 'Northwest'
|
13
|
+
cpf '601.846.536-14'
|
14
|
+
city 'Herndon'
|
15
|
+
zipcode '20170'
|
16
|
+
phone '123-456-7890'
|
17
|
+
alternative_phone '123-456-7899'
|
18
|
+
|
19
|
+
state { |address| address.association(:state) }
|
20
|
+
country do |address|
|
21
|
+
if address.state
|
22
|
+
address.state.country
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/spree_cpf.rb
ADDED
data/script/rails
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
|
2
|
+
|
3
|
+
ENGINE_ROOT = File.expand_path('../..', __FILE__)
|
4
|
+
ENGINE_PATH = File.expand_path('../../lib/spree_cpf/engine', __FILE__)
|
5
|
+
|
6
|
+
require 'rails/all'
|
7
|
+
require 'rails/engine/commands'
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Customer Details" do
|
4
|
+
stub_authorization!
|
5
|
+
|
6
|
+
let!(:address) { create(:address_with_cpf) }
|
7
|
+
let!(:order) { create(:order, :state => 'complete', :completed_at => "2011-02-01 12:36:15", :bill_address => address) }
|
8
|
+
|
9
|
+
before do
|
10
|
+
visit spree.admin_path
|
11
|
+
click_link "Orders"
|
12
|
+
within('table#listing_orders') { click_icon(:edit) }
|
13
|
+
end
|
14
|
+
|
15
|
+
context "editing an order", :js => true do
|
16
|
+
context "ship address has cpf" do
|
17
|
+
before do
|
18
|
+
Spree::Config[:ship_address_has_cpf] = true
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should have cpf field on shipping and billing address" do
|
22
|
+
click_link "Customer Details"
|
23
|
+
page.should have_selector("#order_bill_address_attributes_cpf")
|
24
|
+
page.should have_selector("#order_ship_address_attributes_cpf")
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
context "ship address does not have cpf" do
|
29
|
+
before do
|
30
|
+
Spree::Config[:ship_address_has_cpf] = false
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should not have cpf field on shipping address" do
|
34
|
+
click_link "Customer Details"
|
35
|
+
page.should_not have_selector("#order_ship_address_attributes_cpf")
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Checkout" do
|
4
|
+
|
5
|
+
let!(:country) { create(:country, :states_required => true) }
|
6
|
+
let!(:state) { create(:state, :country => country) }
|
7
|
+
let!(:shipping_method) { create(:shipping_method) }
|
8
|
+
let!(:stock_location) { create(:stock_location) }
|
9
|
+
let!(:mug) { create(:product, :name => "RoR Mug") }
|
10
|
+
let!(:payment_method) { create(:payment_method) }
|
11
|
+
let!(:zone) { create(:zone) }
|
12
|
+
|
13
|
+
context "visitor makes checkout as guest without registration" do
|
14
|
+
before(:each) do
|
15
|
+
stock_location.stock_items.update_all(count_on_hand: 1)
|
16
|
+
end
|
17
|
+
|
18
|
+
context "full checkout", js: true do
|
19
|
+
before do
|
20
|
+
shipping_method.calculator.preferred_amount = 10
|
21
|
+
mug.shipping_category = shipping_method.shipping_categories.first
|
22
|
+
mug.save!
|
23
|
+
end
|
24
|
+
|
25
|
+
after do
|
26
|
+
click_button "Save and Continue"
|
27
|
+
page.should_not have_content("undefined method `promotion'")
|
28
|
+
click_button "Save and Continue"
|
29
|
+
page.should have_content("Shipping total $10.00")
|
30
|
+
end
|
31
|
+
|
32
|
+
describe 'ship address cpf' do
|
33
|
+
describe 'has cpf' do
|
34
|
+
before do
|
35
|
+
Spree::Config[:ship_address_has_cpf] = true
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'fill in ship address cpf, bill address cpf and checkout' do
|
39
|
+
add_mug_and_checkout
|
40
|
+
fill_in_address type: 'bill', fill_cpf: true
|
41
|
+
uncheck 'Use Billing Address'
|
42
|
+
fill_in_address type: 'ship', fill_cpf: true
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe 'does not have cpf' do
|
47
|
+
before do
|
48
|
+
Spree::Config[:ship_address_has_cpf] = false
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'fill in bill address cpf and checkout' do
|
52
|
+
add_mug_and_checkout
|
53
|
+
fill_in_address type: 'bill', fill_cpf: true
|
54
|
+
uncheck 'Use Billing Address'
|
55
|
+
fill_in_address type: 'ship', fill_cpf: false
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def fill_in_address(opts = {})
|
63
|
+
type = opts[:type] || 'bill'
|
64
|
+
fill_cpf ||= opts[:fill_cpf]
|
65
|
+
|
66
|
+
address = "order_#{type}_address_attributes"
|
67
|
+
fill_in "#{address}_firstname", :with => "Ryan"
|
68
|
+
fill_in "#{address}_lastname", :with => "Bigg"
|
69
|
+
fill_in "#{address}_address1", :with => "143 Swan Street"
|
70
|
+
fill_in "#{address}_city", :with => "Richmond"
|
71
|
+
fill_in "#{address}_cpf", :with => "036.142.049-87" if fill_cpf
|
72
|
+
select "United States of America", :from => "#{address}_country_id"
|
73
|
+
select "Alabama", :from => "#{address}_state_id"
|
74
|
+
fill_in "#{address}_zipcode", :with => "12345"
|
75
|
+
fill_in "#{address}_phone", :with => "(555) 555-5555"
|
76
|
+
end
|
77
|
+
|
78
|
+
def add_mug_and_checkout
|
79
|
+
add_mug_to_cart
|
80
|
+
click_button "Checkout"
|
81
|
+
fill_in "order_email", :with => "ryan@spreecommerce.com"
|
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
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
# Run Coverage report
|
2
|
+
require 'simplecov'
|
3
|
+
require 'coveralls'
|
4
|
+
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
|
5
|
+
SimpleCov::Formatter::HTMLFormatter,
|
6
|
+
Coveralls::SimpleCov::Formatter
|
7
|
+
]
|
8
|
+
SimpleCov.start do
|
9
|
+
add_filter 'spec/dummy'
|
10
|
+
add_group 'Controllers', 'app/controllers'
|
11
|
+
add_group 'Helpers', 'app/helpers'
|
12
|
+
add_group 'Mailers', 'app/mailers'
|
13
|
+
add_group 'Models', 'app/models'
|
14
|
+
add_group 'Views', 'app/views'
|
15
|
+
add_group 'Libraries', 'lib'
|
16
|
+
end
|
17
|
+
|
18
|
+
# Configure Rails Environment
|
19
|
+
ENV['RAILS_ENV'] = 'test'
|
20
|
+
|
21
|
+
require File.expand_path('../dummy/config/environment.rb', __FILE__)
|
22
|
+
|
23
|
+
require 'rspec/rails'
|
24
|
+
require 'database_cleaner'
|
25
|
+
require 'ffaker'
|
26
|
+
require 'pry'
|
27
|
+
|
28
|
+
# Requires supporting ruby files with custom matchers and macros, etc,
|
29
|
+
# in spec/support/ and its subdirectories.
|
30
|
+
Dir[File.join(File.dirname(__FILE__), 'support/**/*.rb')].each { |f| require f }
|
31
|
+
|
32
|
+
# Requires factories defined in spree_core
|
33
|
+
require 'spree/testing_support/factories'
|
34
|
+
require 'spree/testing_support/controller_requests'
|
35
|
+
require 'spree/testing_support/authorization_helpers'
|
36
|
+
require 'spree/testing_support/url_helpers'
|
37
|
+
|
38
|
+
# Requires factories defined in lib/spree_cpf/factories.rb
|
39
|
+
require 'spree_cpf/factories'
|
40
|
+
|
41
|
+
require 'capybara/poltergeist'
|
42
|
+
|
43
|
+
Capybara.javascript_driver = :poltergeist
|
44
|
+
Capybara.default_wait_time = 10
|
45
|
+
|
46
|
+
RSpec.configure do |config|
|
47
|
+
config.include FactoryGirl::Syntax::Methods
|
48
|
+
config.include Spree::TestingSupport::UrlHelpers
|
49
|
+
config.include Spree::TestingSupport::Preferences
|
50
|
+
|
51
|
+
config.mock_with :rspec
|
52
|
+
config.color = true
|
53
|
+
config.use_transactional_fixtures = false
|
54
|
+
|
55
|
+
# Ensure Suite is set to use transactions for speed.
|
56
|
+
config.before :suite do
|
57
|
+
DatabaseCleaner.strategy = :transaction
|
58
|
+
DatabaseCleaner.clean_with :truncation
|
59
|
+
end
|
60
|
+
|
61
|
+
# Before each spec check if it is a Javascript test and switch between using database transactions or not where necessary.
|
62
|
+
config.before :each do
|
63
|
+
DatabaseCleaner.strategy = example.metadata[:js] ? :truncation : :transaction
|
64
|
+
DatabaseCleaner.start
|
65
|
+
end
|
66
|
+
|
67
|
+
# After each spec clean the database.
|
68
|
+
config.after :each do
|
69
|
+
DatabaseCleaner.clean
|
70
|
+
end
|
71
|
+
|
72
|
+
config.fail_fast = ENV['FAIL_FAST'] || false
|
73
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'CpfValidator' do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
Spree::Config[:ship_address_has_cpf] = true
|
7
|
+
@validator = CpfValidator.new({attributes: {}})
|
8
|
+
@order = double('order')
|
9
|
+
@order_errors = double('order errors')
|
10
|
+
@order.stub(:errors).and_return(@order_errors)
|
11
|
+
end
|
12
|
+
|
13
|
+
describe 'invalid cpfs' do
|
14
|
+
it 'invalidates a invalid cpf format' do
|
15
|
+
@order.stub_chain(:ship_address, :cpf) { 'Invalid CPF :)' }
|
16
|
+
@order.stub_chain(:bill_address, :cpf) { 'Invalid CPF :)' }
|
17
|
+
@order_errors.should_receive(:add).with(:bill_address, :cpf_invalid)
|
18
|
+
@order_errors.should_receive(:add).with(:ship_address, :cpf_invalid)
|
19
|
+
@validator.validate(@order)
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'invalidates nil cpf values' do
|
23
|
+
@order_errors.should_receive(:add).with(:ship_address, :cpf_invalid).exactly(CpfValidator::NIL_CPFS.length)
|
24
|
+
@order_errors.should_receive(:add).with(:bill_address, :cpf_invalid).exactly(CpfValidator::NIL_CPFS.length)
|
25
|
+
CpfValidator::NIL_CPFS.each do |cpf|
|
26
|
+
@order.stub_chain(:ship_address, :cpf) { cpf }
|
27
|
+
@order.stub_chain(:bill_address, :cpf) { cpf }
|
28
|
+
@validator.validate(@order)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe 'valid cpfs' do
|
34
|
+
let(:valid_cpfs) { ['236.371.868-29', '468.548.242-57', '387.366.318-09'] }
|
35
|
+
|
36
|
+
it 'returns true to valid cpfs' do
|
37
|
+
@order_errors.should_not_receive(:add)
|
38
|
+
@order_errors.should_not_receive(:add)
|
39
|
+
valid_cpfs.each do |cpf|
|
40
|
+
@order.stub_chain(:ship_address, :cpf) { cpf }
|
41
|
+
@order.stub_chain(:bill_address, :cpf) { cpf }
|
42
|
+
@validator.validate(@order)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
data/spree_cpf.gemspec
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
Gem::Specification.new do |s|
|
3
|
+
s.platform = Gem::Platform::RUBY
|
4
|
+
s.name = 'spree_cpf'
|
5
|
+
s.version = '2.1.2'
|
6
|
+
s.summary = 'Spree extension that adds CPF to address field'
|
7
|
+
s.description = 'Spree extension that adds CPF to address field'
|
8
|
+
s.required_ruby_version = '>= 1.9.3'
|
9
|
+
|
10
|
+
s.author = 'Tiago Amaro'
|
11
|
+
s.email = 'tiagocis@gmail.com'
|
12
|
+
s.homepage = 'https://github.com/tiagoamaro/spree_cpf'
|
13
|
+
s.license = 'MIT'
|
14
|
+
|
15
|
+
s.files = `git ls-files`.split("\n")
|
16
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
17
|
+
s.require_path = 'lib'
|
18
|
+
s.requirements << 'none'
|
19
|
+
|
20
|
+
s.add_dependency 'spree_core', '~> 2.1'
|
21
|
+
|
22
|
+
s.add_development_dependency 'capybara', '~> 2.1'
|
23
|
+
s.add_development_dependency 'coffee-rails'
|
24
|
+
s.add_development_dependency 'database_cleaner'
|
25
|
+
s.add_development_dependency 'factory_girl', '~> 4.2'
|
26
|
+
s.add_development_dependency 'ffaker'
|
27
|
+
s.add_development_dependency 'rspec-rails', '~> 2.13'
|
28
|
+
s.add_development_dependency 'poltergeist', '~> 1.4.1'
|
29
|
+
s.add_development_dependency 'pry', '~> 0.9.12.2'
|
30
|
+
s.add_development_dependency 'fuubar', '~> 1.2.1'
|
31
|
+
s.add_development_dependency 'sass-rails'
|
32
|
+
s.add_development_dependency 'simplecov'
|
33
|
+
s.add_development_dependency 'coveralls'
|
34
|
+
end
|
metadata
ADDED
@@ -0,0 +1,259 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: spree_cpf
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2.1.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tiago Amaro
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-11-18 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: spree_core
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.1'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.1'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: capybara
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.1'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.1'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: coffee-rails
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: database_cleaner
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: factory_girl
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ~>
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '4.2'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ~>
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '4.2'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: ffaker
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rspec-rails
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ~>
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '2.13'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ~>
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '2.13'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: poltergeist
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ~>
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 1.4.1
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ~>
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 1.4.1
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: pry
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ~>
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: 0.9.12.2
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ~>
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: 0.9.12.2
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: fuubar
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ~>
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: 1.2.1
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ~>
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: 1.2.1
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: sass-rails
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - '>='
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0'
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - '>='
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0'
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: simplecov
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - '>='
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0'
|
174
|
+
type: :development
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - '>='
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '0'
|
181
|
+
- !ruby/object:Gem::Dependency
|
182
|
+
name: coveralls
|
183
|
+
requirement: !ruby/object:Gem::Requirement
|
184
|
+
requirements:
|
185
|
+
- - '>='
|
186
|
+
- !ruby/object:Gem::Version
|
187
|
+
version: '0'
|
188
|
+
type: :development
|
189
|
+
prerelease: false
|
190
|
+
version_requirements: !ruby/object:Gem::Requirement
|
191
|
+
requirements:
|
192
|
+
- - '>='
|
193
|
+
- !ruby/object:Gem::Version
|
194
|
+
version: '0'
|
195
|
+
description: Spree extension that adds CPF to address field
|
196
|
+
email: tiagocis@gmail.com
|
197
|
+
executables: []
|
198
|
+
extensions: []
|
199
|
+
extra_rdoc_files: []
|
200
|
+
files:
|
201
|
+
- .gitignore
|
202
|
+
- .rspec
|
203
|
+
- .ruby-gemset
|
204
|
+
- .ruby-version
|
205
|
+
- .travis.yml
|
206
|
+
- Gemfile
|
207
|
+
- LICENSE
|
208
|
+
- README.md
|
209
|
+
- Rakefile
|
210
|
+
- Versionfile
|
211
|
+
- app/assets/javascripts/admin/spree_cpf.js
|
212
|
+
- app/assets/javascripts/store/spree_cpf.js
|
213
|
+
- app/assets/stylesheets/admin/spree_cpf.css
|
214
|
+
- app/assets/stylesheets/store/spree_cpf.css
|
215
|
+
- app/lib/spree/permitted_attributes_decorator.rb
|
216
|
+
- app/models/spree/order_decorator.rb
|
217
|
+
- app/overrides/spree/address/_form/add_cpf_to_address_form.html.erb.deface
|
218
|
+
- app/overrides/spree/admin/shared/_address_form/add_cpf_to_admin_address_form.html.erb.deface
|
219
|
+
- app/validators/cpf_validator.rb
|
220
|
+
- config/locales/en.yml
|
221
|
+
- config/routes.rb
|
222
|
+
- db/migrate/20131108001124_add_cpf_to_address.rb
|
223
|
+
- lib/generators/spree_cpf/install/install_generator.rb
|
224
|
+
- lib/spree_cpf.rb
|
225
|
+
- lib/spree_cpf/engine.rb
|
226
|
+
- lib/spree_cpf/factories.rb
|
227
|
+
- script/rails
|
228
|
+
- spec/features/admin/orders/customer_detail_spec.rb
|
229
|
+
- spec/features/frontend/checkout_spec.rb
|
230
|
+
- spec/spec_helper.rb
|
231
|
+
- spec/support/capybara_ext.rb
|
232
|
+
- spec/validators/cpf_validator_spec.rb
|
233
|
+
- spree_cpf.gemspec
|
234
|
+
homepage: https://github.com/tiagoamaro/spree_cpf
|
235
|
+
licenses:
|
236
|
+
- MIT
|
237
|
+
metadata: {}
|
238
|
+
post_install_message:
|
239
|
+
rdoc_options: []
|
240
|
+
require_paths:
|
241
|
+
- lib
|
242
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
243
|
+
requirements:
|
244
|
+
- - '>='
|
245
|
+
- !ruby/object:Gem::Version
|
246
|
+
version: 1.9.3
|
247
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
248
|
+
requirements:
|
249
|
+
- - '>='
|
250
|
+
- !ruby/object:Gem::Version
|
251
|
+
version: '0'
|
252
|
+
requirements:
|
253
|
+
- none
|
254
|
+
rubyforge_project:
|
255
|
+
rubygems_version: 2.0.3
|
256
|
+
signing_key:
|
257
|
+
specification_version: 4
|
258
|
+
summary: Spree extension that adds CPF to address field
|
259
|
+
test_files: []
|