spree_delivery_options 2.1.14 → 2.1.15

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: 70decd42b26f74b7a0a7d84043020dbe632df58d
4
- data.tar.gz: e17addd9a179aa381bd5bfd427f88dbda6321708
3
+ metadata.gz: c2eb54e36ae6b539d55955a467ef7e86ffb8af66
4
+ data.tar.gz: 61f422e99c631a7aa68b5dccd6cdde06630b86e5
5
5
  SHA512:
6
- metadata.gz: c31efcc66ff517e21b6c7357551171040bbe451b2079c72d9cd0a3629f1adf216dcc210c8aa9713be8a3397e6dd38791cc8d8346423c2aa6183c8399efdc7a2b
7
- data.tar.gz: 7eb69bacd16dbafe1aad5fcca17ce831967462a16f236daec2ba496422fd68f179d2d606fe568356395f0852c0a03831b61ab76aefd71f9c33f37ef2fcc45797
6
+ metadata.gz: b83c9fd7738ded9a7dcfc8c0408845a3f8ba943a2edf6a6ccad71748bb63dd7281d437f23d8f78f3f4a2065343f8ca9c979133cd7f3a1c03822bcae9aeb955b6
7
+ data.tar.gz: 6f9e9e7b63c452b54168636945b3a2206fa539f4470f062ec8e1f74852700fd4785e9b11da2dda48e94b492d9f65f8f42784f54a73a77a4d4bc91e9642235fd4
@@ -0,0 +1,3 @@
1
+ ApplicationHelper.class_eval do
2
+ include SpreeDeliveryOptions::BaseHelper
3
+ end
@@ -0,0 +1,34 @@
1
+ module SpreeDeliveryOptions
2
+ module BaseHelper
3
+
4
+ def next_delivery_slot
5
+ delivery_options = JSON.parse(SpreeDeliveryOptions::Config.delivery_time_options)
6
+
7
+ delivery_day = next_delivery_day
8
+ return "" unless delivery_day
9
+
10
+ "#{delivery_day.strftime('%A').titleize} between #{delivery_options[delivery_day.strftime('%A').downcase].first}"
11
+ end
12
+
13
+ def next_delivery_day
14
+ delivery_options = JSON.parse(SpreeDeliveryOptions::Config.delivery_time_options)
15
+
16
+ cutoff_time = Time.now.change(hour: SpreeDeliveryOptions::Config.delivery_cut_off_hour)
17
+
18
+ current_day = Time.now > cutoff_time ? (Date.today + 2.days) : Date.tomorrow
19
+ next_available_day = nil
20
+ counter = 0
21
+
22
+ until next_available_day || counter > 7 do
23
+ if delivery_options[current_day.strftime('%A').downcase]
24
+ next_available_day = current_day
25
+ else
26
+ current_day = current_day + 1.day
27
+ counter = counter + 1
28
+ end
29
+ end
30
+ next_available_day
31
+ end
32
+
33
+ end
34
+ end
@@ -21,6 +21,9 @@ module SpreeDeliveryOptions
21
21
  Dir.glob(File.join(File.dirname(__FILE__), '../../app/controllers/**/*.rb')) do |c|
22
22
  Rails.configuration.cache_classes ? require(c) : load(c)
23
23
  end
24
+ Dir.glob(File.join(File.dirname(__FILE__), '../../app/helpers/**.rb')) do |c|
25
+ Rails.configuration.cache_classes ? require(c) : load(c)
26
+ end
24
27
  Dir.glob(File.join(File.dirname(__FILE__), '../../app/**/*decorator*.rb')) do |c|
25
28
  Rails.configuration.cache_classes ? require(c) : load(c)
26
29
  end
