do not raise an exception if a date time field of a content entry is nil or blank
did
committed Feb 18, 2016
commit 800a9654bf53b71278f60be395eb8e4241cfd4f5
Showing 3
changed files with
12 additions
and 1 deletions
Gemfile
+1
-1
| @@ | @@ -6,7 +6,7 @@ gemspec |
| gem 'rb-fsevent', '~> 0.9.1' | |
| # Development | |
| - | gem 'locomotivecms_steam', github: 'locomotivecms/steam', ref: '55517b81b59166', require: false |
| + | gem 'locomotivecms_steam', github: 'locomotivecms/steam', ref: '0db5573', require: false |
| # gem 'locomotivecms_coal', github: 'locomotivecms/coal', ref: '32b2844', require: false | |
| # gem 'locomotivecms_common', github: 'locomotivecms/common', ref: '3046b79893', require: false | |
locomotive/wagon/decorators/content_entry_decorator.rb b/lib/locomotive/wagon/decorators/content_entry_decorator.rb
+1
-0
| @@ | @@ -45,6 +45,7 @@ module Locomotive |
| end | |
| def decorate_date_time_field(value) | |
| + | return nil if value.nil? |
| value.utc.try(:iso8601) | |
| end | |
spec/unit/decorators/content_entry_decorator_spec.rb
+10
-0
| @@ | @@ -52,6 +52,11 @@ describe Locomotive::Wagon::ContentEntryDecorator do |
| it { is_expected.to eq({ _slug: 'sample', posted_at: '2015-09-26' }) } | |
| + | context 'nil field' do |
| + | let(:attributes) { { posted_at: nil } } |
| + | it { is_expected.to eq({}) } |
| + | end |
| + | |
| end | |
| describe 'date time field' do | |
| @@ | @@ -64,6 +69,11 @@ describe Locomotive::Wagon::ContentEntryDecorator do |
| it { is_expected.to eq({ _slug: 'sample', posted_at: '2015-11-11T17:00:00+00:00' }) } | |
| + | context 'nil field' do |
| + | let(:attributes) { { posted_at: nil } } |
| + | it { is_expected.to eq({}) } |
| + | end |
| + | |
| end | |
| end | |