spree_delivery_options 2.2.2 → 2.2.3

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: 7197ed6715f25f01dc179ffe8f18e8821752ab8c
4
- data.tar.gz: 719ea6457afe6019b8c2fa812ed9f03375d2de8a
3
+ metadata.gz: 0ec4e7709318e9c786e6d425f7cac16cc655d25e
4
+ data.tar.gz: 1433b6e96caf18a0c9e3664ae836865d063d28f0
5
5
  SHA512:
6
- metadata.gz: 9956697e69ff2ec222d1cbdf8a7e044acce5bec06791f5abee21b5c72f56bd298cbedfd0e003bffda023660e23f05a1aeb801328539528b0b4197860aac26965
7
- data.tar.gz: 4518f7274d4cdde0b14cfbb575a710596600c48885b5f1d6952887f1a0121265315c1cc492a13a62c762e7514dbd28ad2962b0c9ca50202f9dc3dbc00c8c61ff
6
+ metadata.gz: 7ceb6777c09c92c3963aba5047910f9a5cf7cf6ca2abb12cdd5fa38688a9fa686fc3de653417ec2f4a25253362967061a911bc93f4f46e61b1e3472094cee7f6
7
+ data.tar.gz: b0e4a50a520b747b2b05b256d217593d5881c69ce331b9f21d692de7bf8cb7af1425cbe37b4994edd37a68c88f448a3e497d53565fe0f7646dcdbdbe47d284f3
@@ -9,7 +9,7 @@ module Spree
9
9
 
10
10
  def update
11
11
  @order = Order.find_by(number: params[:order_id])
12
- if @order.update_attributes(delivery_options_params) && @order.next
12
+ if update_delivery_options(@order) && @order.next
13
13
  flash[:success] = Spree.t('delivery_options_updated')
14
14
  end
15
15
 
@@ -18,6 +18,15 @@ module Spree
18
18
 
19
19
  private
20
20
 
21
+ def update_delivery_options(order)
22
+ order_params = delivery_options_params
23
+ if order_params[:delivery_date]
24
+ @order.delivery_date = order_params.delete(:delivery_date)
25
+ @order.save(validate: false)
26
+ end
27
+ @order.update_attributes(order_params)
28
+ end
29
+
21
30
  def delivery_options_params
22
31
  params.require(:order).permit(:delivery_date, :delivery_time, :delivery_instructions)
23
32
  end
@@ -19,7 +19,7 @@ Spree::Order.class_eval do
19
19
  end
20
20
 
21
21
  def valid_delivery_date?
22
- if self.delivery_date
22
+ if self.delivery_date && self.delivery_date_changed?
23
23
  self.errors[:delivery_date] << 'cannot be today or in the past' if self.delivery_date <= Date.current
24
24
 
25
25
  options = delivery_time_options(self.delivery_date)
@@ -1,6 +1,6 @@
1
1
  <dt><%= t(:delivery_date) %>:</dt>
2
2
  <% if @order.delivery_date != nil %>
3
- <dd id='delivery_date'><%= @order.delivery_date %></dd>
3
+ <dd id='delivery_date'><%= l(@order.delivery_date) %></dd>
4
4
  <% else %>
5
5
  <dd id='delivery_date'>Unknown</dd>
6
6
  <% end %>
@@ -26,18 +26,19 @@ describe Spree::Admin::Orders::DeliveryOptionsController do
26
26
  before :each do
27
27
  Spree::Order.stub(:find_by).and_return(order)
28
28
  order.stub(:update_attributes).and_return(true)
29
+ order.stub(:save)
29
30
  end
30
31
 
31
- it 'should update order' do
32
- order.should_receive(:update_attributes).with({"delivery_date" => tomorrow})
33
-
32
+ it 'should update delivery date and skip validation' do
33
+ order.should_receive(:delivery_date=).with(tomorrow)
34
+ order.should_receive(:save).with(validate: false)
34
35
  spree_post :update, order: {delivery_date: tomorrow}
35
36
  end
36
37
 
37
- it 'should call next if update is successful' do
38
- order.should_receive(:update_attributes).with({"delivery_date" => tomorrow}).and_return(true)
38
+ it 'should update other attributes and call next if update is successful' do
39
+ order.should_receive(:update_attributes).with({"delivery_time" => '7:30am to 9am'}).and_return(true)
39
40
  order.should_receive(:next)
40
- spree_post :update, order: {delivery_date: tomorrow}
41
+ spree_post :update, order: {delivery_date: tomorrow, delivery_time: '7:30am to 9am'}
41
42
  end
42
43
 
43
44
  it 'should render edit when successful' do
@@ -46,14 +47,14 @@ describe Spree::Admin::Orders::DeliveryOptionsController do
46
47
  end
47
48
 
48
49
  it 'should render edit when unsuccessful' do
49
- order.should_receive(:update_attributes).with({"delivery_date" => tomorrow}).and_return false
50
- spree_post :update, order: {delivery_date: tomorrow}
50
+ order.should_receive(:update_attributes).with({"delivery_time" => '7:30am to 9am'}).and_return false
51
+ spree_post :update, order: {delivery_date: tomorrow, delivery_time: '7:30am to 9am'}
51
52
  response.should render_template(:edit)
52
53
  end
53
54
 
54
55
  it 'should not allow to update invalid attributes' do
55
- order.should_receive(:update_attributes).with({"delivery_date" => tomorrow})
56
- spree_post :update, order: {delivery_date: tomorrow, crazy: 'blah'}
56
+ order.should_receive(:update_attributes).with({"delivery_time" => '7:30am to 9am'})
57
+ spree_post :update, order: {delivery_date: tomorrow, delivery_time: '7:30am to 9am', crazy: 'blah'}
57
58
  end
58
59
 
59
60
  end
@@ -51,7 +51,6 @@ describe Spree::Order do
51
51
  SpreeDeliveryOptions::Config.delivery_time_options = {monday: ['Between 6-7am']}.to_json
52
52
  end
53
53
 
54
-
55
54
  it 'should not be valid if delivery date is in the past' do
56
55
  order.delivery_date = Date.yesterday
57
56
  order.valid_delivery_date?.should == false
@@ -2,7 +2,7 @@
2
2
  Gem::Specification.new do |s|
3
3
  s.platform = Gem::Platform::RUBY
4
4
  s.name = 'spree_delivery_options'
5
- s.version = '2.2.2'
5
+ s.version = '2.2.3'
6
6
  s.summary = 'Adds delivery date and time during checkout'
7
7
  s.description = ''
8
8
  s.required_ruby_version = '>= 2.0.0'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spree_delivery_options
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.2
4
+ version: 2.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Francisco Trindade
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-27 00:00:00.000000000 Z
11
+ date: 2014-03-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: spree_core