Add latest added tracks list on the home page
This commit is contained in:
parent
b39bc2d6da
commit
46abe07268
@ -1,5 +1,6 @@
|
|||||||
class HomeController < ApplicationController
|
class HomeController < ApplicationController
|
||||||
def index
|
def index
|
||||||
@playlists = Playlist.all
|
@playlists = Playlist.all
|
||||||
|
@tracks = Track.latest
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -15,4 +15,8 @@ class Track < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
save!
|
save!
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.latest
|
||||||
|
Track.order('created_at DESC')
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
@ -2,3 +2,6 @@
|
|||||||
%ul
|
%ul
|
||||||
- @playlists.each do |p|
|
- @playlists.each do |p|
|
||||||
%li= p.name
|
%li= p.name
|
||||||
|
%ul
|
||||||
|
- @tracks.each do |t|
|
||||||
|
%li= t.name
|
||||||
|
@ -8,3 +8,12 @@ Feature: Home
|
|||||||
Given a playlist named "Electro"
|
Given a playlist named "Electro"
|
||||||
When I am on the home page
|
When I am on the home page
|
||||||
Then I should see "Electro" within "ul>li"
|
Then I should see "Electro" within "ul>li"
|
||||||
|
|
||||||
|
Scenario: Last tracks added
|
||||||
|
Given the following tracks:
|
||||||
|
| name | created_at |
|
||||||
|
| Mega song 1 | 2011-07-27 19:13:42 |
|
||||||
|
| Mega song 2 | 2011-07-27 19:58:57 |
|
||||||
|
When I am on the home page
|
||||||
|
Then I should see "Mega song 2" within "ul>li:first-child"
|
||||||
|
And I should see "Mega song 1" within "ul>li:first-child+li"
|
||||||
|
@ -4,6 +4,12 @@ Given /^a track named "([^"]*)"$/ do |name|
|
|||||||
@track.save_with_file(file, 'audio/mpeg')
|
@track.save_with_file(file, 'audio/mpeg')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Given /^the following tracks:$/ do |table|
|
||||||
|
table.hashes.each do |h|
|
||||||
|
Factory.create(:track, h)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
Then /^I should see an audio player$/ do
|
Then /^I should see an audio player$/ do
|
||||||
page.should have_xpath '//audio'
|
page.should have_xpath '//audio'
|
||||||
end
|
end
|
||||||
|
@ -7,5 +7,12 @@ describe HomeController do
|
|||||||
get :index
|
get :index
|
||||||
assigns[:playlists].should == [playlist]
|
assigns[:playlists].should == [playlist]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'assigns latest tracks as @tracks' do
|
||||||
|
track1 = Factory.create(:track, :created_at => '2011-07-27 19:13:42')
|
||||||
|
track2 = Factory.create(:track, :created_at => '2011-07-27 19:58:57')
|
||||||
|
get :index
|
||||||
|
assigns[:tracks].should == Track.latest
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -56,4 +56,12 @@ describe Track do
|
|||||||
`rm -f #{Rails.root}/data/tracks/*`
|
`rm -f #{Rails.root}/data/tracks/*`
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe '.latest' do
|
||||||
|
it 'returns latest tracks in descending creation date order' do
|
||||||
|
track1 = Factory.create(:track, :created_at => '2011-07-27 19:13:42')
|
||||||
|
track2 = Factory.create(:track, :created_at => '2011-07-27 19:58:57')
|
||||||
|
Track.latest.should == [track2, track1]
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
@ -5,6 +5,9 @@ describe 'home/index.html.haml' do
|
|||||||
assign :playlists, [
|
assign :playlists, [
|
||||||
mock_model('Playlist', :name => 'Electro')
|
mock_model('Playlist', :name => 'Electro')
|
||||||
]
|
]
|
||||||
|
assign :tracks, [
|
||||||
|
mock_model('Track', :name => 'Mega song')
|
||||||
|
]
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'displays a list of playlists' do
|
it 'displays a list of playlists' do
|
||||||
@ -16,4 +19,9 @@ describe 'home/index.html.haml' do
|
|||||||
render
|
render
|
||||||
rendered.should have_selector('a', :text => 'Add a track')
|
rendered.should have_selector('a', :text => 'Add a track')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'displays a list of tracks' do
|
||||||
|
render
|
||||||
|
rendered.should have_selector('ul>li', :text => 'Mega song')
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user