开发者

Cannot Set ActiveRecord ID in Test Environment

In my before_create callback I CAN assign my custom GUID in the production and development environments. However, the same code running in the test environment CANNOT change the value of my custom GUID. See code example below.

require 'rubygems'
require 'uuidtools'
require 'base32/crockford'

class WhatClass < ActiveRecord::Base
  # Declare the non-standard column guid as the primary key
  set_primary_key :guid
  # Use a开发者_Python百科 callback to generate the record id
  before_create :create_uuid

  private
    # This method creates a universally unique identifier (UUID)
    # for an instance of WhatClass. This method is called before the
    # record is created.
    def create_uuid
      # Create the UUID
      uuid = UUIDTools::UUID.sha1_create(UUIDTools::UUID_URL_NAMESPACE, "string-to-create-from")
      self.guid = Base32::Crockford.encode(uuid.to_i)
    end
end

Can someone please explain why self.guid works in production/development but not in test?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