Skip to content
Snippets Groups Projects
Forked from PortalMEC / portalmec
1002 commits behind the upstream repository.
learning_objects.rb 850 B
FactoryGirl.define do
  factory :learning_object, aliases: [:complainable] do
    sequence(:name) { |i| "LearningObject #{i}" }
    sequence(:id_dspace) { |i| i }
    publisher
    score { rand(0.0..1.0) }
    description { Faker::Lorem.paragraph }
    object_type { ObjectType.all.sample }
    language { Language.all.sample }
    author { Faker::Name.name }
    state LearningObject.states[:published]

    transient do
      tags_count 5
      subjects_count 2
      educational_stages_count 1
    end

    after(:create) do |learning_object, evaluator|
      create_list(:tagging, evaluator.tags_count, taggable: learning_object)
      [Subject, EducationalStage].each do |model|
        table = model.to_s.tableize
        learning_object.try(table.to_sym) << model.all.sample(evaluator.try("#{table}_count".to_sym))
      end
    end
  end
end