I'm using Sequel as my ORM and Test::Unit as my testing framework and
have the following model:
class Item < Sequel::Model
validates do
presence_of( :name, :uuid, :vendor_id, :vendor_reference, :amount,
:currency_code )
uniqueness_of( :uuid )
end
def initialize( *args )
super( *args )
self.uuid = UUID.random_create.to_s
end
end
As you can see I overwrite initialize to set up the UUID when the
model is instantiated. In my tests I have the following method which
sets up an Item:
def generate_valid_new_item
item = Item.new do |i|
i.name = random_item_name
i.description = random_description
i.vendor_id = random_vendor_id
i.vendor_reference = random_vendor_reference
i.amount = random_amount
i.currency_code = random_currency_code
i.image_url = random_homepage_url
end
assert( item.valid?, item.errors.full_messages )
item
end
The problem is that when it gets to that assert on the 3rd last line
it fails because item.uuid (which should exist) is nil. I put a
breakpoint in the initialize method and it is never called(!?). I have
no clue how the object is being initialised if new is called but
initialize is not?
The strange thing is that this only happens when I run my unit tests.
If I run 'merb -i' (even with -e test) I can initialise an Item
correctly:
[EMAIL PROTECTED] ~/Projects/boxen $ merb -i -e test
~ loading gem 'merb_sequel' from config/init.rb:30 ...
~ loading gem 'merb_test_unit' from config/init.rb:41 ...
~ The merb_test_unit gem was not found. You may need to install it.
~ Loaded TEST Environment...
~ Connecting to the 'boxen_test' database on 'localhost' using 'postgres' ...
~ Compiling routes...
~ loading gem 'password' from config/init.rb:58 ...
~ loading gem 'validation_extensions' from config/init.rb:59 ...
~ loading gem 'uuidtools' from config/init.rb:60 ...
~ Using 'share-nothing' cookie sessions (4kb limit per client)
irb(main):001:0> item = Item.new
=> #<Item @values={:uuid=>"ef62fa2e-594a-4305-b1bf-8a9b7aec8790"}>
The UUID is definitely present there. Anyone else have some ideas?
Farrel
_______________________________________________
Merb-devel mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/merb-devel