Application.put_env(:sample, Sample.Repo, database: "oban_dev")
Application.put_env(:phoenix, :json_library, Jason)
Application.put_env(:sample, Sample.Endpoint,
http: [ip: {127, 0, 0, 1}, port: 5001],
server: true,
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.Checks.UnverifiedMocks do | |
@moduledoc """ | |
#{__MODULE__} looks for test files that import Mox and use | |
the `expect/4` function, but do not enforce any assertions that | |
the expectations have been called or not either by running `verify_on_exit` | |
from a setup block or calling `verify!/0` or `verify!/1` inline | |
in a test block. | |
""" | |
@message """ |
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 AsyncAssigns do | |
import Phoenix.LiveView, only: [connected?: 1, assign: 2, assign: 3] | |
@doc """ | |
Provides ability to assign default values to the socket, and kick off a | |
process that will send a message to the LiveView. The message payload will | |
be assigned as specified. | |
## Usage | |
Add the following lines to a specific LiveView, or to the web module |
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
Mix.install([ | |
{:dagger, "~> 0.9.4"} | |
]) | |
defmodule Ci do | |
alias Dagger.{Client, Container, Directory, Host} | |
@workdir "/app" | |
# TODO: change to your release name. | |
@release "hello_world_dagger" |
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.DefStructTest do | |
use ExUnit.Case, async: true | |
test "to cover defstruct" do | |
project_structs() | |
|> Enum.each(&assert &1.__struct__(), to_string(&1)) | |
end | |
defp project_structs do | |
{:ok, modules} = :application.get_key(:my_app, :modules) # change to your app's name |
I recently wanted to rename a model and its postgres table in a Phoenix app. Renaming the table was simple and documented, but the table also had constraints, sequences, and indexes that needed to be updated in order for the Ecto model to be able to rely on default naming conventions. I couldn't find any examples of what this would look like but was eventually able to figure it out. For anyone else in the same situation, hopefully this example helps.
In the example below, I'm renaming the Permission
model to Membership
. This model belongs to a User
and an Account
, so it has foreign key constraints that need to be renamed.
defmodule MyApp.Repo.Migrations.RenamePermissionsToMemberships do
use Ecto.Migration
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
MIT License | |
Copyright (c) 2018 Noel Bundick | |
Permission is hereby granted, free of charge, to any person obtaining a copy | |
of this software and associated documentation files (the "Software"), to deal | |
in the Software without restriction, including without limitation the rights | |
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
copies of the Software, and to permit persons to whom the Software is | |
furnished to do so, subject to the following conditions: |
- Error
DEPRECATION WARNING: The success? predicate is deprecated and will be removed in Rails 6.0. Please use successful?
- Sample code
# deprecated
expect(response).to be_success
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 DateTimeGenerators do | |
use ExUnitProperties | |
@time_zones ["Etc/UTC"] | |
def date do | |
gen all year <- integer(1970..2050), | |
month <- integer(1..12), | |
day <- integer(1..31), | |
match?({:ok, _}, Date.from_erl({year, month, day})) do |
NewerOlder