Skip to content

Commit

Permalink
Remove delete for StripePlatformCard
Browse files Browse the repository at this point in the history
  • Loading branch information
joshsmith committed Nov 22, 2016
1 parent b0025a4 commit 0ffbac5
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 36 deletions.
9 changes: 6 additions & 3 deletions lib/code_corps/stripe/stripe_platform_card.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
defmodule CodeCorps.Stripe.StripePlatformCard do
alias CodeCorps.Stripe.Adapters

@api Application.get_env(:code_corps, :stripe)

def create(%{"stripe_token" => stripe_token, "user_id" => user_id} = attributes) do
Expand All @@ -16,7 +18,8 @@ defmodule CodeCorps.Stripe.StripePlatformCard do
defp handle_response(result, _attributes), do: result

defp get_customer(user_id) do
CodeCorps.StripePlatformCustomer |> CodeCorps.Repo.get_by(user_id: user_id)
CodeCorps.StripePlatformCustomer
|> CodeCorps.Repo.get_by(user_id: user_id)
end

defp create_on_stripe(customer, stripe_token) do
Expand All @@ -25,8 +28,8 @@ defmodule CodeCorps.Stripe.StripePlatformCard do

defp get_attributes_for_insert(%Stripe.Card{} = stripe_card, %{} = attributes) do
stripe_card
|> CodeCorps.Stripe.Adapters.StripePlatformCard.to_params
|> CodeCorps.Stripe.Adapters.StripePlatformCard.add_non_stripe_attributes(attributes)
|> Adapters.StripePlatformCard.to_params
|> Adapters.StripePlatformCard.add_non_stripe_attributes(attributes)
end

defp insert_into_db(%{} = attributes) do
Expand Down
22 changes: 0 additions & 22 deletions test/controllers/stripe_platform_card_controller_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -68,26 +68,4 @@ defmodule CodeCorps.StripePlatformCardControllerTest do
assert conn |> make_create_request |> json_response(403)
end
end

describe "delete" do
@tag :authenticated
test "deletes resource", %{conn: conn, current_user: current_user} do
stripe_platform_card = insert(:stripe_platform_card, user: current_user)
assert conn |> request_delete(stripe_platform_card) |> response(204)
end

test "renders 401 when unauthenticated", %{conn: conn} do
assert conn |> request_delete |> json_response(401)
end

@tag :authenticated
test "403 when not authorized", %{conn: conn} do
assert conn |> request_delete |> json_response(403)
end

@tag :authenticated
test "renders 404 when record not found", %{conn: conn} do
assert conn |> request_delete(:not_found) |> json_response(404)
end
end
end
11 changes: 1 addition & 10 deletions web/controllers/stripe_platform_card_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ defmodule CodeCorps.StripePlatformCardController do

alias CodeCorps.StripePlatformCard

plug :load_and_authorize_resource, model: StripePlatformCard, only: [:show, :delete], preload: [:user]
plug :load_and_authorize_resource, model: StripePlatformCard, only: [:show], preload: [:user]
plug :load_and_authorize_changeset, model: StripePlatformCard, only: [:create]

plug JaResource
Expand All @@ -20,22 +20,13 @@ defmodule CodeCorps.StripePlatformCardController do
|> CodeCorps.Stripe.StripePlatformCard.create
|> handle_create_result(conn)
end

defp handle_create_result({:ok, %StripePlatformCard{}} = result, conn) do
result |> CodeCorps.Analytics.Segment.track(:created, conn)
end

defp handle_create_result({:error, %Stripe.APIError{}}, conn) do
conn
|> put_status(500)
|> render(CodeCorps.ErrorView, "500.json-api")
end

defp handle_create_result({:error, %Ecto.Changeset{} = changeset}, _conn), do: changeset

def handle_delete(conn, record) do
record
|> Repo.delete
|> CodeCorps.Analytics.Segment.track(:deleted, conn)
end
end
2 changes: 1 addition & 1 deletion web/router.ex
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ defmodule CodeCorps.Router do
resources "/role-skills", RoleSkillController, only: [:create, :delete]
resources "/skills", SkillController, only: [:create]
resources "/stripe-connect-accounts", StripeConnectAccountController, only: [:show]
resources "/stripe-platform-cards", StripePlatformCardController, only: [:show, :create, :delete]
resources "/stripe-platform-cards", StripePlatformCardController, only: [:show, :create]
resources "/stripe-platform-customers", StripePlatformCustomerController, only: [:show, :create]
resources "/tasks", TaskController, only: [:create, :update]
resources "/users", UserController, only: [:update]
Expand Down

0 comments on commit 0ffbac5

Please sign in to comment.