Forum: Ruby on Rails HashWithIndifferentAccess in testing

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.
Daniel F. (Guest)
on 2008-10-29 21:17
Hi,
I'm trying to externalize the strings in my application, and have this
in the environment.rb file
APP_TEXT =
(HashWithIndifferentAccess).new(YAML::load(File.open("#{RAILS_ROOT}/config/strings.yml"))),
This works fine until I try to do the functional and unit tests, where I
get an uninitialized constant HashWithIndifferentAccess (NameError).
I've tried it with Hash.HashWithIndifferentAccess,
Hash:HashWithIndifferentAccess, and Hash::HashWithIndifferentAccess and
none of these work.
Am I supposed to be including something somewhere inside of the tests?
reHa (Guest)
on 2008-10-29 21:40
(Received via mailing list)
Hi,

Do you put this line APP_TEXT = ...
at the end or beginning of the environment.rb file?
Daniel F. (Guest)
on 2008-10-29 21:43
First I put it right below
require File.join(File.dirname(__FILE__), 'boot')
and then I tried moving it to
Rails::Initializer.run do |config|
  APP_TEXT =
(HashWithIndifferentAccess).new(YAML::load(File.open("#{RAILS_ROOT}/config/strings.yml")))
however this does not work.

reHa wrote:
> Hi,
>
> Do you put this line APP_TEXT = ...
> at the end or beginning of the environment.rb file?
reHa (Guest)
on 2008-10-29 21:47
(Received via mailing list)
I ussually add my things after the initializer - mybe try this way

Rails::Initializer.run do |config|
  #standard stuff
end

#my stuff
APP_TEXT = ....
Frederick C. (Guest)
on 2008-10-29 21:54
(Received via mailing list)
On Oct 29, 7:46 pm, reHa <removed_email_address@domain.invalid> wrote:
> I ussually add my things after the initializer - mybe try this way
>
> Rails::Initializer.run do |config|
>   #standard stuff
> end
>
> #my stuff
> APP_TEXT = ....
>

The reason why this is a good thing is that it means the code runs
after Rails has been loaded. Given that HashWithIndifferentAccess is
part of rails this is a good thing !

Fred
(PS: config/initializers)
Daniel F. (Guest)
on 2008-10-29 22:00
Thanks! that worked perfectly,
I still don't really understand why the error didn't come up during
development and only during the unit testing.  But thanks a lot!

Frederick C. wrote:
> On Oct 29, 7:46�pm, reHa <removed_email_address@domain.invalid> wrote:
>> I ussually add my things after the initializer - mybe try this way
>>
>> Rails::Initializer.run do |config|
>> � #standard stuff
>> end
>>
>> #my stuff
>> APP_TEXT = ....
>>
>
> The reason why this is a good thing is that it means the code runs
> after Rails has been loaded. Given that HashWithIndifferentAccess is
> part of rails this is a good thing !
>
> Fred
> (PS: config/initializers)
reHa (Guest)
on 2008-10-29 22:19
(Received via mailing list)
No problem - actually it is interisting question why it worked on the
development environment but I don't know the answer  ;)
This topic is locked and can not be replied to.