require 'spec_helper' describe "Account", "converting to xml" do before do @account_a = Caren::Store::Account.new( :balance => 3600, :person_id => 1, :billable_timeline_id => 1 ) @account_b = Caren::Store::Account.new( :balance => 3600, :person_id => 1, :billable_timeline_id => 2 ) end it "should be able to convert an account to valid xml" do @account_a.should convert_to_valid_caren_xml end it "should be able to convert an array of accounts to valid xml" do [@account_a,@account_b].should convert_to_valid_caren_array_xml end end describe "Account", "REST methods" do before do account = File.read("spec/fixtures/caren_account.xml") accounts = File.read("spec/fixtures/caren_accounts.xml") amount_xml = "900" account_url = Caren::Api.session.url_for( Caren::Store::Account.resource_url(1) ) accounts_url = Caren::Api.session.url_for( Caren::Store::Account.resource_url ) deposit_url = Caren::Api.session.url_for( Caren::Store::Account.new(:id=>1).deposit_credits_url ) withdraw_url = Caren::Api.session.url_for( Caren::Store::Account.new(:id=>1).withdraw_credits_url ) alt_deposit_url = Caren::Api.session.url_for( Caren::Store::Account.new(:person_id => 1, :billable_timeline_id => 1).deposit_credits_url ) alt_withdraw_url = Caren::Api.session.url_for( Caren::Store::Account.new(:person_id => 1, :billable_timeline_id => 1).withdraw_credits_url ) timestamp = DateTime.now.to_i FakeWeb.register_uri(:get, accounts_url, :body => accounts, :timestamp => timestamp, :signature => Caren::Api.session.sign(timestamp,nil,accounts) ) FakeWeb.register_uri(:get, account_url, :body => account, :timestamp => timestamp, :signature => Caren::Api.session.sign(timestamp,nil,account) ) FakeWeb.register_uri(:post, deposit_url, :body => account, :timestamp => timestamp, :signature => Caren::Api.session.sign(timestamp,nil,account) ) FakeWeb.register_uri(:post, withdraw_url, :body => account, :timestamp => timestamp, :signature => Caren::Api.session.sign(timestamp,nil,account) ) FakeWeb.register_uri(:post, alt_deposit_url, :body => account, :timestamp => timestamp, :signature => Caren::Api.session.sign(timestamp,nil,account) ) FakeWeb.register_uri(:post, alt_withdraw_url, :body => account, :timestamp => timestamp, :signature => Caren::Api.session.sign(timestamp,nil,account) ) end it "should be able to deposit credits to a specific account" do account = Caren::Store::Account.new(:id=>1).deposit_credits(900,Caren::Api.session) account.balance.should == 900 end it "should be able to withdraw credits to a specific account" do account = Caren::Store::Account.new(:id=>1).withdraw_credits(900,Caren::Api.session) account.balance.should == 900 end it "should be able to deposit credits to a specific account (ALT)" do account = Caren::Store::Account.new(:person_id => 1, :billable_timeline_id => 1).deposit_credits(900,Caren::Api.session) account.balance.should == 900 end it "should be able to withdraw credits to a specific account (ALT)" do account = Caren::Store::Account.new(:person_id => 1, :billable_timeline_id => 1).withdraw_credits(900,Caren::Api.session) account.balance.should == 900 end it "should be able to find a specific account" do account = Caren::Store::Account.find 1, Caren::Api.session account.balance.should == 900 end it "should be able to find all accounts" do accounts = Caren::Store::Account.all Caren::Api.session accounts.should have(2).things accounts.first.balance.should == 900 end end