@@ -0,0 +1,45 @@
1
+ require 'spec_helper'
2
+
3
+ describe SpreeDeliveryOptions::BaseHelper do
4
+
5
+ describe 'next delivery slot' do
6
+
7
+ it 'should return first slot for tomorrow if its before cutoff time' do
8
+ SpreeDeliveryOptions::Config.delivery_time_options = {monday: ['6am-7am', '7am-9am'], tuesday: ['9am-12pm']}.to_json
9
+ time_now = DateTime.parse("10/03/2014 #{SpreeDeliveryOptions::Config.delivery_cut_off_hour-1}:00 +1100")
10
+ Timecop.freeze(time_now)
11
+
12
+ helper.next_delivery_slot.should == 'Tuesday between 9am-12pm'
13
+ Timecop.return
14
+ end
15
+
16
+ it 'should return the day after tomorrow morning if its after cutoff time' do
17
+ SpreeDeliveryOptions::Config.delivery_time_options = {monday: ['6am-7am', '7am-9am'], tuesday: ['9am-12pm'], wednesday: ['9am-12pm']}.to_json
18
+ time_now = DateTime.parse("10/03/2014 #{SpreeDeliveryOptions::Config.delivery_cut_off_hour+1}:00 +1100")
19
+ Timecop.freeze(time_now)
20
+
21
+ helper.next_delivery_slot.should == 'Wednesday between 9am-12pm'
22
+ Timecop.return
23
+ end
24
+
25
+ it 'should skip day if deliveries are not available' do
26
+ SpreeDeliveryOptions::Config.delivery_time_options = {monday: ['6am-7am', '7am-9am'], tuesday: ['9am-12pm'], wednesday: ['9am-12pm']}.to_json
27
+ time_now = DateTime.parse("13/03/2014 #{SpreeDeliveryOptions::Config.delivery_cut_off_hour+1}:00 +1100")
28
+ Timecop.freeze(time_now)
29
+
30
+ helper.next_delivery_slot.should == 'Monday between 6am-7am'
31
+ Timecop.return
32
+ end
33
+
34
+ it 'should return nil if no delivery times are avaialble' do
35
+ SpreeDeliveryOptions::Config.delivery_time_options = {}.to_json
36
+ time_now = DateTime.parse("13/03/2014 #{SpreeDeliveryOptions::Config.delivery_cut_off_hour+1}:00 +1100")
37
+ Timecop.freeze(time_now)
38
+
39
+ helper.next_delivery_slot.should == ''
40
+ Timecop.return
41
+ end
42
+
43
+ end
44
+
45
+ end
@@ -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.1.14'
5
+ s.version = '2.1.15'
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.1.14
4
+ version: 2.1.15
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-06 00:00:00.000000000 Z
11
+ date: 2014-03-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: spree_core
@@ -231,6 +231,8 @@ files:
231
231
  - app/assets/stylesheets/store/jquery-ui-1.10.4.custom.css
232
232
  - app/assets/stylesheets/store/spree_delivery_options.css
233
233
  - app/controllers/spree/admin/orders/delivery_options_controller.rb
234
+ - app/helpers/spree/application_helper_decorator.rb
235
+ - app/helpers/spree_delivery_options/base_helper.rb
234
236
  - app/models/spree/order_decorator.rb
235
237
  - app/overrides/add_delivery_info_to_order_details.rb
236
238
  - app/overrides/add_delivery_options_link_order_page.rb
@@ -259,6 +261,7 @@ files:
259
261
  - lib/spree_delivery_options/engine.rb
260
262
  - script/rails
261
263
  - spec/controllers/spree/admin/orders/delivery_options_controller_spec.rb
264
+ - spec/helpers/spree_delivery_options/base_helper_spec.rb
262
265
  - spec/models/order_spec.rb
263
266
  - spec/spec_helper.rb
264
267
  - spree_delivery_options.gemspec
@@ -288,5 +291,6 @@ specification_version: 4
288
291
  summary: Adds delivery date and time during checkout
289
292
  test_files:
290
293
  - spec/controllers/spree/admin/orders/delivery_options_controller_spec.rb
294
+ - spec/helpers/spree_delivery_options/base_helper_spec.rb
291
295
  - spec/models/order_spec.rb
292
296
  - spec/spec_helper.rb