This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Something like this might make testing simpler | |
def assert_email_delivered(email) do | |
email = email |> Bamboo.Mailer.normalize_addresses | |
assert_received({:delivered_bamboo_email, ^email}) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<head> | |
<!-- you could put a helper in the Layout View but it's probably not necessary --> | |
<%= render_existing(@view_module, "seo." <> @view_template, assigns) || render("default_seo.html") %> | |
</head> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
changeset |> changed?(:status, from: "pending", to: "canceled") | |
changeset |> changed?(:status, from: "attending") # for checking if it changed, but we don't care what it changed to | |
def changed?(changeset, field, from: from, to: to) do | |
Ecto.Changeset.get_field(changeset, field) == from | |
&& booking_changeset.changes[field] == to | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def index(conn, params) do | |
Post | |
|> filter_upcoming(params) | |
|> filter_attributes(params, whitelist: ~w(title body) | |
|> filter_timespan(params) | |
# Or simplify it if it's used in multiple controllers | |
Post |> filter_post_params(params) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"timestamp_with_timezone" | |
|> Timex.DateTime.parse("{ISO}") | |
|> Timex.DateConvert.to_erlang_datetime | |
# You probably don't need this next line for most things in Ecto. | |
# Changesets and queries automatically cast erlang timestamps | |
|> Ecto.DateTime.from_erl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule MyApp.Changeset do | |
def cast(model_or_changeset, :empty, required, optional) do | |
Ecto.Changeset.cast(model_or_changeset, :empty, required, optional) | |
end | |
def cast(model_or_changeset, params, required, optional) do | |
param_keys = params |> Map.keys |> Enum.map(&to_string/1) | |
allowed_params = (required ++ optional) |> Enum.map(&to_string/1) | |
disallowed_params = param_keys -- allowed_params |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
:dbg.tracer | |
:dbg.p :all, :c | |
:dbg.tpl ModuleToTrace, :x |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var bourbonPath = require("bourbon").includePaths[0]; | |
exports.config = { | |
// See http://brunch.io/#documentation for docs. | |
files: { | |
javascripts: { | |
joinTo: "js/app.js" | |
// To use a separate vendor.js bundle, specify two files path | |
// https://github.com/brunch/brunch/blob/stable/docs/config.md#files |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ file -I Makefile | |
Makefile: text/x-makefile; charset=us-ascii |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule MyApp.Factory do | |
def user_factory do | |
%User{ | |
email: "[email protected]", | |
name: "Paul" | |
} | |
end | |
end | |
# Makes it easy to organize factories however you want |