From b39bc2d6da60957209ae4547ef35297748b55542 Mon Sep 17 00:00:00 2001 From: Thibault Jouan Date: Wed, 27 Jul 2011 19:34:59 +0000 Subject: [PATCH] Add home page with playlists list and link to add a track --- app/controllers/home_controller.rb | 5 +++++ app/views/home/index.html.haml | 4 ++++ app/views/playlists/index.html.haml | 1 - config/routes.rb | 2 ++ features/home.feature | 10 ++++++++++ features/tracks.feature | 2 +- spec/controllers/home_controller_spec.rb | 11 +++++++++++ spec/views/home/index.html.haml_spec.rb | 19 +++++++++++++++++++ spec/views/playlists/index.html.haml_spec.rb | 5 ----- 9 files changed, 52 insertions(+), 7 deletions(-) create mode 100644 app/controllers/home_controller.rb create mode 100644 app/views/home/index.html.haml create mode 100644 features/home.feature create mode 100644 spec/controllers/home_controller_spec.rb create mode 100644 spec/views/home/index.html.haml_spec.rb diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb new file mode 100644 index 0000000..d12ca98 --- /dev/null +++ b/app/controllers/home_controller.rb @@ -0,0 +1,5 @@ +class HomeController < ApplicationController + def index + @playlists = Playlist.all + end +end diff --git a/app/views/home/index.html.haml b/app/views/home/index.html.haml new file mode 100644 index 0000000..51d5736 --- /dev/null +++ b/app/views/home/index.html.haml @@ -0,0 +1,4 @@ += link_to 'Add a track', new_track_path +%ul + - @playlists.each do |p| + %li= p.name diff --git a/app/views/playlists/index.html.haml b/app/views/playlists/index.html.haml index 3f99cda..86cc038 100644 --- a/app/views/playlists/index.html.haml +++ b/app/views/playlists/index.html.haml @@ -1,5 +1,4 @@ = link_to 'Create playlist', new_playlist_path -= link_to 'Add a track', new_track_path %ul - @playlists.each do |p| %li diff --git a/config/routes.rb b/config/routes.rb index a0403d1..5c96b51 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -3,4 +3,6 @@ Scube::Application.routes.draw do get 'stream', :on => :member end resources :playlists + + root :to => 'home#index' end diff --git a/features/home.feature b/features/home.feature new file mode 100644 index 0000000..9f29745 --- /dev/null +++ b/features/home.feature @@ -0,0 +1,10 @@ +Feature: Home + + So that I can use scube efficiently + As a listener + I want to access the main features and valuable content from the homepage + + Scenario: Playlist access + Given a playlist named "Electro" + When I am on the home page + Then I should see "Electro" within "ul>li" diff --git a/features/tracks.feature b/features/tracks.feature index 0774b99..08741d8 100644 --- a/features/tracks.feature +++ b/features/tracks.feature @@ -10,7 +10,7 @@ Feature: Tracks Then I should see "Mega song" within "h1" Scenario: Create track - Given I am on the playlists page + Given I am on the home page When I follow "Add a track" And I fill in "Name" with "Mega song" And I attach the file "features/fixtures/test.mp3" to "File" diff --git a/spec/controllers/home_controller_spec.rb b/spec/controllers/home_controller_spec.rb new file mode 100644 index 0000000..12cf055 --- /dev/null +++ b/spec/controllers/home_controller_spec.rb @@ -0,0 +1,11 @@ +require 'spec_helper' + +describe HomeController do + describe 'GET index' do + it 'assigns all playlists as @playlists' do + playlist = Factory.create(:playlist) + get :index + assigns[:playlists].should == [playlist] + end + end +end diff --git a/spec/views/home/index.html.haml_spec.rb b/spec/views/home/index.html.haml_spec.rb new file mode 100644 index 0000000..944fddd --- /dev/null +++ b/spec/views/home/index.html.haml_spec.rb @@ -0,0 +1,19 @@ +require 'spec_helper' + +describe 'home/index.html.haml' do + before do + assign :playlists, [ + mock_model('Playlist', :name => 'Electro') + ] + end + + it 'displays a list of playlists' do + render + rendered.should have_selector('ul>li', :text => 'Electro') + end + + it 'displays a link to add a track' do + render + rendered.should have_selector('a', :text => 'Add a track') + end +end diff --git a/spec/views/playlists/index.html.haml_spec.rb b/spec/views/playlists/index.html.haml_spec.rb index 084af6f..af2db4c 100644 --- a/spec/views/playlists/index.html.haml_spec.rb +++ b/spec/views/playlists/index.html.haml_spec.rb @@ -21,9 +21,4 @@ describe 'playlists/index.html.haml' do render rendered.should have_selector('a', :text => 'Electro') end - - it 'displays a link to create a new track' do - render - rendered.should have_selector('a', :text => 'Add a track') - end end