Module: Fixtures::Hash

Extended by:
Hash
Includes:
Fixtures
Included in:
Hash
Defined in:
lib/data_model/fixtures/hash.rb

Overview

Test data for hash schemas

Instance Method Summary collapse

Instance Method Details

#closed_contactExample

hash contact example that is closed to extra keys

Returns:



65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/data_model/fixtures/hash.rb', line 65

def closed_contact
	Example.new(
		[:hash, { open: false },
			[:first_name, :string],
			[:last_name, :string, { optional: true }],
			[:email, :string]],
		variants: {
			valid: example_contact,
			extra_keys: example_contact.merge(extra: "keys")
		},
	)
end

#contactExample

hash contact example

Returns:



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/data_model/fixtures/hash.rb', line 31

def contact
	Example.new(
		[:hash,
			[:first_name, :string],
			[:last_name, :string, { optional: true }],
			[:email, :string]],
		variants: {
			valid: example_contact,
			missing: nil,
			coercible: example_contact.to_a,
			missing_email: example_contact.tap { |h| h.delete(:email) },
			invalid_field: example_contact.merge(email: 123),
			other_type: []
		},
	)
end

#dictionaryExample

alternate hash syntax for when you want to type keys and values

Returns:



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

def dictionary
	Example.new(
		[:hash, [symbol: :string]],
		variants: {
			valid: { foo: "bar" },
			invalid: { foo: 123 }
		},
	)
end

#example_contactHash{Symbol => String}

hash data conforming to the contact schema

Returns:



9
10
11
12
13
14
15
# File 'lib/data_model/fixtures/hash.rb', line 9

def example_contact
	{
		first_name: "foo",
		last_name: "bar",
		email: "[email protected]"
	}
end

#optional_contactExample

hash contact example that is optional

Returns:



50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/data_model/fixtures/hash.rb', line 50

def optional_contact
	Example.new(
		[:hash, { optional: true },
			[:first_name, :string],
			[:last_name, :string, { optional: true }],
			[:email, :string]],
		variants: {
			valid: example_contact,
			missing: nil
		},
	)
end