diff --git a/Gemfile b/Gemfile index 0719b74..f70afb8 100644 --- a/Gemfile +++ b/Gemfile @@ -8,6 +8,8 @@ gem 'haml', '~> 3.1' gem 'bcrypt-ruby', '~> 3.0' +gem 'rabl', '~> 0.6' + group :development, :test do gem 'rspec-rails', '~> 2.6' gem 'capybara', '~> 1.1' diff --git a/Gemfile.lock b/Gemfile.lock index 6068337..d84cc65 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -70,6 +70,9 @@ GEM nokogiri (1.5.0) pg (0.11.0) polyglot (0.3.3) + rabl (0.6.0) + activesupport (>= 2.3.14) + multi_json (~> 1.0.3) rack (1.3.5) rack-cache (1.1) rack (>= 0.4) @@ -146,6 +149,7 @@ DEPENDENCIES haml (~> 3.1) libnotify (~> 0.6) pg (~> 0.11) + rabl (~> 0.6) rails (~> 3.1) rb-inotify (~> 0.8) rspec-rails (~> 2.6) diff --git a/Guardfile b/Guardfile index c7f1664..da0c0d3 100644 --- a/Guardfile +++ b/Guardfile @@ -22,4 +22,8 @@ guard 'rspec', :cli => '--drb', :notification => false do watch('app/controllers/application_controller.rb') { 'spec/controllers' } watch(%r{^app/views/layouts/}) { 'spec/integration' } + + watch(%r{^app/views/(.+)/(?:[^/]+).rabl}) do |m| + "spec/controllers/#{m[1]}_controller_spec.rb" + end end diff --git a/app/controllers/api/v0/playlists_controller.rb b/app/controllers/api/v0/playlists_controller.rb index 7eef349..b4e49a2 100644 --- a/app/controllers/api/v0/playlists_controller.rb +++ b/app/controllers/api/v0/playlists_controller.rb @@ -3,6 +3,5 @@ class Api::V0::PlaylistsController < Api::ApplicationController def index @playlists = Playlist.all - respond_with @playlists end end diff --git a/app/views/api/v0/playlists/index.rabl b/app/views/api/v0/playlists/index.rabl new file mode 100644 index 0000000..3dc40de --- /dev/null +++ b/app/views/api/v0/playlists/index.rabl @@ -0,0 +1,4 @@ +collection @playlists + +attribute :id +attribute :name diff --git a/config/initializers/rabl_init.rb b/config/initializers/rabl_init.rb new file mode 100644 index 0000000..ec298cf --- /dev/null +++ b/config/initializers/rabl_init.rb @@ -0,0 +1,16 @@ +Rabl.configure do |config| + # Commented as these are defaults + # config.cache_sources = false + # config.json_engine = nil # Any multi\_json engines + # config.msgpack_engine = nil # Defaults to ::MessagePack + # config.bson_engine = nil # Defaults to ::BSON + # config.plist_engine = nil # Defaults to ::Plist::Emit + # config.include_json_root = true + config.include_json_root = false + # config.include_msgpack_root = true + # config.include_bson_root = true + # config.include_plist_root = true + # config.include_xml_root = false + # config.enable_json_callbacks = false + # config.xml_options = { :dasherize => true, :skip_types => false } +end diff --git a/spec/controllers/api/v0/playlists_controller_spec.rb b/spec/controllers/api/v0/playlists_controller_spec.rb index 90a0771..f29df71 100644 --- a/spec/controllers/api/v0/playlists_controller_spec.rb +++ b/spec/controllers/api/v0/playlists_controller_spec.rb @@ -20,6 +20,10 @@ describe Api::V0::PlaylistsController do do_get.should have(2).items end + it 'lists playlists with their id' do + do_get.each { |t| t.keys.should include 'id' } + end + it 'lists playlists with their name' do do_get.each { |t| t.keys.should include 'name' } end