FactoryGirl.define do
  sequence :username do |n|
    "JohnDoe#{n}"
  end

  factory :user, aliases: [:creator] do
    username
    password "password"

    factory :user_with_email do
      email "fake@faker.com"
    end

    factory :admin_user do
      id 1
    end
  end

  factory :board do
    creator
    name "test board"
  end

  factory :post do
    user
    board
    content "test content"
    subject "test subject"
  end

  factory :gallery do
    user
    name "test gallery"
  end

  factory :icon do
    user
    url "http://www.fakeicon.com"
    keyword "totally fake"

    factory :uploaded_icon do
      url { "https://d1anwqy6ci9o1i.cloudfront.net/users/#{user.id}/icons/nonsense-fakeimg.png" }
    end
  end

  factory :reply do
    user
    post
    content "test content"
  end

  factory :character do
    user
    name 'test character'
  end

  factory :template do
    user
    name 'test template'
  end

  factory :password_reset do
    user
    factory :expired_password_reset do
      created_at { 3.days.ago }
    end
    factory :used_password_reset do
      used true
    end
  end

  factory :tag do
    sequence :name do |n|
      "Tag#{n}"
    end
    user

    factory :setting do
      type 'Setting'
    end

    factory :content_warning do
      type 'ContentWarning'
    end
  end
end

FactoryGirl.define do
  sequence :username do |n|
    "JohnDoe#{n}"
  end

  factory :user, aliases: [:creator] do
    username
    password "password"
    sequence :email do |n|
      "fake#{n}@faker.com"
    end

    factory :admin_user do
      id 1
    end
  end

  factory :board do
    creator
    name "test board"
  end

  factory :post do
    user
    board
    content "test content"
    subject "test subject"
  end

  factory :gallery do
    user
    name "test gallery"
  end

  factory :icon do
    user
    url "http://www.fakeicon.com"
    keyword "totally fake"

    factory :uploaded_icon do
      url { "https://d1anwqy6ci9o1i.cloudfront.net/users/#{user.id}/icons/nonsense-fakeimg.png" }
    end
  end

  factory :reply do
    user
    post
    content "test content"
  end

  factory :character do
    user
    name 'test character'
  end

  factory :template do
    user
    name 'test template'
  end

  factory :password_reset do
    user
    factory :expired_password_reset do
      created_at { 3.days.ago }
    end
    factory :used_password_reset do
      used true
    end
  end

  factory :tag do
    sequence :name do |n|
      "Tag#{n}"
    end
    user

    factory :setting do
      type 'Setting'
    end

    factory :content_warning do
      type 'ContentWarning'
    end
  end
end

Fix user factory to use email sequence
Fix user factory to use email sequence
