Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure that Validation.type returns correct value #66

Merged
merged 2 commits into from
Aug 26, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Change Log
=======

## Master
### Fixed
* Ensure that `Validation.type` returns correct value [#59](https://github.com/contentful/contentful-management.rb/issues/59), [#66](https://github.com/contentful/contentful-management.rb/issues/66)


## 0.7.1
### Fixed
* `fields_for_query` should only skip `nil` values [#63](https://github.com/contentful/contentful-management.rb/issues/63), [#64](https://github.com/contentful/contentful-management.rb/pull/64)
Expand Down
5 changes: 3 additions & 2 deletions lib/contentful/management/validation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ def properties_to_hash

# Returns type of validation
def type
properties.keys.each do |type|
return type if !self.send(Support.snakify(type)).nil?
properties.keys.reject { |key| key == :validations }.each do |type|
value = self.send(Support.snakify(type))
return type if !value.nil? && value
end
end

Expand Down
7 changes: 7 additions & 0 deletions spec/lib/contentful/management/content_type_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,7 @@ module Management
content_type.fields.create(id: 'valid', name: 'Valid', type: 'Text', validations: [validation_size])
expect(content_type.fields[2].validations.last.properties[:size]['min']).to eq 10
expect(content_type.fields[2].validations.last.properties[:size]['max']).to eq 15
expect(content_type.fields[2].validations.last.type).to be :size
end
end
end
Expand All @@ -591,6 +592,7 @@ module Management
content_type.fields.create(id: 'number', name: 'Number', type: 'Number', validations: [validation_range])
expect(content_type.fields.first.validations.first.properties[:range]['min']).to eq 30
expect(content_type.fields.first.validations.first.properties[:range]['max']).to eq 100
expect(content_type.fields.first.validations.first.type).to be :range
end
end
it 'change `range` validation to existing field' do
Expand All @@ -613,6 +615,7 @@ module Management
validation_present.present = true
content_type.fields.create(id: 'present', name: 'Present', type: 'Text', validations: [validation_present])
expect(content_type.fields.last.validations.last.properties[:present]).to be_truthy
expect(content_type.fields.last.validations.last.type).to be :present
end
end
end
Expand All @@ -625,6 +628,7 @@ module Management
content_type.fields.create(id: 'text', name: 'Text', type: 'Text', validations: [validation_regexp])
expect(content_type.fields.last.validations.first.properties[:regexp]['pattern']).to eq '^such'
expect(content_type.fields.last.validations.first.properties[:regexp]['flags']).to eq 'im'
expect(content_type.fields.last.validations.first.type).to eq :regexp
end
end
end
Expand All @@ -636,6 +640,7 @@ module Management
validation_link_content_type.link_content_type = ['post_content_type']
content_type.fields.create(id: 'entries', validations: [validation_link_content_type])
expect(content_type.fields[1].validations.first.properties[:linkContentType]).to eq %w( post_content_type )
expect(content_type.fields[1].validations.first.type).to be :linkContentType
end
end
end
Expand All @@ -647,6 +652,7 @@ module Management
validation_link_mimetype_group.link_mimetype_group = 'image'
content_type.fields.create(id: 'entries', validations: [validation_link_mimetype_group])
expect(content_type.fields[1].validations.first.properties[:linkMimetypeGroup]).to eq 'image'
expect(content_type.fields[1].validations.first.type).to be :linkMimetypeGroup
end
end
end
Expand All @@ -658,6 +664,7 @@ module Management
validation_link_mimetype_group.link_field = true
content_type.fields.create(id: 'link_field', validations: [validation_link_mimetype_group])
expect(content_type.fields.last.validations.first.properties[:linkField]).to be_truthy
expect(content_type.fields.last.validations.first.type).to be :linkField
end
end
end
Expand Down