require 'spec_helper' describe "ProductCategory", "converting to xml" do before do @product_category_a = Caren::ProductCategory.new( :name => "Services" ) @product_category_b = Caren::ProductCategory.new( :name => "Products" ) end it "should be able to convert a product to valid xml" do @product_category_a.should convert_to_valid_caren_xml end it "should be able to convert an array of products to valid xml" do [@product_category_a,@product_category_b].should convert_to_valid_caren_array_xml end end describe "ProductCategory", "REST methods" do before do product_category = File.read("spec/fixtures/caren_product_category.xml") product_categories = File.read("spec/fixtures/caren_product_categories.xml") product_categories_search = File.read("spec/fixtures/caren_product_categories_search.xml") product_category_url = Caren::Api.session.url_for( Caren::ProductCategory.resource_url(1) ) product_categories_url = Caren::Api.session.url_for( Caren::ProductCategory.resource_url ) search_url = Caren::Api.session.url_for( "#{Caren::ProductCategory.resource_url}?key=name&value=products" ) timestamp = DateTime.now.to_i FakeWeb.register_uri(:get, product_categories_url, :body => product_categories, :timestamp => timestamp, :signature => Caren::Api.session.sign(timestamp,nil,product_categories) ) FakeWeb.register_uri(:get, product_category_url, :body => product_category, :timestamp => timestamp, :signature => Caren::Api.session.sign(timestamp,nil,product_category) ) FakeWeb.register_uri(:get, search_url, :body => product_categories_search, :timestamp => timestamp, :signature => Caren::Api.session.sign(timestamp,nil,product_categories_search) ) end it "should be able to search for a specific product category" do product_categories = Caren::ProductCategory.search :name, "products", Caren::Api.session product_categories.should have(1).things product_categories.first.name.should == "products" end it "should be able to find a product category" do product_category = Caren::ProductCategory.find 1, Caren::Api.session product_category.name.should == "Products" end it "should be able to find all product category" do product_categories = Caren::ProductCategory.all Caren::Api.session product_categories.should have(2).things product_categories.first.name.should == "Products" end end