Forum: Ruby on Rails Help with test configuration

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
19b729d2cf22e50af63a7d5ed39c63f6?d=identicon&s=25 Jonathan Dodson (Guest)
on 2006-01-21 01: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
http://www.opensourcery.com
04cc14ca10d8d5fafbc05ee205641248?d=identicon&s=25 Seth Fitzsimmons (Guest)
on 2006-01-21 01:54
(Received via mailing list)
> work.  Suggestions?
I ran into the same problem last night.  This is what I came up with.

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

environment.rb:
# ...
class Something
  # override constant
  CONSTANT = "something else"
end

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
methods.

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

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

  # ...
end

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

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