Skip to content

Commit

Permalink
Merge pull request #871 from code-corps/fix-github-app-installations-…
Browse files Browse the repository at this point in the history
…on-user

Fix github-app-installations relationship to be available on user view
  • Loading branch information
begedin committed Aug 30, 2017
2 parents 8f41c86 + d0fe416 commit 392541d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/code_corps_web/views/user_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ defmodule CodeCorpsWeb.UserView do

use CodeCorpsWeb.PreloadHelpers,
default_preloads: [
:project_users, :slugged_route, :stripe_connect_subscriptions,
:stripe_platform_card, :stripe_platform_customer,
:user_categories, :user_roles, :user_skills
:github_app_installations, :project_users, :slugged_route,
:stripe_connect_subscriptions, :stripe_platform_card,
:stripe_platform_customer, :user_categories, :user_roles,
:user_skills
]
use CodeCorpsWeb, :view
use JaSerializer.PhoenixView
Expand All @@ -22,6 +23,7 @@ defmodule CodeCorpsWeb.UserView do
has_one :stripe_platform_card, serializer: CodeCorpsWeb.StripePlatformCardView
has_one :stripe_platform_customer, serializer: CodeCorpsWeb.StripePlatformCustomerView

has_many :github_app_installations, serializer: CodeCorpsWeb.GithubAppInstallationView, identifiers: :always
has_many :project_users, serializer: CodeCorpsWeb.ProjectUserView, identifiers: :always
has_many :stripe_connect_subscriptions, serializer: CodeCorpsWeb.StripeConnectSubscriptionView, identifiers: :always
has_many :user_categories, serializer: CodeCorpsWeb.UserCategoryView, identifiers: :always
Expand Down
6 changes: 6 additions & 0 deletions test/lib/code_corps_web/views/user_view_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ defmodule CodeCorpsWeb.UserViewTest do

test "renders all attributes and relationships properly" do
user = insert(:user, first_name: "First", github_avatar_url: "foo", github_id: 123, github_username: "githubuser", last_name: "Last", default_color: "blue")
github_app_installation = insert(:github_app_installation, user: user)
slugged_route = insert(:slugged_route, user: user)
stripe_connect_subscription = insert(:stripe_connect_subscription, user: user)
stripe_platform_card = insert(:stripe_platform_card, user: user)
Expand Down Expand Up @@ -45,6 +46,11 @@ defmodule CodeCorpsWeb.UserViewTest do
"website" => user.website
},
"relationships" => %{
"github-app-installations" => %{
"data" => [
%{"id" => github_app_installation.id |> Integer.to_string, "type" => "github-app-installation"}
]
},
"project-users" => %{
"data" => [
%{"id" => project_user.id |> Integer.to_string, "type" => "project-user"}
Expand Down

0 comments on commit 392541d

Please sign in to comment.