Sha256: 95c5dffba83074701d9aafbd05316334fac888643134edc83416189b8ed73e3d

Contents?: true

Size: 1.22 KB

Versions: 15

Compression:

Stored size: 1.22 KB

Contents

require 'spec_helper'

describe RailsAdmin::Config::Fields::Types::Time do
  describe "#parse_input" do
    before :each do
      @object = FactoryGirl.create(:field_test)
      @time = ::Time.now.getutc
      @field = RailsAdmin.config(FieldTest).fields.find{ |f| f.name == :time_field }
    end

    after :each do
      Time.zone = 'UTC'
    end

    it "reads %H:%M" do
      @object.time_field = @field.parse_input({ :time_field => @time.strftime("%H:%M") })
      expect(@object.time_field.strftime("%H:%M")).to eq(@time.strftime("%H:%M"))
    end

    it "interprets time value as UTC when timezone is specified" do
      Time.zone = 'Eastern Time (US & Canada)' # -05:00
      @object.time_field = @field.parse_input({ :time_field => @time.strftime("%H:%M") })
      expect(@object.time_field.strftime("%H:%M")).to eq(@time.strftime("%H:%M"))
    end

    it "has a customization option" do
      RailsAdmin.config FieldTest do
        edit do
          field :time_field do
            strftime_format "%I:%M %p"
          end
        end
      end
      @object.time_field = @field.parse_input({ :time_field => @time.strftime("%I:%M %p") })
      expect(@object.time_field.strftime("%H:%M")).to eq(@time.strftime("%H:%M"))
    end
  end
end

Version data entries

15 entries across 15 versions & 2 rubygems

Version Path
rails_admin-0.6.0 spec/rails_admin/config/fields/time_spec.rb
rails_admin-0.5.0 spec/rails_admin/config/fields/time_spec.rb
rails_admin-0.4.9 spec/rails_admin/config/fields/time_spec.rb
rails_admin-0.4.8 spec/rails_admin/config/fields/time_spec.rb
rails_admin-0.4.7 spec/rails_admin/config/fields/time_spec.rb
rails_admin-0.4.6 spec/rails_admin/config/fields/time_spec.rb
rails_admin-0.4.5 spec/rails_admin/config/fields/time_spec.rb
rails_admin-0.4.4 spec/rails_admin/config/fields/time_spec.rb
rails_admin-lbgraham-0.4.2 spec/rails_admin/config/fields/time_spec.rb
rails_admin-0.4.3 spec/rails_admin/config/fields/time_spec.rb
rails_admin-0.4.2 spec/rails_admin/config/fields/time_spec.rb
rails_admin-0.4.1 spec/rails_admin/config/fields/time_spec.rb
rails_admin-0.4.0 spec/rails_admin/config/fields/time_spec.rb
rails_admin-0.3.0 spec/unit/config/fields/time_spec.rb
rails_admin-0.2.0 spec/unit/config/fields/time_spec.rb