Skip to content

Commit

Permalink
Stripe external account model, migration, and test
Browse files Browse the repository at this point in the history
  • Loading branch information
paulsullivanjr authored and joshsmith committed Dec 14, 2016
1 parent ea785e5 commit 7898517
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
defmodule CodeCorps.Repo.Migrations.CreateStripeExternalAccount do
use Ecto.Migration

def change do
create table(:stripe_external_accounts) do
add :id_from_stripe, :string, null: false
add :account_id_from_stripe, :string, null: false
add :account_holder_name, :string
add :account_holder_type, :string
add :bank_name, :string
add :country, :string
add :currency, :string
add :default_for_currency, :string
add :fingerprint, :string
add :last4, :string
add :routing_number, :string
add :status, :string

timestamps()
end

end
end
18 changes: 18 additions & 0 deletions test/models/stripe_external_account_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
defmodule CodeCorps.StripeExternalAccountTest do
use CodeCorps.ModelCase

alias CodeCorps.StripeExternalAccount

@valid_attrs %{account_id_from_stripe: "some content", id_from_stripe: "some content"}
@invalid_attrs %{}

test "changeset with valid attributes" do
changeset = StripeExternalAccount.changeset(%StripeExternalAccount{}, @valid_attrs)
assert changeset.valid?
end

test "changeset with invalid attributes" do
changeset = StripeExternalAccount.changeset(%StripeExternalAccount{}, @invalid_attrs)
refute changeset.valid?
end
end
29 changes: 29 additions & 0 deletions web/models/stripe_external_account.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
defmodule CodeCorps.StripeExternalAccount do
use CodeCorps.Web, :model

schema "stripe_external_accounts" do
field :id_from_stripe, :string, null: false
field :account_id_from_stripe, :string, null: false
field :account_holder_name, :string
field :account_holder_type, :string
field :bank_name, :string
field :country, :string
field :currency, :string
field :default_for_currency, :string
field :fingerprint, :string
field :last4, :string
field :routing_number, :string
field :status, :string

timestamps()
end

@doc """
Builds a changeset based on the `struct` and `params`.
"""
def changeset(struct, params \\ %{}) do
struct
|> cast(params, [:id_from_stripe, :account_id_from_stripe, :account_holder_name, :account_holder_type, :bank_name, :country, :currency, :default_for_currency, :fingerprint, :last4, :routing_number, :status])
|> validate_required([:id_from_stripe, :account_id_from_stripe])
end
end

0 comments on commit 7898517

Please sign in to comment.