Skip to content

Instantly share code, notes, and snippets.

@idlehands
idlehands / validate_schema_fields_and_types.ex
Created December 13, 2023 05:15
macro for validating ecto schema fields
defmacro validate_schema_fields_and_types(schema, expected_schemas_and_types) do
quote do
test "#{unquote(schema)}: it has the correct fields and types" do
schema = unquote(schema)
expected_schemas_and_types = unquote(expected_schemas_and_types)
actual_fields_with_types =
for field <- schema.__schema__(:fields) do
type = field_type(schema, field)
@idlehands
idlehands / assert_list_api_ideation.ex
Last active March 8, 2024 20:27
RFC: Ideation for using assert values to compare items in a list
# option 1 - new function
assert_values_for_in_list(
expected_list: {[thing_1, thing_1], :string_keys},
actual_list: return_value, # is list in all the examples
ordered: true,
fields: fields_for(Thing)
)
assert_values_for_in_list(
expected_list: [thing_2, thing_1],
@idlehands
idlehands / field_name_translations.ex
Created March 8, 2024 20:24
RFC: key for adding
assert_values_for(
expected: quote_request,
actual: quote,
fields: fields_for(OmniWeb.Schema.QuoteRequest),
field_name_translations: [
# explicit
origin_postal_code: [actual: :origin_zip],
destination_postal_code: [expected: :destination_zip, actual: :destination_zipcode],
# implicit
pieces: :freight_pieces, # assumes field is from expected and that this is on actual?