Newer
Older
dmpopidor / spec / factories / question_formats.rb
@Bodacious Bodacious on 31 Jul 2018 1 KB Add specs for completing a Plan
# == Schema Information
#
# Table name: question_formats
#
#  id           :integer          not null, primary key
#  title        :string
#  description  :text
#  created_at   :datetime         not null
#  updated_at   :datetime         not null
#  option_based :boolean          default(FALSE)
#  formattype   :integer          default(0)
#

FactoryBot.define do
  factory :question_format do
    title { Faker::Lorem.words(3).join }
    description { "http://test.host" }
    formattype { QuestionFormat::FORMAT_TYPES.sample }

    # Ensures duplicates aren't created
    initialize_with do
      QuestionFormat.find_or_create_by(title: title,
                                       formattype: formattype)
    end

    trait :textarea do
      title "Text area"
      formattype "textarea"
    end

    trait :textfield do
      title "Text field"
      formattype "textfield"
    end

    trait :radiobuttons do
      title "Radio buttons"
      formattype "radiobuttons"
      option_based true
    end

    trait :checkbox do
      title "Check box"
      formattype "checkbox"
      option_based true
    end

    trait :dropdown do
      title "Drop down"
      formattype "dropdown"
      option_based true
    end

    trait :multiselectbox do
      title "Multi select box"
      formattype "multiselectbox"
      option_based true
    end

    trait :date do
      title "Date"
      formattype "date"
    end

    trait :rda_metadata do
      title "RDA Metadata"
      formattype "rda_metadata"
    end

  end
end