--- /dev/null
+$.rails.href = function(element) {
+ if (element.is('a')) {
+ // data-remote=true links must put their remote targets in
+ // data-remote-href="..." instead of href="...". This helps
+ // us avoid accidentally using the same href="..." in both the
+ // remote (Rails UJS) and non-remote (native browser) handlers
+ // -- which differ greatly in how they use that value -- and
+ // forgetting to test any non-remote cases like "open in new
+ // tab". If you really want copy-link-address/open-in-new-tab
+ // to work on a data-remote=true link, supply the
+ // copy-and-pastable URI in href in addition to the AJAX URI
+ // in data-remote-href.
+ //
+ // (Currently, the only places we make any remote links are
+ // link_to() in ApplicationHelper, which renames href="..." to
+ // data-remote-href="...", and select_modal, which builds a
+ // data-remote=true link on the client side.)
+ return element.data('remote-href');
+ } else {
+ // Normal rails-ujs behavior.
+ return element.attr('href');
+ }
+}
return false;
}
$('<a />').
- attr('href', $form.attr('data-search-modal')).
+ attr('data-remote-href', $form.attr('data-search-modal')).
attr('data-remote', 'true').
attr('data-method', 'GET').
hide().
ArvadosBase::resource_class_for_uuid(attrvalue, opts)
end
+ # When using {remote:true} or {method:...}, move the target URI from
+ # href to data-remote-href. Otherwise, browsers offer features like
+ # "open in new window" and "copy link address" which bypass Rails'
+ # click handler and therefore end up at incorrect/nonexistent routes
+ # (by ignoring data-method) and expect to receive pages rather than
+ # javascript responses.
+ #
+ # See assets/javascripts/link_to_remote.js for supporting code.
+ def link_to *args, &block
+ if (args.last and args.last.is_a? Hash and
+ (args.last[:remote] or
+ (args.last[:method] and
+ args.last[:method].to_s.upcase != 'GET')))
+ if Rails.env.test?
+ # Capybara/phantomjs can't click_link without an href, even if
+ # the click handler means it never gets used.
+ raw super.gsub(' href="', ' href="#" data-remote-href="')
+ else
+ # Regular browsers work as desired: users can click A elements
+ # without hrefs, and click handlers fire; but there's no "copy
+ # link address" option in the right-click menu.
+ raw super.gsub(' href="', ' data-remote-href="')
+ end
+ else
+ super
+ end
+ end
+
##
# Returns HTML that links to the Arvados object specified in +attrvalue+
# Provides various output control and styling options.
id: readonly_project_uuid
}, session_for(which_user)
buttons = css_select('[data-method=post]').select do |el|
- el.attributes['href'].match /project.*owner_uuid.*#{readonly_project_uuid}/
+ el.attributes['data-remote-href'].match /project.*owner_uuid.*#{readonly_project_uuid}/
end
if should_show
assert_not_empty(buttons, "did not offer to create a subproject")
wait_for_ajax
# All needed input are filled in. Run this pipeline now
- click_link 'Components'
+ find('a,button', text: 'Components').click
find('a,button', text: 'Run').click
# Pipeline is running. We have a "Stop" button instead now.
# poltergeist returns true for confirm(), so we don't need to accept.
end
end
- wait_for_ajax
+ # Ensure revoked permission disappears from page.
using_wait_time(Capybara.default_wait_time * 3) do
- assert(page.has_no_text?(name),
- "new share row still exists after being revoked")
+ assert_no_text name
assert_equal(start_rows.size - 1, share_rows.size,
"revoking share did not remove row from sharing table")
end