Skip to content

Commit 4adedcd

Browse files
committed
Fix project website and remove some unnecessary columns
1 parent d721dc7 commit 4adedcd

File tree

6 files changed

+51
-48
lines changed

6 files changed

+51
-48
lines changed

lib/code_corps/model/project.ex

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ defmodule CodeCorps.Project do
2929
field :title, :string
3030
field :total_monthly_donated, :integer, default: 0
3131
field :website, :string
32-
field :github_repo, :string
33-
field :github_owner, :string
3432

3533
belongs_to :organization, CodeCorps.Organization
3634

@@ -53,7 +51,9 @@ defmodule CodeCorps.Project do
5351

5452
def changeset(struct, params) do
5553
struct
56-
|> cast(params, [:title, :description, :long_description_markdown, :cloudinary_public_id, :default_color])
54+
|> cast(params, [:title, :description, :long_description_markdown, :cloudinary_public_id, :default_color, :website])
55+
|> prefix_url(:website)
56+
|> validate_format(:website, CodeCorps.Helpers.URL.valid_format())
5757
|> validate_required(:title)
5858
|> generate_slug(:title, :slug)
5959
|> validate_slug(:slug)
@@ -83,9 +83,6 @@ defmodule CodeCorps.Project do
8383
def update_changeset(struct, params) do
8484
struct
8585
|> changeset(params)
86-
|> cast(params, [:website])
87-
|> prefix_url(:website)
88-
|> validate_format(:website, CodeCorps.Helpers.URL.valid_format())
8986
end
9087

9188
def update_total_changeset(struct, params) do

lib/code_corps_web/controllers/project_controller.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ defmodule CodeCorpsWeb.ProjectController do
3737
with %Project{} = project <- Project.Query.find(params),
3838
%User{} = current_user <- conn |> Guardian.Plug.current_resource,
3939
{:ok, :authorized} <- current_user |> Policy.authorize(:update, project),
40-
{:ok, %Project{} = project} <- project |> Project.changeset(params) |> Repo.update,
40+
{:ok, %Project{} = project} <- project |> Project.update_changeset(params) |> Repo.update,
4141
project <- preload(project)
4242
do
4343
conn |> render("show.json-api", data: project)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
defmodule CodeCorps.Repo.Migrations.RemoveGithubRepoAndOwnerFromProject do
2+
use Ecto.Migration
3+
4+
def change do
5+
alter table(:projects) do
6+
remove(:github_repo)
7+
remove(:github_owner)
8+
end
9+
end
10+
end

priv/repo/structure.sql

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -779,8 +779,6 @@ CREATE TABLE projects (
779779
default_color character varying(255),
780780
website character varying(255),
781781
should_link_externally boolean DEFAULT false,
782-
github_repo character varying(255),
783-
github_owner character varying(255),
784782
CONSTRAINT set_long_description_markdown_if_approved CHECK (((long_description_markdown IS NOT NULL) OR (approved = false)))
785783
);
786784

@@ -3885,5 +3883,5 @@ ALTER TABLE ONLY users
38853883
-- PostgreSQL database dump complete
38863884
--
38873885

