Any thoughts anyone?

Colin

2009/5/20 Colin Law <[email protected]>

> I have a table where one of the records is a constant record that I keep
> finding myself referencing the id of in code such as
> if item.id == Item.named_scope_for_constant_record.id
> where the named scope involves a db query.
>
> I thought it would be a good idea to use a constant for this, so in the
> Item model:
> class Item<ActiveRecord::Base
>   CONSTANT_RECORD_ID = named_scope_for_constant_record.id
>  ..
> end
>
> Then I can reference Item::CONSTANT_RECORD_ID which is determined when the
> class is loaded.
>
> This works fine in my application, but in my tests it appears the class is
> loaded before the fixtures as the find fails.  It is ok if I run 'ruby
> test/unit/mytest.rb' but not if I 'rake test'.
>
> Is my analysis of what is happening correct?  If so is there a better way
> of achieving the desired effect?
>
> Colin
>
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to