Skip to content

Commit

Permalink
Merge pull request praxis#171 from rightscale/292_missing_example_for…
Browse files Browse the repository at this point in the history
…_collections

Include full example for Collections
  • Loading branch information
blanquer committed May 25, 2016
2 parents e8fadd1 + 9965b21 commit 132fdfa
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/attributor/types/collection.rb
Expand Up @@ -108,7 +108,10 @@ def self.dump(values, **opts)
def self.describe(shallow = false, example: nil)
hash = super(shallow)
hash[:options] = {} unless hash[:options]
member_example = example.first if example
if example
hash[:example] = example
member_example = example.first
end
hash[:member_attribute] = member_attribute.describe(true, example: member_example)
hash
end
Expand Down
5 changes: 5 additions & 0 deletions spec/types/collection_spec.rb
Expand Up @@ -312,6 +312,7 @@
subject(:described) { type.describe(example: example) }
it 'includes the member_attribute' do
expect(described).to have_key(:member_attribute)
expect(described).not_to have_key(:example)
expect(described[:member_attribute]).not_to have_key(:example)
end

Expand All @@ -322,6 +323,10 @@
expect(described[:member_attribute]).to have_key(:example)
expect(described[:member_attribute]).to eq(type.member_attribute.describe(example: example.first))
end
it 'includes the incoming example for the whole collection as well' do
expect(described).to have_key(:example)
expect(described[:example]).to eq(example)
end
end
end

Expand Down

0 comments on commit 132fdfa

Please sign in to comment.