Skip to content

Commit 72d618e

Browse files
committed
fix: make sure we load module if possible so that it's there when checking if fns exist
1 parent 6c5aa19 commit 72d618e

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
## Changelog
22

3+
# 0.3.3
4+
- Make sure code is loaded before checking if functions exist
5+
36
# 0.3.2
47
- Ensure app modules are compiled, avoiding Module.safe_concat errors re: schema modules
58
- Fix/add random field generators

lib/factory_ex.ex

+8-4
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ defmodule FactoryEx do
6868
end
6969

7070
def build_params(module, params, opts) do
71+
Code.ensure_loaded(module.schema())
7172
opts = NimbleOptions.validate!(opts, @build_definition)
7273

7374
params
@@ -91,6 +92,7 @@ defmodule FactoryEx do
9192
def build_invalid_params(module) do
9293
params = build_params(module)
9394
schema = module.schema()
95+
Code.ensure_loaded(schema)
9496

9597
field = schema.__schema__(:fields)
9698
|> Kernel.--([:updated_at, :inserted_at, :id])
@@ -121,6 +123,7 @@ defmodule FactoryEx do
121123
end
122124

123125
def build(module, params, options) do
126+
Code.ensure_loaded(module.schema())
124127
validate = Keyword.get(options, :validate, true)
125128

126129
params
@@ -145,11 +148,12 @@ defmodule FactoryEx do
145148
end
146149

147150
def insert!(module, params, options) do
148-
validate = Keyword.get(options, :validate, true)
151+
Code.ensure_loaded(module.schema())
152+
validate? = Keyword.get(options, :validate, true)
149153

150154
params
151155
|> module.build()
152-
|> maybe_changeset(module, validate)
156+
|> maybe_changeset(module, validate?)
153157
|> module.repo().insert!(options)
154158
end
155159

@@ -172,8 +176,8 @@ defmodule FactoryEx do
172176
module.repo().delete_all(module.schema(), options)
173177
end
174178

175-
defp maybe_changeset(params, module, validate) do
176-
if validate && schema?(module) do
179+
defp maybe_changeset(params, module, validate?) do
180+
if validate? && schema?(module) do
177181
params = Utils.deep_struct_to_map(params)
178182

179183
if create_changeset_defined?(module.schema()) do

mix.exs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ defmodule FactoryEx.MixProject do
44
def project do
55
[
66
app: :factory_ex,
7-
version: "0.3.2",
7+
version: "0.3.3",
88
elixir: "~> 1.13",
99
description: "Factories for elixir to help create data models at random, this works for any type of ecto structs",
1010
elixirc_paths: elixirc_paths(Mix.env()),

0 commit comments

Comments
 (0)