This generates HTML like this
<a href="/orders/2131771394?update_timestamp=true" onclick="var f = document.createElement('form'); f.style.display = 'none'; this.parentNode.appendChild(f);f.method = 'POST'; f.action = this.href;var m = document.createElement('input'); m.setAttribute('type', 'hidden'); m.setAttribute('name', '_method'); m.setAttribute('value', 'put'); f.appendChild(m);f.submit();return false;">Update timestamp</a>
Basically it creates a normal link, which is overridden by a
javascript function to send a (simulated) put request in stead, that
is all fine, however I would like to create test that asserts that
this javascript is there.
Basically I would like to create a test that fails if my view code was
like this:
link_to('Update timestamp', order_path(@order, :update_timestamp => true)
that is *without* the ':method => :put' as html_options
If I just have a standard assert, like
assert_select "a[href=?]", order_path(order, :update_timestamp => true)
it succeeds even if ':method => :put' is not there.
Does anyone have a good idea of how to assert this.
This generates HTML like this
<a href="/orders/2131771394?update_timestamp=true" onclick="var f = document.createElement('form'); f.style.display = 'none'; this.parentNode.appendChild(f);f.method = 'POST'; f.action = this.href;var m = document.createElement('input'); m.setAttribute('type', 'hidden'); m.setAttribute('name', '_method'); m.setAttribute('value', 'put'); f.appendChild(m);f.submit();return false;">Update timestamp</a>
Basically it creates a normal link, which is overridden by a
javascript function to send a (simulated) put request in stead, that
is all fine, however I would like to create test that asserts that
this javascript is there.
Basically I would like to create a test that fails if my view code was
like this:
link_to('Update timestamp', order_path(@order, :update_timestamp => true)
that is *without* the ':method => :put' as html_options
If I just have a standard assert, like
assert_select "a[href=?]", order_path(order, :update_timestamp => true)
it succeeds even if ':method => :put' is not there.
Does anyone have a good idea of how to assert this.
Jarl
You can do something like assert_select "a[onclick=?]", /<regexp
You can do something like assert_select "a[onclick=?]", /<regexp
>/
Yes, for now I have made like this:
assert_select "a#{PUT}[href=?]", order_path(order, :update_timestamp => true)
and I have declared PUT in test_helper like this:
PUT = "[onclick=\"var f = document.createElement('form'); f.style.display = 'none'; this.parentNode.appendChild(f); f.method = 'POST'; f.action = this.href;var m = document.createElement('input'); m.setAttribute('type', 'hidden'); m.setAttribute('name', '_method'); m.setAttribute('value', 'put'); f.appendChild(m);f.submit();return false;\"]"
Fortunately this PUT value is a constant because it refers to
'this.href', but my tests will break if any other javascript is
generated (in newer version of rails) that has the same functionality,
but differs in just a single space. I hoped to have some kind of test
that the execution of the javascript would result in a HTTP PUT
request.