require 'test_helper'

class MoviesIntegrationTest < ActionController::IntegrationTest
  
  fixtures :movies, :genres, :actors
  def test_adding_movie
    get '/movies/new'
    assert_select "input[type=text][name='movie[title]']"
    assert_difference('Movie.count') do
      post '/movies/create', :movie => { :title => "Godfather",
                             :year_released => '2005',
                             :length => '02:30',
                             :language => 'English'  }
    end
    assert_redirected_to "/movies/#{assigns(:movie).id}"
    follow_redirect!
    assert_select "p", /Godfather/
    assert_select "p", /English/                         
  end
  
  def test_adding_genre
    get '/genres/new'
    assert_select "input[type=text][name='genre[genre_name]']"
    assert_difference('Genre.count') do
        post '/genres/create', :genre => { :genre_name => "Family",
                               :genre_description => 'Fun movies for all ages' }
    end
    assert_redirected_to "/genres/#{assigns(:genre).id}"
    follow_redirect!
    assert_select "p", /Family/
    assert_select "p", /ages/                         
  end
  
  def test_adding_actor
    get '/actors/new'
    assert_select "input[type=text][name='actor[first_name]']"
    assert_select "input[type=text][name='actor[last_name]']"
    assert_difference('Actor.count') do
        post '/actors/create', :actor => { :first_name => "Woody",
                               :last_name => 'Allen' }
    end
    assert_redirected_to "/actors/#{assigns(:actor).id}"
    follow_redirect!                        
  end
  
  def test_adding_photo
    get '/photos/new'
    assert_select "input[type=text][name='photo[description]']"
    assert_difference('Photo.count') do
        post '/photos/create', :photo => { :description => "colorful beach",
                               :name => 'dsc_0540.jpg',
                               :content_type => 'image/jpg',
                               :actor_id => '1',
                               :data => '874f487f48703701gv^%$^',
                               :date_taken => '2009-10-10' }
    end
    assert_redirected_to "/photos/#{assigns(:photo).id}"
    follow_redirect!                        
  end 
    
end  