Redirect in around filter after action has been yielded - redirect

I'm using an around filter which on certain occasions should redirect user to other path AFTER an action has been yielded (either ending with render or redirect).
Writing redirect_to in around filter after yield statement results in double render error. Trying to "reconfigure" response object (by setting body to nil and location header to desired url) results in folloing error (taken from controller specs):
Failure/Error: Unable to find matching line from backtrace
You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.each
Has anybody done anything similar to this?

actually I manged to do redirect in around filter after action has been yielded. You just have to redefine the response.location attribute and reset the response.status to 302 (instead of 200).

You can't yield and then redirect/render afterwards. If you need to use some of the logic in the controller action in your around filter, consider moving that logic to a before_filter, or the first block of your around filter so that its available both in the around filter to determine what to do (redirect, or otherwise yield), and also available to the action you will be yielding to

Related

In Chrome DevTools can you filter to exclude results?

In the Console tab, I have a long list of error messages that originate from a third party library that I can do nothing about. In the Filter textbox, is there some way to write a filter that excludes only errors that match a filter, rather the other way round? For instance, can I filter out messages that match:
Material-UI: The `InputAdornment` variant infers the variant prop you do not have to provide one.
...and show everything else?
In the filter box, the error that you are getting you just start the filter with -
For example, on one site, they were getting the error ERR_BLOCKED_BY_CLIENT to find all errors besides ERR_BLOCKED_BY_CLIENT you would just put -ERR_BLOCKED_BY_CLIENT

Protractor - check if element is present and either stop test or continue

