require 'db/mongo/models/project'

FactoryGirl.define do
  factory :project, class: Devops::Model::Project do
    transient do
      with_env_identifiers ['foo']
      set_environments nil
    end

    id 'my_project'
    run_list []
    description 'desc'
    owner 'root'

    after(:build) do |project, evaluator|
      if evaluator.set_environments
        project.environments = evaluator.set_environments
      else
        if project.environments.empty?
          envs = Devops::Model::EnvironmentsArray.new
          evaluator.with_env_identifiers.map do |env_id|
            envs << build(:environment, id: env_id)
          end
          project.environments = envs
        end
      end

    end
  end
end