I was running a test and I got the error undefined method `node_name' for nil:NilClass.
I added some javascript to one of my files so that instead of going to the new page when you want to make a new post it provides a popup with the form for creating a new post from the current page. Everything works fine however, now when I run my test with minitest capybara I get that error listed above. I'm pretty interested to know how to solve this problem. Here is a copy of my test.
require "test_helper"
feature "as a student I want a working blog so people can post" do
scenario "User can make a post" do
dude_sign_up
dude_log_in
visit posts_path
click_on "New Post"
create_post
page.must_have_content "Post was successfully created"
end
end
the methods described above from my test helper file
def dude_sign_up
visit new_user_path
fill_in "Name", with: "thedude"
fill_in "Email", with: "thedude@cool.com"
fill_in "Password", with: 'password'
fill_in "Bio", with: "the bio"
fill_in "Password confirmation", with: 'password'
click_on "Submit"
end
def dude_log_in
visit new_session_path
fill_in "Email", with: "thedude@cool.com"
fill_in "Password", with: 'password'
click_on "Log In"
end
def create_post
fill_in "Title", with: "this is a test title"
fill_in "Content", with: "oh how this is some crazzzzy content"
click_on "Create Post"
end
post/index.html.erb
<button class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">
New Post
</button>
<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title" id="myModalLabel">New Post</h4>
</div>
<div class="modal-body">
<%= render 'form' %>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
and also Here is my posts/_form.html.erb
<%= form_for @post, :html => {:multipart => true} do |f| %>
<div class="field">
<%= f.label :title %><br>
<%= f.text_field :title %>
</div>
<div class="field">
<p> upload an image if you like</p>
<%= f.file_field :image %>
</div>
<div class="field">
<%= f.label :content %><br>
<%= f.text_area :content %>
</div>
<h1>Select Category</h1>
<%= hidden_field_tag "post[category_ids][]", nil%>
<% Category.all.each do |category| %><br>
<%= check_box_tag "post[category_ids][]", category.id, @post.category_ids.include?(category.id), id: dom_id(category)%>
<%= label_tag dom_id(category), category.name %>
<% end %>
<br>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
full error for the test
test_0002_User can make a post 0:00:01.081 ERROR
undefined method `node_name' for nil:NilClass
Exception `NoMethodError' at:
/Users/cheatermoves/.rvm/gems/ruby-2.0.0-p247/gems/capybara-2.1.0/lib/capybara/node/simple.rb:58:in `tag_name'
/Users/cheatermoves/.rvm/gems/ruby-2.0.0-p247/gems/capybara-2.1.0/lib/capybara/node/simple.rb:46:in `[]'
/Users/cheatermoves/.rvm/gems/ruby-2.0.0-p247/gems/capybara-2.1.0/lib/capybara/rack_test/node.rb:11:in `[]'
/Users/cheatermoves/.rvm/gems/ruby-2.0.0-p247/gems/capybara-2.1.0/lib/capybara/rack_test/form.rb:81:in `method'
/Users/cheatermoves/.rvm/gems/ruby-2.0.0-p247/gems/capybara-2.1.0/lib/capybara/rack_test/form.rb:71:in `submit'
/Users/cheatermoves/.rvm/gems/ruby-2.0.0-p247/gems/capybara-2.1.0/lib/capybara/rack_test/node.rb:55:in `click'
/Users/cheatermoves/.rvm/gems/ruby-2.0.0-p247/gems/capybara-2.1.0/lib/capybara/node/element.rb:118:in `block in click'
/Users/cheatermoves/.rvm/gems/ruby-2.0.0-p247/gems/capybara-2.1.0/lib/capybara/node/base.rb:81:in `synchronize'
/Users/cheatermoves/.rvm/gems/ruby-2.0.0-p247/gems/capybara-2.1.0/lib/capybara/node/element.rb:118:in `click'
/Users/cheatermoves/.rvm/gems/ruby-2.0.0-p247/gems/capybara-2.1.0/lib/capybara/node/actions.rb:13:in `click_link_or_button'
/Users/cheatermoves/.rvm/gems/ruby-2.0.0-p247/gems/capybara-2.1.0/lib/capybara/session.rb:354:in `block (2 levels) in <class:Session>'
/Users/cheatermoves/.rvm/gems/ruby-2.0.0-p247/gems/capybara-2.1.0/lib/capybara/dsl.rb:51:in `block (2 levels) in <module:DSL>'
test/features/blog_system_works_test.rb:15:in `block (2 levels) in <top (required)>
'