Permalink
Browse files

Adding Custodian::Tag.count

  • Loading branch information...
infovore committed Mar 6, 2009
1 parent 34ea63f commit 5bdce2faacb8403f93d7bea9218f2bb4921ebc0c
Showing with 21 additions and 0 deletions.
  1. +10 −0 lib/custodian/tag_class.rb
  2. +11 −0 spec/tag_spec.rb
View
@@ -1,6 +1,12 @@
module Custodian
class Tag
require 'hpricot'
+
+ def self.count(conditions)
+ conditions = normalise_conditions(conditions)
+ xml = request('/content/tags', conditions)
+ count_tags(xml)
+ end
def self.find(type, conditions={})
if type == :all
@@ -18,6 +24,10 @@ def self.find_tags_by_conditions(conditions={})
def self.extract_tags(xml)
Hpricot(xml).search('//tags/tag').collect{|r| Tag.new(r)}
end
+
+ def self.count_tags(xml)
+ Hpricot(xml).search("/tags").first.attributes["count"].to_i
+ end
private
View
@@ -19,6 +19,17 @@
end
end
+describe "Counting results for a particular query" do
+ before(:each) do
+ @search = Custodian::Tag.extract_tags(File.open(File.dirname(__FILE__) + '/tags.xml'))
+ Custodian::Tag.stub!(:count_tags).and_return(Hpricot(File.open(File.dirname(__FILE__) + '/tags.xml')).search("/tags").first.attributes["count"].to_i)
+ end
+
+ it "should return the total number of available results for a query" do
+ Custodian::Tag.count_tags(:q => "uk").should == 13
+ end
+end
+
describe "A tag" do
before(:each) do
@tag = Custodian::Tag.new(Hpricot(File.open(File.dirname(__FILE__) + '/tag.xml')))

0 comments on commit 5bdce2f

Please sign in to comment.