spree_shipping_matrix 0.2.0 → 0.2.1

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.
@@ -1,6 +1,6 @@
1
1
  module Spree
2
2
  class ShippingMatrix < ActiveRecord::Base
3
- has_many :rules, ->{ order('min_line_item_total DESC') },
3
+ has_many :rules, -> { order('min_line_item_total DESC') },
4
4
  class_name: Spree::ShippingMatrixRule,
5
5
  inverse_of: :matrix
6
6
 
@@ -33,7 +33,7 @@ module Spree
33
33
  end
34
34
 
35
35
  def matches_line_item_total?(info)
36
- info[:line_item_total] > min_line_item_total
36
+ info[:line_item_total] >= min_line_item_total
37
37
  end
38
38
  end
39
39
  end
@@ -1,7 +1,7 @@
1
1
  module SpreeShippingMatrix
2
2
  module Generators
3
3
  class InstallGenerator < Rails::Generators::Base
4
- class_option :auto_run_migrations, :type => :boolean, :default => false
4
+ class_option :auto_run_migrations, type: :boolean, default: false
5
5
 
6
6
  def add_javascripts
7
7
  append_file 'vendor/assets/javascripts/spree/backend/all.js', "//= require spree/backend/spree_shipping_matrix\n"
@@ -9,7 +9,6 @@ module SpreeShippingMatrix
9
9
  g.test_framework :rspec
10
10
  end
11
11
 
12
-
13
12
  def self.activate
14
13
  Dir.glob(File.join(File.dirname(__FILE__), '../../app/**/*_decorator*.rb')) do |c|
15
14
  Rails.configuration.cache_classes ? require(c) : load(c)
@@ -1,3 +1,3 @@
1
1
  module SpreeShippingMatrix
2
- VERSION = '0.2.0'
2
+ VERSION = '0.2.1'
3
3
  end
@@ -2,34 +2,41 @@ feature 'Shipping Matrix in checkout flow' do
2
2
  before(:each) do
3
3
  given_there_are_many_spree_roles
4
4
  and_there_are_payment_methods_and_zones
5
- and_there_is_1_shipping_matrix_with_num_of_rules(1)
5
+ and_there_is_1_shipping_matrix_with_rules [['entry', 26, '6.99'],
6
+ ['entry', 52, '5.99'],
7
+ ['vip', 26, '4.99'],
8
+ ['vip', 52, '3.00'],
9
+ ['ultra_vip', 26, '2.00'],
10
+ ['ultra_vip', 52, '1.00'],
11
+ ['press', 26, '0.00'],
12
+ ['press', 52, '0.00']]
6
13
  and_there_is_1_shipping_method_with_matrix_calculator
7
14
  end
8
15
 
