Question: rspec applicationcontroller unknownformat respond to js

Question

rspec applicationcontroller unknownformat respond to js

Answers 0
Added at 2017-01-01 20:01
Tags
Question

I'm new to web design, using rails 5, and otherwise the most current version of everything:

link in a modal div

<div class="col-md-1" id="actionOptions">
  <%= link_to "New Bike Account", new_bike_path, remote: true, id: "newBikeActionModal" %>
</div>

controller:

 def new
    @bike = Bike.new

    respond_to do |format|
      format.js
    end
  end

new.js.erb puts the form in a different div in the modal

$("#actionEdit").html("<%= j render 'form', bike: @bike %>")

rspec tries and fails

RSpec.feature "create a new bike account" do

  ...
  scenario "with valid attributes", js: true do 
    login_as(ryder)
    visit "/"

    page.find("#actionLink").click 
    page.find('#newBikeActionModal').click
    fill_in "Bike Name", with: "ezryder"
    click_button "Create Bike"

like this:

1) Users can create a new Bike account with valid attributes
     Failure/Error:
       respond_to do |format|
         format.js
       end

     ActionController::UnknownFormat:
       ActionController::UnknownFormat
     # ./app/controllers/bikes_controller.rb:13:in `new'
     ...
    # --- Caused by: ---
    # Capybara::ElementNotFound:
    #   Unable to find field "Bike Name"

the site works as intended, but i'm not sure how to get rspec to find form fields when working through ajax, and I can't find how to resolve the unknownformat error. many thanks in advance..

Answers
Source Show
◀ Wstecz