Skip to content

Commit

Permalink
Add approved to projects index
Browse files Browse the repository at this point in the history
  • Loading branch information
joshsmith committed Mar 10, 2017
1 parent 7c89c33 commit d8c6c86
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 12 deletions.
8 changes: 8 additions & 0 deletions lib/code_corps/helpers/query.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ defmodule CodeCorps.Helpers.Query do
query |> where([object], object.id in ^ids)
end

# project queries

def approved_filter(query, approved) do
query |> where([object], object.approved == ^approved)
end

# end project queries

# skill queries

def limit_filter(query, %{"limit" => count}) do
Expand Down
5 changes: 3 additions & 2 deletions test/controllers/project_controller_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ defmodule CodeCorps.ProjectControllerTest do
@invalid_attrs %{title: ""}

describe "index" do
test "lists all entries on index", %{conn: conn} do
[project_1, project_2] = insert_pair(:project)
test "lists all approved entries on index", %{conn: conn} do
[project_1, project_2] = insert_pair(:project, approved: true)
insert(:project, approved: false)

conn
|> request_index
Expand Down
8 changes: 5 additions & 3 deletions test/support/factories.ex
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,13 @@ defmodule CodeCorps.Factories do

def project_factory do
%CodeCorps.Project{
title: sequence(:title, &"Project #{&1}"),
approved: true,
slug: sequence(:slug, &"project-#{&1}"),
title: sequence(:title, &"Project #{&1}"),
website: sequence(:website, &"http://test-#{&1}.com"),

organization: build(:organization),
owner: build(:user),
website: sequence(:website, &"http://test-#{&1}.com")
owner: build(:user)
}
end

Expand Down
3 changes: 2 additions & 1 deletion test/views/project_view_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule CodeCorps.ProjectViewTest do
test "renders all attributes and relationships properly" do
user = insert(:user)
organization = insert(:organization)
project = insert(:project, organization: organization, owner: user, total_monthly_donated: 5000, default_color: "blue")
project = insert(:project, organization: organization, owner: user, total_monthly_donated: 5000, default_color: "blue", approved: true)

donation_goal = insert(:donation_goal, project: project)
project_category = insert(:project_category, project: project)
Expand All @@ -21,6 +21,7 @@ defmodule CodeCorps.ProjectViewTest do
expected_json = %{
"data" => %{
"attributes" => %{
"approved" => true,
"can-activate-donations" => false,
"cloudinary-public-id" => nil,
"description" => project.description,
Expand Down
7 changes: 5 additions & 2 deletions web/controllers/project_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ defmodule CodeCorps.ProjectController do
use CodeCorps.Web, :controller
use JaResource

import CodeCorps.Helpers.Query, only: [slug_finder: 2]
import CodeCorps.Helpers.Query, only: [approved_filter: 2, slug_finder: 2]

alias CodeCorps.Project

Expand All @@ -21,7 +21,10 @@ defmodule CodeCorps.ProjectController do
Project
|> Repo.all(organization_id: slugged_route.organization_id)
end
def handle_index(_conn, _params), do: Project
def handle_index(_conn, _params) do
Project
|> approved_filter(true)
end

def handle_create(_conn, attributes) do
%Project{} |> Project.create_changeset(attributes)
Expand Down
8 changes: 4 additions & 4 deletions web/views/project_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ defmodule CodeCorps.ProjectView do
use JaSerializer.PhoenixView

attributes [
:slug, :title, :can_activate_donations, :cloudinary_public_id,
:approved, :can_activate_donations, :cloudinary_public_id,
:description, :donations_active, :icon_thumb_url,
:icon_large_url, :long_description_body, :long_description_markdown,
:inserted_at, :should_link_externally, :total_monthly_donated, :updated_at,
:website
:icon_large_url, :inserted_at, :long_description_body,
:long_description_markdown, :should_link_externally, :slug, :title,
:total_monthly_donated, :updated_at, :website
]

has_one :organization, serializer: CodeCorps.OrganizationView
Expand Down

0 comments on commit d8c6c86

Please sign in to comment.