Sha256: 7ace4be666ec5fe6a00d89a854137b9ff26f975064b5b335213c8d4d5c07d2b4
Contents?: true
Size: 1.55 KB
Versions: 2
Compression:
Stored size: 1.55 KB
Contents
# encoding: utf-8 require File.expand_path(File.join(File.dirname(__FILE__), 'test_helper')) class AutoIncrementActiveRecordTest < ActiveRecord::TestCase def setup @account1 = Account.create :name => 'My Account' @account2 = Account.create :name => 'My Second Account' @user1 = @account1.users.create :name => 'Felipe' @user2 = @account1.users.create :name => 'Sabrina' @user_account2 = @account2.users.create :name => 'Daniel' @user3 = @account1.users.create :name => 'Paulo' @user3.letter_code = 'Z' @user3.save @user4 = @account1.users.create :name => 'Marlene' @user4.save @user5 = @account1.users.create :name => 'Patricia' @user5.save end test "use initial" do assert_equal 1, @account1.code assert_equal 'A', @user1.letter_code end test "increments numbers" do assert_equal 2, @account2.code end test "increments letters" do assert_equal 'B', @user2.letter_code end test "do not increment outside scope" do assert_equal 'A', @user_account2.letter_code end test "Z increments to AA" do assert_equal 'AA', @user4.letter_code end test "AA increments to AB" do assert_equal 'AB', @user5.letter_code end test "not set column if is already set" do account = Account.new :name => 'Another Account', :code => 50 account.save assert_equal account.code, 50 end test "set column if option force is used" do User.destroy_all user = User.new :name => 'Maria', :letter_code => 'Z' user.save assert_equal user.letter_code, 'A' end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
auto_increment-1.0.0 | test/auto_increment_test.rb |
auto_increment-0.2 | test/auto_increment_test.rb |