Added 'Seedable' concern to (re-)seed models based on their seed files in /db/seeds .

This commit is contained in:
Thorsten Eckel 2017-04-27 11:20:57 +02:00
parent 8ef2970234
commit d160a86e09
2 changed files with 24 additions and 0 deletions

View file

@ -0,0 +1,23 @@
# Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/
module Seedable
extend ActiveSupport::Concern
# methods defined here are going to extend the class, not the instance of it
class_methods do
def reseed
destroy_all
seed
end
def seed
UserInfo.ensure_current_user_id do
load seedfile
end
end
def seedfile
"#{Rails.root}/db/seeds/#{name.pluralize.underscore}.rb"
end
end
end

View file

@ -3,6 +3,7 @@
class Overview < ApplicationModel class Overview < ApplicationModel
include NotifiesClients include NotifiesClients
include LatestChangeObserved include LatestChangeObserved
include Seedable
load 'overview/assets.rb' load 'overview/assets.rb'
include Overview::Assets include Overview::Assets