require 'spec_helper' describe "CareProvider", "converting to xml" do before do @care_provider_a = Caren::CareProvider.new( :name => "Zuwe", :telephone => "112", :website => "http://www.zuwe.nl", :email => "zuwe@example.com", :address_line => "Sesamestreet 1", :url_shortcut => "zuwe", :time_zone => "Amsterdam", :resolution => "exact", :bandwidth => "0", :min_start => "07:00", :max_start => "00:00", :show_employee_name_as_title => true, :show_employee_names => true, :communication => true ) @care_provider_b = Caren::CareProvider.new( :name => "Aveant", :telephone => "112", :website => "http://www.aveant.nl", :email => "aveant@example.com", :address_line => "Sesamestreet 1", :url_shortcut => "zuwe", :time_zone => "Amsterdam", :resolution => "exact", :bandwidth => "0", :min_start => "07:00", :max_start => "00:00", :show_employee_name_as_title => true, :show_employee_names => true, :communication => true ) end it "should be able to convert a person to valid xml" do @care_provider_a.should convert_to_valid_caren_xml end it "should be able to convert an array of people to valid xml" do [@care_provider_a,@care_provider_b].should convert_to_valid_caren_array_xml end it "should be able to generate a proper xml file to update the logo" do filename = "spec/fixtures/bacon.jpg" xml = @care_provider_a.to_logo_xml filename doc = REXML::Document.new(xml) doc.elements.each('care_provider/logo') do |cp| cp.attributes["name"].should == "bacon.jpg" cp.attributes["content-type"].should == "image/jpeg" cp.text.should == Base64.encode64(File.open(filename).read) end end end describe "CareProvider" do it "should be able to convert a image file path to a hash suited for xml conversion" do filename = "spec/fixtures/bacon.jpg" logo = Caren::CareProvider.logo_hash( filename ) logo[:content_type].should == "image/jpeg" logo[:name].should == "bacon.jpg" logo[:content].should == Base64.encode64(File.open(filename).read) end end describe "CareProvider", "REST methods" do before do care_providers = File.read("spec/fixtures/caren_care_providers.xml") care_providers_search = File.read("spec/fixtures/caren_care_providers_search.xml") FakeWeb.register_uri(:put, Caren::CareProvider.resource_url(1), :signature => Caren::Api.sign ) FakeWeb.register_uri(:get, Caren::CareProvider.resource_url, :body => care_providers, :signature => Caren::Api.sign(care_providers) ) FakeWeb.register_uri(:get, "#{Caren::CareProvider.resource_url}?key=url-shortcut&value=pantein", :body => care_providers_search, :signature => Caren::Api.sign(care_providers_search) ) end it "should be able to update a care provider" do lambda{ Caren::CareProvider.new( :caren_id => 1, :name => "Test" ).update }.should_not raise_error end it "should be able to update the logo for a care provider" do lambda{ Caren::CareProvider.new( :caren_id => 1 ).update_logo( "spec/fixtures/bacon.jpg" ) }.should_not raise_error end it "should be able to search for a specific care provider" do care_providers = Caren::CareProvider.search :url_shortcut, "pantein" care_providers.should have(1).things care_providers.first.name.should == "Pantein" care_providers.first.url_shortcut.should == "pantein" end it "should be able to find all care providers" do care_providers = Caren::CareProvider.all care_providers.should have(2).things care_providers.first.name.should == "Demo" care_providers.first.url_shortcut.should == "demo" end end