3888-
INSERT INTO "schema_migrations" (version) VALUES (20160723215749), (20160804000000), (20160804001111), (20160805132301), (20160805203929), (20160808143454), (20160809214736), (20160810124357), (20160815125009), (20160815143002), (20160816020347), (20160816034021), (20160817220118), (20160818000944), (20160818132546), (20160820113856), (20160820164905), (20160822002438), (20160822004056), (20160822011624), (20160822020401), (20160822044612), (20160830081224), (20160830224802), (20160911233738), (20160912002705), (20160912145957), (20160918003206), (20160928232404), (20161003185918), (20161019090945), (20161019110737), (20161020144622), (20161021131026), (20161031001615), (20161121005339), (20161121014050), (20161121043941), (20161121045709), (20161122015942), (20161123081114), (20161123150943), (20161124085742), (20161125200620), (20161126045705), (20161127054559), (20161205024856), (20161207112519), (20161209192504), (20161212005641), (20161214005935), (20161215052051), (20161216051447), (20161218005913), (20161219160401), (20161219163909), (20161220141753), (20161221085759), (20161226213600), (20161231063614), (20170102130055), (20170102181053), (20170104113708), (20170104212623), (20170104235423), (20170106013143), (20170115035159), (20170115230549), (20170121014100), (20170131234029), (20170201014901), (20170201025454), (20170201035458), (20170201183258), (20170220032224), (20170224233516), (20170226050552), (20170228085250), (20170308214128), (20170308220713), (20170308222552), (20170313130611), (20170318032449), (20170318082740), (20170324194827), (20170424215355), (20170501225441), (20170505224222), (20170526095401), (20170602000208), (20170622205732), (20170626231059), (20170628092119), (20170628213609), (20170629183404), (20170630140136), (20170706132431), (20170707213648), (20170711122252), (20170717092127), (20170725060612), (20170727052644), (20170731130121), (20170814131722), (20170913114958), (20170921014405), (20170925214512), (20170925230419), (20170926134646), (20170927100300), (20170928234412), (20171003134956), (20171003225853), (20171006063358), (20171006161407), (20171012215106), (20171012221231), (20171016125229), (20171016125516), (20171016223356), (20171016235656), (20171017235433), (20171019191035), (20171025184225), (20171026010933), (20171027061833), (20171028011642), (20171028173508), (20171030182857), (20171031232023), (20171031234356), (20171101023309), (20171104013543), (20171106045740), (20171106050209), (20171106103153), (20171106200036), (20171109231538), (20171110001134), (20171114010851), (20171114033357), (20171114225214), (20171114225713), (20171114232534), (20171115201624), (20171115225358), (20171119004204), (20171121075226), (20171121144138);
3886+
INSERT INTO "schema_migrations" (version) VALUES (20160723215749), (20160804000000), (20160804001111), (20160805132301), (20160805203929), (20160808143454), (20160809214736), (20160810124357), (20160815125009), (20160815143002), (20160816020347), (20160816034021), (20160817220118), (20160818000944), (20160818132546), (20160820113856), (20160820164905), (20160822002438), (20160822004056), (20160822011624), (20160822020401), (20160822044612), (20160830081224), (20160830224802), (20160911233738), (20160912002705), (20160912145957), (20160918003206), (20160928232404), (20161003185918), (20161019090945), (20161019110737), (20161020144622), (20161021131026), (20161031001615), (20161121005339), (20161121014050), (20161121043941), (20161121045709), (20161122015942), (20161123081114), (20161123150943), (20161124085742), (20161125200620), (20161126045705), (20161127054559), (20161205024856), (20161207112519), (20161209192504), (20161212005641), (20161214005935), (20161215052051), (20161216051447), (20161218005913), (20161219160401), (20161219163909), (20161220141753), (20161221085759), (20161226213600), (20161231063614), (20170102130055), (20170102181053), (20170104113708), (20170104212623), (20170104235423), (20170106013143), (20170115035159), (20170115230549), (20170121014100), (20170131234029), (20170201014901), (20170201025454), (20170201035458), (20170201183258), (20170220032224), (20170224233516), (20170226050552), (20170228085250), (20170308214128), (20170308220713), (20170308222552), (20170313130611), (20170318032449), (20170318082740), (20170324194827), (20170424215355), (20170501225441), (20170505224222), (20170526095401), (20170602000208), (20170622205732), (20170626231059), (20170628092119), (20170628213609), (20170629183404), (20170630140136), (20170706132431), (20170707213648), (20170711122252), (20170717092127), (20170725060612), (20170727052644), (20170731130121), (20170814131722), (20170913114958), (20170921014405), (20170925214512), (20170925230419), (20170926134646), (20170927100300), (20170928234412), (20171003134956), (20171003225853), (20171006063358), (20171006161407), (20171012215106), (20171012221231), (20171016125229), (20171016125516), (20171016223356), (20171016235656), (20171017235433), (20171019191035), (20171025184225), (20171026010933), (20171027061833), (20171028011642), (20171028173508), (20171030182857), (20171031232023), (20171031234356), (20171101023309), (20171104013543), (20171106045740), (20171106050209), (20171106103153), (20171106200036), (20171109231538), (20171110001134), (20171114010851), (20171114033357), (20171114225214), (20171114225713), (20171114232534), (20171115201624), (20171115225358), (20171119004204), (20171121075226), (20171121144138), (20171123065902);
38893887

