spree_zaez_correios 1.0.0 → 3.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1dfa82c49ba7ffa14e9bf28f3f4648b753b982aa
4
- data.tar.gz: 76c7cacc1ffa2e3a67d0bec9aeb91a9a0ad7edf5
3
+ metadata.gz: 6b9150403039861870a11e305908e36a0bb857fe
4
+ data.tar.gz: 31a19ebe11caf76d72e3b047a268e4560a08c79c
5
5
  SHA512:
6
- metadata.gz: 9cd58b0688b475e64114fb533aa904ff50e425575aabe2c0b53229a50632d196eec55e059e57d48e715dd7b804e34d48dbb8f9f8f3ca14b5c03b0f157fe49484
7
- data.tar.gz: e0bc0b003116544ddad40b60eaf8cd8d6d09fc7d893ac36b3cd3d40cc019c7aa794738c616adc35cb2f59285376c52a7a5c39f8b09a3bced65a623218f698293
6
+ metadata.gz: 67f9f9816cd2d1bc8ecad2ac6f9f3e0b3781ee4cf94aa337bd86526e9e590dfbfa94d49e557d33c59c4ffc5ea09e54e3c24821aa44a1851f4e7b56d90df43760
7
+ data.tar.gz: d3936ef4aafb0fb37732136595b46027d23c350ba68e5537c2697be159c301a4a5d9a27b6d61868abfe2f576c807537c80fed109a5ace7c7e2850cd070725955
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
+ --format documentation --color
data/.travis.yml ADDED
@@ -0,0 +1,12 @@
1
+ before_script:
2
+ - sh -e /etc/init.d/xvfb start
3
+ - export DISPLAY=:99.0
4
+ bundler_args: --quiet
5
+ script:
6
+ - bundle exec rake test_app
7
+ - bundle exec rspec
8
+ language: ruby
9
+ rvm:
10
+ - 2.0.0
11
+ - 2.1.2
12
+ - 2.1.5
data/Gemfile ADDED
@@ -0,0 +1,7 @@
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
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,90 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ ## Uncomment and set this to only include directories you want to watch
5
+ # directories %w(app lib config test spec feature)
6
+
7
+ ## Uncomment to clear the screen before every task
8
+ # clearing :on
9
+
10
+ ## Guard internally checks for changes in the Guardfile and exits.
11
+ ## If you want Guard to automatically start up again, run guard in a
12
+ ## shell loop, e.g.:
13
+ ##
14
+ ## $ while bundle exec guard; do echo "Restarting Guard..."; done
15
+ ##
16
+ ## Note: if you are using the `directories` clause above and you are not
17
+ ## watching the project directory ('.'), the you will want to move the Guardfile
18
+ ## to a watched dir and symlink it back, e.g.
19
+ #
20
+ # $ mkdir config
21
+ # $ mv Guardfile config/
22
+ # $ ln -s config/Guardfile .
23
+ #
24
+ # and, you'll have to watch "config/Guardfile" instead of "Guardfile"
25
+
26
+ # Note: The cmd option is now required due to the increasing number of ways
27
+ # rspec may be run, below are examples of the most common uses.
28
+ # * bundler: 'bundle exec rspec'
29
+ # * bundler binstubs: 'bin/rspec'
30
+ # * spring: 'bin/rspec' (This will use spring if running and you have
31
+ # installed the spring binstubs per the docs)
32
+ # * zeus: 'zeus rspec' (requires the server to be started separately)
33
+ # * 'just' rspec: 'rspec'
34
+
35
+ guard :shell do
36
+ watch(/^db\/migrate\/.*\.rb/) do |m|
37
+ puts "#{m[0]} Changed"
38
+ `bundle exec rake test_app`
39
+ end
40
+ end
41
+
42
+ guard :bundler do
43
+ watch('Gemfile')
44
+ # Uncomment next line if Gemfile contain `gemspec' command
45
+ watch(/^.+\.gemspec/)
46
+ end
47
+
48
+ guard :rspec, cmd: "bundle exec rspec" do
49
+ require "guard/rspec/dsl"
50
+ dsl = Guard::RSpec::Dsl.new(self)
51
+
52
+ # Feel free to open issues for suggestions and improvements
53
+
54
+ # RSpec files
55
+ rspec = dsl.rspec
56
+ watch(rspec.spec_helper) { rspec.spec_dir }
57
+ watch(rspec.spec_support) { rspec.spec_dir }
58
+ watch(rspec.spec_files)
59
+
60
+ # Ruby files
61
+ ruby = dsl.ruby
62
+ dsl.watch_spec_files_for(ruby.lib_files)
63
+
64
+ # Rails files
65
+ rails = dsl.rails(view_extensions: %w(erb haml slim))
66
+ dsl.watch_spec_files_for(rails.app_files)
67
+ dsl.watch_spec_files_for(rails.views)
68
+
69
+ watch(rails.controllers) do |m|
70
+ [
71
+ rspec.spec.("routing/#{m[1]}_routing"),
72
+ rspec.spec.("controllers/#{m[1]}_controller"),
73
+ rspec.spec.("acceptance/#{m[1]}")
74
+ ]
75
+ end
76
+
77
+ # Rails config changes
78
+ watch(rails.spec_helper) { rspec.spec_dir }
79
+ watch(rails.routes) { "#{rspec.spec_dir}/routing" }
80
+ watch(rails.app_controller) { "#{rspec.spec_dir}/controllers" }
81
+
82
+ # Capybara features specs
83
+ watch(rails.view_dirs) { |m| rspec.spec.("features/#{m[1]}") }
84
+
85
+ # Turnip features and steps
86
+ watch(%r{^spec/acceptance/(.+)\.feature$})
87
+ watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) do |m|
88
+ Dir[File.join("**/#{m[1]}.feature")][0] || "spec/acceptance"
89
+ end
90
+ end
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Zaez Inovação Digital
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
data/README.md ADDED
@@ -0,0 +1,66 @@
1
+ Spree Zaez Correios [![Build Status](https://travis-ci.org/zaeznet/spree_zaez_correios.svg?branch=3.0-dev)](https://travis-ci.org/zaeznet/spree_zaez_correios)
2
+ =============
3
+
4
+ This gem implements diverse functions in order to enable the use of services from Brazil's Correios in Spree Commerce
5
+
6
+ Installation
7
+ ------------
8
+
9
+ Add spree_correios to your Gemfile:
10
+
11
+ ```ruby
12
+ gem 'spree_zaez_correios'
13
+ ```
14
+
15
+ Bundle your dependencies and run the installation generator:
16
+
17
+ ```shell
18
+ bundle
19
+ bundle exec rails g spree_zaez_correios:install
20
+ ```
21
+
22
+ Testing
23
+ -------
24
+
25
+ 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`.
26
+
27
+ ```shell
28
+ bundle
29
+ bundle exec rake
30
+ ```
31
+
32
+ When testing your applications integration with this extension you may use it's factories.
33
+ Simply add this require statement to your spec_helper:
34
+
35
+ ```ruby
36
+ require 'spree_zaez_correios/factories'
37
+ ```
38
+
39
+ Copyright (c) 2015 [name of extension creator], released under the New BSD License
40
+
41
+
42
+ License
43
+ -------
44
+
45
+ The MIT License (MIT)
46
+
47
+ Copyright (c) 2015 Zaez Inovação Digital
48
+
49
+ Permission is hereby granted, free of charge, to any person obtaining a copy
50
+ of this software and associated documentation files (the "Software"), to deal
51
+ in the Software without restriction, including without limitation the rights
52
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
53
+ copies of the Software, and to permit persons to whom the Software is
54
+ furnished to do so, subject to the following conditions:
55
+
56
+ The above copyright notice and this permission notice shall be included in all
57
+ copies or substantial portions of the Software.
58
+
59
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
60
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
61
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
62
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
63
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
64
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
65
+ SOFTWARE.
66
+
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_zaez_correios'
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,2 @@
1
+ // Placeholder manifest file.
2
+ // the installer will append this file to the app vendored assets here: vendor/assets/javascripts/spree/frontend/all.js'
@@ -0,0 +1,4 @@
1
+ /*
2
+ Placeholder manifest file.
3
+ the installer will append this file to the app vendored assets here: 'vendor/assets/stylesheets/spree/backend/all.css'
4
+ */
@@ -0,0 +1,4 @@
1
+ /*
2
+ Placeholder manifest file.
3
+ the installer will append this file to the app vendored assets here: 'vendor/assets/stylesheets/spree/frontend/all.css'
4
+ */
@@ -0,0 +1,57 @@
1
+ module Spree
2
+ class Calculator::Shipping::CorreiosBaseCalculator < Spree::ShippingCalculator
3
+ preference :token, :string
4
+ preference :password, :string
5
+ preference :additional_days, :integer, default: 0
6
+ preference :additional_value, :integer, default: 0
7
+ preference :declared_value, :boolean, default: false
8
+ preference :receipt_notification, :boolean, default: false
9
+ preference :receive_in_hands, :boolean, default: false
10
+
11
+ attr_reader :delivery_time
12
+
13
+ def compute_package(object)
14
+ return if object.nil?
15
+ order = if object.is_a?(Spree::Order) then object else object.order end
16
+
17
+ stock_location = object.stock_location
18
+
19
+ require 'correios-frete'
20
+
21
+ package = Correios::Frete::Pacote.new
22
+
23
+ object.contents.each do |item|
24
+ weight = item.variant.weight.to_f
25
+ depth = item.variant.depth.to_f
26
+ width = item.variant.width.to_f
27
+ height = item.variant.height.to_f
28
+ package_item = Correios::Frete::PacoteItem.new(peso: weight, comprimento: depth, largura: width, altura: height)
29
+ package.add_item(package_item)
30
+ end
31
+
32
+ calculator = Correios::Frete::Calculador.new do |c|
33
+ c.cep_origem = stock_location.zipcode
34
+ c.cep_destino = order.ship_address.zipcode
35
+ c.encomenda = package
36
+ c.mao_propria = preferred_receive_in_hands
37
+ c.aviso_recebimento = preferred_receipt_notification
38
+ c.valor_declarado = order.amount.to_f if preferred_declared_value
39
+ c.codigo_empresa = preferred_token if preferred_token.present?
40
+ c.senha = preferred_password if preferred_password.present?
41
+ end
42
+
43
+ webservice = calculator.calculate(shipping_method)
44
+ return false if webservice.erro?
45
+
46
+ @delivery_time = webservice.prazo_entrega + preferred_additional_days
47
+
48
+ webservice.valor + preferred_additional_value
49
+ rescue
50
+ false
51
+ end
52
+
53
+ def has_contract?
54
+ preferred_token.present? && preferred_password.present?
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,23 @@
1
+ module Spree
2
+ class Calculator::Shipping::PAC < Calculator::Shipping::CorreiosBaseCalculator
3
+ def self.description
4
+ 'PAC'
5
+ end
6
+
7
+ def shipping_method
8
+ if has_contract?
9
+ :pac_com_contrato
10
+ else
11
+ :pac
12
+ end
13
+ end
14
+
15
+ def shipping_code
16
+ if has_contract?
17
+ 41068
18
+ else
19
+ 41106
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,23 @@
1
+ module Spree
2
+ class Calculator::Shipping::SEDEX < Calculator::Shipping::CorreiosBaseCalculator
3
+ def self.description
4
+ 'SEDEX'
5
+ end
6
+
7
+ def shipping_method
8
+ if preferred_token.present? && preferred_password.present?
9
+ :sedex_com_contrato_1
10
+ else
11
+ :sedex
12
+ end
13
+ end
14
+
15
+ def shipping_code
16
+ if has_contract?
17
+ 40096
18
+ else
19
+ 40010
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,15 @@
1
+ module Spree
2
+ class Calculator::Shipping::SEDEX10 < Calculator::Shipping::CorreiosBaseCalculator
3
+ def self.description
4
+ 'SEDEX 10'
5
+ end
6
+
7
+ def shipping_method
8
+ :sedex_10
9
+ end
10
+
11
+ def shipping_code
12
+ 40215
13
+ end
14
+ end
15
+ end
data/bin/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_zaez_correios/engine', __FILE__)
5
+
6
+ require 'rails/all'
7
+ require 'rails/engine/commands'
@@ -0,0 +1,8 @@
1
+ en:
2
+ declared_value: Declared Value
3
+ receipt_notification: Receipt Confirmation
4
+ receive_in_hands: Receive in Hands
5
+ token: Token
6
+ zipcode: Zipcode
7
+ additional_days: Additional delivery days
8
+ additional_value: Additional value
@@ -0,0 +1,8 @@
1
+ pt-BR:
2
+ declared_value: Valor Declarado
3
+ receipt_notification: Confirmação de Recebimento
4
+ receive_in_hands: Mão Própria
5
+ token: Código Administrativo
6
+ zipcode: CEP
7
+ additional_days: Prazo de entrega adicional (em dias)
8
+ additional_value: Valor adicional
data/config/routes.rb ADDED
@@ -0,0 +1,3 @@
1
+ Spree::Core::Engine.routes.draw do
2
+ # Add your extension routes here
3
+ end
@@ -0,0 +1,31 @@
1
+ module SpreeZaezCorreios
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 'vendor/assets/javascripts/spree/frontend/all.js', "//= require spree/frontend/spree_zaez_correios\n"
9
+ append_file 'vendor/assets/javascripts/spree/backend/all.js', "//= require spree/backend/spree_zaez_correios\n"
10
+ end
11
+
12
+ def add_stylesheets
13
+ inject_into_file 'vendor/assets/stylesheets/spree/frontend/all.css', " *= require spree/frontend/spree_zaez_correios\n", :before => /\*\//, :verbose => true
14
+ inject_into_file 'vendor/assets/stylesheets/spree/backend/all.css', " *= require spree/backend/spree_zaez_correios\n", :before => /\*\//, :verbose => true
15
+ end
16
+
17
+ def add_migrations
18
+ run 'bundle exec rake railties:install:migrations FROM=spree_zaez_correios'
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,20 @@
1
+ module SpreeZaezCorreios
2
+ class Engine < Rails::Engine
3
+ require 'spree/core'
4
+ isolate_namespace Spree
5
+ engine_name 'spree_zaez_correios'
6
+
7
+ # use rspec for tests
8
+ config.generators do |g|
9
+ g.test_framework :rspec
10
+ end
11
+
12
+ def self.activate
13
+ Dir.glob(File.join(File.dirname(__FILE__), '../../app/**/*_decorator*.rb')) do |c|
14
+ Rails.configuration.cache_classes ? require(c) : load(c)
15
+ end
16
+ end
17
+
18
+ config.to_prepare &method(:activate).to_proc
19
+ end
20
+ end
@@ -0,0 +1,7 @@
1
+ FactoryGirl.define do
2
+ factory :order_with_shipments, class: Spree::Order do
3
+ user
4
+ store
5
+ ship_address
6
+ end
7
+ end
@@ -0,0 +1,2 @@
1
+ require 'spree_core'
2
+ require 'spree_zaez_correios/engine'
@@ -0,0 +1,30 @@
1
+ require 'spec_helper'
2
+
3
+ describe Spree::Calculator::Shipping::CorreiosBaseCalculator do
4
+
5
+ before { @calculator = Spree::Calculator::Shipping::CorreiosBaseCalculator.new }
6
+
7
+ it 'should have preferences' do
8
+ preferences = [:token, :password, :additional_days, :additional_value, :declared_value, :receipt_notification, :receive_in_hands]
9
+ expect(@calculator.preferences.keys).to eq(preferences)
10
+ end
11
+
12
+ it 'declared value should default to false' do
13
+ expect(@calculator.preferred_declared_value).to eq(false)
14
+ end
15
+
16
+ it 'receipt notification should default to false' do
17
+ expect(@calculator.preferred_receipt_notification).to eq(false)
18
+ end
19
+
20
+ it 'receive in hands should default to false' do
21
+ expect(@calculator.preferred_receive_in_hands).to eq(false)
22
+ end
23
+
24
+ it 'should have a contract if both token and password are given' do
25
+ expect(@calculator).not_to have_contract
26
+ @calculator.preferred_token = 'some token'
27
+ @calculator.preferred_password = 'some password'
28
+ expect(@calculator).to have_contract
29
+ end
30
+ end
@@ -0,0 +1,38 @@
1
+ require 'spec_helper'
2
+
3
+ describe Spree::Calculator::Shipping::PAC do
4
+ before do
5
+ @pac = Spree::Calculator::Shipping::PAC.new
6
+ end
7
+
8
+ it_behaves_like 'correios calculator'
9
+
10
+ it 'should have a description' do
11
+ expect(@pac.description).to eq('PAC')
12
+ end
13
+
14
+ context 'without a token and password' do
15
+ it 'should have a shipping method of :pac' do
16
+ expect(@pac.shipping_method).to eq(:pac)
17
+ end
18
+
19
+ it 'should have a shipping code of 41106' do
20
+ expect(@pac.shipping_code).to eq(41106)
21
+ end
22
+ end
23
+
24
+ context 'with a token and password' do
25
+ before do
26
+ @pac.preferred_token = 'some token'
27
+ @pac.preferred_password = 'some password'
28
+ end
29
+
30
+ it 'should have a shipping method of :pac_com_contrato' do
31
+ expect(@pac.shipping_method).to eq(:pac_com_contrato)
32
+ end
33
+
34
+ it 'should have a shipping code of 41068' do
35
+ expect(@pac.shipping_code).to eq(41068)
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ describe Spree::Calculator::Shipping::SEDEX10 do
4
+ before do
5
+ @sedex10 = Spree::Calculator::Shipping::SEDEX10.new
6
+ end
7
+
8
+ it_behaves_like 'correios calculator'
9
+
10
+ it 'should have a description' do
11
+ expect(@sedex10.description).to eq('SEDEX 10')
12
+ end
13
+
14
+ context 'without a token and password' do
15
+ it 'should have a shipping method of :pac' do
16
+ expect(@sedex10.shipping_method).to eq(:sedex_10)
17
+ end
18
+
19
+ it 'should have a shipping code of 40215' do
20
+ expect(@sedex10.shipping_code).to eq(40215)
21
+ end
22
+ end
23
+
24
+ end
@@ -0,0 +1,38 @@
1
+ require 'spec_helper'
2
+
3
+ describe Spree::Calculator::Shipping::SEDEX do
4
+ before do
5
+ @sedex = Spree::Calculator::Shipping::SEDEX.new
6
+ end
7
+
8
+ it_behaves_like 'correios calculator'
9
+
10
+ it 'should have a description' do
11
+ expect(@sedex.description).to eq('SEDEX')
12
+ end
13
+
14
+ context 'without a token and password' do
15
+ it 'should have a shipping method of :pac' do
16
+ expect(@sedex.shipping_method).to eq(:sedex)
17
+ end
18
+
19
+ it 'should have a shipping code of 40010' do
20
+ expect(@sedex.shipping_code).to eq(40010)
21
+ end
22
+ end
23
+
24
+ context 'with a token and password' do
25
+ before do
26
+ @sedex.preferred_token = 'some token'
27
+ @sedex.preferred_password = 'some password'
28
+ end
29
+
30
+ it 'should have a shipping method of :pac_com_contrato' do
31
+ expect(@sedex.shipping_method).to eq(:sedex_com_contrato_1)
32
+ end
33
+
34
+ it 'should have a shipping code of 40096' do
35
+ expect(@sedex.shipping_code).to eq(40096)
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,87 @@
1
+ # Run Coverage report
2
+ require 'simplecov'
3
+ SimpleCov.start do
4
+ add_filter 'spec/dummy'
5
+ add_group 'Controllers', 'app/controllers'
6
+ add_group 'Helpers', 'app/helpers'
7
+ add_group 'Mailers', 'app/mailers'
8
+ add_group 'Models', 'app/models'
9
+ add_group 'Views', 'app/views'
10
+ add_group 'Libraries', 'lib'
11
+ end
12
+
13
+ # Configure Rails Environment
14
+ ENV['RAILS_ENV'] = 'test'
15
+
16
+ require File.expand_path('../dummy/config/environment.rb', __FILE__)
17
+
18
+ require 'rspec/rails'
19
+ require 'database_cleaner'
20
+ require 'ffaker'
21
+
22
+ # Requires supporting ruby files with custom matchers and macros, etc,
23
+ # in spec/support/ and its subdirectories.
24
+ Dir[File.join(File.dirname(__FILE__), 'support/**/*.rb')].each { |f| require f }
25
+
26
+ # Requires factories and other useful helpers defined in spree_core.
27
+ require 'spree/testing_support/authorization_helpers'
28
+ require 'spree/testing_support/capybara_ext'
29
+ require 'spree/testing_support/controller_requests'
30
+ require 'spree/testing_support/factories'
31
+ require 'spree/testing_support/url_helpers'
32
+
33
+ # Requires factories defined in lib/spree_zaez_correios/factories.rb
34
+ require 'spree_zaez_correios/factories'
35
+
36
+ RSpec.configure do |config|
37
+ config.include FactoryGirl::Syntax::Methods
38
+
39
+ # Infer an example group's spec type from the file location.
40
+ config.infer_spec_type_from_file_location!
41
+
42
+ # == URL Helpers
43
+ #
44
+ # Allows access to Spree's routes in specs:
45
+ #
46
+ # visit spree.admin_path
47
+ # current_path.should eql(spree.products_path)
48
+ config.include Spree::TestingSupport::UrlHelpers
49
+
50
+ # == Mock Framework
51
+ #
52
+ # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
53
+ #
54
+ # config.mock_with :mocha
55
+ # config.mock_with :flexmock
56
+ # config.mock_with :rr
57
+ config.mock_with :rspec
58
+ config.color = true
59
+
60
+ # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
61
+ config.fixture_path = "#{::Rails.root}/spec/fixtures"
62
+
63
+ # Capybara javascript drivers require transactional fixtures set to false, and we use DatabaseCleaner
64
+ # to cleanup after each test instead. Without transactional fixtures set to false the records created
65
+ # to setup a test will be unavailable to the browser, which runs under a separate server instance.
66
+ config.use_transactional_fixtures = false
67
+
68
+ # Ensure Suite is set to use transactions for speed.
69
+ config.before :suite do
70
+ DatabaseCleaner.strategy = :transaction
71
+ DatabaseCleaner.clean_with :truncation
72
+ end
73
+
74
+ # Before each spec check if it is a Javascript test and switch between using database transactions or not where necessary.
75
+ config.before :each do
76
+ DatabaseCleaner.strategy = RSpec.current_example.metadata[:js] ? :truncation : :transaction
77
+ DatabaseCleaner.start
78
+ end
79
+
80
+ # After each spec clean the database.
81
+ config.after :each do
82
+ DatabaseCleaner.clean
83
+ end
84
+
85
+ config.fail_fast = ENV['FAIL_FAST'] || false
86
+ config.order = "random"
87
+ end
@@ -0,0 +1,105 @@
1
+ shared_examples_for 'correios calculator' do
2
+
3
+ before { @calculator = subject.class.new }
4
+
5
+ context 'compute_package' do
6
+
7
+ # @param url [String]
8
+ #
9
+ # @return [price Float, delivery_time Integer]
10
+ #
11
+ def get_correios_price_and_value_for(url)
12
+ doc = Nokogiri::XML(open(url))
13
+ price = doc.css('Valor').first.content.sub(/,(\d\d)$/, '.\1').to_f
14
+ delivery_time = doc.css('PrazoEntrega').first.content.to_i
15
+ return price, delivery_time
16
+ end
17
+
18
+ before do
19
+ address = FactoryGirl.build(:address, zipcode: '17209420')
20
+ variant = FactoryGirl.build(:variant, weight: 1, height: 5, width: 15, depth: 20)
21
+
22
+ @order = FactoryGirl.build(:order_with_shipments, ship_address: address)
23
+ line_item = FactoryGirl.build(:line_item, variant: variant, price: 100, order: @order)
24
+ @order.line_items << line_item
25
+
26
+ # stock location
27
+ @stock_location = FactoryGirl.build(:stock_location, zipcode: '08465312')
28
+
29
+ # shipment
30
+ @shipment = FactoryGirl.build(:shipment, order: @order, stock_location: @stock_location)
31
+ @shipment.inventory_units << FactoryGirl.build(:inventory_unit, variant: variant, order: @order, line_item: line_item, shipment: @shipment)
32
+
33
+ # package
34
+ @package = @shipment.to_package
35
+ @package.add @shipment.inventory_units.first
36
+
37
+ # default query
38
+ @default_query = {
39
+ nCdEmpresa: nil,
40
+ sDsSenha: nil,
41
+ sCepOrigem: '08465312',
42
+ sCepDestino: '17209420',
43
+ nVlPeso: 1,
44
+ nCdFormato: 1,
45
+ nVlComprimento: 20,
46
+ nVlAltura: 5,
47
+ nVlLargura: 15,
48
+ sCdMaoPropria: 'n',
49
+ nVlValorDeclarado: 0,
50
+ sCdAvisoRecebimento: 'n',
51
+ nCdServico: @calculator.shipping_code,
52
+ nVlDiametro: 0,
53
+ StrRetorno: 'xml'
54
+ }
55
+ end
56
+
57
+ it 'should calculate shipping cost and delivery time' do
58
+ price, delivery_time = get_correios_price_and_value_for("http://ws.correios.com.br/calculador/CalcPrecoPrazo.aspx?#{@default_query.to_query}")
59
+
60
+ expect(@calculator.compute_package(@package)).to eq(price)
61
+ expect(@calculator.delivery_time).to eq(delivery_time)
62
+ end
63
+
64
+ it 'should possible add days to delivery time' do
65
+ price, delivery_time = get_correios_price_and_value_for("http://ws.correios.com.br/calculador/CalcPrecoPrazo.aspx?#{@default_query.to_query}")
66
+
67
+ @calculator.preferred_additional_days = 3
68
+
69
+ @calculator.compute_package(@package)
70
+ expect(@calculator.delivery_time).to eq(delivery_time + 3)
71
+ end
72
+
73
+ it 'should possible add some value to price' do
74
+ price, delivery_time = get_correios_price_and_value_for("http://ws.correios.com.br/calculador/CalcPrecoPrazo.aspx?#{@default_query.to_query}")
75
+
76
+ @calculator.preferred_additional_value = 10.0
77
+
78
+ expect(@calculator.compute_package(@package)).to eq(price + 10.0)
79
+ end
80
+
81
+ it 'should change price according to declared value' do
82
+ query = @default_query.merge({nVlValorDeclarado: '100,00'})
83
+ price, delivery_time = get_correios_price_and_value_for("http://ws.correios.com.br/calculador/CalcPrecoPrazo.aspx?#{query.to_query}")
84
+
85
+ @calculator.preferred_declared_value = true
86
+ expect(@calculator.compute_package(@package)).to eq(price)
87
+ end
88
+
89
+ it 'should change price according to in hands' do
90
+ query = @default_query.merge({sCdMaoPropria: 's'})
91
+ price, delivery_time = get_correios_price_and_value_for("http://ws.correios.com.br/calculador/CalcPrecoPrazo.aspx?#{query.to_query}")
92
+
93
+ @calculator.preferred_receive_in_hands = true
94
+ expect(@calculator.compute_package(@package)).to eq(price)
95
+ end
96
+
97
+ it 'should change price according to receipt notification' do
98
+ query = @default_query.merge({sCdAvisoRecebimento: 's'})
99
+ price, delivery_time = get_correios_price_and_value_for("http://ws.correios.com.br/calculador/CalcPrecoPrazo.aspx?#{query.to_query}")
100
+
101
+ @calculator.preferred_receipt_notification = true
102
+ expect(@calculator.compute_package(@package)).to eq(price)
103
+ end
104
+ end
105
+ end
@@ -0,0 +1,37 @@
1
+ # encoding: UTF-8
2
+ Gem::Specification.new do |s|
3
+ s.platform = Gem::Platform::RUBY
4
+ s.name = 'spree_zaez_correios'
5
+ s.version = '3.0.1'
6
+ s.summary = "Implements diverse functions in order to enable the use of services from Brazil's Correios in Spree Commerce"
7
+ s.description = s.summary
8
+ s.required_ruby_version = '>= 2.0.0'
9
+
10
+ s.author = 'Zaez Team'
11
+ s.email = 'contato@zaez.net'
12
+ s.homepage = 'https://github.com/zaeznet/spree_zaez_correios'
13
+
14
+ s.files = `git ls-files`.split("\n")
15
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
+ s.require_path = 'lib'
17
+ s.requirements << 'none'
18
+
19
+ s.add_dependency 'spree_core', '~> 3.0.0'
20
+ s.add_dependency 'correios-frete', '~> 1.9.3'
21
+
22
+ s.add_development_dependency 'capybara', '~> 2.4'
23
+ s.add_development_dependency 'coffee-rails'
24
+ s.add_development_dependency 'database_cleaner'
25
+ s.add_development_dependency 'factory_girl', '~> 4.5'
26
+ s.add_development_dependency 'ffaker'
27
+ s.add_development_dependency 'rspec-rails', '~> 3.1'
28
+ s.add_development_dependency 'sass-rails', '~> 5.0.0.beta1'
29
+ s.add_development_dependency 'selenium-webdriver'
30
+ s.add_development_dependency 'simplecov'
31
+ s.add_development_dependency 'sqlite3'
32
+ s.add_development_dependency 'guard'
33
+ s.add_development_dependency 'guard-bundler'
34
+ s.add_development_dependency 'guard-rspec'
35
+ s.add_development_dependency 'guard-shell'
36
+
37
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spree_zaez_correios
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 3.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zaez Team
@@ -240,7 +240,38 @@ email: contato@zaez.net
240
240
  executables: []
241
241
  extensions: []
242
242
  extra_rdoc_files: []
243
- files: []
243
+ files:
244
+ - ".gitignore"
245
+ - ".rspec"
246
+ - ".travis.yml"
247
+ - Gemfile
248
+ - Guardfile
249
+ - LICENSE
250
+ - README.md
251
+ - Rakefile
252
+ - app/assets/javascripts/spree/backend/spree_zaez_correios.js
253
+ - app/assets/javascripts/spree/frontend/spree_zaez_correios.js
254
+ - app/assets/stylesheets/spree/backend/spree_zaez_correios.css
255
+ - app/assets/stylesheets/spree/frontend/spree_zaez_correios.css
256
+ - app/models/spree/calculator/shipping/correios_base_calculator.rb
257
+ - app/models/spree/calculator/shipping/pac.rb
258
+ - app/models/spree/calculator/shipping/sedex.rb
259
+ - app/models/spree/calculator/shipping/sedex10.rb
260
+ - bin/rails
261
+ - config/locales/en.yml
262
+ - config/locales/pt-br.yml
263
+ - config/routes.rb
264
+ - lib/generators/spree_zaez_correios/install/install_generator.rb
265
+ - lib/spree_zaez_correios.rb
266
+ - lib/spree_zaez_correios/engine.rb
267
+ - lib/spree_zaez_correios/factories.rb
268
+ - spec/models/spree/calculator/shipping/correios_calculator_spec.rb
269
+ - spec/models/spree/calculator/shipping/pac_spec.rb
270
+ - spec/models/spree/calculator/shipping/sedex10_spec.rb
271
+ - spec/models/spree/calculator/shipping/sedex_spec.rb
272
+ - spec/spec_helper.rb
273
+ - spec/support/correios_shared_examples.rb
274
+ - spree_zaez_correios.gemspec
244
275
  homepage: https://github.com/zaeznet/spree_zaez_correios
245
276
  licenses: []
246
277
  metadata: {}
@@ -266,4 +297,10 @@ signing_key:
266
297
  specification_version: 4
267
298
  summary: Implements diverse functions in order to enable the use of services from
268
299
  Brazil's Correios in Spree Commerce
269
- test_files: []
300
+ test_files:
301
+ - spec/models/spree/calculator/shipping/correios_calculator_spec.rb
302
+ - spec/models/spree/calculator/shipping/pac_spec.rb
303
+ - spec/models/spree/calculator/shipping/sedex10_spec.rb
304
+ - spec/models/spree/calculator/shipping/sedex_spec.rb
305
+ - spec/spec_helper.rb
306
+ - spec/support/correios_shared_examples.rb