Forum: Ruby on Rails Help with test configuration

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Jonathan Dodson (Guest)
on 2006-01-21 02:08
(Received via mailing list)
Thanks in advance for reading this, double thanks for a response, triple
for something that works.

I need a way to separate some environment variables for my development
rails app and for testing my rails app.  I have a few environment.rb
constants set, but when I put them into the config/environment/test.rb
file as constants to override the environment.rb constants, i get an
error that says the constants have already been setup.  I know I can't
set constants twice, I thought the test.rb overwrote the shared
environment.rb file, I guess I am wrong.

Does anyone know how to do this another way?  Perhaps using something
other than constants?  I have tried a few things blind, but they don't
work.  Suggestions?

-Jon Dodson
Open Source Software Engineer
Open Sourcery LLC
Seth Fitzsimmons (Guest)
on 2006-01-21 02:54
(Received via mailing list)
> work.  Suggestions?
I ran into the same problem last night.  This is what I came up with.

class Something
  CONSTANT = "something" unless defined?( CONSTANT ).nil?
  # ...

# ...
class Something
  # override constant
  CONSTANT = "something else"

Class variables look like the other way to do it (esp. if you add a
"config" class method to set them).  However, I was working with
mixins and was getting indeterminate results accessing the class
variable both from within the module and from within overridden

This approach would look something like this:
class Something
  @@variable = "default value"

  def self.config(options = {})
    options = { :variable => @@variable }.update( options ) if
    @@variable = options[:variable]

  # ...

# ...
Something.config( :variable => "overridden value" )

Hope this helps.
This topic is locked and can not be replied to.