require 'spec_helper'

describe 'Reset password' do

  describe "Password reset instructions" do
    before do
      user = create(:user, email: 'foo@wadus.com')
      user.activate!
      visit root_path
      click_link 'password_reset_link'
      current_path.should eq '/password_resets/new'
    end

    it 'should confirm sending instructions' do
      fill_in 'email', with: 'foo@wadus.com'
      click_button 'update_password_button'
      current_path.should eq "/"
      page.should have_content 'Instructions have been sent to your email address.'
    end

    it 'should show error message if user not found' do
      fill_in 'email', with: 'feee@wadus.com'
      click_button 'update_password_button'
      current_path.should eq '/password_resets'
      page.should have_content 'User not found'
    end
  end

  describe "Password change" do
    before do
      user = create(:user_with_forgotten_password, email: 'foo@wadus.com')
      user.activate!
      visit edit_password_reset_path(user.reset_password_token)
    end

    it 'should confirm password change' do
      fill_in 'Password', with: 'foopass'
      fill_in 'Confirm Password', with: 'foopass'
      click_button 'update_password_button'
      current_path.should eq '/'
      page.should have_content 'Password was successfully updated.'
    end
  end

end
