From b27e138fc48a913a88a44714c733c1129c8d4a73 Mon Sep 17 00:00:00 2001 From: ArtOfCode- <hello@artofcode.co.uk> Date: Tue, 12 May 2020 13:02:05 +0100 Subject: [PATCH] Fix privilege seeding --- app/models/privilege.rb | 2 +- db/seeds.rb | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/app/models/privilege.rb b/app/models/privilege.rb index 7779e3a06..a715420c2 100644 --- a/app/models/privilege.rb +++ b/app/models/privilege.rb @@ -7,5 +7,5 @@ class Privilege < ApplicationRecord has_and_belongs_to_many :users - validates :name, uniqueness: true + validates :name, uniqueness: { scope: [:community_id] } end diff --git a/db/seeds.rb b/db/seeds.rb index 77940fde8..70927307c 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -4,7 +4,13 @@ require 'redcarpet/render_strip' Rails.application.eager_load! -Dir.glob(Rails.root.join('db/seeds/**/*.yml')).each do |f| +if ENV['SEEDS'].present? + find_glob = "db/seeds/**/#{ENV['SEEDS'].underscore}.yml" +else + find_glob = 'db/seeds/**/*.yml' +end + +Dir.glob(Rails.root.join(find_glob)).each do |f| basename = Pathname.new(f).relative_path_from(Pathname.new(Rails.root.join('db/seeds'))).to_s type = basename.gsub('.yml', '').singularize.classify.constantize begin -- GitLab