I've been stuck trying to get my requests spec to work. I've tried a number of different approaches I've found thru Google and SO. Below are the following helpers I've tried separately with my request spec:
#spec/support/devise_request_spec_support.rb
module DeviseRequestSpecSupport
def login(user)
post user_session_path, login: user.email, password: 'foobar'
end
end
#spec/support/utilities.rb
include ApplicationHelper
def valid_login(user)
fill_in "user[email]", with: user.email
fill_in "user[password]", with: 'foobar'
click_button "Sign in"
end
def login(user)
visit root_path
valid_login(user)
end
I've tried both above #login
methods separately in my Request spec below:
require 'spec_helper'
describe "Company Admin Dashboard", js: true do
let(:user) { Fabricate(:company_admin) }
before do
login(user)
poll = Fabricate(:poll)
poll.send_to_all_users
end
describe "interacting with the poll box" do
it "displays sent poll in poll box" do
visit root_path
end
end
end
The test will pass but the root_path doesn't display the landing page meant for a logged in user. It shows the public landing page. I've tried debugging with binding.pry and tried logging in manually in test environment but I keep getting an 'Invalid email or password' error. I've checked many times but I've been using the correct email and password of the Fabricated company_admin.
I've also tried the solution proposed here too: https://github.com/plataformatec/devise/wiki/How-To:-Test-with-Capybara
Any help would be greatly appreciated. Not sure where the problem lies. Is it the Fabrication gem, Devise, RSpec or Capybara?