I have a Protractor test that pulls various values from the UI and stores them as variables for comparison with values from a different database.
Now this test needs to run against multiple sites BUT of the 25 maximum data points recorded, some sites only have 22.
Clearly the test fails on those "22" sites since the elements are not present.
What I want to achieve is where there's a "22" site, the tests against the not present elements are ignored and the test proceeds to the end. Conveniently, the "missing" elements are the last ones in the spec.
Crudely speaking...
if element-y is not present end test or if element-y is present continue
Grateful if anyone could advise.
Thanks #sergey. I've modified your example as below....
if (!(await element(by.xpath('//*[#id="root"]/div/div[2]/main/div/div/section[5]/div/div/div[1]/section/div/span')).isPresent())) {
console.warn ('Functions are not present, closing the session')
await browser.close()
I get this error:
if (!(await element(by.xpath('//*[#id="root"]/div/div[2]/main/div/div/section[5]/div/div/div[1]/section/div/span')).isPresent())) {
^^^^^^^
SyntaxError: Unexpected identifier
I've tried using a 'var' instead of the actual element, but get the same result.
Thanks
well the best option that I recall is still pretty dirty... you can do something like this
if (!(await element.isPresent())) {
console.warn('Element not present, closing the session')
await browser.close()
}
And then the rest of test cases will fail as session not found or similar error
The reason you can't do anything better because in protractor you can't do conditional test cases based on a Promise-like condition, if that makes sense...

How to filter by both text and property in Chrome DevTool's network panel?

I want to filter Chrome DevTool's network panel by the method property and text in the URL. For example, if I am searching for the text chromequestion in the URL and only HTTP GET requests (ignore PUT, POST, DELETE, etc).
I am able to filter by text or by method:
I am not able to combine the filter to search by both text and method:
I read the documentation at https://developers.google.com/web/tools/chrome-devtools/network-performance/reference#filters and I am able to filter by multiple properties (.e.g, domain:*.com method:GET). However, I am unable to filter by text and property (e.g., method:GET chromequestion).
Unfortunately, it's not possible to do this currently. I played around in DevTools originally, but couldn't find a way. I later had a look into how the filtering was implemented, and can confirm there's a limitation preventing you from mixing the pre-defined filters and text filters.
Implementation details
This is a bit long but I thought it might be interesting for some to see how it's implemented. I will probably look into improving the implementation, either myself or I'll log it because it's limited.
There's a _parseFilterQuery function that parses the input field and categorises the entries into two arrays. The first is called filters, and it's the pre-defined filtering options, such as method:GET etc. The second is a text array filter, split up by spaces. The parser determines the difference fairly naively, by checking for the occurrence of :, and - at the start (for negation).
Scenario 1
You only input a pre-defined filter, or multiple filters. For each filter, the specific filter function, which looks at the different properties of the request object, is pushed to a network module filters array (this._filters). Later on, for each request, the function is called on it, and a match returns true, otherwise false. This will determine whether the request is shown. There's obviously a requirement for ALL filters to return true for the row to show.
Scenario 2
This is the interesting one, where you input both a pre-defined filter and a bit of text. This covers the Stack Overflow question. The _parseFilterQuery function looks at the text filters first, before the pre-defined ones. In Scenario 1, this was empty, so it was skipped.
We pass each text word to the _createTextFilter, and push each of the resulting filters to the network module filters array. However, the implementation of this is questionable. The only time the actual word passed in is used is to check whether its a negation filter for a bit of text. If the first character is -, it means the user doesn't want to see a request with the following word in the name. For example -icon means don't show any request with that in the name/page. If there is no negation, it simply returns the WHOLE input text as a regular expression, NOT the word passed in. In my case, it returns /method:GET icon/i.
The pre-defined filters are looked at next. In this case, method:GET is pushed.
Finally, it loops over the requests calling each filter on it. However, since the first filter is /method:GET icon/i, it makes ALL other filters redundant because it will NEVER pass. The text filters only apply to name and path, so method:GET in a text filter will be invalid.

Dropbox Api v2 - confusion with cursor and paging for list_folders

The files/list _folders method in api docs has the following for the description of the cursor parameter:
cursor - Pass the cursor into list_folder/continue to see what's changed in the folder since your previous query.
has_more - If true, then there are more entries available. Pass the cursor to list_folder/continue to retrieve the rest.
https://www.dropbox.com/developers/documentation/http/documentation#files-list_folder
Which is it then? If I make another request to list_folders_continue passing in the token, am I requesting another page of results or changes to the folder? If I am requesting another page of results, what is the limit that was applied? And can I control that?
The docs also have the list_folder method under sharing, which appears to have more precise definition of the cursor and the support for the limit parameter
https://www.dropbox.com/developers/documentation/http/documentation#sharing-list_folders
Will the method under files have that too?
Which is it then? If I make another request to list_folders_continue passing in the token, am I requesting another page of results or changes to the folder?
It's both. The /files/list_folder/continue endpoint is used both for returning additional pages of items, as well as getting further updates in the future.
Each page returned by /files/list_folder[/continue] is limited in size, but there is no guaranteed limit, nor can you control that limit. Your app should just always check has_more and call back to /files/list_folder/continue if it is true.
Also, the endpoints /files/list_folder and /sharing/list_folders are different endpoints with different functionality.
The /files/list_folder endpoint is documented as:
Returns the contents of a folder.
The /sharing/list_folders endpoint is documented as:
Return the list of all shared folders the current user has access to.
The two endpoints use different cursors, for use with /files/list_folder/continue and /sharing/list_folders/continue, respectively.
Which is it then? If I make another request to list_folders_continue
passing in the token, am I requesting another page of results or
changes to the folder? If I am requesting another page of results,
what is the limit that was applied? And can I control that?
My own trial and error experimentation has determined that the "It's both" answer posted by Greg is not correct. Specifically, the correct answer is "it's either". See below for more details.
When you call files/list_folder and it returns the entire list of contents (with a has_more value of false), then the cursor returned is suitable for monitoring subsequent changes to the path specified by passing that cursor to files/list_folder/continue.
If files/list_folder returns the first of multiple pages of contents (with a has_more value of true), then the cursor returned is suitable for getting the next page of contents by passing it to files/list_folder/continue. This cursor is not suitable for monitoring for changes (try it yourself, you can call continue as many times as you want with that cursor and you will always get the second page of contents).
It's not entirely clear from the docs, but when getting pages of contents from files/list_folder/continue, each call will return a new cursor, and that new cursor must be passed to a subsequent call to files/list_folder/continue in order to get the next page. You must chain the cursors together in this way until you get the last page (where has_more is false).
The cursor returned in that last call to files/list_folder/continue can then be used in subsequent calls to files/list_folder/continue to monitor for changes to the original path specified in the very first call to files/list_folder.
So the cursor is either suitable for monitoring for changes (when it is returned with a has_more value of false) OR it is suitable for getting a subsequent page of contents (when it is returned with a has_more value of true), regardless of whether the call that produced the cursor was files/list_folder or files/list_folder/continue, but it is never both.

Requesting member of node_element results in "undefined"

I'm using Opa for a school project in which there has to be some synchronization of a textfield between several users. The easy way to solve this, is to transmit the complete field whenever there is a change performed by one of the users. The better way is of course to only transmit the changes.
My idea was to use the caret position in the textfield. As a user types, one can get the last typed character based on the caret position (simply the character before the caret). A DOM element has an easy-to-use field for this called selectionStart. I have this small Javascript for this:
document.getElementById('content').selectionStart
which correctly returns 5 if the caret stands at the fifth character in the field. In Opa, I cannot use selectionStart on either a DOM or a dom_element so I thought I'd write a small plugin. The result is this:
##extern-type dom_element
##register jsGetCaretPosition: dom_element -> int
##args(node)
{
return node.selectionStart;
}
This compiles with the opp-builder without any problem and when I put this small line of code in my Opa script:
#pos = %%caret.jsGetCaretPosition%%(Dom.of_selection(Dom.select_id("content")));
that also compiles without problems. However, when I run the script, it always returns "undefined" and I have no idea what I'm doing wrong. I've looked in the API and Dom.of_selection(Dom.select_id("content")) looked like the correct way to get the corresponding dom_element typed data to give to the plugin. The fact that the plugin returns "undefined" seems to suggest that the selected element does not know the member "selectionStart" eventhough my testcode in Javascript suggest otherwise. Anyone can help?
In Opa dom_element are the results of jQuery selection (i.e. an array of dom nodes). So if I well understood your program you should write something like node[0].selectionStart instead of node.selectionStart.
Moreover you should take care of empty selection and selection which doesn't contains textarea node (without selectionStart property). Perhaps the right code is tmp == undefined ? -1 : tmp = node[0].selectionStart == undefined ? -1 : tmp