Permalink
Browse files

Cache url result

  • Loading branch information...
1 parent beb4f99 commit cc4870eae88c394aa1a8ab6515d99062600fe391 @sam-wan sam-wan committed Apr 17, 2008
Showing with 14 additions and 2 deletions.
  1. +7 −2 lib/result.rb
  2. +7 −0 spec/result_spec.rb
View
@@ -11,8 +11,7 @@ def initialize(name, type, display_url)
end
def url
- doc = Hpricot(open(@display_url))
- (doc/'textarea a').first['href']
+ @url ||= get_url
end
def eql?(result)
@@ -25,5 +24,11 @@ def eql?(result)
def hash
"#{@name}#{@type}#{@display_url}".hash
end
+
+ private
+ def get_url
+ doc = Hpricot(open(@display_url))
+ (doc/'textarea a').first['href']
+ end
end
end
View
@@ -66,4 +66,11 @@ def create_result(options={})
r3 = create_result(:name => 'Different')
[r1, r2, r3].uniq.should == [r1, r3]
end
+
+ it "should cache the url" do
+ r = create_result
+ r.should_receive(:open).once.and_return(@open_result)
+ r.url
+ r.url
+ end
end

0 comments on commit cc4870e

Please sign in to comment.