Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added tests for InvoiceItem, Invoices, Timeslips, Tasks

  • Loading branch information...
commit f53d1d09e1e67fe4704a19f74fc1f4587d8ebc5f 1 parent 33689f5
@aaronrussell authored
View
114 lib/freeagent_api.rb
@@ -46,7 +46,7 @@ class TaxTimeline < Base
# :first_name
# :last_name
#
- # contact = Contact.new :first_name => 'Joe', :last_name => 'Bloggs'
+ # contact = Contact.new params
# contact.save
#
# Update contact
@@ -98,107 +98,59 @@ class Contact < Base
class Project < Base
def invoices
- Invoice.find :all, :params => {:project_id => id}
+ Invoice.find :all, :from => "/projects/#{id}/invoices.xml"
end
-
- def tasks
- Task.find :all, :params => {:project_id => id}
- end
-
+
def timeslips
- Timeslip.find :all, :params => {:project_id => id}
+ Timeslip.find :all, :from => "/projects/#{id}/timeslips.xml"
end
end
- # Find invoices
- #
- # Invoice.find :all, :params => {:project_id => project_id}
- # Invoice.find task_id
- #
- #TODO Create invoice
- #
- #TODO Update invoice
- #
- #TODO Delete project
- #
- ##TODO add Change status methods
- # /invoices/invoice_id/mark_as_draft
- # /invoices/invoice_id/mark_as_sent
- # /invoices/invoice_id/mark_as_cancelled
-
+ # Tasks - Complete
+
+ class Task < Base
+ self.prefix = '/projects/:project_id/'
+ end
+
+ # Invoices - Complete
class Invoice < Base
- self.prefix = '/projects/:project_id/'
+
+ def mark_as_draft
+ connection.put("/invoices/#{id}/mark_as_draft.xml", encode, self.class.headers).tap do |response|
+ load_attributes_from_response(response)
+ end
+ end
+ def mark_as_sent
+ connection.put("/invoices/#{id}/mark_as_sent.xml", encode, self.class.headers).tap do |response|
+ load_attributes_from_response(response)
+ end
+ end
+ def mark_as_cancelled
+ connection.put("/invoices/#{id}/mark_as_cancelled.xml", encode, self.class.headers).tap do |response|
+ load_attributes_from_response(response)
+ end
+ end
+
end
- # Find invoice items
- #
- # InvoiceItem.find :all, :params => {:invoice_id => invoice_id}
- # InvoiceItem.find invoice_item_id, :params => {:invoice_id => invoice_id}
- #
- #TODO Create invoice item
- #
+ # Invoice items - Complete
class InvoiceItem < Base
self.prefix = '/invoices/:invoice_id/'
end
+
+ # Timeslips
- # Find tasks
- #
- # Task.find :all
- # Task.find :all, :params => {:project_id => project_id}
- # Task.find task_id
- #
- #TODO Create task
- #
- #TODO Update task
- #
- #TODO Delete project
- #
-
- class Task < Base
-
- self.prefix = '/projects/:project_id/'
+ class Timeslip < Base
# def self.find(*args)
-# opts = args.slice!(1) || {}
+# opts = args.slice(1) || {}
# self.prefix = "/projects/#{opts[:params][:project_id]}/" if opts[:params] && opts[:params][:project_id]
# super
# end
-
- end
-
- # Find timeslips
- #
- # Timeslip.find :all, :params => {:view => '2009-01-01_2009-10-01'}
- # Timeslip.find :all, :params => {:project_id => project_id}
- # Timeslip.find :timeslip_id
-
-
- class Timeslip < Base
- def self.find(*args)
- opts = args.slice!(1) || {}
- self.prefix = "/projects/#{opts[:params][:project_id]}/" if opts[:params] && opts[:params][:project_id]
- super
- end
-
- end
-
- ####################################################################################
-
-
- class ActiveResource::Connection
- def http
- http = Net::HTTP.new(@site.host, @site.port)
- http.use_ssl = @site.is_a?(URI::HTTPS)
- http.verify_mode = OpenSSL::SSL::VERIFY_NONE if http.use_ssl
- http.read_timeout = @timeout if @timeout
- #Here's the addition that allows you to see the output
- http.set_debug_output $stderr
- return http
- end
end
end
View
4 test/contact_test.rb
@@ -52,10 +52,10 @@ class ContactTest < Test::Unit::TestCase
:first_name => 'Fred',
:last_name => 'Bloggs'
}
- @new_contact = Contact.new params
+ @contact = Contact.new params
end
should "validate and save" do
- assert @new_contact.save_with_validation
+ assert @contact.save_with_validation
end
end
View
66 test/invoice_item_test.rb
@@ -0,0 +1,66 @@
+require 'test_helper'
+
+class InvoiceItemTest < Test::Unit::TestCase
+
+ fake_it_all
+
+ context "InvoiceItem class" do
+ should "has correct collection path" do
+ assert_equal '/invoices/1000/invoice_items.xml', InvoiceItem.collection_path(:invoice_id => 1000)
+ end
+ should "has correct element path" do
+ assert_equal '/invoices/1000/invoice_items/first.xml', InvoiceItem.element_path(:first, :invoice_id => 1000)
+ assert_equal '/invoices/1000/invoice_items/1.xml', InvoiceItem.element_path(1, :invoice_id => 1000)
+ end
+ end
+
+ context "Invoice Items" do
+ setup do
+ @invoice_items = InvoiceItem.find :all, :params => {:invoice_id => 73867}
+ end
+ should "return an array" do
+ assert @invoice_items.is_a? Array
+ end
+ should "return Invoices" do
+ assert_equal 3, @invoice_items.size
+ assert @invoice_items.first.is_a? InvoiceItem
+ end
+ end
+
+ context "Invoice Item" do
+ setup do
+ @invoice_item = InvoiceItem.find 169399, :params => {:invoice_id => 73867}
+ end
+ should "return a Invoice Item" do
+ assert @invoice_item.is_a? InvoiceItem
+ end
+ should "update and save" do
+ @invoice_item.description = 'Create wireframe templates'
+ assert @invoice_item.save
+ end
+ should "be destroyed" do
+ assert @invoice_item.destroy
+ end
+ end
+
+ #TODO - Add test for invalid resource
+ # Need support from fakeweb in order to achieve this
+
+ context "New Invoice Item" do
+ setup do
+ params = {
+ :item_type => 'Hours',
+ :description => 'Create wireframe templates',
+ :quantity => '12',
+ :price => '50',
+ :sales_tax_rate => '15',
+ :invoice_id => '73867'
+ }
+ @invoice_item = InvoiceItem.new params
+ end
+ should "validate and save" do
+ assert @invoice_item.save_with_validation
+ end
+ end
+
+end
View
92 test/invoice_test.rb
@@ -6,57 +6,65 @@ class InvoiceTest < Test::Unit::TestCase
context "Invoice class" do
should "has correct collection path" do
- assert_equal '/projects/1000/invoices.xml', Invoice.collection_path(:project_id => 1000)
+ assert_equal '/invoices.xml', Invoice.collection_path
end
should "has correct element path" do
- assert_equal '/projects/1000/invoices/first.xml', Invoice.element_path(:first, :project_id => 1000)
- assert_equal '/projects/1000/invoices/1.xml', Invoice.element_path(1, :project_id => 1000)
+ assert_equal '/invoices/first.xml', Invoice.element_path(:first)
+ assert_equal '/invoices/1.xml', Invoice.element_path(1)
end
end
-# context "Contacts" do
-# setup do
-# @contacts = Contact.find :all
-# end
-# should "return an array" do
-# assert @contacts.is_a? Array
-# end
-# should "return Contacts" do
-# assert_equal 16, @contacts.size
-# assert @contacts.first.is_a? Contact
-# end
-# end
+ context "Invoices" do
+ setup do
+ @invoices = Invoice.find :all
+ end
+ should "return an array" do
+ assert @invoices.is_a? Array
+ end
+ should "return Invoices" do
+ assert_equal 7, @invoices.size
+ assert @invoices.first.is_a? Invoice
+ end
+ end
-# context "Contact" do
-# setup do
-# @contact = Contact.find 27309
-# end
-# should "return a Contact" do
-# assert @contact.is_a? Contact
-# end
-# should "update and save" do
-# @contact.last_name = 'Roberts'
-# assert @contact.save
-# end
-# should "be destroyed" do
-# assert @contact.destroy
-# end
-# end
+ context "Invoice" do
+ setup do
+ @invoice = Invoice.find 73867
+ end
+ should "return a Invoice" do
+ assert @invoice.is_a? Invoice
+ end
+ should "update and save" do
+ @invoice.last_name = 'Roberts'
+ assert @invoice.save
+ end
+ should "be destroyed" do
+ assert @invoice.destroy
+ end
+ should "change status" do
+ assert @invoice.mark_as_draft
+ assert @invoice.mark_as_sent
+ assert @invoice.mark_as_cancelled
+ end
+ end
#TODO - Add test for invalid resource
# Need support from fakeweb in order to achieve this
-# context "New Contact" do
-# setup do
-# params = {
-# :first_name => 'Fred',
-# :last_name => 'Bloggs'
-# }
-# @new_contact = Contact.new params
-# end
-# should "validate and save" do
-# assert @new_contact.save_with_validation
-# end
-# end
+ context "New Invoice" do
+ setup do
+ params = {
+ :contact_id => '29899',
+ :project_id => '21445',
+ :dated_on => '2009-10-26T00:00:00Z',
+ :reference => 'INV100',
+ :status => 'Draft'
+ }
+ @invoice = Invoice.new params
+ end
+ should "validate and save" do
+ assert @invoice.save_with_validation
+ end
+ end
end
View
39 test/project_test.rb
@@ -63,5 +63,44 @@ class ProjectTest < Test::Unit::TestCase
end
end
+ context "Nested Invoices" do
+ setup do
+ @project = Project.find 17820
+ @invoices = @project.invoices
+ @invoice = @invoices.first
+ end
+ should "be Invoices" do
+ assert @invoices.is_a? Array
+ assert_equal 1, @invoices.size
+ assert @invoices.first.is_a? Invoice
+ end
+ should "be updateable" do
+ @invoice.comments = "This is a test comment"
+ assert @invoice.save
+ end
+ should "be deletable" do
+ assert @invoice.destroy
+ end
+ end
+
+ context "Nested Timeslips" do
+ setup do
+ @project = Project.find 17820
+ @timeslips = @project.timeslips
+ @timeslip = @timeslips.first
+ end
+ should "be Timeslips" do
+ assert @timeslips.is_a? Array
+ assert_equal 24, @timeslips.size
+ assert @timeslips.first.is_a? Timeslip
+ end
+ should "be updateable" do
+ @timeslip.hours = '1'
+ assert @timeslip.save
+ end
+ should "be deletable" do
+ assert @timeslip.destroy
+ end
+ end
end
View
40 test/stubs/invoice_items/find_all
@@ -0,0 +1,40 @@
+HTTP/1.1 200 OK
+Status: 200
+Content-Type: application/xml; charset=utf-8
+
+<?xml version="1.0" encoding="UTF-8"?>
+<invoice-items type="array">
+ <invoice-item>
+ <description>Email build, testing and delivery.</description>
+ <id type="integer">168981</id>
+ <invoice-id type="integer">73867</invoice-id>
+ <item-type>Hours</item-type>
+ <price type="decimal">35.0</price>
+ <project-id type="integer" nil="true"></project-id>
+ <quantity type="decimal">6.0</quantity>
+ <sales-tax-rate type="decimal">15.0</sales-tax-rate>
+ <second-sales-tax-rate type="decimal">0.0</second-sales-tax-rate>
+ </invoice-item>
+ <invoice-item>
+ <description>1/2 day training session.</description>
+ <id type="integer">169399</id>
+ <invoice-id type="integer">73867</invoice-id>
+ <item-type>Training</item-type>
+ <price type="decimal">350.0</price>
+ <project-id type="integer" nil="true"></project-id>
+ <quantity type="decimal">1.0</quantity>
+ <sales-tax-rate type="decimal">15.0</sales-tax-rate>
+ <second-sales-tax-rate type="decimal">0.0</second-sales-tax-rate>
+ </invoice-item>
+ <invoice-item>
+ <description>Travel costs</description>
+ <id type="integer">169403</id>
+ <invoice-id type="integer">73867</invoice-id>
+ <item-type>Expenses</item-type>
+ <price type="decimal">110.0</price>
+ <project-id type="integer" nil="true"></project-id>
+ <quantity type="decimal">1.0</quantity>
+ <sales-tax-rate type="decimal">15.0</sales-tax-rate>
+ <second-sales-tax-rate type="decimal">0.0</second-sales-tax-rate>
+ </invoice-item>
+</invoice-items>
View
15 test/stubs/invoice_items/find_single
@@ -0,0 +1,15 @@
+HTTP/1.1 200 OK
+Status: 200
+Content-Type: application/xml; charset=utf-8
+
+<invoice-item>
+ <description>1/2 day training session.</description>
+ <id type="integer">169399</id>
+ <invoice-id type="integer">73867</invoice-id>
+ <item-type>Training</item-type>
+ <price type="decimal">350.0</price>
+ <project-id type="integer" nil="true"></project-id>
+ <quantity type="decimal">1.0</quantity>
+ <sales-tax-rate type="decimal">15.0</sales-tax-rate>
+ <second-sales-tax-rate type="decimal">0.0</second-sales-tax-rate>
+</invoice-item>
View
239 test/stubs/invoices/find_all
@@ -0,0 +1,239 @@
+HTTP/1.1 200 OK
+Status: 200
+Content-Type: application/xml; charset=utf-8
+
+<?xml version="1.0" encoding="UTF-8"?>
+<invoices type="array">
+ <invoice>
+ <id type="integer">61761</id>
+ <company-id type="integer">3795</company-id>
+ <project-id type="integer"></project-id>
+ <contact-id type="integer">27318</contact-id>
+ <dated-on type="datetime">2009-04-07T00:00:00Z</dated-on>
+ <due-on type="datetime">2009-04-21T00:00:00Z</due-on>
+ <reference>INV014</reference>
+ <net-value type="decimal">1944.0</net-value>
+ <sales-tax-value type="decimal">0.0</sales-tax-value>
+ <status>Paid</status>
+ <comments></comments>
+ <discount-percent type="decimal"></discount-percent>
+ <omit-header type="boolean">false</omit-header>
+ <payment-terms-in-days type="integer">14</payment-terms-in-days>
+ <written-off-date type="datetime"></written-off-date>
+ <invoice-items type="array">
+ <invoice-item>
+ <description>Contract work</description>
+ <id type="integer">142835</id>
+ <invoice-id type="integer">61761</invoice-id>
+ <item-type>-no unit-</item-type>
+ <price type="decimal">1944.0</price>
+ <project-id type="integer" nil="true"></project-id>
+ <quantity type="decimal">1.0</quantity>
+ <sales-tax-rate type="decimal">15.0</sales-tax-rate>
+ <second-sales-tax-rate type="decimal">0.0</second-sales-tax-rate>
+ </invoice-item>
+ </invoice-items>
+ </invoice>
+ <invoice>
+ <id type="integer">61765</id>
+ <company-id type="integer">3795</company-id>
+ <project-id type="integer"></project-id>
+ <contact-id type="integer">27309</contact-id>
+ <dated-on type="datetime">2009-04-07T00:00:00Z</dated-on>
+ <due-on type="datetime">2009-04-21T00:00:00Z</due-on>
+ <reference>INV015</reference>
+ <net-value type="decimal">175.0</net-value>
+ <sales-tax-value type="decimal">0.0</sales-tax-value>
+ <status>Paid</status>
+ <comments></comments>
+ <discount-percent type="decimal"></discount-percent>
+ <omit-header type="boolean">false</omit-header>
+ <payment-terms-in-days type="integer">14</payment-terms-in-days>
+ <written-off-date type="datetime"></written-off-date>
+ <invoice-items type="array">
+ <invoice-item>
+ <description>Contract work</description>
+ <id type="integer">142843</id>
+ <invoice-id type="integer">61765</invoice-id>
+ <item-type>-no unit-</item-type>
+ <price type="decimal">175.0</price>
+ <project-id type="integer" nil="true"></project-id>
+ <quantity type="decimal">1.0</quantity>
+ <sales-tax-rate type="decimal">15.0</sales-tax-rate>
+ <second-sales-tax-rate type="decimal">0.0</second-sales-tax-rate>
+ </invoice-item>
+ </invoice-items>
+ </invoice>
+ <invoice>
+ <id type="integer">61764</id>
+ <company-id type="integer">3795</company-id>
+ <project-id type="integer"></project-id>
+ <contact-id type="integer">27307</contact-id>
+ <dated-on type="datetime">2009-04-16T00:00:00Z</dated-on>
+ <due-on type="datetime">2009-04-30T00:00:00Z</due-on>
+ <reference>INV016</reference>
+ <net-value type="decimal">35.0</net-value>
+ <sales-tax-value type="decimal">0.0</sales-tax-value>
+ <status>Paid</status>
+ <comments></comments>
+ <discount-percent type="decimal"></discount-percent>
+ <omit-header type="boolean">false</omit-header>
+ <payment-terms-in-days type="integer">14</payment-terms-in-days>
+ <written-off-date type="datetime"></written-off-date>
+ <invoice-items type="array">
+ <invoice-item>
+ <description>Contract work</description>
+ <id type="integer">142842</id>
+ <invoice-id type="integer">61764</invoice-id>
+ <item-type>-no unit-</item-type>
+ <price type="decimal">35.0</price>
+ <project-id type="integer" nil="true"></project-id>
+ <quantity type="decimal">1.0</quantity>
+ <sales-tax-rate type="decimal">15.0</sales-tax-rate>
+ <second-sales-tax-rate type="decimal">0.0</second-sales-tax-rate>
+ </invoice-item>
+ </invoice-items>
+ </invoice>
+ <invoice>
+ <id type="integer">61767</id>
+ <company-id type="integer">3795</company-id>
+ <project-id type="integer"></project-id>
+ <contact-id type="integer">27311</contact-id>
+ <dated-on type="datetime">2009-04-16T00:00:00Z</dated-on>
+ <due-on type="datetime">2009-04-30T00:00:00Z</due-on>
+ <reference>INV017</reference>
+ <net-value type="decimal">385.0</net-value>
+ <sales-tax-value type="decimal">0.0</sales-tax-value>
+ <status>Paid</status>
+ <comments></comments>
+ <discount-percent type="decimal"></discount-percent>
+ <omit-header type="boolean">false</omit-header>
+ <payment-terms-in-days type="integer">14</payment-terms-in-days>
+ <written-off-date type="datetime"></written-off-date>
+ <invoice-items type="array">
+ <invoice-item>
+ <description>Contract work</description>
+ <id type="integer">142845</id>
+ <invoice-id type="integer">61767</invoice-id>
+ <item-type>-no unit-</item-type>
+ <price type="decimal">385.0</price>
+ <project-id type="integer" nil="true"></project-id>
+ <quantity type="decimal">1.0</quantity>
+ <sales-tax-rate type="decimal">15.0</sales-tax-rate>
+ <second-sales-tax-rate type="decimal">0.0</second-sales-tax-rate>
+ </invoice-item>
+ </invoice-items>
+ </invoice>
+ <invoice>
+ <id type="integer">61768</id>
+ <company-id type="integer">3795</company-id>
+ <project-id type="integer"></project-id>
+ <contact-id type="integer">27318</contact-id>
+ <dated-on type="datetime">2009-05-04T00:00:00Z</dated-on>
+ <due-on type="datetime">2009-05-18T00:00:00Z</due-on>
+ <reference>INV018</reference>
+ <net-value type="decimal">1038.51</net-value>
+ <sales-tax-value type="decimal">0.0</sales-tax-value>
+ <status>Paid</status>
+ <comments></comments>
+ <discount-percent type="decimal"></discount-percent>
+ <omit-header type="boolean">false</omit-header>
+ <payment-terms-in-days type="integer">14</payment-terms-in-days>
+ <written-off-date type="datetime"></written-off-date>
+ <invoice-items type="array">
+ <invoice-item>
+ <description>Contract work</description>
+ <id type="integer">142846</id>
+ <invoice-id type="integer">61768</invoice-id>
+ <item-type>-no unit-</item-type>
+ <price type="decimal">1038.51</price>
+ <project-id type="integer" nil="true"></project-id>
+ <quantity type="decimal">1.0</quantity>
+ <sales-tax-rate type="decimal">15.0</sales-tax-rate>
+ <second-sales-tax-rate type="decimal">0.0</second-sales-tax-rate>
+ </invoice-item>
+ </invoice-items>
+ </invoice>
+ <invoice>
+ <id type="integer">61769</id>
+ <company-id type="integer">3795</company-id>
+ <project-id type="integer"></project-id>
+ <contact-id type="integer">27309</contact-id>
+ <dated-on type="datetime">2009-05-05T00:00:00Z</dated-on>
+ <due-on type="datetime">2009-05-19T00:00:00Z</due-on>
+ <reference>INV019</reference>
+ <net-value type="decimal">70.0</net-value>
+ <sales-tax-value type="decimal">0.0</sales-tax-value>
+ <status>Paid</status>
+ <comments></comments>
+ <discount-percent type="decimal"></discount-percent>
+ <omit-header type="boolean">false</omit-header>
+ <payment-terms-in-days type="integer">14</payment-terms-in-days>
+ <written-off-date type="datetime"></written-off-date>
+ <invoice-items type="array">
+ <invoice-item>
+ <description>Contract work</description>
+ <id type="integer">142847</id>
+ <invoice-id type="integer">61769</invoice-id>
+ <item-type>-no unit-</item-type>
+ <price type="decimal">70.0</price>
+ <project-id type="integer" nil="true"></project-id>
+ <quantity type="decimal">1.0</quantity>
+ <sales-tax-rate type="decimal">15.0</sales-tax-rate>
+ <second-sales-tax-rate type="decimal">0.0</second-sales-tax-rate>
+ </invoice-item>
+ </invoice-items>
+ </invoice>
+ <invoice>
+ <id type="integer">73867</id>
+ <company-id type="integer">3795</company-id>
+ <project-id type="integer"></project-id>
+ <contact-id type="integer">27308</contact-id>
+ <dated-on type="datetime">2009-10-08T00:00:00Z</dated-on>
+ <due-on type="datetime">2009-10-22T00:00:00Z</due-on>
+ <reference>INV034</reference>
+ <net-value type="decimal">670.0</net-value>
+ <sales-tax-value type="decimal">0.0</sales-tax-value>
+ <status>Overdue</status>
+ <comments></comments>
+ <discount-percent type="decimal"></discount-percent>
+ <omit-header type="boolean">false</omit-header>
+ <payment-terms-in-days type="integer">14</payment-terms-in-days>
+ <written-off-date type="datetime"></written-off-date>
+ <invoice-items type="array">
+ <invoice-item>
+ <description>Email build, testing and delivery.</description>
+ <id type="integer">168981</id>
+ <invoice-id type="integer">73867</invoice-id>
+ <item-type>Hours</item-type>
+ <price type="decimal">35.0</price>
+ <project-id type="integer" nil="true"></project-id>
+ <quantity type="decimal">6.0</quantity>
+ <sales-tax-rate type="decimal">15.0</sales-tax-rate>
+ <second-sales-tax-rate type="decimal">0.0</second-sales-tax-rate>
+ </invoice-item>
+ <invoice-item>
+ <description>1/2 day training session.</description>
+ <id type="integer">169399</id>
+ <invoice-id type="integer">73867</invoice-id>
+ <item-type>Training</item-type>
+ <price type="decimal">350.0</price>
+ <project-id type="integer" nil="true"></project-id>
+ <quantity type="decimal">1.0</quantity>
+ <sales-tax-rate type="decimal">15.0</sales-tax-rate>
+ <second-sales-tax-rate type="decimal">0.0</second-sales-tax-rate>
+ </invoice-item>
+ <invoice-item>
+ <description>Travel costs</description>
+ <id type="integer">169403</id>
+ <invoice-id type="integer">73867</invoice-id>
+ <item-type>Expenses</item-type>
+ <price type="decimal">110.0</price>
+ <project-id type="integer" nil="true"></project-id>
+ <quantity type="decimal">1.0</quantity>
+ <sales-tax-rate type="decimal">15.0</sales-tax-rate>
+ <second-sales-tax-rate type="decimal">0.0</second-sales-tax-rate>
+ </invoice-item>
+ </invoice-items>
+ </invoice>
+</invoices>
View
57 test/stubs/invoices/find_single
@@ -0,0 +1,57 @@
+HTTP/1.1 200 OK
+Status: 200
+Content-Type: application/xml; charset=utf-8
+
+<?xml version="1.0" encoding="UTF-8"?>
+<invoice>
+ <id type="integer">73867</id>
+ <company-id type="integer">3795</company-id>
+ <project-id type="integer"></project-id>
+ <contact-id type="integer">27308</contact-id>
+ <dated-on type="datetime">2009-10-08T00:00:00Z</dated-on>
+ <due-on type="datetime">2009-10-22T00:00:00Z</due-on>
+ <reference>INV034</reference>
+ <net-value type="decimal">670.0</net-value>
+ <sales-tax-value type="decimal">0.0</sales-tax-value>
+ <status>Overdue</status>
+ <comments></comments>
+ <discount-percent type="decimal"></discount-percent>
+ <omit-header type="boolean">false</omit-header>
+ <payment-terms-in-days type="integer">14</payment-terms-in-days>
+ <written-off-date type="datetime"></written-off-date>
+ <invoice-items type="array">
+ <invoice-item>
+ <description>Email build, testing and delivery.</description>
+ <id type="integer">168981</id>
+ <invoice-id type="integer">73867</invoice-id>
+ <item-type>Hours</item-type>
+ <price type="decimal">35.0</price>
+ <project-id type="integer" nil="true"></project-id>
+ <quantity type="decimal">6.0</quantity>
+ <sales-tax-rate type="decimal">15.0</sales-tax-rate>
+ <second-sales-tax-rate type="decimal">0.0</second-sales-tax-rate>
+ </invoice-item>
+ <invoice-item>
+ <description>1/2 day training session.</description>
+ <id type="integer">169399</id>
+ <invoice-id type="integer">73867</invoice-id>
+ <item-type>Training</item-type>
+ <price type="decimal">350.0</price>
+ <project-id type="integer" nil="true"></project-id>
+ <quantity type="decimal">1.0</quantity>
+ <sales-tax-rate type="decimal">15.0</sales-tax-rate>
+ <second-sales-tax-rate type="decimal">0.0</second-sales-tax-rate>
+ </invoice-item>
+ <invoice-item>
+ <description>Travel costs</description>
+ <id type="integer">169403</id>
+ <invoice-id type="integer">73867</invoice-id>
+ <item-type>Expenses</item-type>
+ <price type="decimal">110.0</price>
+ <project-id type="integer" nil="true"></project-id>
+ <quantity type="decimal">1.0</quantity>
+ <sales-tax-rate type="decimal">15.0</sales-tax-rate>
+ <second-sales-tax-rate type="decimal">0.0</second-sales-tax-rate>
+ </invoice-item>
+ </invoice-items>
+</invoice>
View
92 test/stubs/projects/invoices
@@ -0,0 +1,92 @@
+HTTP/1.1 200 OK
+Status: 200
+Content-Type: application/xml; charset=utf-8
+
+<?xml version="1.0" encoding="UTF-8"?>
+<invoices type="array">
+ <invoice>
+ <id type="integer">66913</id>
+ <company-id type="integer">3795</company-id>
+ <project-id type="integer">17820</project-id>
+ <contact-id type="integer">27314</contact-id>
+ <dated-on type="datetime">2009-09-14T00:00:00Z</dated-on>
+ <due-on type="datetime">2009-09-28T00:00:00Z</due-on>
+ <reference>INV033</reference>
+ <net-value type="decimal">3000.0</net-value>
+ <sales-tax-value type="decimal">0.0</sales-tax-value>
+ <status>Paid</status>
+ <comments></comments>
+ <discount-percent type="decimal"></discount-percent>
+ <omit-header type="boolean">false</omit-header>
+ <payment-terms-in-days type="integer">14</payment-terms-in-days>
+ <written-off-date type="datetime"></written-off-date>
+ <invoice-items type="array">
+ <invoice-item>
+ <description>Back end development</description>
+ <id type="integer">153069</id>
+ <invoice-id type="integer">66913</invoice-id>
+ <item-type>Days</item-type>
+ <price type="decimal">200.0</price>
+ <project-id type="integer" nil="true"></project-id>
+ <quantity type="decimal">2.5</quantity>
+ <sales-tax-rate type="decimal">0.0</sales-tax-rate>
+ <second-sales-tax-rate type="decimal">0.0</second-sales-tax-rate>
+ </invoice-item>
+ <invoice-item>
+ <description>Briefing and research</description>
+ <id type="integer">153070</id>
+ <invoice-id type="integer">66913</invoice-id>
+ <item-type>Days</item-type>
+ <price type="decimal">200.0</price>
+ <project-id type="integer" nil="true"></project-id>
+ <quantity type="decimal">1.0</quantity>
+ <sales-tax-rate type="decimal">0.0</sales-tax-rate>
+ <second-sales-tax-rate type="decimal">0.0</second-sales-tax-rate>
+ </invoice-item>
+ <invoice-item>
+ <description>Front end development</description>
+ <id type="integer">153071</id>
+ <invoice-id type="integer">66913</invoice-id>
+ <item-type>Days</item-type>
+ <price type="decimal">200.0</price>
+ <project-id type="integer" nil="true"></project-id>
+ <quantity type="decimal">3.5</quantity>
+ <sales-tax-rate type="decimal">0.0</sales-tax-rate>
+ <second-sales-tax-rate type="decimal">0.0</second-sales-tax-rate>
+ </invoice-item>
+ <invoice-item>
+ <description>Game website development</description>
+ <id type="integer">153072</id>
+ <invoice-id type="integer">66913</invoice-id>
+ <item-type>Days</item-type>
+ <price type="decimal">200.0</price>
+ <project-id type="integer" nil="true"></project-id>
+ <quantity type="decimal">2.0</quantity>
+ <sales-tax-rate type="decimal">0.0</sales-tax-rate>
+ <second-sales-tax-rate type="decimal">0.0</second-sales-tax-rate>
+ </invoice-item>
+ <invoice-item>
+ <description>Mobile website development</description>
+ <id type="integer">153073</id>
+ <invoice-id type="integer">66913</invoice-id>
+ <item-type>Days</item-type>
+ <price type="decimal">200.0</price>
+ <project-id type="integer" nil="true"></project-id>
+ <quantity type="decimal">5.0</quantity>
+ <sales-tax-rate type="decimal">0.0</sales-tax-rate>
+ <second-sales-tax-rate type="decimal">0.0</second-sales-tax-rate>
+ </invoice-item>
+ <invoice-item>
+ <description>Photographic website development</description>
+ <id type="integer">153074</id>
+ <invoice-id type="integer">66913</invoice-id>
+ <item-type>Days</item-type>
+ <price type="decimal">200.0</price>
+ <project-id type="integer" nil="true"></project-id>
+ <quantity type="decimal">1.0</quantity>
+ <sales-tax-rate type="decimal">0.0</sales-tax-rate>
+ <second-sales-tax-rate type="decimal">0.0</second-sales-tax-rate>
+ </invoice-item>
+ </invoice-items>
+ </invoice>
+</invoices>
View
223 test/stubs/projects/timeslips
@@ -0,0 +1,223 @@
+HTTP/1.1 200 OK
+Status: 200
+Content-Type: application/xml; charset=utf-8
+
+<?xml version="1.0" encoding="UTF-8"?>
+<timeslips type="array">
+ <timeslip>
+ <comment></comment>
+ <dated-on type="datetime">2009-09-09T00:00:00Z</dated-on>
+ <hours type="decimal">3.75</hours>
+ <id type="integer">74814</id>
+ <task-id type="integer">13161</task-id>
+ <updated-at type="datetime">2009-09-14T19:56:37Z</updated-at>
+ <user-id type="integer">5193</user-id>
+ </timeslip>
+ <timeslip>
+ <comment></comment>
+ <dated-on type="datetime">2009-09-09T00:00:00Z</dated-on>
+ <hours type="decimal">3.75</hours>
+ <id type="integer">74815</id>
+ <task-id type="integer">12684</task-id>
+ <updated-at type="datetime">2009-09-14T19:56:37Z</updated-at>
+ <user-id type="integer">5193</user-id>
+ </timeslip>
+ <timeslip>
+ <comment></comment>
+ <dated-on type="datetime">2009-09-10T00:00:00Z</dated-on>
+ <hours type="decimal">3.75</hours>
+ <id type="integer">75967</id>
+ <task-id type="integer">12683</task-id>
+ <updated-at type="datetime">2009-09-14T19:56:36Z</updated-at>
+ <user-id type="integer">5193</user-id>
+ </timeslip>
+ <timeslip>
+ <comment></comment>
+ <dated-on type="datetime">2009-09-10T00:00:00Z</dated-on>
+ <hours type="decimal">3.75</hours>
+ <id type="integer">75966</id>
+ <task-id type="integer">13161</task-id>
+ <updated-at type="datetime">2009-09-14T19:56:37Z</updated-at>
+ <user-id type="integer">5193</user-id>
+ </timeslip>
+ <timeslip>
+ <comment></comment>
+ <dated-on type="datetime">2009-09-11T00:00:00Z</dated-on>
+ <hours type="decimal">7.5</hours>
+ <id type="integer">75968</id>
+ <task-id type="integer">13161</task-id>
+ <updated-at type="datetime">2009-09-14T19:56:37Z</updated-at>
+ <user-id type="integer">5193</user-id>
+ </timeslip>
+ <timeslip>
+ <comment></comment>
+ <dated-on type="datetime">2009-09-14T00:00:00Z</dated-on>
+ <hours type="decimal">7.5</hours>
+ <id type="integer">76010</id>
+ <task-id type="integer">13161</task-id>
+ <updated-at type="datetime">2009-09-14T22:33:55Z</updated-at>
+ <user-id type="integer">5193</user-id>
+ </timeslip>
+ <timeslip>
+ <comment></comment>
+ <dated-on type="datetime">2009-09-15T00:00:00Z</dated-on>
+ <hours type="decimal">3.75</hours>
+ <id type="integer">76292</id>
+ <task-id type="integer">13161</task-id>
+ <updated-at type="datetime">2009-09-15T20:13:10Z</updated-at>
+ <user-id type="integer">5193</user-id>
+ </timeslip>
+ <timeslip>
+ <comment></comment>
+ <dated-on type="datetime">2009-09-16T00:00:00Z</dated-on>
+ <hours type="decimal">7.5</hours>
+ <id type="integer">78004</id>
+ <task-id type="integer">12683</task-id>
+ <updated-at type="datetime">2009-09-20T11:39:39Z</updated-at>
+ <user-id type="integer">5193</user-id>
+ </timeslip>
+ <timeslip>
+ <comment></comment>
+ <dated-on type="datetime">2009-09-17T00:00:00Z</dated-on>
+ <hours type="decimal">7.5</hours>
+ <id type="integer">78005</id>
+ <task-id type="integer">12683</task-id>
+ <updated-at type="datetime">2009-09-20T11:39:47Z</updated-at>
+ <user-id type="integer">5193</user-id>
+ </timeslip>
+ <timeslip>
+ <comment></comment>
+ <dated-on type="datetime">2009-09-18T00:00:00Z</dated-on>
+ <hours type="decimal">7.5</hours>
+ <id type="integer">78006</id>
+ <task-id type="integer">12683</task-id>
+ <updated-at type="datetime">2009-09-20T11:39:55Z</updated-at>
+ <user-id type="integer">5193</user-id>
+ </timeslip>
+ <timeslip>
+ <comment></comment>
+ <dated-on type="datetime">2009-09-21T00:00:00Z</dated-on>
+ <hours type="decimal">7.5</hours>
+ <id type="integer">78793</id>
+ <task-id type="integer">12683</task-id>
+ <updated-at type="datetime">2009-09-22T15:52:37Z</updated-at>
+ <user-id type="integer">5193</user-id>
+ </timeslip>
+ <timeslip>
+ <comment></comment>
+ <dated-on type="datetime">2009-09-22T00:00:00Z</dated-on>
+ <hours type="decimal">3.75</hours>
+ <id type="integer">78794</id>
+ <task-id type="integer">12683</task-id>
+ <updated-at type="datetime">2009-09-22T15:52:46Z</updated-at>
+ <user-id type="integer">5193</user-id>
+ </timeslip>
+ <timeslip>
+ <comment></comment>
+ <dated-on type="datetime">2009-09-23T00:00:00Z</dated-on>
+ <hours type="decimal">7.5</hours>
+ <id type="integer">79115</id>
+ <task-id type="integer">12683</task-id>
+ <updated-at type="datetime">2009-09-23T19:12:53Z</updated-at>
+ <user-id type="integer">5193</user-id>
+ </timeslip>
+ <timeslip>
+ <comment></comment>
+ <dated-on type="datetime">2009-09-24T00:00:00Z</dated-on>
+ <hours type="decimal">7.5</hours>
+ <id type="integer">79691</id>
+ <task-id type="integer">12683</task-id>
+ <updated-at type="datetime">2009-09-24T18:58:44Z</updated-at>
+ <user-id type="integer">5193</user-id>
+ </timeslip>
+ <timeslip>
+ <comment></comment>
+ <dated-on type="datetime">2009-09-25T00:00:00Z</dated-on>
+ <hours type="decimal">7.5</hours>
+ <id type="integer">80083</id>
+ <task-id type="integer">12684</task-id>
+ <updated-at type="datetime">2009-09-25T17:45:32Z</updated-at>
+ <user-id type="integer">5193</user-id>
+ </timeslip>
+ <timeslip>
+ <comment></comment>
+ <dated-on type="datetime">2009-09-28T00:00:00Z</dated-on>
+ <hours type="decimal">7.5</hours>
+ <id type="integer">82076</id>
+ <task-id type="integer">12684</task-id>
+ <updated-at type="datetime">2009-10-01T18:59:36Z</updated-at>
+ <user-id type="integer">5193</user-id>
+ </timeslip>
+ <timeslip>
+ <comment></comment>
+ <dated-on type="datetime">2009-09-29T00:00:00Z</dated-on>
+ <hours type="decimal">3.75</hours>
+ <id type="integer">82077</id>
+ <task-id type="integer">12684</task-id>
+ <updated-at type="datetime">2009-10-01T18:59:44Z</updated-at>
+ <user-id type="integer">5193</user-id>
+ </timeslip>
+ <timeslip>
+ <comment></comment>
+ <dated-on type="datetime">2009-09-29T00:00:00Z</dated-on>
+ <hours type="decimal">3.75</hours>
+ <id type="integer">82078</id>
+ <task-id type="integer">12683</task-id>
+ <updated-at type="datetime">2009-10-01T18:59:55Z</updated-at>
+ <user-id type="integer">5193</user-id>
+ </timeslip>
+ <timeslip>
+ <comment></comment>
+ <dated-on type="datetime">2009-09-30T00:00:00Z</dated-on>
+ <hours type="decimal">7.5</hours>
+ <id type="integer">82079</id>
+ <task-id type="integer">12683</task-id>
+ <updated-at type="datetime">2009-10-01T19:00:08Z</updated-at>
+ <user-id type="integer">5193</user-id>
+ </timeslip>
+ <timeslip>
+ <comment></comment>
+ <dated-on type="datetime">2009-10-01T00:00:00Z</dated-on>
+ <hours type="decimal">7.5</hours>
+ <id type="integer">82080</id>
+ <task-id type="integer">12683</task-id>
+ <updated-at type="datetime">2009-10-01T19:00:15Z</updated-at>
+ <user-id type="integer">5193</user-id>
+ </timeslip>
+ <timeslip>
+ <comment></comment>
+ <dated-on type="datetime">2009-10-02T00:00:00Z</dated-on>
+ <hours type="decimal">7.5</hours>
+ <id type="integer">82575</id>
+ <task-id type="integer">12684</task-id>
+ <updated-at type="datetime">2009-10-04T00:47:46Z</updated-at>
+ <user-id type="integer">5193</user-id>
+ </timeslip>
+ <timeslip>
+ <comment></comment>
+ <dated-on type="datetime">2009-10-05T00:00:00Z</dated-on>
+ <hours type="decimal">7.5</hours>
+ <id type="integer">84445</id>
+ <task-id type="integer">12683</task-id>
+ <updated-at type="datetime">2009-10-08T15:29:30Z</updated-at>
+ <user-id type="integer">5193</user-id>
+ </timeslip>
+ <timeslip>
+ <comment></comment>
+ <dated-on type="datetime">2009-10-06T00:00:00Z</dated-on>
+ <hours type="decimal">7.5</hours>
+ <id type="integer">84446</id>
+ <task-id type="integer">15291</task-id>
+ <updated-at type="datetime">2009-10-08T15:29:47Z</updated-at>
+ <user-id type="integer">5193</user-id>
+ </timeslip>
+ <timeslip>
+ <comment></comment>
+ <dated-on type="datetime">2009-10-08T00:00:00Z</dated-on>
+ <hours type="decimal">3.75</hours>
+ <id type="integer">84447</id>
+ <task-id type="integer">12683</task-id>
+ <updated-at type="datetime">2009-10-08T15:29:59Z</updated-at>
+ <user-id type="integer">5193</user-id>
+ </timeslip>
+</timeslips>
View
42 test/stubs/tasks/find_all
@@ -0,0 +1,42 @@
+HTTP/1.1 200 OK
+Status: 200
+Content-Type: application/xml; charset=utf-8
+
+<?xml version="1.0" encoding="UTF-8"?>
+<tasks type="array">
+ <task>
+ <id type="integer">12683</id>
+ <name>Back end development</name>
+ <project-id type="integer">17820</project-id>
+ </task>
+ <task>
+ <id type="integer">12685</id>
+ <name>Briefing and research</name>
+ <project-id type="integer">17820</project-id>
+ </task>
+ <task>
+ <id type="integer">15291</id>
+ <name>Documentation</name>
+ <project-id type="integer">17820</project-id>
+ </task>
+ <task>
+ <id type="integer">12684</id>
+ <name>Front end development</name>
+ <project-id type="integer">17820</project-id>
+ </task>
+ <task>
+ <id type="integer">12921</id>
+ <name>Photography project</name>
+ <project-id type="integer">17820</project-id>
+ </task>
+ <task>
+ <id type="integer">12841</id>
+ <name>Game website development</name>
+ <project-id type="integer">17820</project-id>
+ </task>
+ <task>
+ <id type="integer">13161</id>
+ <name>Mobile website development</name>
+ <project-id type="integer">17820</project-id>
+ </task>
+</tasks>
View
10 test/stubs/tasks/find_single
@@ -0,0 +1,10 @@
+HTTP/1.1 200 OK
+Status: 200
+Content-Type: application/xml; charset=utf-8
+
+<?xml version="1.0" encoding="UTF-8"?>
+<task>
+ <id type="integer">13161</id>
+ <name>Mobile website development</name>
+ <project-id type="integer">17820</project-id>
+</task>
View
52 test/stubs/timeslips/find_all
@@ -0,0 +1,52 @@
+HTTP/1.1 200 OK
+Status: 200
+Content-Type: application/xml; charset=utf-8
+
+<?xml version="1.0" encoding="UTF-8"?>
+<timeslips type="array">
+ <timeslip>
+ <comment></comment>
+ <dated-on type="datetime">2009-10-01T00:00:00Z</dated-on>
+ <hours type="decimal">7.5</hours>
+ <id type="integer">82080</id>
+ <task-id type="integer">12683</task-id>
+ <updated-at type="datetime">2009-10-01T19:00:15Z</updated-at>
+ <user-id type="integer">5193</user-id>
+ </timeslip>
+ <timeslip>
+ <comment></comment>
+ <dated-on type="datetime">2009-10-02T00:00:00Z</dated-on>
+ <hours type="decimal">7.5</hours>
+ <id type="integer">82575</id>
+ <task-id type="integer">12684</task-id>
+ <updated-at type="datetime">2009-10-04T00:47:46Z</updated-at>
+ <user-id type="integer">5193</user-id>
+ </timeslip>
+ <timeslip>
+ <comment></comment>
+ <dated-on type="datetime">2009-10-05T00:00:00Z</dated-on>
+ <hours type="decimal">7.5</hours>
+ <id type="integer">84445</id>
+ <task-id type="integer">12683</task-id>
+ <updated-at type="datetime">2009-10-08T15:29:30Z</updated-at>
+ <user-id type="integer">5193</user-id>
+ </timeslip>
+ <timeslip>
+ <comment></comment>
+ <dated-on type="datetime">2009-10-06T00:00:00Z</dated-on>
+ <hours type="decimal">7.5</hours>
+ <id type="integer">84446</id>
+ <task-id type="integer">15291</task-id>
+ <updated-at type="datetime">2009-10-08T15:29:47Z</updated-at>
+ <user-id type="integer">5193</user-id>
+ </timeslip>
+ <timeslip>
+ <comment></comment>
+ <dated-on type="datetime">2009-10-08T00:00:00Z</dated-on>
+ <hours type="decimal">3.75</hours>
+ <id type="integer">84447</id>
+ <task-id type="integer">12683</task-id>
+ <updated-at type="datetime">2009-10-08T15:29:59Z</updated-at>
+ <user-id type="integer">5193</user-id>
+ </timeslip>
+</timeslips>
View
14 test/stubs/timeslips/find_single
@@ -0,0 +1,14 @@
+HTTP/1.1 200 OK
+Status: 200
+Content-Type: application/xml; charset=utf-8
+
+<?xml version="1.0" encoding="UTF-8"?>
+<timeslip>
+ <comment></comment>
+ <dated-on type="datetime">2009-10-05T00:00:00Z</dated-on>
+ <hours type="decimal">7.5</hours>
+ <id type="integer">84445</id>
+ <task-id type="integer">12683</task-id>
+ <updated-at type="datetime">2009-10-08T15:29:30Z</updated-at>
+ <user-id type="integer">5193</user-id>
+</timeslip>
View
52 test/task_test.rb
@@ -1,15 +1,59 @@
require 'test_helper'
-
class TaskTest < Test::Unit::TestCase
context "Task class" do
should "have correct collection path" do
- assert Task.collection_path(:project_id => 1000) === '/projects/1000/tasks.xml'
+ assert_equal '/projects/1000/tasks.xml', Task.collection_path(:project_id => 1000)
end
should "have correct element path" do
- assert Task.element_path(:first, :project_id => 1000) === '/projects/1000/tasks/first.xml'
- assert Task.element_path(1000, :project_id => 1000) === '/projects/1000/tasks/1000.xml'
+ assert_equal '/projects/1000/tasks/first.xml', Task.element_path(:first, :project_id => 1000)
+ assert_equal '/projects/1000/tasks/1000.xml', Task.element_path(1000, :project_id => 1000)
+ end
+ end
+
+ context "Tasks" do
+ setup do
+ @tasks = Task.find :all, :params => {:project_id => 17820}
+ end
+ should "return an array" do
+ assert @tasks.is_a? Array
+ end
+ should "return Tasks" do
+ assert_equal 7, @tasks.size
+ assert @tasks.first.is_a? Task
+ end
+ end
+
+ context "Task" do
+ setup do
+ @task = Task.find 13161, :params => {:project_id => 17820}
+ end
+ should "return a Invoice" do
+ assert @task.is_a? Task
+ end
+ should "update and save" do
+ @task.name = 'Development'
+ assert @task.save
+ end
+ should "be destroyed" do
+ assert @task.destroy
+ end
+ end
+
+ #TODO - Add test for invalid resource
+ # Need support from fakeweb in order to achieve this
+
+ context "New Task" do
+ setup do
+ params = {
+ :project_id => '17820',
+ :name => 'Creative design'
+ }
+ @task = Task.new params
+ end
+ should "validate and save" do
+ assert @task.save_with_validation
end
end
View
54 test/test_helper.rb
@@ -28,34 +28,62 @@ def fake_it_all
site_url = 'https://testuser:testpass@testuser.freeagentcentral.com'
# GET URLs
- { '/company/invoice_timeline.xml' => File.join('company', 'invoice_timeline'),
- '/company/tax_timeline.xml' => File.join('company', 'tax_timeline'),
- '/contacts.xml' => File.join('contacts', 'find_all'),
- '/contacts/27309.xml' => File.join('contacts', 'find_single'),
- '/projects.xml' => File.join('projects', 'find_all'),
- '/projects/17820.xml' => File.join('projects', 'find_single'),
- '/projects/17820/invoices.xml' => File.join('invoices', 'find_all')
+ { '/company/invoice_timeline.xml' => File.join('company', 'invoice_timeline'),
+ '/company/tax_timeline.xml' => File.join('company', 'tax_timeline'),
+ '/contacts.xml' => File.join('contacts', 'find_all'),
+ '/contacts/27309.xml' => File.join('contacts', 'find_single'),
+ '/projects.xml' => File.join('projects', 'find_all'),
+ '/projects/17820.xml' => File.join('projects', 'find_single'),
+ '/projects/17820/tasks.xml' => File.join('tasks', 'find_all'),
+ '/projects/17820/tasks/13161.xml' => File.join('tasks', 'find_single'),
+ '/invoices.xml' => File.join('invoices', 'find_all'),
+ '/invoices/73867.xml' => File.join('invoices', 'find_single'),
+ '/projects/17820/invoices.xml' => File.join('projects', 'invoices'),
+ '/invoices/73867/invoice_items.xml' => File.join('invoice_items', 'find_all'),
+ '/invoices/73867/invoice_items/169399.xml' => File.join('invoice_items', 'find_single'),
+ '/timeslips.xml?view=2009-10-01_2009-10-10' => File.join('timeslips', 'find_all'),
+ '/timeslips/84445.xml' => File.join('timeslips', 'find_single'),
+ '/projects/17820/timeslips.xml' => File.join('projects', 'timeslips'),
}.each do |path, stub|
FakeWeb.register_uri(:get, site_url+path, :response => stub_file(stub))
end
# POST URLs
- { '/contacts.xml' => File.join('http', '201'),
- '/projects.xml' => File.join('http', '201')
+ { '/contacts.xml' => File.join('http', '201'),
+ '/projects.xml' => File.join('http', '201'),
+ '/projects/17820/tasks.xml' => File.join('http', '201'),
+ '/invoices.xml' => File.join('http', '201'),
+ '/invoices/73867/invoice_items.xml' => File.join('http', '201'),
+ '/timeslips.xml' => File.join('http', '201'),
}.each do |path, stub|
FakeWeb.register_uri(:post, site_url+path, :response => stub_file(stub))
end
# PUT URLs
- { '/contacts/27309.xml' => File.join('http', '200'),
- '/projects/17820.xml' => File.join('http', '200')
+ { '/contacts/27309.xml' => File.join('http', '200'),
+ '/projects/17820.xml' => File.join('http', '200'),
+ '/projects/17820/tasks/13161.xml' => File.join('http', '200'),
+ '/invoices/73867.xml' => File.join('http', '200'),
+ '/invoices/73867/mark_as_draft.xml' => File.join('http', '200'),
+ '/invoices/73867/mark_as_sent.xml' => File.join('http', '200'),
+ '/invoices/73867/mark_as_cancelled.xml' => File.join('http', '200'),
+ '/invoices/66913.xml' => File.join('http', '200'),
+ '/invoices/73867/invoice_items/169399.xml' => File.join('http', '200'),
+ '/timeslips/84445.xml' => File.join('http', '200'),
+ '/timeslips/74814.xml' => File.join('http', '200'),
}.each do |path, stub|
FakeWeb.register_uri(:put, site_url+path, :response => stub_file(stub))
end
# DELETE URLs
- { '/contacts/27309.xml' => File.join('http', '200'),
- '/projects/17820.xml' => File.join('http', '200')
+ { '/contacts/27309.xml' => File.join('http', '200'),
+ '/projects/17820.xml' => File.join('http', '200'),
+ '/projects/17820/tasks/13161.xml' => File.join('http', '200'),
+ '/invoices/73867.xml' => File.join('http', '200'),
+ '/invoices/66913.xml' => File.join('http', '200'),
+ '/invoices/73867/invoice_items/169399.xml' => File.join('http', '200'),
+ '/timeslips/84445.xml' => File.join('http', '200'),
+ '/timeslips/74814.xml' => File.join('http', '200'),
}.each do |path, stub|
FakeWeb.register_uri(:delete, site_url+path, :response => stub_file(stub))
end
View
62 test/timeslip_test.rb
@@ -0,0 +1,62 @@
+require 'test_helper'
+
+class TimeslipTest < Test::Unit::TestCase
+
+ context "Timeslip class" do
+ should "have correct collection path" do
+ assert_equal '/timeslips.xml', Timeslip.collection_path
+ end
+ should "have correct element path" do
+ assert_equal '/timeslips/first.xml', Timeslip.element_path(:first)
+ assert_equal '/timeslips/1000.xml', Timeslip.element_path(1000)
+ end
+ end
+
+ context "Timeslips" do
+ setup do
+ @timeslips = Timeslip.find :all, :params => {:view => '2009-10-01_2009-10-10'}
+ end
+ should "return an array" do
+ assert @timeslips.is_a? Array
+ end
+ should "return Timeslips" do
+ assert_equal 5, @timeslips.size
+ assert @timeslips.first.is_a? Timeslip
+ end
+ end
+
+ context "Timeslip" do
+ setup do
+ @timeslip = Timeslip.find 84445
+ end
+ should "return a Invoice" do
+ assert @timeslip.is_a? Timeslip
+ end
+ should "update and save" do
+ @timeslip.hours = '10'
+ assert @timeslip.save
+ end
+ should "be destroyed" do
+ assert @timeslip.destroy
+ end
+ end
+
+ #TODO - Add test for invalid resource
+ # Need support from fakeweb in order to achieve this
+
+ context "New Timeslip" do
+ setup do
+ params = {
+ :user_id => '5193',
+ :hours => '4',
+ :dated_on => '2009-10-05T00:00:00Z',
+ :task_id => '12683',
+ }
+ @timeslip = Timeslip.new params
+ end
+ should "validate and save" do
+ assert @timeslip.save_with_validation
+ end
+ end
+
+end
Please sign in to comment.
Something went wrong with that request. Please try again.