Rails I18n not cascading - ruby-on-rails

I would like to use the I18n cascading module as described here, but I cannot get the cascading to working.
I've a YAML file as follows:
follows:
every_x_day: "value here"
...
main:
...
In follows/main view, I'm calling the t helper for the key '.every_x_day', which is just short for 'follows.main.every_x_day'. No such key is of course found, so I would expect the cascading to look next for 'follows.every_x_day', but this does not happen.
I've seen the question and the answer here: I've added the
I18n.backend.class.send(:include, I18n::Backend::Cascade)
to application.rb. But when I call the translation helper with cascade: true, it simply does not cascade. The page just shows that the translation is missing (key name on magenta background).
I've also checked it with this i18n patch. It also shows that no cascading search happens. It just looks for the most specific key, doesn't find anything, and stops searching.
Any ideas what is causing this behaviour?

Ok, so I assume that you have something like this in your code:
<%= t('.every_x_day', cascade: true) %>
Are you completely sure, that '.every_x_day' starts looking for the key in 'follows.main.every_x_day' The way I describe it in the answer in my original question is the normal behaviour for the I18n and the lazy-lookup in views. So, the first thing I would try is to pass the full key into the helper:
<%= t('follows.main.every_x_day', cascade: true) %>
Then you can at least be sure, that your original lookup-path is correct.
If that doesn't work, then the cascading module isn't loaded.
Did you put the code inside the config-options? (see my updated_answer).
If it still doesn't work, come back at me and we will try to figure it out together.

Turns out the issue was caused by the I18n-monkeypatch (see the original question). After disabling the monkeypatch, the cascading took place as it should. This was carelessness on my part, apparently I never tested the app without the monkeypatch.
Anyway, thanks for taking the time to help klaffenboeck.

Related

Capybara: Finding a second checkbox which is identical to the first

I am writing tests for view files. I have a page with two checkboxes which allows the user to Select All items in two different lists. However, the checkboxes are part of a partial so are identical. I have managed to check the first one using:
first(:checkbox, "Select all").click
But I am unable to check the second. I have tried replacing first with last and with second but to no avail.
I think I may need to use the find selector but am struggling with that also. Any help much appreciated.
Thanks
UPDATE
It appears that this in fact another issue. I think that any checkbox that impacts on other checkboxes does not work as expected when "checked" by Capybara. So the current answers below work in the sense that they do check the checkbox, but the expected behaviour does not occur i.e. the checkboxes linked to them do not get "checked". I may be wrong though.
try this
# find the second checkbox
find('input[type="checkbox"]:nth-child(2)').click
You can use find all
all('input[type="checkbox"]', :text => 'Select all')[1].click
Whoops. Turns out it was a JS issue and not Capybara macthers! Thanks for the help though!

DNN jQuery conflict - pop up window won't close

I'm working on a DNN site that has been set up before my time here.
There's some conflict with the jQuery I believe, which prevents the modal pop up window in the attached calendar (link) events to not close properly:
http://www.sim-one.ca/NewsandEvents/calendar-of-events.aspx
I tried eliminating one script call at a time to see which one could be messing this up to no avail.
When I test this with the default theme it works like a charm.
Any ideas? Anyone came across something like this before?
Thank you!
You've got plenty of 404 errors on that page, ensure first, that files are in their place.
For example, http://www.sim-one.ca/NewsandEvents/Portals/_default/Skins/SimTwo/includes/js/jquery.listnav-2.1.js was not found. Ensure this path exists.
I agree with Anrie that your references are broken. For example, http://www.sim-one.ca/NewsandEvents/Portals/_default/Skins/SimTwo/includes/css/custom-theme/jquery-ui-1.8.9.custom.css is showing 404 but http://www.sim-one.ca/Portals/_default/Skins/SimTwo/includes/css/custom-theme/jquery-ui-1.8.9.custom.css
You can just use links like :
/Portals/_default/Skins/SimTwo/includes/css/custom-theme/jquery-ui-1.8.9.custom.css in order to fix this in skin file or use <%= SkinPath %>.
Try adding return false; on your event after calling the dnnModal.show()

incorporating all views into one view

