sk-api 1.0.6 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- require "#{File.dirname(__FILE__)}/../spec_helper"
1
+ require 'spec/spec_helper'
2
2
 
3
3
  describe SKApi::Resources::Invoice, "in general" do
4
4
 
@@ -34,10 +34,24 @@ describe SKApi::Resources::Invoice, "a new invoice" do
34
34
  it "should create a doc" do
35
35
  doc = SKApi::Resources::Invoice.new()
36
36
  doc.title = 'A Document from the API'
37
+ doc.notes_before = 'Your shiny new invoice [number]'
38
+ doc.notes_after = 'Please pay me'
37
39
  doc.client_id = @client.id
38
40
  doc.save
39
41
  doc.errors.should be_empty
40
42
  doc.new?.should be_false
43
+ doc.notes_before.should == 'Your shiny new invoice [number]'
44
+ doc.destroy
45
+ end
46
+
47
+ it "should create a doc with default before after texts" do
48
+ doc = SKApi::Resources::Invoice.new()
49
+ doc.title = 'A Document from the API'
50
+ doc.client_id = @client.id
51
+ doc.save
52
+ doc.errors.should be_empty
53
+ doc.new?.should be_false
54
+ doc.notes_before.should_not be_empty
41
55
  doc.destroy
42
56
  end
43
57
 
@@ -59,6 +73,7 @@ describe SKApi::Resources::Invoice, "Edit an invoice" do
59
73
  @client.save.should be_true
60
74
  @doc = SKApi::Resources::Invoice.new()
61
75
  @doc.title = 'A Document from the API'
76
+ @doc.notes_before = 'Your invoice [number]'
62
77
  @doc.client_id = @client.id
63
78
  @doc.save.should be_true
64
79
  end
@@ -69,12 +84,14 @@ describe SKApi::Resources::Invoice, "Edit an invoice" do
69
84
 
70
85
  it "should edit a doc" do
71
86
  old_lock_version = @doc.lock_version
87
+ @doc.notes_before.should == 'Your invoice [number]'
72
88
  @doc.notes_before = 'You will recieve the amout of:'
73
- @doc.notes_before = 'Payment made to you bank Account'
89
+ @doc.notes_after = 'Payment made to you bank Account'
74
90
  @doc.title = 'Changed doc title'
75
91
 
76
92
  @doc.save.should be_true
77
93
  @doc.lock_version.should > old_lock_version # because save returns the data
94
+ @doc.notes_before.should == 'You will recieve the amout of:'
78
95
  end
79
96
 
80
97
  it "should fail edit without a client" do
@@ -92,7 +109,7 @@ describe SKApi::Resources::Invoice, "with line items" do
92
109
  @client.save.should be_true
93
110
  #setup test doc to work with
94
111
  @doc = SKApi::Resources::Invoice.new(:client_id => @client.id,
95
- :line_items => [{ :position=>1, :description => 'Pork Chops', :quantity => 12, :price_single =>'10.00' }] )
112
+ :line_items => [{ :position=>1, :description => 'Pork Chops', :quantity => 12, :price_single =>'10.00' }] )
96
113
  @doc.save.should be_true
97
114
  end
98
115
 
@@ -126,54 +143,3 @@ describe SKApi::Resources::Invoice, "with line items" do
126
143
  end
127
144
 
128
145
  end
