Sha256: e87ac28aadcb6c143c5df4b32b274e4ecf5d73334ac030abcaf9326c37ef2a2d

Contents?: true

Size: 909 Bytes

Versions: 1

Compression:

Stored size: 909 Bytes

Contents

# frozen_string_literal: true

require 'rails_helper'

RSpec.describe User, 'filters:date' do
  before do
    described_class.normalizy_rules = {}
  end

  specify do
    described_class.normalizy :birthday, with: :date

    expected = Time.new(1984, 10, 23, 0, 0, 0, 0)

    expect(described_class.create(birthday: '1984-10-23').birthday).to eq expected
  end

  specify do
    described_class.normalizy :birthday, with: { date: { format: '%y/%m/%d' } }

    expected = Time.new(1984, 10, 23, 0, 0, 0, 0)

    expect(described_class.create(birthday: '84/10/23').birthday).to eq expected
  end

  specify do
    described_class.normalizy :birthday, with: { date: { time_zone: 'Brasilia' } }

    hours    = offset_in_hours('America/Sao_Paulo')
    expected = Time.new(1984, 10, 23, 0, 0, 0, 0) + (hours.hours * -1)

    expect(described_class.create(birthday: '1984-10-23').birthday).to eq expected
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
normalizy-0.2.0 spec/normalizy/extensions/filters/date_spec.rb