Sha256: 7e0c1f1e2c2d4551b39e95e2685c31c83fde4cdc6d0ef2f74d06bdc49381b914

Contents?: true

Size: 942 Bytes

Versions: 3

Compression:

Stored size: 942 Bytes

Contents

require "rails_helper"

class Event
  include ActiveModel::Model

  attr_accessor :when
end

describe "DateTimePickerInput", type: :helper do
  describe "#input" do
    def input_for(object, attr_name, options={})
      helper.simple_form_for object, url: '' do |f|
        f.input attr_name, options
      end
    end

    context "field without value" do
      let(:obj)  { Event.new }

      it "includes default `date_extra_formats" do
        output = input_for(obj, :when, as: :date_time_picker)
        expect(output).to match /data-date-format=.*YYYY-MM-DD HH:mm:ss ZZ.*"/
      end
    end

    context "field with value" do
      let(:obj)  { Event.new(when: time) }
      let(:time) { Time.current }

      it "includes formatted value" do
        output = input_for(obj, :when, as: :date_time_picker)
        expect(output).to match /value="#{Regexp.quote(time.utc.strftime("%Y-%m-%d %H:%M:%S %z"))}"/
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
datetime_picker_input-4.17.47 spec/app/inputs/date_time_picker_input_spec.rb
datetime_picker_input-4.17.37.1 spec/app/inputs/date_time_picker_input_spec.rb
datetime_picker_input-4.17.37 spec/app/inputs/date_time_picker_input_spec.rb