129
- =begin
130
- describe SKApi::Resources::Invoice, "with line items" do
131
-
132
- before :all do
133
- @client = SKApi::Resources::Client.new(:organisation=>'Credit Note API-Tester')
134
- @client.save.should be_true
135
- #setup test doc to work with
136
- @doc = SKApi::Resources::Invoice.new(:client_id => @client.id,
137
- :line_items => [{ :position=>1, :description => 'Pork Chops', :quantity => 12, :price_single =>'10.00' }] )
138
- @doc.save.should be_true
139
- end
140
-
141
- after :all do
142
- delete_test_data(@doc, @client)
143
- end
144
-
145
- it "should create a line item" do
146
- @doc.line_items.length.should == 1
147
- @doc.line_items.first.description.should == 'Pork Chops'
148
- @doc.price_total.should == 120.0
149
- end
150
-
151
- it "should edit line item" do
152
- @doc.line_items[0].description = 'Egg Sandwich'
153
- @doc.save
154
- @doc.line_items.length.should == 1
155
- @doc.line_items.first.description.should == 'Egg Sandwich'
156
- end
157
-
158
- it "should add line item" do
159
- item = SKApi::Resources::LineItem.new( { :position=>2, :description => 'Goat-Pie', :price_single => 10, :quantity=>10} )
160
- product = SKApi::Resources::Product.new(:name=>'Eis am Stiel', :price => 1.50, :tax=>19, :description => 'Mmmhh lecker Eis')
161
- product.save.should be_true
162
- item1 = SKApi::Resources::LineItem.new( { :position=>3, :use_product => 1, :quantity => 10 } )
163
- @doc.line_items << item
164
- @doc.line_items << item1
165
- @doc.save
166
- @doc.line_items.length.should == 3
167
- @doc.price_total.should == 220.0
168
- end
169
-
170
- xit "should add line item and use product information" do
171
-
172
- @doc.line_items << item
173
- @doc.save
174
- @doc.line_items.length.should == 3
175
- @doc.price_total.should == 15.0
176
-
177
- product.destroy
178
- end
179
- =end
@@ -1,4 +1,4 @@
1
- require "#{File.dirname(__FILE__)}/../spec_helper"
1
+ require 'spec/spec_helper'
2
2
 
3
3
  describe SKApi::Resources::Product, "in general" do
4
4
 
@@ -29,11 +29,10 @@ describe SKApi::Resources::Product, "in general" do
29
29
  product.errors.full_messages.should == ["Name can't be blank"]
30
30
  end
31
31
 
32
- it "should create a product with price 0.0 when price is missing" do
32
+ it "should fail create a product without price" do
33
33
  product = SKApi::Resources::Product.new(:name => 'No brain')
34
- product.save
35
- # product.save.should == false
36
- product.price.should == 0.0
34
+ product.save.should == false
35
+ product.errors.full_messages.should == ["Price can't be blank"]
37
36
  end
38
37
 
39
38
  it "should find a product by id" do
@@ -59,9 +58,9 @@ describe SKApi::Resources::Product, "in general" do
59
58
  product = SKApi::Resources::Product.find(@product.id)
60
59
  # convert to json and read raw without activeresource assigning classes
61
60
  json = product.to_json
62
- obj = Rufus::Json.decode(json)
61
+ obj = ActiveSupport::JSON.decode(json)
63
62
  lambda {
64
- JSON::Schema.validate(obj, SKApi::Resources::Product.schema)
63
+ JSON::Schema.validate(obj['product'], SKApi::Resources::Product.schema)
65
64
  }.should_not raise_error
66
65
  end
67
66
 
@@ -69,7 +68,6 @@ describe SKApi::Resources::Product, "in general" do
69
68
  product = SKApi::Resources::Product.find(@product.id)
70
69
  # convert to json and read raw without activeresource assigning classes
71
70
  hash_obj = SKApi::Resources::Product.to_hash_from_schema(product)
72
- # hash_obj.should == ''
73
71
  lambda {
74
72
  JSON::Schema.validate(hash_obj['product'], SKApi::Resources::Product.schema)
75
73
  }.should_not raise_error
data/spec/spec_helper.rb CHANGED
@@ -3,6 +3,7 @@ require 'spec'
3
3
  require "#{File.dirname(__FILE__)}/../lib/sk_api"
4
4
  require File.dirname(__FILE__) + '/../vendor/jsonschema-1.0.0/lib/jsonschema'
5
5
 
6
+ puts "Testing with ActiveResource Version: #{ActiveResource::VERSION::STRING}. Make sure this matches the version in your app. .. Yes this sucks!"
6
7
 
7
8
  def delete_test_data(doc, client)
8
9
  doc.destroy
@@ -1,4 +1,4 @@
1
- require "#{File.dirname(__FILE__)}/../spec_helper"
1
+ require 'spec/spec_helper'
2
2
 
3
3
  describe SKApi::Utils::FieldMap do
4
4