Rubocop - ArgumentAlignment does not appear to be working - ruby-on-rails

Posting this question and deleted my original because it was not properly describing the issue
I've been working on getting things aligned properly in my code. I am looking to try and enforce this:
method(
key1: 'value1',
key2: 'value2'
)
and not
method( key1: 'value1',
key2: 'value2'
)
also not
method(
key1: 'value1',
key2: 'value2'
)
This is where things are falling down.
I currently have:
Layout/FirstMethodArgumentLineBreak
Layout/FirstArgumentIndentation
Those get me 99% of the way. However, the only way it appears to get the last piece working is
Layout/ArgumentAlignment
I've tried both EnforcedStyle: with_first_argument as well as EnforcedStyle: with_fixed_indentation (both of which in this case should be the same). However, nothing ever gets flagged when they are not aligned.

I found the issue...we are currently using ruby-2.4.x, which only allows up to rubocop 1.12.1. We are currently working on upgrading to 2.6.8.
I found that Layout/AttributeAlignment is not working properly in 1.12.1, however it is working in the current version 1.45.1.
So this is a notice to anyone still using the older version that this cop is not currently working properly.

Related

Pagination in Angular2 (On Rails5)

Normally with Rails, I'd use will_paginate and call it a day, but I'm using Rails5 purely as an API, and front-end is completely Angular2.
I've looked into NG Bootstrap4's Pagination but I'm having quite a few issues getting it to do anything besides render - And I can imagine why. What is the proper process for Paginating on Angular? I tried using will-paging to paginate the JSON but instead I just limit the results.
I also looked into ng2-pagination which seemed to have a lot of the features I wanted, but I started getting
Uncaught TypeError: ctorParameters.map is not a function errors for everything so I thought maybe I should take it a step back.
Would the proper process be to use the controller in Rails to append a 'page' parameter to the JSON Results? Or would something more like Virtualization be the route I should go?
Having quite a few issues - Even once I have the bar active, it obviously can't control my script.
getDecks(): Observable<Deck[]> {
return this.http.get(this.decksUrl)
.map((response: Response) => <Deck[]>response.json())
.catch(this.handleError);
}
this is the call that contacts the API and gets the response - I feel like I would involve the 'page' here to actually allow Pagination to do something?
I was able to figure it out - multiple issues. For those wondering:
Uncaught TypeError: ctorParameters.map is not a function seems to be a compilation issue with newer packages.
Different library but similar issues
I upgraded Ang2 + Respective libraries to remove error. From there the instructions made a lot more sense.
The pipe should be built directly into your ngFor
<span *ngFor="let deck of decks| paginate: { itemsPerPage: 10, currentPage: p }" class="list-group-item list-group-item-action">
Then placing
<pagination-controls (pageChange)="p = $event"></pagination-controls>
Where-ever you want an async bar resolves the issue.
Works perfectly - Library is Ng2-Pagination

Rails I18n not cascading

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.

How to get native country name with Google Closure I18n?

I am trying to see if I can use Google Closure library form my webapp's internationalization and localization needs. I tried to find any tutorials on the subject, but could not find any and it seems I am stuck when trying on my own.
I am interested in getting the native name of a country.
I am not sure how I should use the the goog.locale component, though. It seems that for example, goog.locale.getNativeCountryName('EE') always returns 'EE', instead of 'Eesti' as I would expect it to.
goog.require('goog.locale');
...
console.log( goog.locale.getNativeCountryName('EE') ) // Outputs: 'EE'
Maybe I am missing some dependencies?
EDIT: After fiddling around a little bit I discovered that if I use et_EE instead of EE, I get the expected 'Eesti'. However, that just seems plain wrong. et_EE is a locale code, not a country code, and the function clearly expects a country code... Maybe I am still doing something wrong?
getNativeCountryName() receives a language code (in this case et) and not a country code (EE). See the API docs:
Returns the country name of the provided language code in its native
language.
Therefore:
goog.require('goog.locale');
...
console.log( goog.locale.getNativeCountryName('et') ) // Should return 'Eesti'

How to fill tinymce-rails editor with capybara and selenium?