test/lib/code_corps/model/project_test.exs

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,42 @@ defmodule CodeCorps.ProjectTest do
4343
{_, changeset} = Repo.insert(changeset)
4444
assert_error_message(changeset, :slug, "has already been taken")
4545
end
46+
47+
test "requires :website to be in proper format" do
48+
project = %Project{}
49+
attrs = %{website: "bad <> website"}
50+
51+
changeset = Project.changeset(project, attrs)
52+
53+
assert_error_message(changeset, :website, "has invalid format")
54+
end
55+
56+
test "doesn't require :website to be part of the changes" do
57+
project = %Project{}
58+
attrs = %{}
59+
60+
changeset = Project.changeset(project, attrs)
61+
62+
refute Keyword.has_key?(changeset.errors, :website)
63+
end
64+
65+
test "prefixes website with 'http://' if there is no prefix" do
66+
project = %Project{website: "https://first.com"}
67+
attrs = %{website: "example.com"}
68+
69+
changeset = Project.changeset(project, attrs)
70+
71+
assert changeset.changes.website == "http://example.com"
72+
end
73+
74+
test "doesn't make a change to the url when there is no param for it" do
75+
project = %Project{website: "https://first.com"}
76+
attrs = %{}
77+
78+
changeset = Project.changeset(project, attrs)
79+
80+
refute Map.has_key?(changeset.changes, :website)
81+
end
4682
end
4783

4884
describe "create_changeset/3" do
@@ -92,41 +128,5 @@ defmodule CodeCorps.ProjectTest do
92128
changeset = Project.update_changeset(%Project{}, %{organization_id: 1})
93129
assert :error == changeset |> fetch_change(:organization_id)
94130
end
95-
96-
test "requires :website to be in proper format" do
97-
project = %Project{}
98-
attrs = %{website: "bad <> website"}
99-
100-
changeset = Project.update_changeset(project, attrs)
101-
102-
assert_error_message(changeset, :website, "has invalid format")
103-
end
104-
105-
test "doesn't require :website to be part of the changes" do
106-
project = %Project{}
107-
attrs = %{}
108-
109-
changeset = Project.update_changeset(project, attrs)
110-
111-
refute Keyword.has_key?(changeset.errors, :website)
112-
end
113-
114-
test "prefixes website with 'http://' if there is no prefix" do
115-
project = %Project{website: "https://first.com"}
116-
attrs = %{website: "example.com"}
117-
118-
changeset = Project.update_changeset(project, attrs)
119-
120-
assert changeset.changes.website == "http://example.com"
121-
end
122-
123-
test "doesn't make a change to the url when there is no param for it" do
124-
project = %Project{website: "https://first.com"}
125-
attrs = %{}
126-
127-
changeset = Project.update_changeset(project, attrs)
128-
129-
refute Map.has_key?(changeset.changes, :website)
130-
end
131131
end
132132
end

test/support/factories.ex

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,6 @@ defmodule CodeCorps.Factories do
165165
slug: sequence(:slug, &"project-#{&1}"),
166166
title: sequence(:title, &"Project #{&1}"),
167167
website: sequence(:website, &"http://test-#{&1}.com"),
168-
github_repo: nil,
169-
github_owner: nil,
170168

171169
organization: build(:organization)
172170
}

0 commit comments

Comments
 (0)