Skip to content

Commit bd81623

Browse files
committed
fix pre elixir 1.6 error with missing Code.format_string!
1 parent d659989 commit bd81623

File tree

3 files changed

+40
-23
lines changed

3 files changed

+40
-23
lines changed

lib/mix/mix_utils.ex

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,4 +125,12 @@ defmodule Coherence.Mix.Utils do
125125
authenticatable: "session_controller.ex",
126126
unlockable_with_token: "unlock_controller.ex"
127127
]
128+
129+
def format_string!(string) do
130+
if function_exported?(Code, :format_string!, 1) do
131+
Code.format_string!(string)
132+
else
133+
string
134+
end
135+
end
128136
end

lib/mix/tasks/coh.install.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ defmodule Mix.Tasks.Coh.Install do
346346

347347
if confirmed do
348348
# File.write!(@config_file, source <> "\n" <> string)
349-
File.write!(@config_file, Code.format_string!(source <> "\n" <> string))
349+
File.write!(@config_file, format_string!(source <> "\n" <> string))
350350
shell_info(config, "Your config/config.exs file was updated.")
351351
false
352352
else

test/mix/tasks/coh.install_test.exs

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -30,32 +30,41 @@ defmodule Mix.Tasks.Coh.InstallTest do
3030
~w(--emails --repo=TestCoherence.Repo --log-only --no-migrations --module=TestCoherence)
3131
|> Mix.Tasks.Coh.Install.run()
3232

33-
assert_file("config/config.exs", [
34-
"config :coherence,",
35-
"user_schema: TestCoherence.Coherence.User,",
36-
"repo: TestCoherence.Repo,",
37-
"module: TestCoherence",
38-
"router: TestCoherenceWeb.Router",
39-
"web_module: TestCoherenceWeb",
40-
"messages_backend: TestCoherenceWeb.Coherence.Messages,",
41-
"opts: [:authenticatable]"
42-
])
33+
assert_file("config/config.exs", fn file ->
34+
expected =
35+
[
36+
"config :coherence,",
37+
"user_schema: TestCoherence.Coherence.User,",
38+
"repo: TestCoherence.Repo,",
39+
"module: TestCoherence",
40+
"router: TestCoherenceWeb.Router",
41+
"web_module: TestCoherenceWeb",
42+
"messages_backend: TestCoherenceWeb.Coherence.Messages,",
43+
"opts: [:authenticatable]"
44+
]
45+
|> Enum.join("")
46+
47+
String.replace(file, "\n", "") =~ expected
48+
end)
4349

44-
assert_file("config/config.exs", [
45-
"registration_permitted_attributes: [\n \"email\",\n \"name\",\n \"password\",\n \"current_password\",\n \"password_confirmation\"\n ],\n"
46-
])
50+
assert_file("config/config.exs", fn file ->
51+
String.replace(file, "\n\s+", "") =~
52+
~s(registration_permitted_attributes: ["email","name","password","current_password","password_confirmation"])
53+
end)
4754

48-
assert_file("config/config.exs", [
49-
"invitation_permitted_attributes: [\"name\", \"email\"],\n"
50-
])
55+
assert_file("config/config.exs", fn file ->
56+
String.replace(file, "\n\s+", "") =~ ~s(invitation_permitted_attributes: ["name","email"])
57+
end)
5158

52-
assert_file("config/config.exs", [
53-
"password_reset_permitted_attributes: [\n \"reset_password_token\",\n \"password\",\n \"password_confirmation\"\n ],\n"
54-
])
59+
assert_file("config/config.exs", fn file ->
60+
String.replace(file, "\n\s+", "") =~
61+
~s(password_reset_permitted_attributes: ["reset_password_token","password","password_confirmation"])
62+
end)
5563

56-
assert_file("config/config.exs", [
57-
"session_permitted_attributes: [\"remember\", \"email\", \"password\"],"
58-
])
64+
assert_file("config/config.exs", fn file ->
65+
String.replace(file, "\n\s+", "") =~
66+
~s(session_permitted_attributes: ["remember","email","password"])
67+
end)
5968
end)
6069
end
6170

0 commit comments

Comments
 (0)