Sha256: 1b5a777ae483fe4621a26790fe937de5ec92073b46040b53c2ed1eb84197280e

Contents?: true

Size: 1.21 KB

Versions: 1

Compression:

Stored size: 1.21 KB

Contents

require 'spec_helper'

describe BetterDatePicker::Model do
  class Widget
    include ActiveModel::Model
    include ActiveModel::Validations::Callbacks
    include BetterDatePicker::Model


    attr_accessor :built_at

    better_time_picker :built_at
  end

  it 'allows the setting of a date via a string' do
    widget = Widget.new
    date_string = '03/09/1984'
    widget.built_at_date = date_string
    expect(widget.built_at).to eql(Chronic.parse(date_string))
  end

  it 'sets the date to nil when assigned' do
    widget = Widget.new
    widget.built_at = Date.today
    widget.built_at_date = nil
    expect(widget.built_at).to be_nil
  end

  it 'sets the date to nil when a badly formed string is assigned' do
    widget = Widget.new
    widget.built_at = Date.today
    widget.built_at_date = "INVALID DATE"
    expect(widget.built_at).to be_nil
  end

  it 'sets the date string when the date is set' do
    widget = Widget.new
    widget.built_at = Date.today
    expect(widget.built_at_date).to be_kind_of(String)
  end

  it 'nils the date string when the date is assigned nil' do
    widget = Widget.new
    widget.built_at_date = 'yesterday'
    widget.built_at = nil
    expect(widget.built_at_date).to be_nil
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
better_date_picker-0.0.1 spec/better_date_picker/model_spec.rb