spree_active_shipping 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. data/.gitignore +2 -0
  2. data/README.md +67 -0
  3. data/Rakefile +45 -0
  4. data/app/controllers/admin/shipments_controller_decorator.rb +11 -0
  5. data/app/controllers/admin/shipping_methods_controller_decorator.rb +15 -0
  6. data/app/controllers/checkout_controller_decorator.rb +11 -0
  7. data/app/models/calculator/active_shipping.rb +126 -0
  8. data/app/models/calculator/fedex/base.rb +8 -0
  9. data/app/models/calculator/fedex/base.rb~ +7 -0
  10. data/app/models/calculator/fedex/express_saver.rb +5 -0
  11. data/app/models/calculator/fedex/first_overnight.rb +5 -0
  12. data/app/models/calculator/fedex/ground.rb +5 -0
  13. data/app/models/calculator/fedex/ground_home_delivery.rb +5 -0
  14. data/app/models/calculator/fedex/international_economy.rb +5 -0
  15. data/app/models/calculator/fedex/international_economy_freight.rb +5 -0
  16. data/app/models/calculator/fedex/international_first.rb +5 -0
  17. data/app/models/calculator/fedex/international_ground.rb +5 -0
  18. data/app/models/calculator/fedex/international_priority.rb +5 -0
  19. data/app/models/calculator/fedex/international_priority_freight.rb +5 -0
  20. data/app/models/calculator/fedex/international_priority_saturday_delivery.rb +5 -0
  21. data/app/models/calculator/fedex/one_day_freight.rb +5 -0
  22. data/app/models/calculator/fedex/one_day_freight_saturday_delivery.rb +5 -0
  23. data/app/models/calculator/fedex/priority_overnight.rb +5 -0
  24. data/app/models/calculator/fedex/priority_overnight_saturday_delivery.rb +5 -0
  25. data/app/models/calculator/fedex/saver.rb +5 -0
  26. data/app/models/calculator/fedex/saver.rb~ +5 -0
  27. data/app/models/calculator/fedex/standard_overnight.rb +5 -0
  28. data/app/models/calculator/fedex/three_day_freight.rb +5 -0
  29. data/app/models/calculator/fedex/three_day_freight_saturday_delivery.rb +5 -0
  30. data/app/models/calculator/fedex/two_day.rb +5 -0
  31. data/app/models/calculator/fedex/two_day_freight.rb +5 -0
  32. data/app/models/calculator/fedex/two_day_freight_saturday_delivery.rb +5 -0
  33. data/app/models/calculator/fedex/two_day_saturday_delivery.rb +5 -0
  34. data/app/models/calculator/ups/base.rb +15 -0
  35. data/app/models/calculator/ups/ground.rb +5 -0
  36. data/app/models/calculator/ups/next_day_air.rb +5 -0
  37. data/app/models/calculator/ups/next_day_air_early_am.rb +5 -0
  38. data/app/models/calculator/ups/next_day_air_saver.rb +5 -0
  39. data/app/models/calculator/ups/saver.rb +5 -0
  40. data/app/models/calculator/ups/second_day_air.rb +5 -0
  41. data/app/models/calculator/ups/three_day_select.rb +5 -0
  42. data/app/models/calculator/ups/worldwide_expedited.rb +5 -0
  43. data/app/models/calculator/usps/base.rb +5 -0
  44. data/app/models/calculator/usps/express_mail.rb +5 -0
  45. data/app/models/calculator/usps/express_mail_international.rb +5 -0
  46. data/app/models/calculator/usps/media_mail.rb +5 -0
  47. data/app/models/calculator/usps/priority_mail.rb +5 -0
  48. data/app/models/calculator/usps/priority_mail_international.rb +5 -0
  49. data/app/models/calculator/usps/priority_mail_large_flat_rate_box.rb +5 -0
  50. data/app/models/calculator/usps/priority_mail_regular_medium_flat_rate_boxes.rb +5 -0
  51. data/app/models/calculator/usps/priority_mail_small_flat_rate_box.rb +5 -0
  52. data/app/views/admin/shipping_methods/_form.html.erb +42 -0
  53. data/config/locales/en.yml +3 -0
  54. data/lib/active_shipping_configuration.rb +25 -0
  55. data/lib/spree/active_shipping/config.rb +22 -0
  56. data/lib/spree/active_shipping/ups_override.rb +274 -0
  57. data/lib/spree/shipping_error.rb +3 -0
  58. data/lib/spree_active_shipping.rb +74 -0
  59. data/lib/tasks/active_shipping_extension_tasks.rake +29 -0
  60. data/spec/lib/spree/bogus_calculator.rb +11 -0
  61. data/spec/lib/spree/bogus_carrier.rb +15 -0
  62. data/spec/models/active_shipping_calculator_spec.rb +51 -0
  63. data/spec/spec.opts +6 -0
  64. data/spec/spec_helper.rb +33 -0
  65. data/spree_active_shipping.gemspec +23 -0
  66. metadata +184 -0
