Implement tracks/{show,listen}
This commit is contained in:
parent
3e7f4a7168
commit
34b38b77cf
8
app/controllers/tracks_controller.rb
Normal file
8
app/controllers/tracks_controller.rb
Normal file
@ -0,0 +1,8 @@
|
||||
class TracksController < ApplicationController
|
||||
def show
|
||||
@track = Track.find params[:id]
|
||||
end
|
||||
|
||||
def stream
|
||||
end
|
||||
end
|
3
app/models/track.rb
Normal file
3
app/models/track.rb
Normal file
@ -0,0 +1,3 @@
|
||||
class Track < ActiveRecord::Base
|
||||
validates_presence_of :name
|
||||
end
|
3
app/views/tracks/show.html.haml
Normal file
3
app/views/tracks/show.html.haml
Normal file
@ -0,0 +1,3 @@
|
||||
%h1= @track.name
|
||||
%audio{:src => stream_track_path(@track)}
|
||||
Your browser does not support the audio element
|
@ -1,3 +1,6 @@
|
||||
Scube::Application.routes.draw do
|
||||
resources :tracks do
|
||||
get 'stream', :on => :member
|
||||
end
|
||||
resources :playlists
|
||||
end
|
||||
|
13
db/migrate/20110713182005_create_tracks.rb
Normal file
13
db/migrate/20110713182005_create_tracks.rb
Normal file
@ -0,0 +1,13 @@
|
||||
class CreateTracks < ActiveRecord::Migration
|
||||
def self.up
|
||||
create_table :tracks do |t|
|
||||
t.string :name
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
|
||||
def self.down
|
||||
drop_table :tracks
|
||||
end
|
||||
end
|
@ -10,7 +10,7 @@
|
||||
#
|
||||
# It's strongly recommended to check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(:version => 20110711195337) do
|
||||
ActiveRecord::Schema.define(:version => 20110713182005) do
|
||||
|
||||
create_table "playlists", :force => true do |t|
|
||||
t.string "name"
|
||||
@ -18,4 +18,10 @@ ActiveRecord::Schema.define(:version => 20110711195337) do
|
||||
t.datetime "updated_at"
|
||||
end
|
||||
|
||||
create_table "tracks", :force => true do |t|
|
||||
t.string "name"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
end
|
||||
|
||||
end
|
||||
|
11
features/step_definitions/tracks_step.rb
Normal file
11
features/step_definitions/tracks_step.rb
Normal file
@ -0,0 +1,11 @@
|
||||
Given /^a track named "([^"]*)"$/ do |name|
|
||||
@track = Track.create!(:name => name)
|
||||
end
|
||||
|
||||
Then /^I should see an audio player$/ do
|
||||
page.should have_xpath '//audio'
|
||||
end
|
||||
|
||||
Then /^it should provide an audio stream for "([^"]*)"$/ do |name|
|
||||
page.should have_xpath "//audio[@src='#{stream_track_path(@track)}']"
|
||||
end
|
@ -1,31 +1,19 @@
|
||||
module NavigationHelpers
|
||||
# Maps a name to a path. Used by the
|
||||
#
|
||||
# When /^I go to (.+)$/ do |page_name|
|
||||
#
|
||||
# step definition in web_steps.rb
|
||||
#
|
||||
def path_to(page_name)
|
||||
case page_name
|
||||
|
||||
when /^the home\s?page$/
|
||||
'/'
|
||||
|
||||
# Add more mappings here.
|
||||
# Here is an example that pulls values out of the Regexp:
|
||||
#
|
||||
# when /^(.*)'s profile page$/i
|
||||
# user_profile_path(User.find_by_login($1))
|
||||
|
||||
else
|
||||
begin
|
||||
page_name =~ /^the (.*) page$/
|
||||
path_components = $1.split(/\s+/)
|
||||
self.send(path_components.push('path').join('_').to_sym)
|
||||
rescue NoMethodError, ArgumentError
|
||||
raise "Can't find mapping from \"#{page_name}\" to a path.\n" +
|
||||
"Now, go and add a mapping in #{__FILE__}"
|
||||
end
|
||||
when /^the home\s?page$/
|
||||
'/'
|
||||
when /^the track page for "([^\"]*)"$/
|
||||
track_path Track.find_by_name($1)
|
||||
else
|
||||
begin
|
||||
page_name =~ /^the (.*) page$/
|
||||
path_components = $1.split(/\s+/)
|
||||
self.send(path_components.push('path').join('_').to_sym)
|
||||
rescue NoMethodError, ArgumentError
|
||||
raise "Can't find mapping from \"#{page_name}\" to a path.\n" +
|
||||
"Now, go and add a mapping in #{__FILE__}"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
16
features/tracks.feature
Normal file
16
features/tracks.feature
Normal file
@ -0,0 +1,16 @@
|
||||
Feature: Tracks
|
||||
|
||||
So that I can listen music
|
||||
As a listener
|
||||
I want to add, manage and listen some tracks
|
||||
|
||||
Scenario: Show track
|
||||
Given a track named "Mega song"
|
||||
When I go to the track page for "Mega song"
|
||||
Then I should see "Mega song" within "h1"
|
||||
|
||||
Scenario: Listen track
|
||||
Given a track named "Mega song"
|
||||
When I go to the track page for "Mega song"
|
||||
Then I should see an audio player
|
||||
And it should provide an audio stream for "Mega song"
|
17
spec/controllers/tracks_controller_spec.rb
Normal file
17
spec/controllers/tracks_controller_spec.rb
Normal file
@ -0,0 +1,17 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe TracksController do
|
||||
def valid_attributes
|
||||
{
|
||||
:name => 'Mega song'
|
||||
}
|
||||
end
|
||||
|
||||
describe 'GET show' do
|
||||
it 'assigns the requested track as @track' do
|
||||
track = Track.create! valid_attributes
|
||||
get :show, :id => track.id.to_s
|
||||
assigns[:track].should == track
|
||||
end
|
||||
end
|
||||
end
|
18
spec/models/track_spec.rb
Normal file
18
spec/models/track_spec.rb
Normal file
@ -0,0 +1,18 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe Track do
|
||||
subject { track }
|
||||
let(:track) { Track.new :name => 'Mega song' }
|
||||
|
||||
context 'with valid attributes' do
|
||||
it { should be_valid }
|
||||
end
|
||||
|
||||
context 'when name empty' do
|
||||
before do
|
||||
track.name = ''
|
||||
end
|
||||
|
||||
it { should_not be_valid }
|
||||
end
|
||||
end
|
30
spec/views/tracks/show.html.haml_spec.rb
Normal file
30
spec/views/tracks/show.html.haml_spec.rb
Normal file
@ -0,0 +1,30 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe 'tracks/show.html.haml' do
|
||||
let(:track) do
|
||||
mock_model('Track', :name => 'Mega song')
|
||||
end
|
||||
|
||||
before do
|
||||
assign :track, track
|
||||
end
|
||||
|
||||
it 'displays the name of the track' do
|
||||
render
|
||||
rendered.should have_selector('h1', :text => 'Mega song')
|
||||
end
|
||||
|
||||
context 'audio tag' do
|
||||
it 'provides an audio stream for the track' do
|
||||
render
|
||||
rendered.should have_selector('audio[src]')
|
||||
end
|
||||
|
||||
it 'displays a text fallback for UA without support' do
|
||||
render
|
||||
rendered.should have_selector('audio',
|
||||
:text => 'Your browser does not support the audio element'
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
Loading…
x
Reference in New Issue
Block a user