Skip to content

Commit

Permalink
<< strikes again
Browse files Browse the repository at this point in the history
  • Loading branch information
jcs committed Aug 24, 2012
1 parent c945f29 commit edcee1b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
10 changes: 5 additions & 5 deletions app/models/story.rb
Expand Up @@ -66,8 +66,8 @@ class Story < ActiveRecord::Base
end

def self.find_recent_similar_by_url(url)
urls = [ url ]
urls2 = [ url ]
urls = [ url.to_s ]
urls2 = [ url.to_s ]

# https
urls.each do |u|
Expand All @@ -79,7 +79,7 @@ def self.find_recent_similar_by_url(url)
# trailing slash
urls.each do |u|
urls2.push u.gsub(/\/+\z/, "")
urls2.push (u << "/")
urls2.push (u + "/")
end
urls = urls2.clone

Expand All @@ -91,9 +91,9 @@ def self.find_recent_similar_by_url(url)
urls = urls2.clone

conds = [ "created_at >= ? AND (", (Time.now - 30.days) ]
urls.uniq.each_with_index do |url,x|
urls.uniq.each_with_index do |u,x|
conds[0] << (x == 0 ? "" : " OR ") << "url = ?"
conds.push url
conds.push u
end
conds[0] << ")"

Expand Down
7 changes: 7 additions & 0 deletions spec/models/story_spec.rb
Expand Up @@ -103,4 +103,11 @@
s = Story.make(:title => "The One-second War (What Time Will You Die?) ")
s.title_as_url.should == "the_one-second_war_what_time_will_you_die"
end

it "sets the url properly" do
s = Story.make(:title => "blah")
s.url = "https://factorable.net/"
s.valid?
s.url.should == "https://factorable.net/"
end
end

0 comments on commit edcee1b

Please sign in to comment.