[Bugfix] Check for regex errors before saving a source (#296)
* Added error if provided regex is invalid * improved test
This commit is contained in:
@@ -659,6 +659,28 @@ defmodule Pinchflat.SourcesTest do
|
||||
end
|
||||
end
|
||||
|
||||
describe "change_source/3 when testing regex validation" do
|
||||
test "succeeds when a valid regex is provided" do
|
||||
source = source_fixture()
|
||||
|
||||
assert %{errors: []} = Sources.change_source(source, %{title_filter_regex: "(?i)^How to Bike$"})
|
||||
end
|
||||
|
||||
test "succeeds when a regex is set back to nil" do
|
||||
source = source_fixture(%{title_filter_regex: "(?i)^How to Bike$"})
|
||||
|
||||
assert %{errors: []} = Sources.change_source(source, %{title_filter_regex: nil})
|
||||
end
|
||||
|
||||
test "fails when an invalid regex is provided" do
|
||||
source = source_fixture()
|
||||
|
||||
changeset = Sources.change_source(source, %{title_filter_regex: "*FOO"})
|
||||
|
||||
assert "is invalid" in errors_on(changeset).title_filter_regex
|
||||
end
|
||||
end
|
||||
|
||||
describe "change_source/3 when testing original_url validation" do
|
||||
test "succeeds when an original URL is valid" do
|
||||
source = source_fixture()
|
||||
|
||||
Reference in New Issue
Block a user