service_contract 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c9da1cdc017268f0fc828d1e33277639fccbecf8
4
- data.tar.gz: 29be99f6911a39ec5f4d0deeaae962a46e3e29d4
3
+ metadata.gz: 3ece676fe679b6486a503e341a6b566b67e19cbd
4
+ data.tar.gz: 54a78577a17d36b8b3541185aeede59dcb2b32f0
5
5
  SHA512:
6
- metadata.gz: 7ef421e78853b1643c38562efbcb79701f5eb287ec3dd0a77a310275ea3f24305bbeb3f75373f6440d3f563d13be222f96981f2988c13ab2498280d1cba65e55
7
- data.tar.gz: 3088c10ee0e92b76a31de3fe12d973839e3aa04807125bf302791bc5347beb65730c6f91e292c4823207a9e2c84b6863e93d41de4839fb73ee5a2cf06e0c2f56
6
+ metadata.gz: 29275de62be450eab48f0d59a2e620e922db90d71747a63bb4129d361ed416b6a6136f2854ddb72198a3c246b922f25491325de2fc942b449196c1fffd0b9a07
7
+ data.tar.gz: fc9814bb7a0615a27c8cc4210c87eca4bc371381efd93af0c4d6379b35d8258eb8177004acfdbbca004a39610506fa37e439e95c72c5bd7481a49fb6f733b1a9
@@ -16,6 +16,10 @@ module ServiceContract
16
16
  # type should have fields
17
17
  type.fields.each do |field|
18
18
 
19
+ #Does data contain attributes that the contract doesn't specify?
20
+ data_extra_attrs = (data.keys.map(&:to_sym) - type.fields.map{|n| n.name.to_sym})
21
+ assert_equal 0, data_extra_attrs.size, "#{type.name} contains attributes not described in contract: #{data_extra_attrs.join(',')}"
22
+
19
23
  # ensure the field is present
20
24
  value = data.fetch(field.name) do
21
25
  data.fetch(field.name.to_sym) do
@@ -25,6 +25,11 @@ module ServiceContract
25
25
  protected
26
26
 
27
27
  def request_method
28
+ #Check for [<METHOD>] at the front of the doc string. this signals an action override
29
+ if doc =~ /^\[([A-Z]+)\].+$/
30
+ return $1
31
+ end
32
+
28
33
  case name
29
34
  when "create"
30
35
  "POST"
@@ -1,3 +1,3 @@
1
1
  module ServiceContract
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -58,4 +58,24 @@ class AssertionsTest < Minitest::Test
58
58
  assert_endpoint_response([{customer_id: [1,2,3]}], endpoint)
59
59
  end
60
60
 
61
+ def test_uncontracted_data_not_matching
62
+ service = SampleService.find(2)
63
+ assert service, "expect to find a service by version"
64
+
65
+ protocol = service.protocol("search_param")
66
+ endpoint = protocol.endpoint("index")
67
+
68
+ # test can be nil
69
+ failure_data = nil
70
+ begin
71
+ assert_endpoint_response([{customer_id: nil, bogus_param: 1}], endpoint)
72
+ rescue Minitest::Assertion => failure
73
+ failure_data = failure
74
+ end
75
+
76
+ assert !failure_data.nil?
77
+ assert failure_data.to_s.include?("not described in contract: bogus_param")
78
+
79
+ end
80
+
61
81
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: service_contract
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Ching
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-22 00:00:00.000000000 Z
11
+ date: 2015-02-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: avro