Connecting the JavaScript to the Server Code

Were you to run the RSpec tests now that you’ve moved all the logic to JavaScript, you’d find that both tests in spec/system/add_task_spec.rb fail. The first test, which did not run in the JavaScript browser, fails because without JavaScript the tasks don’t display at all. That’s to be expected, and the test can be removed as its logic is now covered elsewhere.

The JavaScript test also fails for a couple of reasons. The simple one is the JavaScript makes a new Ajax call to get the JSON data for the tasks. To make that work, you need to make a small change to the ProjectsController#show method:

 def​ show
  @project = Project.find(params[​:id​]) ...

Get Rails 5 Test Prescriptions now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.