9
- [['entry', 26, '2.99'],
10
- ['entry', 52, '0.00'],
11
- ['vip', 26, '2.99'],
12
- ['vip', 52, '0.00'],
13
- ['ultra_vip', 26, '0.00'],
14
- ['ultra_vip', 52, '0.00'],
16
+ [['entry', 26, '6.99'],
17
+ ['entry', 52, '5.99'],
18
+ ['vip', 26, '4.99'],
19
+ ['vip', 52, '3.00'],
20
+ ['ultra_vip', 26, '2.00'],
21
+ ['ultra_vip', 52, '1.00'],
15
22
  ['press', 26, '0.00'],
16
23
  ['press', 52, '0.00']].each do |role, order_value, price|
17
24
  scenario "Delivery price as #{role}" do
18
25
  given_i_am_logged_in_as_user_with(role)
19
- when_i_have_reached_the_delivery_stage_of_checkout
20
- and_my_basket_value_is(order_value)
26
+ when_my_basket_value_is(order_value)
27
+ and_i_have_reached_the_delivery_stage_of_checkout
21
28
  then_i_should_see_the_delivery_price_of(price)
22
29
  end
23
30
 
24
31
  scenario "Cheapest shipping method for #{role}" do
25
32
  given_i_am_logged_in_as_user_with(role)
26
- when_there_is_more_than_one_shipping_method
27
- and_my_basket_value_is(order_value)
33
+ when_my_basket_value_is(order_value)
34
+ and_there_is_more_than_one_shipping_method
28
35
  then_i_should_see_the_cheapest_delivery_price_of(price)
29
36
  end
30
37
  end
31
38
 
32
- scenario "Free shipping method always wins" do
39
+ scenario 'Free shipping method always wins' do
33
40
  given_i_am_logged_in
34
41
  when_there_is_a_free_delivery_method
35
42
  then_the_delivery_should_be_free
@@ -45,12 +52,18 @@ end
45
52
  def and_there_are_payment_methods_and_zones
46
53
  FactoryGirl.create(:check_payment_method)
47
54
  country = FactoryGirl.create(:country)
48
- Spree::Zone.global.members << Spree::ZoneMember.create(:zoneable => country)
49
- country.states << FactoryGirl.create(:state, :country => country)
55
+ Spree::Zone.global.members << Spree::ZoneMember.create(zoneable: country)
56
+ country.states << FactoryGirl.create(:state, country: country)
50
57
  end
51
58
 
52
- def and_there_is_1_shipping_matrix_with_num_of_rules(num_of_rules)
53
- @matrix = create(:shipping_matrix_with_rules, num_of_rules: num_of_rules)
59
+ def and_there_is_1_shipping_matrix_with_rules(rules)
60
+ @matrix = create(:shipping_matrix)
61
+
62
+ rules.each do |role, min_line_item_total, amount|
63
+ @matrix.rules.create(role: Spree::Role.find_by(name: role),
64
+ min_line_item_total: min_line_item_total,
65
+ amount: amount)
66
+ end
54
67
  end
55
68
 
56
69
  def and_there_is_1_shipping_method_with_matrix_calculator
@@ -58,24 +71,30 @@ def and_there_is_1_shipping_method_with_matrix_calculator
58
71
  create(:shipping_method, calculator: calc)
59
72
  end
60
73
 
61
- def when_i_have_reached_the_delivery_stage_of_checkout
62
- order = OrderWalkthrough.up_to('delivery')
63
- order.update(user_id: @user.id)
64
- Spree::CheckoutController.any_instance.stub(:current_order => order)
74
+ def when_my_basket_value_is(value)
75
+ @order = Spree::Order.create!(user: @user)
76
+ line_item = create(:line_item, price: value, order: @order)
77
+ line_item.variant.update!(price: value)
78
+ @order.reload
65
79
  end
66
80
 
67
- def and_my_basket_value_is(value)
68
- Spree::LineItem.first.update(price: value)
81
+ def and_i_have_reached_the_delivery_stage_of_checkout
82
+ @order.bill_address = FactoryGirl.create(:address, :country_id => Spree::Zone.global.members.first.zoneable.id)
83
+ @order.ship_address = FactoryGirl.create(:address, :country_id => Spree::Zone.global.members.first.zoneable.id)
84
+ @order.next!
85
+ @order.next!
86
+ Spree::CheckoutController.any_instance.stub(:current_order => @order)
69
87
  end
70
88
 
71
- def when_there_is_more_than_one_shipping_method
89
+ def and_there_is_more_than_one_shipping_method
72
90
  create(:shipping_method)
73
- when_i_have_reached_the_delivery_stage_of_checkout
91
+ and_i_have_reached_the_delivery_stage_of_checkout
74
92
  end
75
93
 
76
94
  def when_there_is_a_free_delivery_method
77
95
  create(:free_shipping_method)
78
- when_i_have_reached_the_delivery_stage_of_checkout
96
+ when_my_basket_value_is(10)
97
+ and_i_have_reached_the_delivery_stage_of_checkout
79
98
  end
80
99
 
81
100
  def then_i_should_see_the_delivery_price_of(expected_delivery)
@@ -85,5 +85,5 @@ RSpec.configure do |config|
85
85
  end
86
86
 
87
87
  config.fail_fast = ENV['FAIL_FAST'] || false
88
- config.order = "random"
88
+ config.order = 'random'
89
89
  end
@@ -2,10 +2,12 @@ describe Spree::ShippingMatrixRule do
2
2
  context 'when created' do
3
3
  subject { described_class.create(attrs) }
4
4
 
5
- let(:attrs) { { role: create(:role),
6
- min_line_item_total: 50,
7
- amount: 2.99,
8
- matrix: create(:shipping_matrix) } }
5
+ let(:attrs) do
6
+ { role: create(:role),
7
+ min_line_item_total: 50,
8
+ amount: 2.99,
9
+ matrix: create(:shipping_matrix) }
10
+ end
9
11
 
10
12
  context 'and all required parameters are provided' do
11
13
  it { is_expected.to be_valid }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spree_shipping_matrix
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-08-29 00:00:00.000000000 Z
12
+ date: 2014-09-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: spree_core
@@ -278,7 +278,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
278
278
  version: '0'
279
279
  segments:
280
280
  - 0
281
- hash: -3748712467567725661
281
+ hash: -1089415386179746999
282
282
  requirements:
283
283
  - none
284
284
  rubyforge_project: