Guest User

Untitled

a guest
Mar 2nd, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 6.14 KB | None | 0 0
  1. require 'spec_helper'
  2.  
  3. describe "Albums" do
  4.   before(:each) do
  5.     sign_in
  6.     current_path.should == root_path
  7.   end
  8.  
  9.   it "lets create new" do
  10.     start_new_album(:title => true, :image => :medium)
  11.     current_path.should == album_path(@user.albums.last)
  12.     page.should have_xpath("//img[@src=\"#{@user.albums.last.cover.url(:medium)}\"]")
  13.   end
  14.  
  15.   it "shouldn't be created if image too small" do
  16.     start_new_album(:title => true, :image => :small)
  17.     current_path.should == albums_path
  18.     page.should have_content("#{I18n.t("validate.cover.width")} 200")
  19.     page.should have_content("#{I18n.t("validate.cover.height")} 200")
  20.   end
  21.  
  22.   it "shouldn't be created if title or image blank" do
  23.     start_new_album
  24.     current_path.should == albums_path
  25.     page.should have_content("Title can't be blank")
  26.     page.should have_content("Cover file name can't be empty")
  27.   end
  28.  
  29.   it "shouldn't be created if album cover is not image" do
  30.     start_new_album(:title => true, :image => :not_image)
  31.     current_path.should == albums_path
  32.     page.should have_content("Cover should be image")
  33.   end
  34.  
  35.   it "should truncate title on the album page" do
  36.     album = Factory.create(:album, :user => @user, :title => "Album title that should be truncated")
  37.     visit albums_path
  38.     page.should have_content(truncate_title(album, 12))
  39.     page.should have_content(album.user.name)
  40.   end
  41.  
  42.   describe "Managing album" do
  43.     describe "Starting new album" do
  44.       before(:each) do
  45.         @album = Factory(:album, :user_id => @user)
  46.         visit album_path(@album.id)
  47.         current_path.should == album_path(@album.id)
  48.       end
  49.      
  50.       it "lets edit album and get success" do
  51.         start_new_album({:title => true, :image => :medium}, @album)
  52.         current_path.should == album_path(@album)
  53.       end
  54.      
  55.       it "page should contain album title and user name" do
  56.         page.should have_content(@album.title)
  57.         page.should have_content(@album.user.name)
  58.       end
  59.      
  60.       it "page should contain album cover" do
  61.         page.should have_xpath("//img[@src=\"#{@album.cover.url(:medium)}\"]")
  62.       end
  63.      
  64.       it "page should not contain self link" do
  65.         page.all('a', :text => @album.title).should == []
  66.       end
  67.      
  68.       describe "Creating album collection" do
  69.         before(:each) do
  70.           create_album_collection(5, @user, @album)
  71.         end
  72.        
  73.         it "checking tracks collection in albums" do
  74.           visit album_path(@album)
  75.           Track.all.map {|track| find('.playlist').should have_content(track.title)}
  76.         end
  77.        
  78.         it "checking managing tracks list" do
  79.           track = Factory(:track, :user_id => @user)
  80.           visit album_path(@album)
  81.           find('.managing_list').should have_content(track.title)
  82.         end
  83.        
  84.         describe "Tracks managment" do
  85.           it 'can add track to album' do
  86.             @album = Factory(:album, :user_id => @user)
  87.             track = Factory(:track, :user_id => @user)
  88.             visit album_path(@album)
  89.             find('.managing_list').click_link track.title
  90.             find('.playlist').should have_content(track.title)
  91.             find('.managing_list').should have_no_content(track.title)
  92.             @album.tracks.find_by_id(track).should == track
  93.           end
  94.  
  95.           it 'can remove track from album' do
  96.             visit album_path(@album)
  97.             track = @album.tracks.last
  98.             find(:xpath, "//div[@data-track-id=\"#{track.id}\"]/..").click_link "Remove from collection"
  99.             find('.playlist').should have_no_content(track.title)
  100.             find('.managing_list').should have_content(track.title)
  101.             @album.tracks.find_by_id(track).should == nil
  102.           end
  103.  
  104.           it "should access to destroy path" do
  105.             track = @album.tracks.last
  106.             destroy_from_collection(track, @album)
  107.             current_path.should == album_path(@album)
  108.             find('.playlist').should have_no_content(track.title)
  109.             @album.tracks.find_by_id(track).should == nil
  110.           end
  111.         end
  112.       end
  113.  
  114.       describe "should not contain remove from collection if it's not user collection" do
  115.         before(:each) do
  116.           user = Factory(:user)
  117.           @album = Factory(:album, :user => user)
  118.           create_album_collection(5, user, @album)
  119.         end
  120.  
  121.         it "should not contain link remove" do
  122.           visit album_path(@album)
  123.           page.should have_no_content("Remove from collection")
  124.         end
  125.  
  126.         it "should not access to destroy path" do
  127.           track = @album.tracks.last
  128.           destroy_from_collection(track, @album)
  129.           current_path.should == album_path(@album)
  130.           find('.playlist').should have_content(track.title)
  131.         end
  132.  
  133.         it "should redirected when going to edit path" do
  134.           visit edit_album_path(@album)
  135.           current_path.should == album_path(@album)
  136.         end
  137.       end
  138.      
  139.       it 'trying to get edit page' do
  140.         page.should have_content("Edit")
  141.         click_link "Edit"
  142.         current_path.should == edit_album_path(@album)
  143.       end
  144.      
  145.       it "trying destroy album" do
  146.         page.should have_content("Destroy")
  147.         click_link "Destroy"
  148.         current_path.should == user_path(@album.user)
  149.         Album.find_by_id(@album).should == nil
  150.       end
  151.     end
  152.  
  153.     describe "Operations that user can't do" do
  154.       before(:each) do
  155.         @album = Factory.create(:album)
  156.       end
  157.       it 'hide Edit link if not user album' do
  158.         visit album_path(@album)
  159.         page.should have_no_content("Edit")
  160.       end
  161.  
  162.       it "should not destroy album if it's not user album" do
  163.         page.driver.delete("/albums/#{@album.id}")
  164.         visit page.driver.response.location
  165.         Album.find_by_id(@album).should == @album
  166.       end
  167.  
  168.       it "it should not contain track managing list" do
  169.         visit album_path(@album)
  170.         current_path.should == album_path(@album)
  171.         page.should have_no_selector('#managing_list')
  172.         page.should have_no_content("Destroy")
  173.       end
  174.     end
  175.   end
  176. end
Add Comment
Please, Sign In to add comment