Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

undefined method `link_to_remote' in MiniTest for application_helper test

While migrating an application from Rails 2.3.17 to 3.2.21.. We are facing an issue with Rails legacy form helper link_to_remote while testing with MiniTest.

In older version of rails we have used link_to_remote form helper which is removed in Rails 3. To provide support we have added prototype_legacy_helper plugin in our application which works fine in UI but tests for that fails and throws error like given below:

NoMethodError: undefined method `link_to_remote' for #<ApplicationHelperTest:0xc800dd4>

This is our code inside ApplicationHelper

def reservation_menu_command_link(command, *args)
  ...
  command_link = link_to_remote(anchor_text,options = {}, {:class => style_class})
  ...
end

This is our test case for application_helper test

def test_reservation_menu_command_link
  options = { :lodging_view => lv}
  assert_equal(%q{xyz}, reservation_menu_command_link(:cancel_all_possible, options))
end

So you can see that we have a method reservation_menu_command_link and we used it inside our UI which works fine but test for this definition fails.

Could anyone can help me out from this behaviour of plugin?

like image 770
Nishant Upadhyay Avatar asked Nov 09 '22 20:11

Nishant Upadhyay


1 Answers

link_to_remote was deprecated between rails 2 and 3 the correct usage these days is

link_to 'Foo', { action: 'create' }, remote: true. Hopefully that helps

like image 142
RyanMacG Avatar answered Nov 15 '22 04:11

RyanMacG