Forum: Ruby on Rails Functional test problem with environments variables

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.
4a021d3e4528fb8ab78ef7fc4b6822cc?d=identicon&s=25 Bao Lee (burninglegion)
on 2006-02-27 05:15
Hi guys,

i have been experiencing this problem once i put in some constant
declarations in /config/environments/development.rb. I declared it very
normally like this :

USER_DETAILS = {
:name => 'abc',
:password => '123'}

it works in the controller and when i run the application, i managed to
get the values out from the development.rb by using some statements like
@user = ['USER_DETAILS'].name.

But when i code the functional test, even the most simple test like
test_index in user_controller_test, it failed and result in this error :
NameError: uninitialized constant USER_DETAILS

inside the test_index is like this:
class UserControllerTest < Test::Unit::TestCase
  def setup
    @user = User.new
  end
  def test_index
    get :index
    assert_response :success
  end
end

Is there anything that went wrong? Is there any files i need to set to
tell rails to go to the config file to get the constant USER_DETAILS?
Thanks for any help anyone can provide.
59de94a56fd2c198f33d9515d1c05961?d=identicon&s=25 Tom Mornini (Guest)
on 2006-02-27 06:11
(Received via mailing list)
On Feb 26, 2006, at 8:15 PM, bao lee wrote:

> managed to
> get the values out from the development.rb by using some statements
> like
> @user = ['USER_DETAILS'].name.
>
> But when i code the functional test, even the most simple test like
> test_index in user_controller_test, it failed and result in this
> error :
> NameError: uninitialized constant USER_DETAILS
>
> inside the test_index is like this:

Development and Test are different environments...

Put it in top level environment.rb

--
-- Tom Mornini
This topic is locked and can not be replied to.