Remove last playlists and tracks from home
This commit is contained in:
parent
4b0f4d391f
commit
b25fbaac5e
@ -3,6 +3,8 @@ class ApplicationController < ActionController::Base
|
|||||||
|
|
||||||
before_filter :authenticate!
|
before_filter :authenticate!
|
||||||
|
|
||||||
|
helper_method :current_user?
|
||||||
|
|
||||||
def current_user= user
|
def current_user= user
|
||||||
session[:user_id] = user.id
|
session[:user_id] = user.id
|
||||||
end
|
end
|
||||||
@ -11,6 +13,10 @@ class ApplicationController < ActionController::Base
|
|||||||
@current_user ||= User.find_by(id: session[:user_id]) if session[:user_id]
|
@current_user ||= User.find_by(id: session[:user_id]) if session[:user_id]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def current_user?
|
||||||
|
!!@current_user
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
|
@ -1,6 +1,4 @@
|
|||||||
class HomeController < ApplicationController
|
class HomeController < ApplicationController
|
||||||
def index
|
def index
|
||||||
@playlists = Playlist.all
|
|
||||||
@tracks = Track.latest
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,9 +1 @@
|
|||||||
= link_to 'Add a track', new_track_path
|
= link_to 'Add a track', new_track_path
|
||||||
|
|
||||||
%ul
|
|
||||||
- @playlists.each do |p|
|
|
||||||
%li= p.name
|
|
||||||
|
|
||||||
%ul
|
|
||||||
- @tracks.each do |t|
|
|
||||||
%li= t.name
|
|
||||||
|
@ -7,10 +7,9 @@
|
|||||||
|
|
||||||
%body
|
%body
|
||||||
%header
|
%header
|
||||||
|
- if current_user?
|
||||||
%nav
|
%nav
|
||||||
%ul
|
%ul
|
||||||
%li
|
|
||||||
= link_to 'Scube', root_path
|
|
||||||
%li
|
%li
|
||||||
= link_to 'Playlists', playlists_path
|
= link_to 'Playlists', playlists_path
|
||||||
%li
|
%li
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
Rails.application.routes.draw do
|
Rails.application.routes.draw do
|
||||||
|
root 'home#index'
|
||||||
|
|
||||||
namespace :api do
|
namespace :api do
|
||||||
resources :sounds, only: [:show]
|
resources :sounds, only: [:show]
|
||||||
resources :tracks, only: [:index]
|
resources :tracks, only: [:index]
|
||||||
@ -20,6 +22,4 @@ Rails.application.routes.draw do
|
|||||||
end
|
end
|
||||||
|
|
||||||
resources :playlists
|
resources :playlists
|
||||||
|
|
||||||
root to: 'home#index'
|
|
||||||
end
|
end
|
||||||
|
@ -1,20 +0,0 @@
|
|||||||
describe HomeController do
|
|
||||||
include UserControllerHelpers
|
|
||||||
|
|
||||||
before { sign_in }
|
|
||||||
|
|
||||||
describe 'GET index' do
|
|
||||||
it 'assigns all playlists as @playlists' do
|
|
||||||
playlist = FactoryGirl.create(:playlist)
|
|
||||||
get :index
|
|
||||||
expect(assigns[:playlists]).to eq [playlist]
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'assigns latest tracks as @tracks' do
|
|
||||||
FactoryGirl.create(:track, created_at: '2011-07-27 19:13:42')
|
|
||||||
FactoryGirl.create(:track, created_at: '2011-07-27 19:58:57')
|
|
||||||
get :index
|
|
||||||
expect(assigns[:tracks]).to eq Track.latest
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
@ -1,28 +0,0 @@
|
|||||||
feature 'Home page' do
|
|
||||||
include UserIntegrationHelpers
|
|
||||||
|
|
||||||
background { sign_in }
|
|
||||||
|
|
||||||
scenario 'displays playlists' do
|
|
||||||
FactoryGirl.create(:playlist, name: 'Electro')
|
|
||||||
|
|
||||||
visit root_path
|
|
||||||
|
|
||||||
expect(page).to have_content 'Electro'
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario 'displays last track added' do
|
|
||||||
FactoryGirl.create(:track,
|
|
||||||
name: 'Mega song 1',
|
|
||||||
created_at: '2011-07-27 19:13:42'
|
|
||||||
)
|
|
||||||
FactoryGirl.create(:track,
|
|
||||||
name: 'Mega song 2',
|
|
||||||
created_at: '2011-07-27 19:58:57'
|
|
||||||
)
|
|
||||||
|
|
||||||
visit root_path
|
|
||||||
|
|
||||||
expect(page.body).to match /Mega song 2.+Mega song 1/m
|
|
||||||
end
|
|
||||||
end
|
|
@ -1,21 +0,0 @@
|
|||||||
describe 'home/index' do
|
|
||||||
before do
|
|
||||||
assign :playlists, [mock_model(Playlist, name: 'Electro')]
|
|
||||||
assign :tracks, [mock_model(Track, name: 'Mega song')]
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'displays a list of playlists' do
|
|
||||||
render
|
|
||||||
expect(rendered).to have_selector 'ul>li', text: 'Electro'
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'displays a link to add a track' do
|
|
||||||
render
|
|
||||||
expect(rendered).to have_selector 'a', text: 'Add a track'
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'displays a list of tracks' do
|
|
||||||
render
|
|
||||||
expect(rendered).to have_selector 'ul>li', text: 'Mega song'
|
|
||||||
end
|
|
||||||
end
|
|
Loading…
x
Reference in New Issue
Block a user