I have trouble with using capybara to test tinymce form. I'm using tinymce-rails and have 7 editors in my form. Also I'm using asciimath plugin with tinymce.
Everything works fine, but I'm unable to write tests to fill in tinymce editor.
Here is how my step definition code looks like, very similar to what is described here:
within_frame("content_ifr") do
editor = page.find_by_id('tinymce')
editor.native.send_keys 'test'
end
The problem is when I run the following:
editor.native.clear # works, clear the editor area, I'm testing this with pry
editor.native.send_keys :tab # works, moves focus to next input
editor.native.send_keys 'test' # returns "", nothing happens, nothing in editor
So clear and send_keys :tab work as expected. But I can't send any string. send_keys function is always returning empty string, and nothing happens when I do test using pry.
What is going wrong here? and how can I debug / investigate the problem?
Thanks.
I know that this is an old question but I just found it while trying to solve this issue as well.
Although the original question said that he has 7 tinymce's on the same page I think that my solution might work for him too but I do know it will work if there is one tinymce as was my case.
In my request spec I used this:
page.execute_script('$(tinymce.editors[0].setContent("my content here"))')
The page.execute_script with tell it to run the jQuery function. It then finds the first tincymce editor and sets the content.
Worked like a charm for me. I think if there are more than one tinymce it can be called by its position.
Switching to chrome as described here solved my problem.
Obviously the problem is related with a bug in firefox driver.
Still i think it is a valid question for firefox.
Try to switch to an iframe that contains tinymce textarea input, and than send_keys:
# +session+ is an instance of Capybara::Session class
browser = session.driver.browser
browser.switch_to.frame(iframe_id)
editor.native.send_keys(text)
browser.switch_to.default_content
I had the same issue. After a day fighting, my tests finally passed.
The code that I am using is:
within_frame("producto_condiciones_ifr") do
editor = page.find_by_id('tinymce')
editor.native.send_keys 'filling text'
end
The first line is a method of capybara. The parameter passed is the ID of the iframe.
Line #2 is a must.
In line #3 goes the text that you wish to place inside TinyMCE
just came across this problem with RoR and rspec
I managed to solve by doing this:
within_frame { page.find_by_id("tinymce").set("new content here") }
the set method will replace any existing content by the new one
if you want to keep the current content and add things to it, use the send_keys method

How to get parent node in Capybara?

I'm working with many jQuery plugins, that often create DOM elements without id or other identification properties, and the only way to get them in Capybara (for clicking for example) - is to get their neighbor (another child of its ancestor) first. But I didn't find anywhere, does Capybara support such things for example:
find('#some_button').parent.fill_in "Name:", :with => name
?
I really found jamuraa's answer helpful, but going for full xpath gave me a nightmare of a string in my case, so I happily made use of the ability to concatenate find's in Capybara, allowing me to mix css and xpath selection. Your example would then look like this:
find('#some_button').find(:xpath,".//..").fill_in "Name:", :with => name
Capybara 2.0 update: find(:xpath,".//..") will most likely result in an Ambiguous match error. In that case, use first(:xpath,".//..") instead.
I found the following that does work:
find(:xpath, '..')
Capybara has been updated to support this.
https://github.com/jnicklas/capybara/pull/505
There isn't a way to do this with capybara and CSS. I've used XPath in the past to accomplish this goal though, which does have a way to get the parent element and is supported by Capybara:
find(:xpath, '//*[#id="some_button"]/..').fill_in "Name:", :with => name
If you stumbled across this trying to figure out how to find any parent (as in ancestor) node (as hinted at in #vrish88's comment on #Pascal Lindelauf's answer):
find('#some_button').find(:xpath, 'ancestor::div[#id="some_div_id"]')
This answer pertains to how to manipulate a sibling element which is what I believe the original question is alluding to
Your question hypothesis works with a minor tweak. If the dynamically generated field looks like this and does not have an id:
<div>
<input></input>
<button>Test</button>
</div>
Your query would then be:
find('button', text: 'Test').find(:xpath, "..").find('input').set('whatever')
If the dynamically generated input does come attached with an id element (be careful with these though as in angular, they are wont to change based on adding and deleting elements) it would be something like this:
find('button', text: 'Test').find(:xpath, "..").fill_in('#input_1', with: 'whatever')
Hope that helps.
I'm using a different approach by finding the parent element first using the text within this parent element:
find("<parent element>", text: "text within your #some_button").fill_in "Name:", with: name
Maybe this is useful in a similiar situation.
As mentioned in comment by #Tyler Rick Capybara in these days have methods[
ancestor(selector) and sibling(selector)
I needed to find an ancestor with a css class, though it was indeterminate if it the target ancestor had one or more css classes present, so I didn't see a way to make a deterministic xpath query. I worked this up instead:
def find_ancestor_with_class(field, cssClass)
ancestor = field
loop do
ancestor = ancestor.find(:xpath, '..')
break if ancestor.nil?
break if ancestor.has_css? cssClass
end
ancestor
end
Warning: use this sparingly, it could cost you a lot of time in tests so make sure the ancestor is just a few hops away.
Here it is
http://rubydoc.info/github/jnicklas/capybara/master/Capybara/Node/Base:parent
There is a parent method present;)

Resources