Skip to content

Commit

Permalink
https://github.com/bonfire-networks/bonfire-app/issues/851
Browse files Browse the repository at this point in the history
  • Loading branch information
mayel committed Feb 16, 2024
1 parent 394508b commit 8280937
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 37 deletions.
28 changes: 16 additions & 12 deletions lib/modularity/test_interactive.ex
Original file line number Diff line number Diff line change
Expand Up @@ -244,21 +244,25 @@ defmodule Bonfire.Common.Test.Interactive do
`@tag db_sandbox: false`
"""
def setup_test_repo(tags) do
wrap_test_in_transaction_and_rollback =
Bonfire.Common.Config.get(:sql_sandbox, true) && tags[:db_sandbox] != false
repo = repo()

# if wrap_test_in_transaction_and_rollback,
# do: info("Wrapping tests in DB transactions to be rolled back"),
# else: info("*Not* wrapping tests in DB transactions")
if GenServer.whereis(repo) do
wrap_test_in_transaction_and_rollback =
Bonfire.Common.Config.get(:sql_sandbox, true) && tags[:db_sandbox] != false

:ok =
Ecto.Adapters.SQL.Sandbox.checkout(repo(),
sandbox: wrap_test_in_transaction_and_rollback
)
# if wrap_test_in_transaction_and_rollback,
# do: info("Wrapping tests in DB transactions to be rolled back"),
# else: info("*Not* wrapping tests in DB transactions")

if not wrap_test_in_transaction_and_rollback or !tags[:async] do
info("Running Ecto in shared mode")
Ecto.Adapters.SQL.Sandbox.mode(repo(), {:shared, self()})
:ok =
Ecto.Adapters.SQL.Sandbox.checkout(repo,
sandbox: wrap_test_in_transaction_and_rollback
)

if not wrap_test_in_transaction_and_rollback or !tags[:async] do
info("Running Ecto in shared mode")
Ecto.Adapters.SQL.Sandbox.mode(repo, {:shared, self()})
end
end
end
end
14 changes: 13 additions & 1 deletion lib/repo/repo_template.ex
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,15 @@ defmodule Bonfire.Common.RepoTemplate do
e in DBConnection.ConnectionError ->
error(
e,
"DBConnection.ConnectionError prevented a database query, returning #{inspect(fallback)} as fallback"
"DBConnection.ConnectionError prevented a database query, returning a fallback"
)

fallback

e in RuntimeError ->
error(
e,
"RuntimeError when attempting a database query, returning a fallback"
)

fallback
Expand Down Expand Up @@ -337,6 +345,10 @@ defmodule Bonfire.Common.RepoTemplate do
rescue
exception in Postgrex.Error ->
handle_postgrex_exception(exception, __STACKTRACE__, [])

e in RuntimeError ->
error(e, "Could not fetch list from database")
[]
end

@doc "Execute a query to delete all matching records."
Expand Down
52 changes: 28 additions & 24 deletions lib/text.ex
Original file line number Diff line number Diff line change
Expand Up @@ -170,31 +170,35 @@ defmodule Bonfire.Common.Text do
end

def markdown_as_html_mdex(content, opts) do
[
parse: [
smart: false
],
render: [
hardbreaks: true,
_unsafe: opts[:__unsafe__],
escape: !opts[:__unsafe__]
],
extension: [
strikethrough: true,
tasklist: true,
# can't use because things @ mentions are emails
autolink: false,
table: true,
tagfilter: true,
header_ids: ""
],
features: [
# TODO: auto-set appropriate theme based on user's daisy theme
syntax_highlight_theme: "adwaita_dark"
if module_enabled?(MDEx, opts) do
[
parse: [
smart: false
],
render: [
hardbreaks: true,
_unsafe: opts[:__unsafe__],
escape: !opts[:__unsafe__]
],
extension: [
strikethrough: true,
tasklist: true,
# can't use because things @ mentions are emails
autolink: false,
table: true,
tagfilter: true,
header_ids: ""
],
features: [
# TODO: auto-set appropriate theme based on user's daisy theme
syntax_highlight_theme: "adwaita_dark"
]
]
]
|> Keyword.merge(opts)
|> MDEx.to_html(content, ...)
|> Keyword.merge(opts)
|> MDEx.to_html(content, ...)
else
content
end
end

def markdown_as_html_earmark(content, opts) do
Expand Down

0 comments on commit 8280937

Please sign in to comment.