Permalink
Browse files

Merge pull request #69 from AndrewLorente/fewer-false-positives

Fewer false-positives in requires_openid_auth?
  • Loading branch information...
2 parents b3eb4a4 + 768c144 commit 21737938da0ac72033d410f0bbca8aa1e3e8318a @xaviershay committed Dec 2, 2012
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 2173793

Please sign in to comment.