-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #390 from dgmstuart/dgms/validation-of-one-offs
Validations: handle one-offs
- Loading branch information
Showing
6 changed files
with
170 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
spec/support/shared_examples/validates_no_one_off_workshops.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# frozen_string_literal: true | ||
|
||
RSpec.shared_examples "validates no one off workshops" do |model_name| | ||
include ActiveSupport::Testing::TimeHelpers | ||
|
||
before { travel_to Date.parse("2010-01-01") } | ||
|
||
it "is invalid for classes happening on just one date" do | ||
model = build(model_name, event_type: "weekly_class", first_date: "2011-11-01", last_date: "2011-11-01") | ||
|
||
model.valid? | ||
expect(model.errors.messages).to eq(base: ["It looks like you're trying to list a one-off workshop"]) | ||
end | ||
|
||
it "is valid with a valid http url" do | ||
model = build(model_name, url: "http://foo.com") | ||
|
||
expect(model).to be_valid | ||
end | ||
|
||
it "is invalid with url missing a scheme" do | ||
model = build(model_name, url: "www.foo.com") | ||
model.valid? | ||
expect(model.errors.messages).to eq(url: ["is not a valid URI"]) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters