Skip to content
This repository has been archived by the owner on Mar 27, 2023. It is now read-only.

Commit

Permalink
Only validate has_link if body/desc is present
Browse files Browse the repository at this point in the history
  • Loading branch information
Vincent Martinez committed Mar 1, 2017
1 parent 5cff047 commit a135db5
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/models/share/email.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Share::Email < ActiveRecord::Base
include Share::Variant

validates :subject, :body, presence: true
validate :has_link
validate :has_link, unless: -> { body.nil? }

def has_link
errors.add(:body, 'does not contain {LINK}') unless body.match?(/\{LINK\}/)
Expand Down
2 changes: 1 addition & 1 deletion app/models/share/twitter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Share::Twitter < ActiveRecord::Base
include Share::Variant

validates :description, presence: true
validate :has_link
validate :has_link, unless: -> { description.nil? }

def has_link
errors.add(:description, 'does not contain {LINK}') unless description.match?(/\{LINK\}/)
Expand Down

0 comments on commit a135db5

Please sign in to comment.