sk-api 1.0.3 → 1.0.4

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.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.3
1
+ 1.0.4
@@ -20,25 +20,14 @@ module ActiveResource
20
20
  end
21
21
  end
22
22
 
23
- # Ooverridden to grab the data(clients- collection) from json:
23
+ # Ooverridden to grab the data(= clients-collection) from json:
24
24
  # { 'collection'=> will_paginate infos,
25
25
  # 'links' => prev/next links
26
- # >> 'clients'=> [data], <<
26
+ # 'clients'=> [data], << what we need
27
27
  # }
28
28
  def self.instantiate_collection(collection, prefix_options = {})
29
29
  collection = collection[ self.element_name.pluralize ] if collection.is_a?(Hash)
30
30
  collection.collect! { |record| instantiate_record(record, prefix_options) }
31
31
  end
32
32
  end
33
- end
34
-
35
- # Force json decoding using Rufus
36
- module ActiveResource
37
- module Formats
38
- module JsonFormat
39
- def decode(json)
40
- Rufus::Json.decode(json)
41
- end
42
- end
43
- end
44
33
  end
@@ -13,10 +13,10 @@ module SKApi
13
13
 
14
14
  # Define the connection to be used when talking to a salesking server
15
15
  def self.set_connection(opts)
16
- self.site = opts[:site] #"http://demo.salesking.local:3000/api/"
17
- self.user = opts[:user] # "demo@salesking.eu"
18
- self.password = opts[:password] #"demo"
19
- self.format = opts[:format].to_sym #:json
16
+ self.site = opts[:site]
17
+ self.user = opts[:user]
18
+ self.password = opts[:password]
19
+ self.format = opts[:format].to_sym
20
20
  end
21
21
 
22
22
  end
@@ -6,13 +6,6 @@ module SKApi
6
6
  save_with_validation
7
7
  end
8
8
 
9
- # not realy stable yet
10
- def validate_schema
11
- json = self.to_json
12
- obj = Rufus::Json.decode(json)
13
- JSON::Schema.validate(obj, SKApi::Resources::Client.schema)
14
- end
15
-
16
9
  def self.schema
17
10
  { "type" => "object",
18
11
  "properties" => SKApi::Resources::Client.schema_props}
@@ -12,7 +12,7 @@ module SKApi
12
12
  end
13
13
 
14
14
  def self.schema_props
15
- {
15
+ {
16
16
  "id" => {"type" => "string", "identity" => true , "readonly" => true},
17
17
  "position" => {"type" => "integer"},
18
18
  "product_id" => {"type" => "string", "optional" => true},
@@ -23,9 +23,10 @@ module SKApi
23
23
  "price_single" => {"type" => "number"},
24
24
  "discount" => {"type" => "number", "optional" => true},
25
25
  "tax" => {"type" => "number", "optional" => true},
26
+ "use_product" => {"type" => "boolean", "optional" => true},
26
27
  "created_at" => {"type" => "string", "format" =>"date-time", "optional" => true, "readonly" => true},
27
28
  "updated_at" => {"type" => "string", "format" =>"date-time", "optional" => true, "readonly" => true}
28
- }
29
+ }
29
30
  end
30
31
  end
31
32
  end
@@ -23,8 +23,8 @@ module SKApi
23
23
  "tag_list" => {"type" => "string", "optional" => true},
24
24
  "lock_version" => {"type" => "integer", "readonly" => true, "optional" => true},
25
25
  "published_at" => {"type" => "string", "format" =>"date", "optional" => true},
26
- "created_at" => {"type" => "string", "format" =>"date-time", "optional" => true, "readonly" => true},
27
- "updated_at" => {"type" => "string", "format" =>"date-time", "optional" => true, "readonly" => true},
26
+ "created_at" => {"type" => "string", "format" =>"date-time", "optional" => true, "readonly" => true },
27
+ "updated_at" => {"type" => "string", "format" =>"date-time", "optional" => true, "readonly" => true },
28
28
  }
29
29
  end #schema_props
30
30
 
@@ -3,36 +3,42 @@ require "#{File.dirname(__FILE__)}/../spec_helper"
3
3
  describe SKApi::Resources::Invoice, "in general" do
4
4
 
5
5
  before :all do
6
- #setup test doc to work with
7
- # create client
8
6
  @client = SKApi::Resources::Client.new(:organisation=>'Invoice API-Tester')
9
7
  @client.save.should be_true
10
- # @doc = SKApi::Resources::Invoice.new()
11
- @doc = SKApi::Resources::Invoice.new(:client_id => @client.id,
12
- :line_items => [{ :position=>1, :description => 'Pork Chops', :quantity => 12, :price_single =>'10.00' }] )
13
- @doc.save.should be_true
14
- # @doc.title = 'A Document from the API'
15
- # @doc.client_id = @client.id
16
- # @doc.save
17
- # @doc.errors.full_messages.should == 'adfd'
8
+ @doc = SKApi::Resources::Invoice.new()
9
+ @doc.title = 'A Document from the API'
10
+ @doc.client_id = @client.id
18
11
  @doc.save.should be_true
19
12
  end
20
13
 
21
14
  after :all do
22
- #delete test doc
23
- @doc.destroy
15
+ delete_test_data(@doc, @client)
16
+ end
17
+
18
+ it "should find a doc" do
19
+ doc = SKApi::Resources::Invoice.find(@doc.id)
20
+ doc.title.should == @doc.title
21
+ end
22
+ end
23
+
24
+ describe SKApi::Resources::Invoice, "a new invoice" do
25
+
26
+ before :all do
27
+ @client = SKApi::Resources::Client.new(:organisation=>'Invoice API-Tester')
28
+ @client.save.should be_true
29
+ end
30
+ after :all do
24
31
  @client.destroy
