Module: Fixtures::Hash
Overview
Test data for hash schemas
Instance Method Summary collapse
-
#closed_contact ⇒ Example
hash contact example that is closed to extra keys.
-
#contact ⇒ Example
hash contact example.
-
#dictionary ⇒ Example
alternate hash syntax for when you want to type keys and values.
-
#example_contact ⇒ Hash{Symbol => String}
hash data conforming to the contact schema.
-
#optional_contact ⇒ Example
hash contact example that is optional.
Instance Method Details
#closed_contact ⇒ Example
hash contact example that is closed to extra keys
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 |
#contact ⇒ Example
hash contact example
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 |
#dictionary ⇒ Example
alternate hash syntax for when you want to type keys and values
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_contact ⇒ Hash{Symbol => String}
hash data conforming to the contact schema
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_contact ⇒ Example
hash contact example that is optional
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 |