Testing a nested resource for a signed in user

How do I make sure group is getting created within the signed in user? The logic is working but on the tests this does not and gives me error

result should have been changed by 1, but was changed by 0

My current testing code is which is not working is below:

require "spec_helper"

describe "Groups" do
  it "signed in user should be able to create a group" do
    user = FactoryGirl.create(:user)
	  visit '/'
	  click_link "Log In"

	  fill_in "session_email",with: user.email
	  fill_in "session_password",with:user.password
	  within("#login-content") do
     click_button "Login"
     fill_in "group", with: "Electronics"
     # save_and_open_page
     expect{click_button "Create"}.to change{user.groups.count}.by(1)


This is my input field.

  <input  name="group"/>

I think is happening because I am calling a javascript function on the button click which is creating the group by sending an ajax. But then how do I test this on the javascript side? Is jasmine the answer?

Add js: true to your test:

it "signed in user should be able to create a group", js: true do

It would probably work just with default capybara web driver, but I would suggest you to install capybara-webkit.

Also there is one catch up regarding database transactions. You can find more info on my blog: http://rubybeginner.com/javascript-in-integration-tests.html

Does doing js: true call in the proper jquery function?

What @patrikbona meant is to add js: true in your specs.

it "signed in user should be able to create a group", js: true do

Adding this will instruct capybara to use it’s javascript driver (selenium by default). You should see your Firefox open up and clicks being performed.

@lenartr I am not using a form_for on group but rather calling a javascript function which then actually does the work of creating the group using an ajax post.

For now I just created a form_for for testing that the group is getting created. But I want to remove that.