Sha256: 565a2f69eaa582eaffd35a1adbb1024b306718f2f3faa80809b3f76cc92cf99c

Contents?: true

Size: 1.27 KB

Versions: 4

Compression:

Stored size: 1.27 KB

Contents

require File.join(File.dirname(__FILE__), "..", "spec_helper.rb")

describe 'Validations', :validations => true do
  before :all do
    class Person
      include Ampere::Model
      
      field :first_name
      field :last_name
      field :email
      
      validates_presence_of :last_name
      validates_format_of :email, :with => /\A\w+@\w+\.com\Z/i
    end
    
  end
  
  it 'should validate presence of items' do
    alice = Person.new :first_name => 'Alice',
                       :last_name  => 'Steel',
                       :email      => 'alice@steel.com'
    bob   = Person.new :first_name => 'Bob',
                       :email      => 'bob@bob.com'
    alice.should be_valid
    alice.errors.should be_empty
    bob.should be_invalid
    bob.errors.should_not be_empty
  end
  
  it 'should validate format of items' do
    charlie = Person.new :first_name => 'Charlie',
                         :last_name  => 'Steel',
                         :email      => 'c h a r l i e @ charlie .com'
    charlie.should_not be_valid
  end
  
  # Since this is accomplished by including a module, what is being tested here
  # is that the module got included correctly and works. For testing of all the
  # other kinds of validations, run the tests for ActiveModel::Validations.
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
ampere-1.2.2 spec/models/validations_spec.rb
ampere-1.2.1 spec/models/validations_spec.rb
ampere-1.2.0 spec/models/validations_spec.rb
ampere-1.1.1 spec/models/validations_spec.rb