service_contract 0.0.6 → 0.0.7

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: d38c280ba7b06845cf4c85d8520c57182697a22a
4
- data.tar.gz: 847f9a80067c2dd0fcbd0794eef9ddc9718c9963
3
+ metadata.gz: ee4858e3b13b2a6f81dcec74ed7fe5bf0844bd1e
4
+ data.tar.gz: f96f3c732a2fb5ecab8268cfda2a2e86048d7431
5
5
  SHA512:
6
- metadata.gz: 1783066a056427df7822e5c0f2786b8db8b325771ad5a46bcf9b7f75e2f768e6dd26405bb73c856e7888dd7116987675475e78f121f996265cc6c5d353ad7d70
7
- data.tar.gz: 2200d948b56253ba75e8205b7c9584887228bd6609515b1d868056e89b997d7a7116c89e01b091ba71a69956f7fb47e21e1f47e5024a12f670a73e49e34933b8
6
+ metadata.gz: 823d6d06c37ad5dbb1c876e537f874910ffa0a8f98bfa5eb8a9090d9bcb4e94b9618158b51a21dfb2205e61317bd9caced1a7203ee74ee864443d504f72dedc7
7
+ data.tar.gz: 3f5e6cca2da6c3fefa541290d17a7877468b52fb9b28bcb51ce6300c9c4ed23aa3a2d745b0b0c7856c34ac097fa2aaa5bce58e7329ce24b89310eb18709e05d3
data/Rakefile CHANGED
@@ -9,5 +9,6 @@ Rake::TestTask.new(:test) do |t|
9
9
  t.verbose = false
10
10
  end
11
11
 
12
+ require 'service_contract/tasks'
12
13
 
13
- task default: :test
14
+ task default: :test
@@ -8,6 +8,10 @@ module ServiceContract
8
8
  raise :not_implemented
9
9
  end
10
10
 
11
+ def subtype
12
+ nil
13
+ end
14
+
11
15
  def default
12
16
  nil
13
17
  end
@@ -13,11 +13,20 @@ module ServiceContract
13
13
  end
14
14
  else
15
15
  type.fields.each do |field|
16
- assert data.has_key?(field.name), "expected #{type.name} to have attribute: #{field.name}"
17
- value = data.fetch(field.name)
16
+ value = data.fetch(field.name) do
17
+ data.fetch(field.name.to_sym) do
18
+ assert false, "expected #{type.name} to have attribute: #{field.name}"
19
+ end
20
+ end
18
21
 
19
22
  expected_classes = classes_for_parameter(field)
20
23
  assert (allow_nil && value.nil?) || expected_classes.any?{|klass| value.is_a?(klass)}, "expected #{type.name}.#{field.name} to be a #{expected_classes.join(", ")}"
24
+
25
+ if field.type == "array"
26
+ value.each do |val|
27
+ assert_data_matches_type(val, field.subtype)
28
+ end
29
+ end
21
30
  end
22
31
  end
23
32
  end
@@ -25,7 +34,11 @@ module ServiceContract
25
34
  protected
26
35
 
27
36
  def classes_for_parameter(field)
28
- classes = case field.type
37
+ type = field.type
38
+ type = type.type_sym.to_s if type.respond_to?(:type_sym)
39
+ classes = case type
40
+ when "array"
41
+ Array
29
42
  when "int"
30
43
  Fixnum
31
44
  when "string"
@@ -11,6 +11,17 @@ module ServiceContract
11
11
  definition.type.type_sym.to_s
12
12
  end
13
13
 
14
+ def subtype
15
+ item = definition.type.is_a?(::Avro::Schema::ArraySchema) ?
16
+ definition.type.items :
17
+ nil
18
+ return nil unless item
19
+
20
+ item.is_a?(::Avro::Schema::PrimitiveSchema) ?
21
+ item.type_sym.to_s :
22
+ item
23
+ end
24
+
14
25
  def default
15
26
  definition.default
16
27
  end
@@ -1,3 +1,3 @@
1
1
  module ServiceContract
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
@@ -0,0 +1,40 @@
1
+ require 'test_helper'
2
+
3
+ class AssertionsTest < Minitest::Test
4
+ include ServiceContract::Assertions
5
+
6
+ def test_data_matching
7
+ service = SampleService.find(1)
8
+ assert service, "expect to find a service by version"
9
+ assert_equal "1", service.version
10
+
11
+ assert_equal 2, service.protocols.length
12
+ protocol = service.protocol("location")
13
+ endpoint = protocol.endpoint("index")
14
+
15
+ data = [{
16
+ id: 1,
17
+ type: 'state',
18
+ county_name: nil,
19
+ state_name: 'Washington',
20
+ country_name: 'United States',
21
+ city_name: nil,
22
+ neighborhood_name: nil,
23
+ postal_code_name: nil,
24
+ latitude: 47.6097,
25
+ longitude: 122.3331,
26
+ population: 634_535,
27
+ foo: [
28
+ {
29
+ timestamp: 1410278741
30
+ }
31
+ ],
32
+ updated_at: {
33
+ timestamp: 1410278741
34
+ }
35
+ }]
36
+
37
+ assert_endpoint_response(data, endpoint)
38
+ end
39
+
40
+ end
@@ -37,18 +37,6 @@
37
37
  }, {
38
38
  "name" : "postal_code_name",
39
39
  "type" : "string"
40
- }, {
41
- "name" : "to_location",
42
- "type" : "string"
43
- }, {
44
- "name" : "to_short_location",
45
- "type" : "string"
46
- }, {
47
- "name" : "to_long_location",
48
- "type" : "string"
49
- }, {
50
- "name" : "to_location_with_region",
51
- "type" : "string"
52
40
  }, {
53
41
  "name" : "latitude",
54
42
  "type" : "float"
@@ -58,6 +46,12 @@
58
46
  }, {
59
47
  "name" : "population",
60
48
  "type" : "int"
49
+ }, {
50
+ "name" : "foo",
51
+ "type" : {
52
+ "type" : "array",
53
+ "items" : "Timestamp"
54
+ }
61
55
  }, {
62
56
  "name" : "updated_at",
63
57
  "type" : "Timestamp"
@@ -17,13 +17,10 @@ protocol Location {
17
17
  string city_name;
18
18
  string neighborhood_name;
19
19
  string postal_code_name;
20
- string to_location;
21
- string to_short_location;
22
- string to_long_location;
23
- string to_location_with_region;
24
20
  float latitude;
25
21
  float longitude;
26
22
  int population;
23
+ array<Timestamp> foo;
27
24
  Timestamp updated_at;
28
25
  }
29
26
 
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.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Ching
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-03 00:00:00.000000000 Z
11
+ date: 2014-09-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: avro
@@ -104,6 +104,7 @@ files:
104
104
  - lib/service_contract/version.rb
105
105
  - service_contract.gemspec
106
106
  - src/avro-tools-1.7.7.jar
107
+ - test/assertions_test.rb
107
108
  - test/sample/1/compiled/location.avpr
108
109
  - test/sample/1/compiled/sales_region.avpr
109
110
  - test/sample/1/source/location.avdl
@@ -135,6 +136,7 @@ signing_key:
135
136
  specification_version: 4
136
137
  summary: Abstract the definition of a service's interface contract
137
138
  test_files:
139
+ - test/assertions_test.rb
138
140
  - test/sample/1/compiled/location.avpr
139
141
  - test/sample/1/compiled/sales_region.avpr
140
142
  - test/sample/1/source/location.avdl