Module: Fixtures::Date

Extended by:
Date
Includes:
Fixtures
Included in:
Date
Defined in:
lib/data_model/fixtures/date.rb

Overview

Provides fixtures for testing date types

Instance Method Summary collapse

Instance Method Details

#earliestExample

A date schema that has a restriction on the earliest date

Returns:



45
46
47
# File 'lib/data_model/fixtures/date.rb', line 45

def earliest
	Example.new([:date, { earliest: earliest_date }], variants:)
end

#earliest_dateDate

Returns a date that is used by the #earliest example.

Returns:

  • (Date)

    a date that is used by the #earliest example



8
9
10
# File 'lib/data_model/fixtures/date.rb', line 8

def earliest_date
	return ::Date.today - 1
end

#latestExample

A date schema that has a restriction on the latest date

Returns:



51
52
53
# File 'lib/data_model/fixtures/date.rb', line 51

def latest
	Example.new([:date, { latest: latest_date }], variants:)
end

#latest_dateDate

Returns a date that is used by the #latest example.

Returns:

  • (Date)

    a date that is used by the #latest example



13
14
15
# File 'lib/data_model/fixtures/date.rb', line 13

def latest_date
	return ::Date.today + 1
end

#optionalExample

A date schema that is optional

Returns:



39
40
41
# File 'lib/data_model/fixtures/date.rb', line 39

def optional
	Example.new([:date, { optional: true }], variants:)
end

#simpleExample

A simple date schema

Returns:



33
34
35
# File 'lib/data_model/fixtures/date.rb', line 33

def simple
	Example.new([:date], variants:)
end

#variantsHash{Symbol => untyped}

Returns the variants used by each example.

Returns:

  • (Hash{Symbol => untyped})

    the variants used by each example



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/data_model/fixtures/date.rb', line 18

def variants
	today = ::Date.today

	{
		date: today,
		string: [today.to_s, today],
		invalid: "invalid",
		early: earliest_date - 1,
		late: latest_date + 1,
		missing: nil
	}
end