diff --git a/lib/collection-json/attributes/data.rb b/lib/collection-json/attributes/data.rb index 8ee1ad4..e8e925e 100644 --- a/lib/collection-json/attributes/data.rb +++ b/lib/collection-json/attributes/data.rb @@ -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 diff --git a/spec/collection-json_spec.rb b/spec/collection-json_spec.rb index 37dc252..7e60b2b 100644 --- a/spec/collection-json_spec.rb +++ b/spec/collection-json_spec.rb @@ -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