require File.dirname(__FILE__) + '/../test_helper'

class MovieShowtimeTestCase < Test::Unit::TestCase
  def setup
    @theatre = Theatre.create!(
       :name => 'Ruby Palace',
       :address_line_1 => '123 Broadway',
       :address_city => 'Cambridge',
       :address_state => 'MA',
       :address_zip_code => '02139',
       :phone_number => '5555555555')

    @movie = Movie.create!(
      :name => 'Casablanca',
      :rating => 'PG',
      :length_minutes => '10')
  end

  #
  # Testy modelowe integralnoci referencyjnej
  #    

  def test_add_showtime_no_movie
    st = MovieShowtime.new(:theatre => @theatre,
                           :auditorium => '1',
                           :start_time => Time.now.xmlschema);
    assert !st.save, "Walidacja nie wykrya braku skojarzenia z filmem"
  end; 

  def test_add_showtime_no_theatre
    st = MovieShowtime.new(:movie => @movie,
                           :auditorium => '1',
                           :start_time => Time.now.xmlschema);
    assert !st.save, "Walidacja nie wykrya braku skojarzenia z kinem"
  end; 
  
  #
  # Testy bazodanowe integralnoci referencyjnej
  #    
  
  def test_db_add_showtime_no_movie
    test_for_db_error "Baza danych nie wykrya braku skojarzenia z filmem" do
      st = MovieShowtime.new(:theatre => @theatre,
                             :auditorium => '1',
                             :start_time => Time.now.xmlschema);
      st.save_with_validation(false)
    end
  end  
   
  def test_db_add_showtime_no_theatre
    test_for_db_error "Baza danych nie wykrya braku skojarzenia z kinem" do
      st = MovieShowtime.new(:movie => @movie,
                             :auditorium => '1',
                             :start_time => Time.now.xmlschema);
      st.save_with_validation(false)
    end
  end  

  def test_db_add_showtime_invalid_references
    test_for_db_error "Baza danych nie wykrya bdu w skojarzeniach" do
      st = MovieShowtime.new(:movie_id => 12,
                             :theatre_id => 99,
                             :auditorium => '1'
                             );
      st.save_with_validation(false)
    end
  end
end

