Sha256: 8e2057a4f1231c89897614fe49b42c6334efa347fdca02686a11c1da8327aac8

Contents?: true

Size: 1.52 KB

Versions: 2

Compression:

Stored size: 1.52 KB

Contents

FactoryGirl.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.profile { FactoryGirl.create(:profile) }
    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.profile { FactoryGirl.create(:profile) }
    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.profile { FactoryGirl.create(:profile) }
    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

2 entries across 2 versions & 1 rubygems

Version Path
enju_seed-0.3.0.beta.4 spec/factories/user.rb
enju_seed-0.3.0.beta.3 spec/factories/user.rb