assert_select not working after upgrading to latest rails version - ruby

I have the following HTML snippet, and my assert_select is no longer working (after upgrading to the latest version of Rails):
<div id="content">
<div class="container">
<div class="foo">
<h2>Latest</h2>
<p>
<a href="/downloads/latest.zip" class="button download">
<span>Download</span>
</a>
</p>
</div>
</div>
</div>
Here's the assertion:
assert_select '.container a.downloadbutton[href^=/downloads]', assigns(:downloads).count
Here's the error:
Expected exactly 1 element matching ".container a.button[href^='/downloads']", found 0.
Anyone know what I'm doing wrong?
Thanks!!!
V

Looks like a mismatch in the class between the classes in the code fragment 'button' and 'download' and the class in the assertion 'downloadbutton'. Perhaps getting rid of the space between 'button' and 'download' in the fragment will work.

Related

How to properly get the value contained inside a section using XPath?

having the following HTML (snippet grabbed from the web page I wanted to scrape):
<div class="ulListContainer">
<section class="stockUpdater">
<ul class="column4">
<li>
<img src="1.png" alt="">
<strong>
Buy*
</strong>
<strong>
Sell*
</strong>
</li>
<li>
<header>
$USD
</header>
<span class="">
20.90
</span>
<span class="">
23.15
</span>
</li>
</ul>
<ul>...</ul>
</section>
</div>
how do I get the 2nd li 1st span value using XPath? The result should be 20.90.
I have tried the following //div[#class="ulListContainer"]/section/ul[1]/li[2]/span[1] but I am not getting any values. I must said this is being used from a Google Sheet and using the function IMPORTXML (not sure what version of XPath it does uses) can I get some help?
Update
Apparently Google Sheets does not support such "complex" XPath expression since it seems to work fine:
Update 1
As requested I've shared the Google Sheet I am using to test this, here is the link
What you need is :
=IMPORTXML(A1;"//li[contains(text(),'USD')]/span[1]")
Removing section from your original XPath will work too :
=IMPORTXML(A1;"//div[#class='ulListContainer']/ul[1]/li[2]/span[1]")
Try this:
=IMPORTXML("URL","//span[1]")
Change URL to the actual website link/URL

Thymeleaf switch block returns incorrect value

I have a switch block in my thymeleaf page where I show an image depending on the reputation score of the user:
<h1>
<span th:text="#{user.reputation} + ${reputation}">Reputation</span>
</h1>
<div th:if="${reputation lt 0}">
<img th:src="#{/css/img/troll.png}"/>
</div>
<div th:if="${reputation} == 0">
<img th:src="#{/css/img/smeagol.jpg}"/>
</div>
<div th:if="${reputation gt 0} and ${reputation le 5}">
<img th:src="#{/css/img/samwise.png}"/>
</div>
<div th:if="${reputation gt 5} and ${reputation le 15}">
<img th:src="#{/css/img/frodo.png}"/>
</div>
<div th:if="${reputation gt 15}">
<img th:src="#{/css/img/gandalf.jpg}"/>
</div>
This statement always returns smeagol (so reputation 0), eventhough the reputation of this user is 7: example
EDIT:
I was wrong, the image showing was a rogue line:
<!--<img th:src="#{/css/img/smeagol.jpg}"/>-->
but I commented it out. Now there is no image showing.
EDIT2:
changed my comparators (see original post) and now I get the following error:
The value of attribute "th:case" associated with an element type "div" must not contain the '<' character.
EDIT3:
Works now, updated original post to working code
According to the documentation, Thymeleaf's switch statement works just like Java's - and the example suggests the same.
In other words: you cannot do
<th:block th:switch="${reputation}">
<div th:case="${reputation} < 0">
[...]
but would need to do
<th:block th:switch="${reputation}">
<div th:case="0">
[...]
which is not what you want.
Instead, you will have to use th:if, i.e. something like this:
<div th:if="${reputation} < 0">
<img th:src="#{/css/img/troll.png}"/>
</div>
Change
<div th:case="0">
<img th:src="#{/css/img/smeagol.jpg}"/>
</div>
to
<div th:case="${reputation == 0}">
<img th:src="#{/css/img/smeagol.jpg}"/>
</div>

Extension doesn´t work after deleted Cache

