-
-
Save dnch/1499277 to your computer and use it in GitHub Desktop.
WTF!
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
class User | |
include Mongoid::Document | |
field :email | |
validates_format_of :email, :with => /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,6}$/i, :message => "is not a valid email adress." | |
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
# Maybe I'm just old-school, but I prefer this... | |
describe User do | |
it "validates email addresses" do | |
subject.email = '[email protected]' | |
subject.should be_valid | |
subject.email = 'b!o^[email protected]' | |
subject.should_not be_valid | |
# don't forget to check for valid and invalid domains... | |
subject.email = '[email protected]' | |
subject.should be_valid | |
subject.email = 'bot@kimono_app.com' | |
subject.should_not be_valid | |
# and those bastards, leading and trailing whitespace... | |
subject.email = ' [email protected]' | |
subject.should_not be_valid | |
subject.email = '[email protected] ' | |
subject.should_not be_valid | |
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
3) User | |
Failure/Error: it { should validate_format_of(:email).to_allow('[email protected]').not_to_allow('b!o^[email protected]') } | |
Expected User to validate format of "email" allowing the value "[email protected]" and not allowing the value "b!o^[email protected]"; instead got "format" validator on "email" with "b!o^[email protected]" as a valid value | |
# ./spec/models/user_spec.rb:15:in `__script__' | |
# kernel/common/eval18.rb:43:in `instance_eval' | |
# kernel/bootstrap/array18.rb:16:in `map' | |
# kernel/bootstrap/array18.rb:16:in `map' | |
# kernel/loader.rb:686:in `run_at_exits' | |
# kernel/loader.rb:706:in `epilogue' | |
# kernel/loader.rb:837:in `main' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment