Sha256: f4e58ef283896b9e5f9c1218ed71f80f7fc209f6b9cce07f81dac1c18875ac03

Contents?: true

Size: 766 Bytes

Versions: 2

Compression:

Stored size: 766 Bytes

Contents

puts "Loading ThecoreAuthCommons seeds"
email = ENV["ADMIN_EMAIL"].presence || "admin@example.com"
psswd = ENV["ADMIN_PASSWORD"].presence || "changeme"

u = User.find_or_initialize_by(email: email)
u.username = "Administrator"
u.password = u.password_confirmation = psswd
u.admin = true
u.save(validate: false)


@values = {
    predicates: %i[can cannot],
    actions: %i[manage create read update destroy],
    targets: ApplicationRecord.subclasses.map {|d| d.to_s.underscore}.to_a.unshift(:all)
}

def fill table
    model = table.to_s.classify.constantize
    model.reset_column_information
    model.upsert_all @values[table].map { |p| {name: p, created_at: Time.now, updated_at: Time.now} }, unique_by: [:name]
end

fill :predicates
fill :actions
fill :targets

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
thecore_auth_commons-2.3.3 db/seeds.rb
thecore_auth_commons-2.3.2 db/seeds.rb