i have a problem with one of my extensions i created with Extensionbuilder.
After i deleted the Cache there is no content anymore!
<f:flashMessages renderMode="div"/>
<div class="tx-camping-list">
<f:for each="{offers}" as="offer" iteration="it">
<div class="content-list-item">
<div class="contentLeft floatLeft">
<f:render partial="BaseItem/ListImages" arguments="{item:offer}" />
<div class="wrap-right floatRight">
<h3>
<f:link.action arguments="{offer:offer}">
<f:format.raw>{offer.names}</f:format.raw>
</f:link.action>
</h3>
<h4>
<f:format.raw>{offer.teaser}</f:format.raw>
</h4>
<div class="description"><f:format.crop maxCharacters="240"><f:format.html>{offer.description}</f:format.html></f:format.crop>
<p>
<f:link.action arguments="{offer:offer}">
<f:translate key="read_more" default="Read more" /> >
</f:link.action>
</p>
</div>
</div>
</div>
<div class="roomPrice floatRight">
<f:render partial="Price/ListPriceBox" arguments="{item:offer}" />
<f:render partial="BaseItem/Button" arguments="{item:offer,type:'Offer'}"/>
</div>
<div class="clearFloat"></div>
</div>
</f:for>
</div>
The image, {offer.names}, {offer.teaser} etc. is NULL, BUT the link {offer:offer} is working
When i reload the page the first time after i deleted the Cache i get the error:
The argument “each” was registered with type “array”, but is of type “string” in view helper
After a reload everything works fine except this plugin!
Maybe some of you can help me
Thanks
Use <f:debug> to find out what you real values are. You cannot loop over a string. Most likely, you are mistaken over your nesting level of your object.
Also do not use <f:format.raw> unless you already ensured, that the contend is htmlspecialchar'd. Otherwise you loose the XSS protection.
This can just fix the error if its caused by a missing reference on records
You could try to add the following line of code to your setup.ts (or .txt; depending on configuration and personal preferences):
File: slider/Configuration/TypoScript/setup.ts:
plugin.tx_slider.persistence.storagePid = 15
Note: replace tx_slider with your extensionkey and the 15 with the pagenumber where your records (in this case your offer-records) are located

listElement property not behaving as expected

Hi have created a JSFiddle of my problem here.
http://jsfiddle.net/L7o1nct6/2/
I will also repeat the code here as Stackoverflow is forcing me to do.
JavaScript
<!-- using fine uploader 5.1.3 at http://keysymmetrics.com/jsfiddle/jquery.fine-uploader.js -->
$(document).ready(function()
{
$("#fine-uploader").fineUploader({
listElement: $('#listElement'),
debug: true,
template: 'qq-template-bootstrap',
request: {
endpoint: "/my-endpoint"
}
});
});
HTML
<script type="text/template" id="qq-template-bootstrap" class="qq-uploader-selector">
<div class="row">
<div class="col-sm-4" >
<div class="qq-upload-button-selector
qq-upload-drop-area-selector
drag-drop-area" >
<div>Drag and drop files here or click to upload</div>
</div>
</div>
</div>
<div class="qq-upload-list-selector" id="#listElement" >
<div class="panel panel-default" >
<div class="panel-body" >
<div class="qq-progress-bar-container-selector progress">
<div class="qq-progress-bar-selector progress-bar"></div>
</div>
<span class="qq-upload-spinner-selector qq-upload-spinner"></span>
<span class="qq-upload-file-selector qq-upload-file"></span>
<span class="qq-upload-size-selector qq-upload-size"></span>
<span class="qq-upload-status-text-selector qq-upload-status-text"></span>
<img class="qq-thumbnail-selector" qq-max-size="100" />
</div><!-- close panel-body -->
</div><!-- close panel -->
</div>
</script>
<h1>Fine Uploader Test</h1>
<div id="fine-uploader"></div>
When viewing the JSFiddle example, if you open the debug console, you will see the message "Uncaught Error: Could not find the file list container in the template!".
I am unsure what this means, I thought I could use the listElement property to tell fine-uploader which element to use for this list?
On a side note, if I cut and paste the div with id=listElement and move it adjacent to the div with class=qq-upload-button-selector then this example works fine.
Any help would be appreciated, I have spent hours on this and haven't found an answer for this on stackoverflow either.
A couple issues with your code:
"#listelement" is not a valid html element ID in all browsers.
You are attempting to select an element that does not yet exist in the DOM. It's not clear why you are specifying a list element anyway. Fine uploader should find the list in the template when it renders.

XPath Getting child elements from html

I am trying to find the xpath for only the child of a navigation bar. The path which I am trying at the moment is //div[#class='navCol subMenus'] from this peace of HTML.
<div class="PrimaryNavigationContainer">
<div class="PrimaryNavigation">
<div class="Menu">
<div>
<span>Brands</span>
<div class="navCol">
<div>
<a class="NoLink unselectable"><span>Shop by Brand</span></a>
<div class="navCol subMenus">
<div>
<span>blah</span>
I have tried a number of Xpath syntax but none seem to work to bring up just the sub categories. Thank you for any help which you can provide.

Resources