Merge branch 'api-json-root_revert'
Revert default rails behavior for JSON root in API responses, and tune index views to play nicely with Ember.js DS.RESTAdapter defaults.
This commit is contained in:
commit
b642666728
@ -1,4 +1,3 @@
|
|||||||
collection @playlists
|
collection @playlists, root: :playlists, object_root: false
|
||||||
|
|
||||||
attribute :id
|
extends 'api/playlists/show'
|
||||||
attribute :name
|
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
collection @tracks
|
collection @tracks, root: :tracks, object_root: false
|
||||||
|
|
||||||
attribute :id
|
extends 'api/tracks/show'
|
||||||
attribute :name
|
|
||||||
|
|
||||||
node(:sound_url, if: ->(t) { t.sound? }) { |t| api_sound_url t.sound }
|
node(:sound_url, if: ->(t) { t.sound? }) { |t| api_sound_url t.sound }
|
||||||
|
@ -1,16 +0,0 @@
|
|||||||
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
|
|
@ -9,6 +9,6 @@ ActiveSupport.on_load(:action_controller) do
|
|||||||
end
|
end
|
||||||
|
|
||||||
# To enable root element in JSON for ActiveRecord objects.
|
# To enable root element in JSON for ActiveRecord objects.
|
||||||
ActiveSupport.on_load(:active_record) do
|
# ActiveSupport.on_load(:active_record) do
|
||||||
self.include_root_in_json = true
|
# self.include_root_in_json = true
|
||||||
end
|
# end
|
||||||
|
@ -13,7 +13,7 @@ describe 'API sign in' do
|
|||||||
it 'signs the user in with valid credentials' do
|
it 'signs the user in with valid credentials' do
|
||||||
do_create
|
do_create
|
||||||
|
|
||||||
expect(json).to eq(id: user.id)
|
expect(json).to eq(user: { id: user.id })
|
||||||
end
|
end
|
||||||
|
|
||||||
[:email, :password].each do |attr|
|
[:email, :password].each do |attr|
|
||||||
|
@ -7,33 +7,35 @@ describe 'API playlists' do
|
|||||||
playlist = create :playlist
|
playlist = create :playlist
|
||||||
get api_playlists_path, format: :json
|
get api_playlists_path, format: :json
|
||||||
|
|
||||||
expect(json).to match [
|
expect(json).to eq(
|
||||||
a_hash_including(
|
playlists: [{
|
||||||
id: an_instance_of(Fixnum),
|
id: playlist.id,
|
||||||
name: playlist[:name]
|
name: playlist.name
|
||||||
)
|
}]
|
||||||
]
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'shows a playlist' do
|
it 'shows a playlist' do
|
||||||
playlist = create :playlist
|
playlist = create :playlist
|
||||||
get api_playlist_path playlist, format: :json
|
get api_playlist_path playlist, format: :json
|
||||||
|
|
||||||
expect(json).to match(
|
expect(json).to eq(
|
||||||
id: playlist.id,
|
playlist: {
|
||||||
name: playlist.name
|
id: playlist.id,
|
||||||
|
name: playlist.name
|
||||||
|
}
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'creates playlist' do
|
it 'creates playlist' do
|
||||||
playlist = attributes_for :playlist
|
playlist = attributes_for :playlist
|
||||||
post api_playlists_path,
|
post api_playlists_path, format: :json, playlist: playlist
|
||||||
format: :json,
|
|
||||||
playlist: playlist
|
|
||||||
|
|
||||||
expect(json).to match(
|
expect(json).to match(
|
||||||
id: an_instance_of(Fixnum),
|
playlist: {
|
||||||
name: playlist[:name]
|
id: an_instance_of(Fixnum),
|
||||||
|
name: playlist[:name]
|
||||||
|
}
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -8,26 +8,30 @@ describe 'API tracks' do
|
|||||||
track_2 = create :track, name: 'Track 2'
|
track_2 = create :track, name: 'Track 2'
|
||||||
get api_tracks_path, format: :json
|
get api_tracks_path, format: :json
|
||||||
|
|
||||||
expect(json).to eq [
|
expect(json).to eq(
|
||||||
{
|
tracks: [
|
||||||
id: track_1.id,
|
{
|
||||||
name: 'Track 1',
|
id: track_1.id,
|
||||||
sound_url: api_sound_url(track_1.sound)
|
name: 'Track 1',
|
||||||
},
|
sound_url: api_sound_url(track_1.sound)
|
||||||
{
|
},
|
||||||
id: track_2.id,
|
{
|
||||||
name: 'Track 2'
|
id: track_2.id,
|
||||||
}
|
name: 'Track 2'
|
||||||
]
|
}
|
||||||
|
]
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'shows a track' do
|
it 'shows a track' do
|
||||||
track = create :track
|
track = create :track
|
||||||
get api_track_path track, format: :json
|
get api_track_path track, format: :json
|
||||||
|
|
||||||
expect(json).to match(
|
expect(json).to eq(
|
||||||
id: track.id,
|
track: {
|
||||||
name: track.name
|
id: track.id,
|
||||||
|
name: track.name
|
||||||
|
}
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user