# Functional testing

**URL:** <https://www.ruby-forum.com/t/functional-testing/101347>\
**Category:** Rails I18n\
**Created:** [August 4, 2006, 11:38am UTC](https://www.ruby-forum.com/t/functional-testing/101347 "2006-08-04T11:38:31Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bonne\_Eggleston](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/46a35a/32.png) [@Bonne\_Eggleston](https://www.ruby-forum.com/u/Bonne_Eggleston)\
**Post date:** [August 4, 2006, 11:38am UTC](https://www.ruby-forum.com/t/functional-testing/101347/1 "2006-08-04T11:38:31Z")

</div>

Hi there,  
I’m implementing the Globalize plugin on my application, and so far it’s  
working quite well.  
One problem I’m having is that I can’t do any functional tests.  
It appears as though the locale is not set for the tests, and an error  
is  
thrown by the find\_every function where it tries to get the language  
code.  
This problem is not seen outside of testing.

is this common? Can anyone else reproduce it? Is there a fix?  
I’m using Rails 1.1 and the 1.1 branch of Globalize.

Also the include\_translated option for the find method doesn’t appear to  
work.  
Is there some trick to use it? It always throws an invalid option error.

Regards,  
Bonne Eggeleston.

---

<div class="post-metadata">

**Author:** ![Bonne\_Eggleston](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/46a35a/32.png) [@Bonne\_Eggleston](https://www.ruby-forum.com/u/Bonne_Eggleston)\
**Post date:** [August 7, 2006, 2:11am UTC](https://www.ruby-forum.com/t/functional-testing/101347/2 "2006-08-07T02:11:03Z")

</div>

I am having about the same issue. I’m using Globalize with a switch in  
the url like “:locale/:controller/…” and it breaks functional tests,  
spitting out “No url can be generated for the hash”-routing errors. I’ve  
tried to get around this by setting up a redirect. This would even come  
in handy for other reasons. What I tried to achieve is that urls without  
the locale like “[www.url.com/mycontroller/](http://www.url.com/mycontroller/)” would get redirected to  
“[www.url.com/en/mycontroller/](http://www.url.com/en/mycontroller/)”, with “en” here being the default locale.  
Does anyone know how to get this done?

Greetings  
Patrick

---

<div class="post-metadata">

**Author:** ![Bonne\_Eggleston](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/46a35a/32.png) [@Bonne\_Eggleston](https://www.ruby-forum.com/u/Bonne_Eggleston)\
**Post date:** [December 8, 2006, 8:42pm UTC](https://www.ruby-forum.com/t/functional-testing/101347/3 "2006-12-08T20:42:42Z")

</div>

Bonne Eggleston wrote:

> Hi there,  
> I’m implementing the Globalize plugin on my application, and so far it’s  
> working quite well.  
> One problem I’m having is that I can’t do any functional tests.  
> It appears as though the locale is not set for the tests.

Having the same problem. I’ve had to comment out all my functional tests  
for the moment because of locale not being set. Anyone know of a  
solution?

---

<div class="post-metadata">

**Author:** ![Bonne\_Eggleston](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/46a35a/32.png) [@Bonne\_Eggleston](https://www.ruby-forum.com/u/Bonne_Eggleston)\
**Post date:** [December 9, 2006, 6:33pm UTC](https://www.ruby-forum.com/t/functional-testing/101347/4 "2006-12-09T18:33:37Z")

</div>

Posted about it here also:

> **[bitbutter.com](http://ww38.bitbutter.com/5/globalize-did-localebase_language-eat-my-functional-tests/)**
>
> This domain may be for sale!

---

<div class="post-metadata">

**Author:** ![Bonne\_Eggleston](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/46a35a/32.png) [@Bonne\_Eggleston](https://www.ruby-forum.com/u/Bonne_Eggleston)\
**Post date:** [December 12, 2006, 3:21pm UTC](https://www.ruby-forum.com/t/functional-testing/101347/5 "2006-12-12T15:21:12Z")

</div>

Bitbutter wrote:

> Posted about it here also:  
> [bitbutter.com](http://www.bitbutter.com/5/globalize-did-localebase_language-eat-my-functional-tests/)

I’m experiencing the same problem, but since I’ve just started learning  
Rails, I can’t seem to fix it. Does anyone have a solution yet?

---

<div class="post-metadata">

**Author:** ![Bonne\_Eggleston](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/46a35a/32.png) [@Bonne\_Eggleston](https://www.ruby-forum.com/u/Bonne_Eggleston)\
**Post date:** [December 12, 2006, 4:23pm UTC](https://www.ruby-forum.com/t/functional-testing/101347/6 "2006-12-12T16:23:08Z")

</div>

Benjamin K. wrote:

> try this:
> 
> Loading test environment.
> 
> > > Locale  
> > > =\> Globalize::Locale
> > 
> > > Locale.set\_base\_language Language.pick(‘en’)  
> > > =\> English
> > 
> > > Locale.base\_language  
> > > =\> English
> > 
> > > Locale.set\_base\_language Language.pick(‘de’)  
> > > =\> German
> > 
> > > Locale.base\_language  
> > > =\> German

Odd, i get an error when i try that:

Loading test environment.

> > Locale  
> > =\> Globalize::Locale
> 
> > Locale.set\_base\_language Language.pick(‘en’)  
> > ArgumentError: bad format for , not rfc-3066 compliant  
> > from  
> > ./script/…/config/…/config/…/vendor/plugins/globalize/lib/globalize/localization/rfc\_3066.rb:6:in  
> > `parse' from ./script/../config/../config/../vendor/plugins/globalize/lib/globalize/localization/locale.rb:64:in`set\_base\_language’  
> > from (irb):2
> 
> >

(rails 1.1.6.5618)

---

<div class="post-metadata">

**Author:** ![Bonne\_Eggleston](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/46a35a/32.png) [@Bonne\_Eggleston](https://www.ruby-forum.com/u/Bonne_Eggleston)\
**Post date:** [December 12, 2006, 4:06pm UTC](https://www.ruby-forum.com/t/functional-testing/101347/7 "2006-12-12T16:06:24Z")

</div>

On Dec 12, 2006, at 15:21, KJ Wierenga wrote:

> Bitbutter wrote:
> 
> > Posted about it here also:  
> > [bitbutter.com](http://www.bitbutter.com/5/globalize-did-localebase_language-eat-)  
> > my-functional-tests/
> 
> I’m experiencing the same problem, but since I’ve just started  
> learning  
> Rails, I can’t seem to fix it. Does anyone have a solution yet?

try this:

Loading test environment.

> > Locale  
> > =\> Globalize::Locale  
> > Locale.set\_base\_language Language.pick(‘en’)  
> > =\> English  
> > Locale.base\_language  
> > =\> English  
> > Locale.set\_base\_language Language.pick(‘de’)  
> > =\> German  
> > Locale.base\_language  
> > =\> German

---

<div class="post-metadata">

**Author:** ![Bonne\_Eggleston](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/46a35a/32.png) [@Bonne\_Eggleston](https://www.ruby-forum.com/u/Bonne_Eggleston)\
**Post date:** [December 12, 2006, 4:36pm UTC](https://www.ruby-forum.com/t/functional-testing/101347/8 "2006-12-12T16:36:44Z")

</div>

KJ Wierenga wrote:

> When I use Locale.set\_base\_language Language.pick(‘en’) function I get:
> 
> /vendor/plugins/globalize/lib/globalize/localization/rfc\_3066.rb:6:in  
> `parse’: bad format for , not rfc-3066 compliant (ArgumentError)

So same error as Bitbutter. I’m using Rails 1.1.6 on Windows

---

<div class="post-metadata">

**Author:** ![Bonne\_Eggleston](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/46a35a/32.png) [@Bonne\_Eggleston](https://www.ruby-forum.com/u/Bonne_Eggleston)\
**Post date:** [December 12, 2006, 4:34pm UTC](https://www.ruby-forum.com/t/functional-testing/101347/9 "2006-12-12T16:34:40Z")

</div>

When I use Locale.set\_base\_language Language.pick(‘en’) function I get:

/vendor/plugins/globalize/lib/globalize/localization/rfc\_3066.rb:6:in  
`parse’: bad format for , not rfc-3066 compliant (ArgumentError)

---

<div class="post-metadata">

**Author:** ![Bonne\_Eggleston](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/46a35a/32.png) [@Bonne\_Eggleston](https://www.ruby-forum.com/u/Bonne_Eggleston)\
**Post date:** [December 12, 2006, 5:11pm UTC](https://www.ruby-forum.com/t/functional-testing/101347/10 "2006-12-12T17:11:13Z")

</div>

(KJ Wierenga: i initially tried a set up like the one you posted but  
also ran into similar recursion difficulties. If you like you can mail  
me at kj.1.cbit AT [spamgourmet.com](http://spamgourmet.com) and i’ll send you some examples of  
the sessions based approach i’m using now)

---

<div class="post-metadata">

**Author:** ![Bonne\_Eggleston](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/46a35a/32.png) [@Bonne\_Eggleston](https://www.ruby-forum.com/u/Bonne_Eggleston)\
**Post date:** [December 12, 2006, 4:39pm UTC](https://www.ruby-forum.com/t/functional-testing/101347/11 "2006-12-12T16:39:07Z")

</div>

I managed to get rid of the ‘base\_language’ not set error by having the  
following code in my ApplicationController:

class ApplicationController \< ActionController::Base  
model :cart  
model :line\_item

before\_filter :set\_locale  
after\_filter :set\_charset

def set\_locale  
if !params[:locale].nil? && LOCALES.keys.include?(params[:locale])  
Locale.set LOCALES[params[:locale]]  
else  
if Locale.base\_language  
redirect\_to params.merge( ‘locale’ =\> Locale.base\_language.code  
)  
else  
redirect\_to params.merge( ‘locale’ =\> ‘en’ )  
end  
return true  
end  
end

…  
end

But now I get:

Exception: Render and/or redirect were called multiple times in this  
action. Please note that you may only call render OR redirect, and only  
once per action. Also note that neither redirect nor render terminate  
execution of the action, so if you want to exit an action after  
redirecting, you need to do something like “redirect\_to(…) and  
return”. Finally, note that to cause a before filter to halt execution  
of the rest of the filter chain, the filter must return false,  
explicitly, so “render(…) and return false”.  
d:/Tools/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action\_controller/base.rb:840:in  
`redirect_to' d:/Tools/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/base.rb:854:in`redirect\_to’  
D:/Projects/Rails/depot/config/…/app/controllers/application.rb:43:in  
`authorize' d:/Tools/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/filters.rb:399:in`send’  
d:/Tools/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action\_controller/filters.rb:399:in  
`call_filters' d:/Tools/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/filters.rb:394:in`each’  
d:/Tools/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action\_controller/filters.rb:394:in  
`call_filters' d:/Tools/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/filters.rb:383:in`before\_action’  
d:/Tools/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action\_controller/filters.rb:365:in  
`perform_action_without_benchmark' d:/Tools/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/benchmarking.rb:69:in`perform\_action\_without\_rescue’  
d:/Tools/InstantRails/ruby/lib/ruby/1.8/benchmark.rb:293:in `measure' d:/Tools/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/benchmarking.rb:69:in`perform\_action\_without\_rescue’  
d:/Tools/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action\_controller/rescue.rb:82:in  
`perform_action' d:/Tools/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/base.rb:408:in`send’  
d:/Tools/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action\_controller/base.rb:408:in  
`process_without_filters' d:/Tools/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/filters.rb:377:in`process\_without\_session\_management\_support’  
d:/Tools/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action\_controller/session\_management.rb:117:in  
`process_without_test' d:/Tools/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/test_process.rb:16:in`process’  
d:/Tools/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action\_controller/test\_process.rb:363:in  
`process' d:/Tools/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/test_process.rb:336:in`get’  
D:\Projects\Rails\depot/test/functional/login\_controller\_test.rb:17:in  
`test_index' d:/Tools/InstantRails/ruby/lib/ruby/1.8/test/unit/testcase.rb:72:in` **send** ’  
d:/Tools/InstantRails/ruby/lib/ruby/1.8/test/unit/testcase.rb:72:in  
`run' d:/Tools/InstantRails/ruby/lib/ruby/1.8/test/unit/testsuite.rb:34:in`run’  
d:/Tools/InstantRails/ruby/lib/ruby/1.8/test/unit/testsuite.rb:33:in  
`each' d:/Tools/InstantRails/ruby/lib/ruby/1.8/test/unit/testsuite.rb:33:in`run’  
d:/Tools/InstantRails/ruby/lib/ruby/1.8/test/unit/testsuite.rb:34:in  
`run' d:/Tools/InstantRails/ruby/lib/ruby/1.8/test/unit/testsuite.rb:33:in`each’  
d:/Tools/InstantRails/ruby/lib/ruby/1.8/test/unit/testsuite.rb:33:in  
`run' d:/Tools/InstantRails/ruby/lib/ruby/1.8/test/unit/ui/testrunnermediator.rb:46:in`run\_suite’  
D:/Tools/RadRails\_0\_7\_2/plugins/org.rubypeople.rdt.testunit\_0.8.0.604272100PRD/ruby/RemoteTestRunner.rb:107:in  
`start_mediator' D:/Tools/RadRails_0_7_2/plugins/org.rubypeople.rdt.testunit_0.8.0.604272100PRD/ruby/RemoteTestRunner.rb:52:in`start’  
D:/Tools/RadRails\_0\_7\_2/plugins/org.rubypeople.rdt.testunit\_0.8.0.604272100PRD/ruby/RemoteTestRunner.rb:272

---

<div class="post-metadata">

**Author:** ![Bonne\_Eggleston](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/46a35a/32.png) [@Bonne\_Eggleston](https://www.ruby-forum.com/u/Bonne_Eggleston)\
**Post date:** [December 12, 2006, 6:24pm UTC](https://www.ruby-forum.com/t/functional-testing/101347/12 "2006-12-12T18:24:58Z")

</div>

Perhaps you meant to return false in a filter chain after a redirect?

[http://weblog.jamisbuck.org/2005/7/8/rails-tip-of-the-day](http://weblog.jamisbuck.org/2005/7/8/rails-tip-of-the-day)

FYI: be careful with the set\_charset action:

[http://www.nabble.com/FIXED-Internet-Explorer-cannot-download-pages-tf2716459s17045.html](http://www.nabble.com/FIXED-Internet-Explorer-cannot-download-pages-tf2716459s17045.html)

On 12/12/06, Bitbutter [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> [http://rubyforge.org/mailman/listinfo/railsi18n-discussion](http://rubyforge.org/mailman/listinfo/railsi18n-discussion)

–  
Charles Brian Q.  
self-promotion: [www.seebq.com](http://www.seebq.com)  
highgroove studios: [www.highgroove.com](http://www.highgroove.com)  
slingshot hosting: [www.slingshothosting.com](http://www.slingshothosting.com)
