Skip to content

Commit

Permalink
Merge pull request #495 from code-corps/261-add-donations-active-to-p…
Browse files Browse the repository at this point in the history
…rojects

Add donations_active to project views
  • Loading branch information
joshsmith committed Nov 27, 2016
2 parents 14d5b67 + c65271b commit 5c9a524
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
28 changes: 28 additions & 0 deletions test/views/project_view_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ defmodule CodeCorps.ProjectViewTest do
"data" => %{
"attributes" => %{
"description" => project.description,
"donations-active" => true,
"icon-large-url" => CodeCorps.ProjectIcon.url({project.icon, project}, :large),
"icon-thumb-url" => CodeCorps.ProjectIcon.url({project.icon, project}, :thumb),
"inserted-at" => project.inserted_at,
Expand Down Expand Up @@ -83,4 +84,31 @@ defmodule CodeCorps.ProjectViewTest do

assert rendered_json == expected_json
end

test "renders donations-active true when project has donations and a plan" do
project = insert(:project)
insert(:donation_goal, project: project)
insert(:stripe_connect_plan, project: project)

conn = Phoenix.ConnTest.build_conn
rendered_json = render(CodeCorps.ProjectView, "show.json-api", data: project, conn: conn)
assert rendered_json["data"]["attributes"]["donations-active"] == true
end

test "renders donations-active false when project has donations and no plan" do
project = insert(:project)
insert(:donation_goal, project: project)

conn = Phoenix.ConnTest.build_conn
rendered_json = render(CodeCorps.ProjectView, "show.json-api", data: project, conn: conn)
assert rendered_json["data"]["attributes"]["donations-active"] == false
end

test "renders donations-active false when project has no donations and no plan" do
project = insert(:project)

conn = Phoenix.ConnTest.build_conn
rendered_json = render(CodeCorps.ProjectView, "show.json-api", data: project, conn: conn)
assert rendered_json["data"]["attributes"]["donations-active"] == false
end
end
8 changes: 6 additions & 2 deletions web/views/project_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ defmodule CodeCorps.ProjectView do
use JaSerializer.PhoenixView

attributes [
:slug, :title, :description, :icon_thumb_url, :icon_large_url,
:long_description_body, :long_description_markdown,
:slug, :title, :description, :donations_active, :icon_thumb_url,
:icon_large_url, :long_description_body, :long_description_markdown,
:inserted_at, :total_monthly_donated, :updated_at]

has_one :organization, serializer: CodeCorps.OrganizationView
Expand All @@ -20,6 +20,10 @@ defmodule CodeCorps.ProjectView do
has_many :project_skills, serializer: CodeCorps.ProjectSkillView, identifiers: :always
has_many :tasks, serializer: CodeCorps.TaskView, identifiers: :always

def donations_active(project, _conn) do
Enum.any?(project.donation_goals) && project.stripe_connect_plan != nil
end

def icon_large_url(project, _conn) do
CodeCorps.ProjectIcon.url({project.icon, project}, :large)
end
Expand Down

0 comments on commit 5c9a524

Please sign in to comment.