Method: Pageflow::Seeds#user

Defined in:
lib/pageflow/seeds.rb

#user(attributes) {|user| ... } ⇒ User

Create a User if none with the given email exists yet.

Parameters:

  • attributes (Hash)

    attributes to override defaults

Options Hash (attributes):

  • :email (String)

    required

Yields:

  • (user)

    a block to be called before the user is saved

Returns:

  • (User)

    newly created user



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/pageflow/seeds.rb', line 72

def user(attributes, &block)
  default_attributes = {
    password: default_user_password,
    first_name: 'Elliot',
    last_name: 'Example'
  }

  User.find_or_create_by!(attributes.slice(:email)) do |user|
    user.attributes = default_attributes.merge(attributes)
    user.password_confirmation = user.password

    say_creating_user(user)
    yield(user) if block_given?
  end
end