require 'spec_helper' describe "Link", "converting to xml" do before do @link_a = Caren::Link.new( :patient_number => "12345" ) @link_b = Caren::Link.new( :patient_number => "67890" ) end it "should be able to convert a link to valid xml" do @link_a.should convert_to_valid_caren_xml end it "should be able to convert an array of links to valid xml" do [@link_a,@link_b].should convert_to_valid_caren_array_xml end end describe "Link", "REST methods" do before do links = File.read("spec/fixtures/caren_links.xml") search = File.read("spec/fixtures/caren_links_search.xml") FakeWeb.register_uri(:get, Caren::Link.resource_url, :body => links, :signature => Caren::Api.sign(links) ) FakeWeb.register_uri(:get, "#{Caren::Link.resource_url}?key=external-id&value=1", :body => search, :signature => Caren::Api.sign(search) ) FakeWeb.register_uri(:post, Caren::Link.resource_url, :status => 201, :signature => Caren::Api.sign ) end it "should be able to create a new link using the API" do lambda{ Caren::Link.new( :patient_number => "12345" ).create }.should_not raise_error end it "should be find all links using the API" do links = Caren::Link.all links.should have(3).things links.first.id.should == 1 links.first.status.should == "confirmed" links.first.external_id.should == "1" links.first.person_name.should == "Andre Foeken" links.first.person_id.should == 3 end it "should be find a specific link using the API" do links = Caren::Link.search(:external_id, 1) links.should have(1).thing end end