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 +4 -4
- data/app/controllers/spree/admin/orders/delivery_options_controller.rb +10 -1
- data/app/models/spree/order_decorator.rb +1 -1
- data/app/views/spree/admin/shared/_admin_order_information_delivery_date.html.erb +1 -1
- data/spec/controllers/spree/admin/orders/delivery_options_controller_spec.rb +11 -10
- data/spec/models/order_spec.rb +0 -1
- data/spree_delivery_options.gemspec +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0ec4e7709318e9c786e6d425f7cac16cc655d25e
|
4
|
+
data.tar.gz: 1433b6e96caf18a0c9e3664ae836865d063d28f0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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)
|
@@ -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
|
32
|
-
order.should_receive(:
|
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({"
|
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({"
|
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({"
|
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
|
data/spec/models/order_spec.rb
CHANGED
@@ -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
|
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.
|
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-
|
11
|
+
date: 2014-03-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: spree_core
|