when a user visit the home page of my site he will be redirected
depending on his culture, so if his culture is english he will be
redirected to myapp/en if he is italian to myapp/it and so on....
how can I say this with rspec?
I was trying something like:
it "should redirect to spanish home page" do
get 'index'
#don't know how to say the culture is spanish
response.should redirect_to(spanish_home_page)
end
any help?
Thanks
Gnagno
--
Posted via http://www.ruby-forum.com/.
_______________________________________________
rspec-users mailing list
rspec...@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users
How does the application detect the user's "culture"?
Cheers,
-Tom
Thanks for your reply Tom,
in my home controller I have a line like this for each language:
redirect_to localized_home_page_path :culture => 'es' and return if
request.env['HTTP_ACCEPT_LANGUAGE'].include? 'es-ES'
as I said before I am just 'experimenting and playing' so any suggestion
is accepted :)
maybe I should access to the request object from my spec code?
--
Posted via http://www.ruby-forum.com/.
Tom Stuart wrote:Thanks for your reply Tom,
> How does the application detect the user's "culture"?
>
> Cheers,
> -Tom
in my home controller I have a line like this for each language:
redirect_to localized_home_page_path :culture => 'es' and return if
request.env['HTTP_ACCEPT_LANGUAGE'].include? 'es-ES'
I didn't find the cucumber forum, so please forgive me if I am too much
out of topic here.
I was trying to achieve the same with cucumber, so I wrote this:
Scenario Outline: visit home page and get redirect to localized home
page
Given my culture is <culture>
When I go to the home page
Then I should be redirected to the <page>
Examples:
| culture | page |
| italian | italian_home_page |
| english | english_home_page |
| french | french_home_page |
| spanish | spanish_home_page |
| german | german_home_page |
| japanese | japanese_home_page |
but I cannot access request.env from a cucumber step, and moreover I
think accessing to request.env from cucumber could tie it too much to
the application, am I right?
> Sorry, I have one more question,
>
> I didn't find the cucumber forum, so please forgive me if I am too
> much
> out of topic here.
http://wiki.github.com/aslakhellesoy/cucumber/get-in-touch
> I was trying to achieve the same with cucumber, so I wrote this:
>
> Scenario Outline: visit home page and get redirect to localized home
> page
> Given my culture is <culture>
> When I go to the home page
> Then I should be redirected to the <page>
>
> Examples:
> | culture | page |
> | italian | italian_home_page |
> | english | english_home_page |
> | french | french_home_page |
> | spanish | spanish_home_page |
> | german | german_home_page |
> | japanese | japanese_home_page |
>
> but I cannot access request.env from a cucumber step, and moreover I
> think accessing to request.env from cucumber could tie it too much to
> the application, am I right?
Right. You need to ask the cukes group (or the webrat group, or the
rails group) about how you pass HTTP headers with your in the step
"When I go to the home page".
>
> --
> Posted via http://www.ruby-forum.com/.
> _______________________________________________
> rspec-users mailing list
> rspec...@rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
cheers,
Matt
http://mattwynne.net
+447974 430184
in my step definitions I just put:
Given /^my culture is (.+)$/ do |culture|
header "HTTP_ACCEPT_LANGUAGE", "it-IT" if culture == 'italian'
header "HTTP_ACCEPT_LANGUAGE", "en-GB" if culture == 'english'
header "HTTP_ACCEPT_LANGUAGE", "fr-FR" if culture == 'french'
header "HTTP_ACCEPT_LANGUAGE", "es-ES" if culture == 'spanish'
header "HTTP_ACCEPT_LANGUAGE", "de-DE" if culture == 'german'
header "HTTP_ACCEPT_LANGUAGE", "en-US" if culture == 'american'
header "HTTP_ACCEPT_LANGUAGE", "jp-JP" if culture == 'japanese'
end
and it works :)