Skip to content

Commit

Permalink
Replace spaces in list name when defining schema modules
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Grieve committed Jun 25, 2020
1 parent 40b13a6 commit 4c5c82c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/ecto_gss/schema.ex
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ defmodule EctoGSS.Schema do
def gss_schema_type, do: true
end

safe_list_name = String.replace(list, " ", "")

Module.create(
Module.concat(EctoGSS.Schema, "#{list}.#{gss_column}"),
Module.concat(EctoGSS.Schema, "#{safe_list_name}.#{gss_column}"),
code,
Macro.Env.location(__ENV__)
)
Expand Down
23 changes: 23 additions & 0 deletions test/ecto/schema_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
defmodule EctoGSS.SchemaTest do
use ExUnit.Case, async: true

defmodule Account do
use EctoGSS.Schema, {
:model,
columns: ["A", "Y"],
list: "All Accounts",
spreadsheet: "1h85keViqbRzgTN245gEw5s9roxpaUtT7i-mNXQtT8qQ"
}

use Ecto.Schema

schema "accounts" do
field(:nickname, EctoGSS.Schema.AllAccounts.A)
field(:email, EctoGSS.Schema.AllAccounts.Y)
end
end

test "list names with spaces" do
assert match?({:module, _}, Code.ensure_compiled(EctoGSS.Schema.AllAccounts.A))
end
end

0 comments on commit 4c5c82c

Please sign in to comment.