title: Validation failed: Email has already been taken
body: <p>Please note, I'm having this error <strong>not when creating</strong> user, but <strong>when editing</strong>.</p>
  
  <p>I believe that email uniqueness's check can be done within the <code>devise</code>.</p>
  
  <p>Github repo: <a href="https://github.com/tenzan/shop" rel="nofollow">https://github.com/tenzan/shop</a> , but <code>editing_users_spec.rb</code> is not there yet.</p>
  
  <pre><code>$ bundle exec rspec spec/features/admin/editing_users_spec.rb
  FF
  
  Failures:
  
    1) Admins can change a user's details with valid details
       Failure/Error: let(:user) {FactoryGirl.create(:user)}
       ActiveRecord::RecordInvalid:
         Validation failed: Email has already been taken
       # ./spec/features/admin/editing_users_spec.rb:5:in `block (2 levels) in &lt;top (required)&gt;'
       # ./spec/features/admin/editing_users_spec.rb:9:in `block (2 levels) in &lt;top (required)&gt;'
  
    2) Admins can change a user's details when toggling a user's admin ability
       Failure/Error: let(:user) {FactoryGirl.create(:user)}
       ActiveRecord::RecordInvalid:
         Validation failed: Email has already been taken
       # ./spec/features/admin/editing_users_spec.rb:5:in `block (2 levels) in &lt;top (required)&gt;'
       # ./spec/features/admin/editing_users_spec.rb:9:in `block (2 levels) in &lt;top (required)&gt;'
  
  Finished in 0.05535 seconds (files took 2.29 seconds to load)
  2 examples, 2 failures
  
  Failed examples:
  
  rspec ./spec/features/admin/editing_users_spec.rb:13 # Admins can change a user's details with valid details
  rspec ./spec/features/admin/editing_users_spec.rb:22 # Admins can change a user's details when toggling a user's admin ability
  </code></pre>
  
  <p><strong>spec/features/admin/editing_users_spec.rb</strong>:</p>
  
  <pre><code>require 'rails_helper'
  
  RSpec.feature "Admins can change a user's details" do
    let(:admin_user) { FactoryGirl.create(:user, :admin)}
    let(:user) {FactoryGirl.create(:user)}
  
    before do
      login_as(admin_user)
      visit admin_user_path(user)
      click_link 'Edit User'
    end
  
    scenario 'with valid details' do
      fill_in 'Email', with: 'newuser@example.com'
      click_button 'Update User'
  
      expect(page).to have_content 'User has been updated.'
      expect(page).to have_content 'newuser@example.com'
      expect(page).not_to have_content user.email
    end
  
    scenario "when toggling a user's admin ability" do
      check 'Is an admin?'
      click_button 'Update User'
  
      expect(page).to have_content 'User has been updated.'
      expect(page).to have_content "#{user.email} (Admin)"
    end
  end
  </code></pre>