FactoryBot.define do

  factory :price_plan do
    sequence(:name) {|n| "plan#{n}" }
    number_of_urls 5
    screenshot false
    price 0
  end

  factory :user do
    sequence(:email) {|n| "user#{n}@miniurl.com" }
    password "secret"
    activation_state "active"
    price_plan_id 1
  end

  factory :admin, parent: :user do
    admin true
  end

  factory :url do
    transient do
      screenshot false
    end

    sequence(:original) {|n| "http://url#{n}.com"}
    sequence(:mini) {|n| "mini#{n}"}
    association :user, factory: :user
    screenshot_requested { screenshot }

    after(:build) do |url, evaluator|
      if evaluator.screenshot.present?
        url.screenshot.attach(io: File.open(evaluator.screenshot), filename: "test.png")
      end
    end
  end

end
