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"
end
fill_in "group", with: "Electronics"
# save_and_open_page
expect{click_button "Create"}.to change{user.groups.count}.by(1)
end
end
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?