Just wondering what the shorthand would be in Rails to do this (if any):
I have views/pages/ containing 5 html.erb files and they all use the same default layout.html.erb, with one yield statement in the middle of it (the standard setup).
Now I want one view that incorporates all 5 of those erb files above contiguously, one after the other, in place of the one existing yield statement in that same layout.html.erb.
What minimal changes would I make to the layout.html.erb to accomplish this.
(Rails Newbie - like it more than Django now).
Ah,
I see what you're saying. Try this. Have your file structure such that all the views for said controller are in one folder...
#controllers_views = Dir.glob("your/controllers/views/*.erb")
#controllers_views.each { |cv| puts cv }
Seems like that would work, I'm away from my dev box or I'd test it for you.
Hope that helps.
Good luck!
You could always have a javascript that requests the sequential yields at a time interval as an ajax request. Then just your target element change to reflect the updated information.
Alternatively load all 5 into different divisions, and have them revolve visibility, like a picture gallery. CSS3 could pull this off.
http://speckyboy.com/2010/06/09/10-pure-css3-image-galleries-and-sliders/

How to click on the second link with the same text using Capybara in Rails 3?

In a view file I have:
= link_to 'View', post
= link_to 'View', comment
In a spec file (I'm using Capybara):
click_on 'View'
It clicks on the first link, but I want it to click on the second one. How can I do it?
You could try to find all entries and deal with an array:
page.all('a')[1].click
Would help to have a class or use within to scope your search ;)
There's probably a few ways but I usually scope something like this.
within(".comment") do
click_on("View")
end
There's quite possibly/probably alternatives as well. I usually do my acceptance testing from cucumber, so my steps typically look like
When I follow "View" within the comment element
Where I have a step that translates within the comment element to a scoped call to the step itself (which I think is built into the latest capybara web_steps)
The worst thing about "the second" link is that it can become the third or the first or even the twenty fifth someday. So, scoping with a within block is the best way. Example:
within(".comment") do
click_on("View")
end
But if it is difficult to specify the link with a within scope (which sometimes it really is), I guess the way to click the second link with a certain text is:
find(:xpath, "(//a[text()='View'])[2]").click
In later versions of capybara (2.0.2, for example) both click_on 'View' and click_link 'View' will raise an ambiguous match error:
Failure/Error: click_on 'View'
Capybara::Ambiguous:
Ambiguous match, found 2 elements matching link or button "View"
So this won't do even if you want to click the first link (or if any link would be ok, which is my case).
As far as I understand this is made to force people write more specific tests where particular links are clicked.
It definitely could be tricky to debug the code if you accidentally placed two or more links with identical text and try to see what is happening. It's good to rely on something that is unlikely to change and specifying a link with a within block is a nice way to do this.
There are many ways for solving this type of problems.
Do it like this
if(page.find("a")[:href] == "comment")
click_on("View")
or
page.find("a:eq(2)").click
Remember javascript indexing starts with 0 while In Capybara, indexing starts with 1. So use a:eq(2) here for second href.
For capybara 2 solution:
within(".comment") do
click_on("View")
end
would not help if you have a few .comment. So simple use: page.first(:link, "View").click
This works for me if you have several rows of identical classes and you want to find the second row. Like a previous author mentioned, capybara indexing starts at 1.
within all(".trip-row")[2] do
assert page.has_content?("content")
end
If you use capybara-ui you could define the widget, or reusable DOM reference, for each widget.
# define your widget. in this case,
# we're defining it in a role
widget :view_post, ['.post', text: 'View']
widget :view_comment, ['.comment', text: 'View']
# then click that widget in the test
role.click :view_post
role.click :view_comment

ASP.NET MVC JavaScript Routing

Spoiler alert: this is NOW a question, so apologies to anyone that read it purely as a discursive topic :)
Anyway, I was doing a little research today re adding routes via javascript when i thought that a bit of google research wouldn't hurt. Basically, my aim was to do away with the following type of construct within my views:
and replace it with something akin to:
well, i lucked out a little today after finding this fantastic article (which isn't mine nor do i have any affiliation other than respect for the piece of work):
http://weblogs.asp.net/zowens/archive/2010/12/20/asp-net-mvc-javascript-routing.aspx
this really has been a missing link (or so i thought) for me when dealing with routes via javascript. However, the 2nd code example is misleading and actually won't produce what the example leads on. Can anyone suggest a fix for this and/or an alternative solution to allow this fluent convention of js routes within mvc views??
cheers...
[edit] - question edited 22:16 GMT to explore deeper options on this topic, plus changed title (removed OT portion).
So the question is why the second code example won't work as expected. Here's the answer, post currently doesn't return anything. This is an example of a certain developer not looking at the details of the code. When you use homePageUrl, the value will be undefined.
To actually get the home page URL, you'd do the following:
$.routeManager.action({controller:'Home', action:'Index'}).toUrl()
So, the moral of the story is that the code is a bit broken. The post action SHOULD return an object where you can put "toUrl()" right after the post is performed, like this:
$.routeManager.action({controller:'Home', action:'Index'})
.post(function(data){ alert(data); })
.toUrl();
I'll be fixing this bug in a bit!

Resources