25
- lambda {
26
- doc = SKApi::Resources::Invoice.find(@doc.id)
27
- }.should raise_error(ActiveResource::ResourceNotFound)
28
- lambda {
29
- client = SKApi::Resources::Client.find(@client.id)
30
- }.should raise_error(ActiveResource::ResourceNotFound)
31
32
  end
32
33
 
33
34
  it "should create a doc" do
34
- @doc.errors.should be_empty
35
- @doc.new?.should be_false
35
+ doc = SKApi::Resources::Invoice.new()
36
+ doc.title = 'A Document from the API'
37
+ doc.client_id = @client.id
38
+ doc.save
39
+ doc.errors.should be_empty
40
+ doc.new?.should be_false
41
+ doc.destroy
36
42
  end
37
43
 
38
44
  it "should fail create a doc" do
@@ -42,34 +48,36 @@ describe SKApi::Resources::Invoice, "in general" do
42
48
  doc.errors.on(:client_id).should == "can't be blank"
43
49
  end
44
50
 
45
- it "should find a doc" do
46
- doc = SKApi::Resources::Invoice.find(@doc.id)
47
- doc.title.should == @doc.title
51
+ end
52
+
53
+ describe SKApi::Resources::Invoice, "Edit an invoice" do
54
+
55
+ before :all do
56
+ #setup test doc to work with
57
+ # create client
58
+ @client = SKApi::Resources::Client.new(:organisation=>'Invoice API-Tester')
59
+ @client.save.should be_true
60
+ @doc = SKApi::Resources::Invoice.new()
61
+ @doc.title = 'A Document from the API'
62
+ @doc.client_id = @client.id
63
+ @doc.save.should be_true
48
64
  end
49
65
 
50
- it "should validate raw json object with schema" do
51
- doc = SKApi::Resources::Invoice.find(@doc.id)
52
- # doc.number.should=='23'
53
- # convert to json and read raw without activeresource assigning classes
54
- json = doc.to_json
55
- obj = Rufus::Json.decode(json)
56
- lambda {
57
- JSON::Schema.validate(obj, SKApi::Resources::Invoice.schema)
58
- }.should_not raise_error
66
+ after :all do
67
+ delete_test_data(@doc, @client)
59
68
  end
60
69
 
61
70
  it "should edit a doc" do
62
- # @doc.lock_version.should == 0 # dont work cause doc is saved twice, for recalc of totals
63
71
  old_lock_version = @doc.lock_version
64
72
  @doc.notes_before = 'You will recieve the amout of:'
65
73
  @doc.notes_before = 'Payment made to you bank Account'
66
74
  @doc.title = 'Changed doc title'
67
-
75
+
68
76
  @doc.save.should be_true
69
77
  @doc.lock_version.should > old_lock_version # because save returns the data
70
78
  end
71
79
 
72
- it "should fail edit a doc" do
80
+ it "should fail edit without a client" do
73
81
  @doc.client_id = ''
74
82
  @doc.save.should == false
75
83
  @doc.errors.count.should == 1
@@ -89,11 +97,7 @@ describe SKApi::Resources::Invoice, "with line items" do
89
97
  end
90
98
 
91
99
  after :all do
92
- @client.destroy #also destroys all docs
93
- # @doc.destroy
94
- lambda {
95
- doc = SKApi::Resources::Invoice.find(@doc.id)
96
- }.should raise_error(ActiveResource::ResourceNotFound)
100
+ delete_test_data(@doc, @client)
97
101
  end
98
102
 
99
103
  it "should create a line item" do
@@ -115,7 +119,5 @@ describe SKApi::Resources::Invoice, "with line items" do
115
119
  @doc.save
116
120
  @doc.line_items.length.should == 2
117
121
  @doc.price_total.should == 220.0
118
- # @doc.line_items[0].zip = '40001'
119
- # @doc.line_items.[1].zip.should == '40001'
120
122
  end
121
- end
123
+ end
data/spec/spec_helper.rb CHANGED
@@ -2,11 +2,23 @@ require 'rubygems'
2
2
  require 'spec'
3
3
  require "#{File.dirname(__FILE__)}/../lib/sk_api"
4
4
 
5
- ##
5
+
6
+ def delete_test_data(doc, client)
7
+ doc.destroy
8
+ client.destroy
9
+ lambda {
10
+ doc = SKApi::Resources::Invoice.find(doc.id)
11
+ }.should raise_error(ActiveResource::ResourceNotFound)
12
+ lambda {
13
+ client = SKApi::Resources::Client.find(client.id)
14
+ }.should raise_error(ActiveResource::ResourceNotFound)
15
+ end
16
+
6
17
  SKApi::CONNECTION = {
7
18
  :site => "http://demo.salesking.local:3000/api/",
8
19
  :user => "demo@salesking.eu",
9
20
  :password => "demo",
10
21
  :format => :json
11
22
  } unless defined?(SKApi::CONNECTION)
12
- SKApi::Resources::Base.set_connection(SKApi::CONNECTION)
23
+ SKApi::Resources::Base.set_connection(SKApi::CONNECTION)
24
+
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 1
7
7
  - 0
8
- - 3
9
- version: 1.0.3
8
+ - 4
9
+ version: 1.0.4
10
10
  platform: ruby
11
11
  authors:
12
12
  - Georg Leciejewski
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-03-06 00:00:00 +01:00
17
+ date: 2010-03-07 00:00:00 +01:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency