Skip to content

Commit 6581a21

Browse files
committed
Add validation inclusion for sync states
1 parent ec5f89e commit 6581a21

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

lib/code_corps/model/github_repo.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ defmodule CodeCorps.GithubRepo do
4545
|> validate_inclusion(:sync_state, sync_states())
4646
end
4747

48-
defp sync_states do
48+
def sync_states do
4949
~w{
5050
unsynced
5151
fetching_pull_requests errored_fetching_pull_requests

test/lib/code_corps/model/github_repo_test.exs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,23 @@ defmodule CodeCorps.GithubRepoTest do
2525
end
2626
end
2727

28+
describe "update_sync_changeset/2" do
29+
test "with valid attributes" do
30+
GithubRepo.sync_states |> Enum.each(fn state ->
31+
attrs = @valid_attrs |> Map.put(:sync_state, state)
32+
changeset = GithubRepo.update_sync_changeset(%GithubRepo{}, attrs)
33+
assert changeset.valid?
34+
end)
35+
end
36+
37+
test "with invalid attributes" do
38+
attrs = @valid_attrs |> Map.put(:sync_state, "not_a_valid_sync_state")
39+
changeset = GithubRepo.update_sync_changeset(%GithubRepo{}, attrs)
40+
refute changeset.valid?
41+
assert changeset.errors[:sync_state] == {"is invalid", [validation: :inclusion]}
42+
end
43+
end
44+
2845
test "deletes associated ProjectGithubRepo records when deleting GithubRepo" do
2946
github_repo = insert(:github_repo)
3047
insert_pair(:project_github_repo, github_repo: github_repo)

0 commit comments

Comments
 (0)