From b25fbaac5e48e4ca207a6d5bd8d1688f10b4fa6b Mon Sep 17 00:00:00 2001 From: Thibault Jouan Date: Fri, 1 May 2015 11:03:34 +0000 Subject: [PATCH] Remove last playlists and tracks from home --- app/controllers/application_controller.rb | 6 +++++ app/controllers/home_controller.rb | 2 -- app/views/home/index.html.haml | 8 ------- app/views/layouts/application.html.haml | 15 ++++++------ config/routes.rb | 4 ++-- spec/controllers/home_controller_spec.rb | 20 ---------------- spec/features/home_spec.rb | 28 ----------------------- spec/views/home/index.html.haml_spec.rb | 21 ----------------- 8 files changed, 15 insertions(+), 89 deletions(-) delete mode 100644 spec/controllers/home_controller_spec.rb delete mode 100644 spec/features/home_spec.rb delete mode 100644 spec/views/home/index.html.haml_spec.rb diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index beb03b7..e2ac36a 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -3,6 +3,8 @@ class ApplicationController < ActionController::Base before_filter :authenticate! + helper_method :current_user? + def current_user= user session[:user_id] = user.id end @@ -11,6 +13,10 @@ class ApplicationController < ActionController::Base @current_user ||= User.find_by(id: session[:user_id]) if session[:user_id] end + def current_user? + !!@current_user + end + protected diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index e8ea6df..95f2992 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -1,6 +1,4 @@ class HomeController < ApplicationController def index - @playlists = Playlist.all - @tracks = Track.latest end end diff --git a/app/views/home/index.html.haml b/app/views/home/index.html.haml index bd56b72..88ad007 100644 --- a/app/views/home/index.html.haml +++ b/app/views/home/index.html.haml @@ -1,9 +1 @@ = link_to 'Add a track', new_track_path - -%ul - - @playlists.each do |p| - %li= p.name - -%ul - - @tracks.each do |t| - %li= t.name diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index 6a7ffdc..7741308 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -7,13 +7,12 @@ %body %header - %nav - %ul - %li - = link_to 'Scube', root_path - %li - = link_to 'Playlists', playlists_path - %li - = link_to 'Sign out', signout_path + - if current_user? + %nav + %ul + %li + = link_to 'Playlists', playlists_path + %li + = link_to 'Sign out', signout_path = yield diff --git a/config/routes.rb b/config/routes.rb index abd30bf..3feef6c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,6 @@ Rails.application.routes.draw do + root 'home#index' + namespace :api do resources :sounds, only: [:show] resources :tracks, only: [:index] @@ -20,6 +22,4 @@ Rails.application.routes.draw do end resources :playlists - - root to: 'home#index' end diff --git a/spec/controllers/home_controller_spec.rb b/spec/controllers/home_controller_spec.rb deleted file mode 100644 index dc5dd32..0000000 --- a/spec/controllers/home_controller_spec.rb +++ /dev/null @@ -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 diff --git a/spec/features/home_spec.rb b/spec/features/home_spec.rb deleted file mode 100644 index 300ef9f..0000000 --- a/spec/features/home_spec.rb +++ /dev/null @@ -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 diff --git a/spec/views/home/index.html.haml_spec.rb b/spec/views/home/index.html.haml_spec.rb deleted file mode 100644 index 897e959..0000000 --- a/spec/views/home/index.html.haml_spec.rb +++ /dev/null @@ -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