Skip to content

Commit

Permalink
add collection.template.data[n].options because duh.
Browse files Browse the repository at this point in the history
This is not canon but we need it to move forward.

Yes, this means you could do collection.items[n].data[y].options. Don't do that.

hat tip: http://schinckel.net/2012/03/10/collection%2Bjson-primer-%28and-comments%29/

reference: mamund/collection-json#6
  • Loading branch information
mustmodify committed Dec 4, 2013
1 parent 5cf559c commit 5ff4eb1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/collection-json/attributes/data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,9 @@ class Data < Attribute
attribute :name
attribute :value
attribute :prompt
attribute :options,
transform: lambda { |data| data.each.map { |d| Data.from_hash(d) }},
default: [],
find_method: {method_name: :datum, key: 'name'}
end
end
17 changes: 17 additions & 0 deletions spec/collection-json_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,23 @@
response.queries.first.data.first.name.should eq('search')
response.query('search').prompt.should eq('Search')
end

it 'includes the unapproved but totally necessary "options" attribute on data.' do
CollectionJSON.generate_for('/friends/') do |api|
api.set_template do |api|
api.add_data "force-side", options: [
{
value: 'dark',
prompt: 'Dark Side'
},
{
value: 'light',
prompt: 'Light Side'
}
]
end
end.to_json.should == %|{"collection":{"href":"/friends/","template":{"data":[{"name":"force-side","options":[{"value":"dark","prompt":"Dark Side"},{"value":"light","prompt":"Light Side"}]}]}}}|
end
end

describe :parse do
Expand Down

0 comments on commit 5ff4eb1

Please sign in to comment.