Sha256: af81176bc4f4bbf9d9a4e8b4960966569e280da7d68476937e88eb5827662600

Contents?: true

Size: 1.48 KB

Versions: 1

Compression:

Stored size: 1.48 KB

Contents

require File.join(File.dirname(__FILE__), '..', 'spec_helper')

describe Rails::Authentication::Errors do
  
  before(:each) do
    @errors = Rails::Authentication::Errors.new
  end
  
  it "should report that it is empty on first creation" do
    @errors.empty?.should == true
  end

  it "should continue to report that it is empty even after being checked" do
    @errors.on(:foo)
    @errors.empty?.should == true
  end

  it "should add an error" do
    @errors.add(:login, "Login or password incorrect")
    @errors[:login].should == ["Login or password incorrect"]
  end

  it "should allow many errors to be added to the same field" do
    @errors.add(:login, "bad 1")
    @errors.add(:login, "bad 2")
    @errors.on(:login).should == ["bad 1", "bad 2"]
  end

  it "should give the full messages for an error" do
    @errors.add(:login, "login wrong")
    @errors.add(:password, "password wrong")
    ["password wrong", "login wrong"].each do |msg|
      @errors.full_messages.should include(msg)
    end
  end

  it "should return the error for a specific field / label" do
    @errors.add(:login, "wrong")
    @errors.on(:login).should == ["wrong"]
  end

  it "should return nil for a specific field if it's not been set" do
    @errors.on(:not_there).should be_nil
  end

  it "should provide an errors instance method on the Authentication instance" do
    a = Rails::Authentication.new(ActionController::TestSession.new)
    a.errors.should be_a_kind_of(Rails::Authentication::Errors)
  end  
  
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
myobie-rails-auth-0.0.4 spec/core/errors_spec.rb