Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'spec_helper'
- describe "Albums" do
- before(:each) do
- sign_in
- current_path.should == root_path
- end
- it "lets create new" do
- start_new_album(:title => true, :image => :medium)
- current_path.should == album_path(@user.albums.last)
- page.should have_xpath("//img[@src=\"#{@user.albums.last.cover.url(:medium)}\"]")
- end
- it "shouldn't be created if image too small" do
- start_new_album(:title => true, :image => :small)
- current_path.should == albums_path
- page.should have_content("#{I18n.t("validate.cover.width")} 200")
- page.should have_content("#{I18n.t("validate.cover.height")} 200")
- end
- it "shouldn't be created if title or image blank" do
- start_new_album
- current_path.should == albums_path
- page.should have_content("Title can't be blank")
- page.should have_content("Cover file name can't be empty")
- end
- it "shouldn't be created if album cover is not image" do
- start_new_album(:title => true, :image => :not_image)
- current_path.should == albums_path
- page.should have_content("Cover should be image")
- end
- it "should truncate title on the album page" do
- album = Factory.create(:album, :user => @user, :title => "Album title that should be truncated")
- visit albums_path
- page.should have_content(truncate_title(album, 12))
- page.should have_content(album.user.name)
- end
- describe "Managing album" do
- describe "Starting new album" do
- before(:each) do
- @album = Factory(:album, :user_id => @user)
- visit album_path(@album.id)
- current_path.should == album_path(@album.id)
- end
- it "lets edit album and get success" do
- start_new_album({:title => true, :image => :medium}, @album)
- current_path.should == album_path(@album)
- end
- it "page should contain album title and user name" do
- page.should have_content(@album.title)
- page.should have_content(@album.user.name)
- end
- it "page should contain album cover" do
- page.should have_xpath("//img[@src=\"#{@album.cover.url(:medium)}\"]")
- end
- it "page should not contain self link" do
- page.all('a', :text => @album.title).should == []
- end
- describe "Creating album collection" do
- before(:each) do
- create_album_collection(5, @user, @album)
- end
- it "checking tracks collection in albums" do
- visit album_path(@album)
- Track.all.map {|track| find('.playlist').should have_content(track.title)}
- end
- it "checking managing tracks list" do
- track = Factory(:track, :user_id => @user)
- visit album_path(@album)
- find('.managing_list').should have_content(track.title)
- end
- describe "Tracks managment" do
- it 'can add track to album' do
- @album = Factory(:album, :user_id => @user)
- track = Factory(:track, :user_id => @user)
- visit album_path(@album)
- find('.managing_list').click_link track.title
- find('.playlist').should have_content(track.title)
- find('.managing_list').should have_no_content(track.title)
- @album.tracks.find_by_id(track).should == track
- end
- it 'can remove track from album' do
- visit album_path(@album)
- track = @album.tracks.last
- find(:xpath, "//div[@data-track-id=\"#{track.id}\"]/..").click_link "Remove from collection"
- find('.playlist').should have_no_content(track.title)
- find('.managing_list').should have_content(track.title)
- @album.tracks.find_by_id(track).should == nil
- end
- it "should access to destroy path" do
- track = @album.tracks.last
- destroy_from_collection(track, @album)
- current_path.should == album_path(@album)
- find('.playlist').should have_no_content(track.title)
- @album.tracks.find_by_id(track).should == nil
- end
- end
- end
- describe "should not contain remove from collection if it's not user collection" do
- before(:each) do
- user = Factory(:user)
- @album = Factory(:album, :user => user)
- create_album_collection(5, user, @album)
- end
- it "should not contain link remove" do
- visit album_path(@album)
- page.should have_no_content("Remove from collection")
- end
- it "should not access to destroy path" do
- track = @album.tracks.last
- destroy_from_collection(track, @album)
- current_path.should == album_path(@album)
- find('.playlist').should have_content(track.title)
- end
- it "should redirected when going to edit path" do
- visit edit_album_path(@album)
- current_path.should == album_path(@album)
- end
- end
- it 'trying to get edit page' do
- page.should have_content("Edit")
- click_link "Edit"
- current_path.should == edit_album_path(@album)
- end
- it "trying destroy album" do
- page.should have_content("Destroy")
- click_link "Destroy"
- current_path.should == user_path(@album.user)
- Album.find_by_id(@album).should == nil
- end
- end
- describe "Operations that user can't do" do
- before(:each) do
- @album = Factory.create(:album)
- end
- it 'hide Edit link if not user album' do
- visit album_path(@album)
- page.should have_no_content("Edit")
- end
- it "should not destroy album if it's not user album" do
- page.driver.delete("/albums/#{@album.id}")
- visit page.driver.response.location
- Album.find_by_id(@album).should == @album
- end
- it "it should not contain track managing list" do
- visit album_path(@album)
- current_path.should == album_path(@album)
- page.should have_no_selector('#managing_list')
- page.should have_no_content("Destroy")
- end
- end
- end
- end
Add Comment
Please, Sign In to add comment