Sha256: 8acda2baa9a6070c483f132c74df74d1c63b0c9ccb55f914e752d2b4bbfd43df

Contents?: true

Size: 1.59 KB

Versions: 8

Compression:

Stored size: 1.59 KB

Contents

FactoryBot.define do
  factory :user, class: 'Symphonia::User' do
    sequence(:first_name) { |n| "#{Faker::Name.first_name} #{n}" }
    sequence(:last_name) { |n| "#{Faker::Name.last_name} #{n}" }
    sequence(:email) { |n| "#{n}" + Faker::Internet.email }
    login { email }
    admin { false }
    password { SecureRandom.hex(16) }
    # password_confirmation { password }
    last_request_at { Time.now }

    trait :admin do
      admin { true }
    end

    trait :with_preferences do
      transient do
        preference_names { [] }
      end
      after(:build) do |user, evaluator|
        user.preferences = evaluator.preference_names.collect { |pref_name| Symphonia::EmailPreference.find_by(name: pref_name) || FactoryBot.create(:email_preference, name: pref_name) }
      end
    end
    factory :admin_user, traits: [:admin]
  end

  factory :role, class: 'Symphonia::Role' do
    sequence(:name) { |n| "#{Faker::Job.title} #{n}" }
  end

  factory :attachment, class: 'Symphonia::Attachment' do
    association :attachable, factory: :user
  end

  factory :file, parent: :attachment, class: 'Symphonia::CommonFile' do
    attachment { File.new(File.expand_path('../../support/common_file.txt', __FILE__)) }
  end

  factory :image, parent: :attachment, class: 'Symphonia::Image' do
    attachment { File.new(File.expand_path('../../support/symphonia.jpg', __FILE__)) }
  end

  factory :preference, class: 'Symphonia::Preference' do

    factory :email_preference, class: 'Symphonia::EmailPreference' do
      trait :user_registered do
        name { :notify_after_user_registered }
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
symphonia-3.1.3 spec/factories/factories.rb
symphonia-3.1.2 spec/factories/factories.rb
symphonia-3.1.1 spec/factories/factories.rb
symphonia-3.1.0 spec/factories/factories.rb
symphonia-3.0.3 spec/factories/factories.rb
symphonia-3.0.2 spec/factories/factories.rb
symphonia-3.0.1 spec/factories/factories.rb
symphonia-3.0.0 spec/factories/factories.rb