Permalink
Browse files

Merge pull request #38 from seomoz/fix-37

Fix 37
  • Loading branch information...
2 parents ebe6310 + 54395e8 commit 7aad75dd9008947343f4cc9fddb7e50601caa25c @myronmarston myronmarston committed Dec 2, 2013
Showing with 31 additions and 3 deletions.
  1. +3 −0 .travis.yml
  2. +4 −1 lib/interpol/endpoint.rb
  3. +24 −2 spec/unit/interpol/endpoint_spec.rb
View
@@ -8,4 +8,7 @@ rvm:
- 2.0.0
- jruby-19mode
- rbx-19mode
+matrix:
+ allow_failures:
+ - rvm: rbx-19mode
@@ -279,7 +279,10 @@ def conditionally_make_nullable(raw_schema)
types = Array(raw_schema['type'])
return if types.none? || types.include?('null')
- raw_schema['type'] = (types << "null")
+ # Mark as non-nullable so it doesn't try to recurse down into it
+ # and make it nullable at that level (since we are taking care of it at this level)
+ sub_schema = raw_schema.merge('nullable' => false)
+ raw_schema.replace('type' => ['null', sub_schema])
end
def should_be_nullable?(raw_schema)
@@ -420,6 +420,28 @@ def new_with(hash)
expect { subject.validate_data!('foo' => nil) }.not_to raise_error
end
+ it 'works with enums' do
+ schema['properties']['foo'] = {
+ 'type' => 'string',
+ 'enum' => %w[ A B C D F ]
+ }
+
+ expect { subject.validate_data!('foo' => nil) }.not_to raise_error
+ expect { subject.validate_data!('foo' => 'A') }.not_to raise_error
+ expect { subject.validate_data!('foo' => 'F') }.not_to raise_error
+ expect { subject.validate_data!('foo' => 'E') }.to raise_error(ValidationError)
+ end
+
+ it 'allows enums to be non-nullable' do
+ schema['properties']['foo'] = {
+ 'nullable' => false,
+ 'type' => 'string',
+ 'enum' => %w[ A B C D F ]
+ }
+
+ expect { subject.validate_data!('foo' => nil) }.to raise_error(ValidationError)
+ end
+
it 'does not add an extra `null` entry to an existing nullable union type' do
schema['properties']['foo']['type'] = %w[ integer null ]
@@ -820,7 +842,7 @@ def new_with(hash)
ex.data["array"] << 0
end
- modified_example = example.apply_filters([filter], request_env)
+ example.apply_filters([filter], request_env)
expect(example.data).to eq(data_2)
end
@@ -834,7 +856,7 @@ def new_with(hash)
ex.data << 0
end
- modified_example = example.apply_filters([filter], request_env)
+ example.apply_filters([filter], request_env)
expect(example.data).to eq(data_2)
end

0 comments on commit 7aad75d

Please sign in to comment.