Permalink
Browse files

Fewer false-positives in requires_openid_auth?

  • Loading branch information...
Andrew Lorente
Andrew Lorente committed Dec 2, 2012
1 parent b3eb4a4 commit 768c144249b92c2a0f008c23681aa5cadcc1beb9
Showing with 8 additions and 3 deletions.
  1. +1 −1 app/models/comment.rb
  2. +7 −2 spec/models/comment_spec.rb
View
@@ -29,7 +29,7 @@ def blank_openid_fields
def requires_openid_authentication?
return false unless author
- !!(author =~ %r{^https?://} || author.index('.'))
+ !!(author =~ %r{^https?://} || author =~ /\w+\.\w+/)
end
def trusted_user?
@@ -42,13 +42,18 @@ def set_comment_attributes(comment, extra = {})
@comment.should be_valid
end
- it "requires OpenID authentication when the author's name contains a period" do
+ it "requires OpenID authentication when the author's name looks like a url" do
@comment.author = "Don Alias"
@comment.requires_openid_authentication?.should == false
@comment.author = "enkiblog.com"
@comment.requires_openid_authentication?.should == true
end
+ it "doesn't require auth just because the author's name contains a dot" do
+ @comment.author = "Dr. Alias"
+ @comment.requires_openid_authentication?.should == false
+ end
+
it "requires OpenID authentication when the author's name starts with http" do
@comment.author = "http://localhost:9294"
@comment.requires_openid_authentication?.should == true
@@ -174,7 +179,7 @@ def set_comment_attributes(comment, extra = {})
end
describe Comment, '#requires_openid_authentication?' do
- describe 'with an author containing a .' do
+ describe 'with an author that looks like a url' do
subject { Comment.new(:author => 'example.com').requires_openid_authentication? }
it { should be }

0 comments on commit 768c144

Please sign in to comment.