1 require File.dirname(__FILE__) + '/../spec_helper'
3 describe ApplicationHelper do
4 it "should generate an id and class for an in-place editor" do
5 @song = mock_model(Song)
6 result = in_place_options(:song, :title)
8 result[:id].should include("song_title_#{@song.id}")
9 result[:class].should == 'in_place_editor_field'
13 describe ApplicationHelper, "with a current song" do
14 it "should give the current song a current CSS class" do
15 @song = mock_model(Song)
16 song_class(@song).should include('current')
19 it "should not give a non-current song a current CSS class" do
20 @song = mock_model(Song)
21 song_class(mock_model(Song)).should_not include('current')
25 describe ApplicationHelper, "without a current song" do
26 it "should not give a current CSS class if there is no current song" do
27 song_class(mock_model(Song)).should_not include('current')
31 describe ApplicationHelper, "with a current show" do
32 it "should give the current show a current CSS class" do
33 @show = mock_model(Show)
34 show_class(@show).should include('current')
37 it "should not give a non-current show a current CSS class" do
38 @show = mock_model(Show)
39 show_class(mock_model(Show)).should_not include('current')
43 describe ApplicationHelper, "without a current show" do
44 it "should not give a current CSS class if there is no current show" do
45 show_class(mock_model(Show)).should_not include('current')
49 describe ApplicationHelper, "logged in" do
51 @songs = mock("songs_proxy")
52 @shows = mock("shows_proxy")
53 @user = mock_model(User, :songs => @songs, :shows => @shows)
54 stub!(:logged_in?).and_return(true)
55 stub!(:current_user).and_return(@user)
58 it "should get a list of all the user's songs" do
59 @songs.should_receive(:find).and_return(["a song"]) # who cares if it returns a string
60 all_songs.size.should == 1
63 it "should get a list of all the user's shows" do
64 @shows.should_receive(:find).and_return(["a show"]) # again, who cares?
65 all_shows.size.should == 1
69 describe ApplicationHelper, "logged out" do
71 stub!(:logged_in?).and_return(false)
74 it "should retrieve an empty list of songs" do
75 all_songs.size.should == 0
78 it "should retrieve an empty list of shows" do
79 all_shows.size.should == 0
83 describe ApplicationHelper, "with a flash notice" do
85 @flash = mock("flash")
88 it "should display notice box if there is a flash notice" do
89 @flash.should_receive(:has_key?).with(:notice).and_return(true)
90 notice_options.should_not have_key(:style)
94 describe ApplicationHelper, "without a flash notice" do
96 @flash = mock("flash")
99 it "should not display notice box if there is no flash notice" do
100 @flash.should_receive(:has_key?).with(:notice).and_return(false)
101 notice_options.should have_key(:style)