require 'rails_helper'

RSpec.feature '<%= human_name %> signs in' do

scenario 'with valid credentials' do

<% if fixture_replacement == :factory_bot -%>

<%= singular_name %> = create :<%= singular_name %>

<% elsif fixture_replacement == :fabrication -%>

<%= singular_name %> = Fabricate :<%= singular_name %>

<% end -%>

  visit new_<%= singular_name %>_session_path

  fill_in 'Email', with: <%= singular_name %>.email
  fill_in 'Password', with: <%= singular_name %>.password
  click_button 'Log in'

  expect(page).to have_text 'Signed in successfully.'
  expect(page).to have_link 'Sign Out'
  expect(page).to have_current_path root_path
end

scenario 'with invalid credentials' do

<% if fixture_replacement == :factory_bot -%>

<%= singular_name %> = build :<%= singular_name %>

<% elsif fixture_replacement == :fabrication -%>

<%= singular_name %> = Fabricate.build :<%= singular_name %>

<% end -%>

  visit new_<%= singular_name %>_session_path

  fill_in 'Email', with: <%= singular_name %>.email
  fill_in 'Password', with: <%= singular_name %>.password
  click_button 'Log in'

  expect(page).to have_text 'Invalid Email or password.'
  expect(page).to have_no_link 'Sign Out'
end

end