Sha256: 75e05451385e50e6cebf293c9c08e5ad25fda0e0db7f587da10622390154f891

Contents?: true

Size: 1.37 KB

Versions: 3

Compression:

Stored size: 1.37 KB

Contents

FactoryBot.define do
  factory :admin, class: User do |f|
    f.sequence(:username){|n| "admin_#{n}"}
    f.sequence(:email){|n| "admin_#{n}@example.jp"}
    f.password 'adminpassword'
    f.password_confirmation 'adminpassword'
    f.after(:create) do |user|
      user_has_role = UserHasRole.new
      user_has_role.assign_attributes({user_id: user.id, role_id: Role.find_by_name('Administrator').id})
      user_has_role.save
      user.reload
    end
  end

  factory :librarian, class: User do |f|
    f.sequence(:username){|n| "librarian_#{n}"}
    f.sequence(:email){|n| "librarian_#{n}@example.jp"}
    f.password 'librarianpassword'
    f.password_confirmation 'librarianpassword'
    f.after(:create) do |user|
      user_has_role = UserHasRole.new
      user_has_role.assign_attributes({user_id: user.id, role_id: Role.find_by_name('Librarian').id})
      user_has_role.save
      user.reload
    end
  end

  factory :user, class: User do |f|
    f.sequence(:username){|n| "user_#{n}"}
    f.sequence(:email){|n| "user_#{n}@example.jp"}
    f.password 'userpassword'
    f.password_confirmation 'userpassword'
    f.after(:create) do |user|
      user_has_role = UserHasRole.new
      user_has_role.assign_attributes({user_id: user.id, role_id: Role.find_by_name('User').id})
      user_has_role.save
      user.reload
    end
  end

  factory :invalid_user, class: User do |f|
  end
end

Version data entries

3 entries across 3 versions & 3 rubygems

Version Path
enju_search_log-0.3.0.beta.1 spec/factories/user.rb
enju_leaf-1.2.2 spec/factories/user.rb
enju_seed-0.2.3 spec/factories/user.rb