Sha256: 47568e06e903b6b20ea403d6d295b060c636176389766d12165f009ec3d41647

Contents?: true

Size: 1.54 KB

Versions: 4

Compression:

Stored size: 1.54 KB

Contents

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

class TestWithOptionalDependency < Test::Unit::TestCase

  def setup
    # Turn off the validates_presence_of call
    Author.depends_on :profile, :validates_presence_if => false, 
      :attrs => [:first_name, :last_name, :email]

    # Turn off the validates_presence_of and the validates_associated calls
    Artist.depends_on :profile, :validates_presence_if => false, 
      :validates_associated_if => false,
      :attrs => [:first_name, :last_name, :email]
    
    @author = Author.new
    @artist = Artist.new
  end
  
  def test_author_should_be_valid_without_profile
    @author.login = 'joe'
    
    @author.valid?
    puts @author.errors.full_messages.to_sentence
    
    assert @author.valid?
  end
  
  def test_author_should_be_invalid_with_invalid_profile
    @author.login = 'joe'
    @author.first_name = 'joe'
    
    assert !@author.valid?
  end
  
  def test_author_should_be_valid_with_profile_attributes
    @author.login = 'joe'
    @author.first_name = 'joe'
    @author.last_name = 'bloggs'
    @author.email = 'joe@bloggs.co.uk'
    
    assert @author.valid?
  end

  def test_artist_should_not_save_with_invalid_profile
    @artist.login = 'joe'
    @artist.first_name = 'joe'
    
    assert !@artist.save
  end

  def test_artist_should_save_with_valid_profile
    @artist.login = 'joe'
    @artist.first_name = 'joe'
    @artist.last_name = 'bloggs'
    @artist.email = 'joe@bloggs.co.uk'
    
    assert @artist.save
  end
  
end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
johnsbrn-classy-inheritance-0.6.8.1 test/test_with_optional_dependency.rb
johnsbrn-classy-inheritance-0.6.8.3 test/test_with_optional_dependency.rb
johnsbrn-classy-inheritance-0.6.8.2 test/test_with_optional_dependency.rb
classy-inheritance-0.7.0 test/test_with_optional_dependency.rb