Sha256: 422ed911553c0cc24d34893c9cfc51083b1e0cb2b256be3eddd359820b6dd3a5

Contents?: true

Size: 1009 Bytes

Versions: 1

Compression:

Stored size: 1009 Bytes

Contents

require 'active_record_spec_helper'
require 'models/user'

describe User do
  def three_times(klass)
    3.times do
      klass.create
    end
  end

  class UserWithError < User
    at_most(3, { message: "KHAAAN" })
  end

  class Book < User; end

  describe 'at_most(3)' do
    it 'should not fail when under the user limit' do
      User.create.should be_valid
    end

    it 'should make objects up to the limit without failing' do
      lambda { three_times(User) }.should_not raise_error
    end

    it 'should fail on the fourth creation' do
      three_times(User)
      User.create.should_not be_valid
    end

    it 'should accept a custom error in the method' do
      three_times(UserWithError)
      # en.activerecord.errors.models.users.at_most
      UserWithError.create.errors.inspect.should include("KHAAAN")
    end

    it 'should prefer a specific i18n option' do
      three_times(Book)
      # en.at_most
      Book.create.errors.inspect.should include("Fallback")
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
at_most-0.0.1 spec/user_spec.rb