@@ -0,0 +1,3 @@
1
+ module Spree
2
+ class ShippingError < RuntimeError; end
3
+ end
@@ -0,0 +1,74 @@
1
+ require 'spree_core'
2
+ require 'active_shipping'
3
+
4
+ module ActiveShippingExtension
5
+ class Engine < Rails::Engine
6
+
7
+ def self.activate
8
+ Dir.glob(File.join(File.dirname(__FILE__), "../app/models/calculator/**/*.rb")) do |c|
9
+ Rails.env.production? ? require(c) : load(c)
10
+ end
11
+
12
+ Dir.glob(File.join(File.dirname(__FILE__), "spree/**/*.rb")) do |c|
13
+ Rails.env.production? ? require(c) : load(c)
14
+ end
15
+
16
+ [
17
+ Calculator::Ups::Ground,
18
+ Calculator::Ups::NextDayAir,
19
+ Calculator::Ups::NextDayAirEarlyAm,
20
+ Calculator::Ups::NextDayAirSaver,
21
+ Calculator::Ups::Saver,
22
+ Calculator::Ups::SecondDayAir,
23
+ Calculator::Ups::ThreeDaySelect,
24
+ Calculator::Ups::WorldwideExpedited,
25
+ Calculator::Fedex::ExpressSaver,
26
+ Calculator::Fedex::FirstOvernight,
27
+ Calculator::Fedex::Ground,
28
+ Calculator::Fedex::GroundHomeDelivery,
29
+ Calculator::Fedex::InternationalEconomy,
30
+ Calculator::Fedex::InternationalEconomyFreight,
31
+ Calculator::Fedex::InternationalFirst,
32
+ Calculator::Fedex::InternationalGround,
33
+ Calculator::Fedex::InternationalPriority,
34
+ Calculator::Fedex::InternationalPriorityFreight,
35
+ Calculator::Fedex::InternationalPrioritySaturdayDelivery,
36
+ Calculator::Fedex::OneDayFreight,
37
+ Calculator::Fedex::OneDayFreightSaturdayDelivery,
38
+ Calculator::Fedex::PriorityOvernight,
39
+ Calculator::Fedex::PriorityOvernightSaturdayDelivery,
40
+ Calculator::Fedex::StandardOvernight,
41
+ Calculator::Fedex::ThreeDayFreight,
42
+ Calculator::Fedex::ThreeDayFreightSaturdayDelivery,
43
+ Calculator::Fedex::StandardOvernight,
44
+ Calculator::Fedex::ThreeDayFreight,
45
+ Calculator::Fedex::ThreeDayFreightSaturdayDelivery,
46
+ Calculator::Fedex::TwoDay,
47
+ Calculator::Fedex::TwoDayFreight,
48
+ Calculator::Fedex::TwoDayFreightSaturdayDelivery,
49
+ Calculator::Fedex::TwoDaySaturdayDelivery,
50
+ Calculator::Usps::MediaMail,
51
+ Calculator::Usps::ExpressMail,
52
+ Calculator::Usps::ExpressMailInternational,
53
+ Calculator::Usps::PriorityMail,
54
+ Calculator::Usps::PriorityMailInternational,
55
+ Calculator::Usps::PriorityMailSmallFlatRateBox,
56
+ Calculator::Usps::PriorityMailRegularMediumFlatRateBoxes,
57
+ Calculator::Usps::PriorityMailLargeFlatRateBox
58
+ ].each(&:register)
59
+
60
+ Dir.glob(File.join(File.dirname(__FILE__), "../app/**/*_decorator*.rb")) do |c|
61
+ Rails.env.production? ? require(c) : load(c)
62
+ end
63
+
64
+ #Only required until following active_shipping commit is merged (add negotiated rates).
65
+ #http://github.com/BDQ/active_shipping/commit/2f2560d53aa7264383e5a35deb7264db60eb405a
66
+ ActiveMerchant::Shipping::UPS.send(:include, Spree::ActiveShipping::UpsOverride)
67
+
68
+ end
69
+
70
+ config.autoload_paths += %W(#{config.root}/lib)
71
+ config.to_prepare &method(:activate).to_proc
72
+
73
+ end
74
+ end
@@ -0,0 +1,29 @@
1
+ namespace :db do
2
+ desc "Bootstrap your database for Spree."
3
+ task :bootstrap => :environment do
4
+ # load initial database fixtures (in db/sample/*.yml) into the current environment's database
5
+ ActiveRecord::Base.establish_connection(RAILS_ENV.to_sym)
6
+ Dir.glob(File.join(ActiveShippingExtension.root, "db", 'sample', '*.{yml,csv}')).each do |fixture_file|
7
+ Fixtures.create_fixtures("#{ActiveShippingExtension.root}/db/sample", File.basename(fixture_file, '.*'))
8
+ end
9
+
10
+ end
11
+ end
12
+
13
+ namespace :spree do
14
+ namespace :extensions do
15
+ namespace :active_shipping do
16
+ desc "Copies public assets of the Active Shipping to the instance public/ directory."
17
+ task :update => :environment do
18
+ is_svn_or_dir = proc {|path| path =~ /\.svn/ || File.directory?(path) }
19
+ Dir[ActiveShippingExtension.root + "/public/**/*"].reject(&is_svn_or_dir).each do |file|
20
+ path = file.sub(ActiveShippingExtension.root, '')
21
+ directory = File.dirname(path)
22
+ puts "Copying #{path}..."
23
+ mkdir_p RAILS_ROOT + directory
24
+ cp file, RAILS_ROOT + path
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,11 @@
1
+ module Spree
2
+ module ActiveShipping
3
+ # Bogus calcualtor for testing purposes. Uses the common functionality of ActiveShippingCalcualtor but
4
+ # doesn't actually use a real carrier to obtain rates.
5
+ class BogusCalculator < Calculator::ActiveShipping
6
+ def carrier
7
+ Spree::ActiveShipping::BogusCarrier
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,15 @@
1
+ module Spree
2
+ module ActiveShipping
3
+ # Bogus carrier useful for testing. For some reasons the plugin version of this class does not work
4
+ # properly (it fails to return a RateResponse)
5
+ class BogusCarrier < ActiveMerchant::Shipping::Carrier
6
+ def name
7
+ "BogusCarrier"
8
+ end
9
+
10
+ def find_rates(origin, destination, packages, options = {})
11
+ RateResponse.new(true, "Bogus rate response.")
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,51 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+ include ActiveMerchant::Shipping
3
+
4
+ module ActiveShipping
5
+ describe Calculator do
6
+ # NOTE: All specs will use the bogus calculator (no login information needed)
7
+
8
+ let(:country) { mock_model Country, :iso => "US", :state => mock_model(State, :abbr => "MD") }
9
+ let(:address) { mock_model Address, :country => country, :state => country.state, :city => "Chevy Chase", :zipcode => "20815" }
10
+ let(:line_item_1) { mock_model(LineItem, :variant_id => 1, :quantity => 2, :variant => mock_model(Variant, :weight => 10)) }
11
+ let(:line_item_2) { mock_model(LineItem, :variant_id => 2, :quantity => 1, :variant => mock_model(Variant, :weight => 5.25)) }
12
+ let(:order) { mock_model Order, :number => "R12345", :ship_address => address, :line_items => [ line_item_1, line_item_2 ] }
13
+
14
+ let(:carrier) { Spree::ActiveShipping::BogusCarrier.new }
15
+ let(:calculator) { Spree::ActiveShipping::BogusCalculator.new }
16
+
17
+ before(:each) do
18
+ Spree::ActiveShipping::Config.set(:units => "imperial")
19
+ Spree::ActiveShipping::Config.set(:unit_multiplier => 16)
20
+
21
+ calculator.stub!(:carrier).and_return(carrier)
22
+ Rails.cache.clear
23
+ end
24
+
25
+ describe "compute" do
26
+ it "should use the carrier supplied in the initializer" do
27
+ carrier.should_receive(:find_rates).and_return(ActiveMerchant::Shipping::RateResponse.new(true, "Foo"))
28
+ calculator.compute(order)
29
+ end
30
+ it "should multiply the weight by the line item quantity" do
31
+ line_item_1.should_receive(:quantity).and_return(2)
32
+ calculator.compute(order)
33
+ end
34
+ it "should ignore variants that have a nil weight" do
35
+ line_item_1.variant.stub(:weight => nil)
36
+ calculator.compute(order)
37
+ end
38
+ it "should create a package with the correct total weight in ounces" do
39
+ # (10 * 2 + 5.25 * 1) * 16 = 404
40
+ Package.should_receive(:new).with(404, [], :units => :imperial)
41
+ calculator.compute(order)
42
+ end
43
+ it "should check the cache first before finding rates" do
44
+ Rails.cache.fetch(calculator.send(:cache_key, order)) { Hash.new }
45
+ carrier.should_not_receive(:find_rates)
46
+ calculator.compute(order)
47
+ end
48
+ end
49
+ end
50
+
51
+ end
@@ -0,0 +1,6 @@
1
+ --colour
2
+ --format
3
+ progress
4
+ --loadby
5
+ mtime
6
+ --reverse
@@ -0,0 +1,33 @@
1
+ # This file is copied to ~/spec when you run 'ruby script/generate rspec'
2
+ # from the project root directory.
3
+ ENV["RAILS_ENV"] ||= 'test'
4
+ require File.expand_path("../test_app/config/environment", __FILE__)
5
+ require 'rspec/rails'
6
+
7
+ # Requires supporting files with custom matchers and macros, etc,
8
+ # in ./support/ and its subdirectories.
9
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
10
+ Dir["#{File.dirname(__FILE__)}/lib/**/*.rb"].each {|f| require f}
11
+
12
+ RSpec.configure do |config|
13
+ # == Mock Framework
14
+ #
15
+ # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
16
+ #
17
+ # config.mock_with :mocha
18
+ # config.mock_with :flexmock
19
+ # config.mock_with :rr
20
+ config.mock_with :rspec
21
+
22
+ config.fixture_path = "#{::Rails.root}/spec/fixtures"
23
+
24
+ #config.include Devise::TestHelpers, :type => :controller
25
+ # If you're not using ActiveRecord, or you'd prefer not to run each of your
26
+ # examples within a transaction, comment the following line or assign false
27
+ # instead of true.
28
+ config.use_transactional_fixtures = true
29
+
30
+ Spree::ActiveShipping::BogusCalculator.register
31
+ end
32
+
33
+ #@configuration ||= AppConfiguration.find_or_create_by_name("Default configuration")
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.platform = Gem::Platform::RUBY
5
+
6
+ s.name = 'spree_active_shipping'
7
+ s.version = '1.0.0'
8
+ s.authors = ["Sean Schofield"]
9
+ s.email = 'sean@railsdog.com'
10
+ s.homepage = 'http://github.com/spree/spree_active_shipping'
11
+ s.summary = 'Spree extension for providing shipping methods that wrap the active_shipping plugin.'
12
+ s.description = 'Spree extension for providing shipping methods that wrap the active_shipping plugin.'
13
+ s.required_ruby_version = '>= 1.8.7'
14
+ s.rubygems_version = '1.3.6'
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.require_paths = ["lib"]
19
+
20
+ s.add_dependency('spree_core', '>= 0.30.1')
21
+ s.add_dependency('active_shipping', '0.9.3')
22
+ s.add_dependency('activemerchant', '1.9.0')
23
+ end
metadata ADDED
@@ -0,0 +1,184 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: spree_active_shipping
3
+ version: !ruby/object:Gem::Version
4
+ hash: 23
5
+ prerelease: false
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - 0
10
+ version: 1.0.0
11
+ platform: ruby
12
+ authors:
13
+ - Sean Schofield
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-12-22 00:00:00 +00:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: spree_core
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 101
30
+ segments:
31
+ - 0
32
+ - 30
33
+ - 1
34
+ version: 0.30.1
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: active_shipping
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - "="
44
+ - !ruby/object:Gem::Version
45
+ hash: 61
46
+ segments:
47
+ - 0
48
+ - 9
49
+ - 3
50
+ version: 0.9.3
51
+ type: :runtime
52
+ version_requirements: *id002
53
+ - !ruby/object:Gem::Dependency
54
+ name: activemerchant
55
+ prerelease: false
56
+ requirement: &id003 !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - "="
60
+ - !ruby/object:Gem::Version
61
+ hash: 51
62
+ segments:
63
+ - 1
64
+ - 9
65
+ - 0
66
+ version: 1.9.0
67
+ type: :runtime
68
+ version_requirements: *id003
69
+ description: Spree extension for providing shipping methods that wrap the active_shipping plugin.
70
+ email: sean@railsdog.com
71
+ executables: []
72
+
73
+ extensions: []
74
+
75
+ extra_rdoc_files: []
76
+
77
+ files:
78
+ - .gitignore
79
+ - README.md
80
+ - Rakefile
81
+ - app/controllers/admin/shipments_controller_decorator.rb
82
+ - app/controllers/admin/shipping_methods_controller_decorator.rb
83
+ - app/controllers/checkout_controller_decorator.rb
84
+ - app/models/calculator/active_shipping.rb
85
+ - app/models/calculator/fedex/base.rb
86
+ - app/models/calculator/fedex/base.rb~
87
+ - app/models/calculator/fedex/express_saver.rb
88
+ - app/models/calculator/fedex/first_overnight.rb
89
+ - app/models/calculator/fedex/ground.rb
90
+ - app/models/calculator/fedex/ground_home_delivery.rb
91
+ - app/models/calculator/fedex/international_economy.rb
92
+ - app/models/calculator/fedex/international_economy_freight.rb
93
+ - app/models/calculator/fedex/international_first.rb
94
+ - app/models/calculator/fedex/international_ground.rb
95
+ - app/models/calculator/fedex/international_priority.rb
96
+ - app/models/calculator/fedex/international_priority_freight.rb
97
+ - app/models/calculator/fedex/international_priority_saturday_delivery.rb
98
+ - app/models/calculator/fedex/one_day_freight.rb
99
+ - app/models/calculator/fedex/one_day_freight_saturday_delivery.rb
100
+ - app/models/calculator/fedex/priority_overnight.rb
101
+ - app/models/calculator/fedex/priority_overnight_saturday_delivery.rb
102
+ - app/models/calculator/fedex/saver.rb
103
+ - app/models/calculator/fedex/saver.rb~
104
+ - app/models/calculator/fedex/standard_overnight.rb
105
+ - app/models/calculator/fedex/three_day_freight.rb
106
+ - app/models/calculator/fedex/three_day_freight_saturday_delivery.rb
107
+ - app/models/calculator/fedex/two_day.rb
108
+ - app/models/calculator/fedex/two_day_freight.rb
109
+ - app/models/calculator/fedex/two_day_freight_saturday_delivery.rb
110
+ - app/models/calculator/fedex/two_day_saturday_delivery.rb
111
+ - app/models/calculator/ups/base.rb
112
+ - app/models/calculator/ups/ground.rb
113
+ - app/models/calculator/ups/next_day_air.rb
114
+ - app/models/calculator/ups/next_day_air_early_am.rb
115
+ - app/models/calculator/ups/next_day_air_saver.rb
116
+ - app/models/calculator/ups/saver.rb
117
+ - app/models/calculator/ups/second_day_air.rb
118
+ - app/models/calculator/ups/three_day_select.rb
119
+ - app/models/calculator/ups/worldwide_expedited.rb
120
+ - app/models/calculator/usps/base.rb
121
+ - app/models/calculator/usps/express_mail.rb
122
+ - app/models/calculator/usps/express_mail_international.rb
123
+ - app/models/calculator/usps/media_mail.rb
124
+ - app/models/calculator/usps/priority_mail.rb
125
+ - app/models/calculator/usps/priority_mail_international.rb
126
+ - app/models/calculator/usps/priority_mail_large_flat_rate_box.rb
127
+ - app/models/calculator/usps/priority_mail_regular_medium_flat_rate_boxes.rb
128
+ - app/models/calculator/usps/priority_mail_small_flat_rate_box.rb
129
+ - app/views/admin/shipping_methods/_form.html.erb
130
+ - config/locales/en.yml
131
+ - lib/active_shipping_configuration.rb
132
+ - lib/spree/active_shipping/config.rb
133
+ - lib/spree/active_shipping/ups_override.rb
134
+ - lib/spree/shipping_error.rb
135
+ - lib/spree_active_shipping.rb
136
+ - lib/tasks/active_shipping_extension_tasks.rake
137
+ - spec/lib/spree/bogus_calculator.rb
138
+ - spec/lib/spree/bogus_carrier.rb
139
+ - spec/models/active_shipping_calculator_spec.rb
140
+ - spec/spec.opts
141
+ - spec/spec_helper.rb
142
+ - spree_active_shipping.gemspec
143
+ has_rdoc: true
144
+ homepage: http://github.com/spree/spree_active_shipping
145
+ licenses: []
146
+
147
+ post_install_message:
148
+ rdoc_options: []
149
+
150
+ require_paths:
151
+ - lib
152
+ required_ruby_version: !ruby/object:Gem::Requirement
153
+ none: false
154
+ requirements:
155
+ - - ">="
156
+ - !ruby/object:Gem::Version
157
+ hash: 57
158
+ segments:
159
+ - 1
160
+ - 8
161
+ - 7
162
+ version: 1.8.7
163
+ required_rubygems_version: !ruby/object:Gem::Requirement
164
+ none: false
165
+ requirements:
166
+ - - ">="
167
+ - !ruby/object:Gem::Version
168
+ hash: 3
169
+ segments:
170
+ - 0
171
+ version: "0"
172
+ requirements: []
173
+
174
+ rubyforge_project:
175
+ rubygems_version: 1.3.7
176
+ signing_key:
177
+ specification_version: 3
178
+ summary: Spree extension for providing shipping methods that wrap the active_shipping plugin.
179
+ test_files:
180
+ - spec/lib/spree/bogus_calculator.rb
181
+ - spec/lib/spree/bogus_carrier.rb
182
+ - spec/models/active_shipping_calculator_spec.rb
183
+ - spec/spec.opts
184
+ - spec/spec_helper.rb