Skip to content

Commit

Permalink
Adding count_results to Custodian::Article
Browse files Browse the repository at this point in the history
  • Loading branch information
infovore committed Mar 6, 2009
1 parent 7f8c77c commit 7179a7a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lib/custodian/article_class.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
module Custodian
class Article
require 'hpricot'


def self.count(conditions)
conditions = normalise_conditions(conditions)
count_results(request('/content/search', conditions))
end

def self.find(type, conditions={})
if type.class == Fixnum
find_article_by_id(type)
Expand Down Expand Up @@ -31,6 +36,10 @@ def self.extract_articles(xml)
def self.extract_article(xml)
Article.new(Hpricot(xml).search("/content").first)
end

def self.count_results(xml)
Hpricot(xml).search("/search").first.attributes["count"].to_i
end

private

Expand Down
11 changes: 11 additions & 0 deletions spec/article_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,17 @@
end
end

describe "Counting results for a particular query" do
before(:each) do
Custodian::Article.stub!(:count_tags).and_return(Hpricot(File.open(File.dirname(__FILE__) + '/search.xml')).search("/search").first.attributes["count"].to_i)
end

it "should return the total number of available results for a query" do
Custodian::Article.count_tags(:q => "uk").should == 1007029
end
end


describe "An article" do
before(:each) do
@article = Custodian::Article.new(Hpricot(File.open(File.dirname(__FILE__) + '/article.xml')))
Expand Down

0 comments on commit 7179a7a

Please sign in to comment.