diff --git a/Gemfile b/Gemfile index 9c3590017..ca6c7856d 100644 --- a/Gemfile +++ b/Gemfile @@ -131,6 +131,10 @@ gem 'pg_search' # Subscriptions, Billing gem 'stripe' +## - helper gems --## +## to populate db with sample data +gem 'faker' + group :production, :staging do # we dont want request timing out in development while using byebug gem 'rack-timeout' @@ -158,10 +162,6 @@ group :test do gem 'webmock' end -group :development, :test, :staging do - gem 'faker' -end - group :development, :test do gem 'active_record_query_trace' ##--- gems for debugging and error reporting ---## diff --git a/app/controllers/super_admin/accounts_controller.rb b/app/controllers/super_admin/accounts_controller.rb index 3d038281c..5bc487475 100644 --- a/app/controllers/super_admin/accounts_controller.rb +++ b/app/controllers/super_admin/accounts_controller.rb @@ -43,7 +43,7 @@ class SuperAdmin::AccountsController < SuperAdmin::ApplicationController # for more information def seed - Seeders::AccountSeeder.new(account: requested_resource).perform! + Internal::SeedAccountJob.perform_later(requested_resource) redirect_back(fallback_location: [namespace, requested_resource], notice: 'Account seeding triggered') end end diff --git a/app/jobs/internal/seed_account_job.rb b/app/jobs/internal/seed_account_job.rb new file mode 100644 index 000000000..d10a84f3f --- /dev/null +++ b/app/jobs/internal/seed_account_job.rb @@ -0,0 +1,7 @@ +class Internal::SeedAccountJob < ApplicationJob + queue_as :low + + def perform(account) + Seeders::AccountSeeder.new(account: account).perform! + end +end diff --git a/app/views/super_admin/accounts/_seed_data.html.erb b/app/views/super_admin/accounts/_seed_data.html.erb index e7a5b5afd..80bb6c7eb 100644 --- a/app/views/super_admin/accounts/_seed_data.html.erb +++ b/app/views/super_admin/accounts/_seed_data.html.erb @@ -1,4 +1,4 @@ -<% if !Rails.env.production? || ENV.fetch('ENABLE_ACCOUNT_SEEDING', nil) %> +<% if ENV.fetch('ENABLE_ACCOUNT_SEEDING', !Rails.env.production?) %>

<%= form_for([:seed, namespace, page.resource], method: :post, html: { class: "form" }) do |f| %> diff --git a/lib/seeders/account_seeder.rb b/lib/seeders/account_seeder.rb index 5302daefe..1f665acc5 100644 --- a/lib/seeders/account_seeder.rb +++ b/lib/seeders/account_seeder.rb @@ -10,7 +10,7 @@ class Seeders::AccountSeeder def initialize(account:) - raise 'Account Seeding is not allowed in production.' if Rails.env.production? + raise 'Account Seeding is not allowed.' unless ENV.fetch('ENABLE_ACCOUNT_SEEDING', !Rails.env.production?) @account_data = HashWithIndifferentAccess.new(YAML.safe_load(File.read(Rails.root.join('lib/seeders/seed_data.yml')))) @account = account diff --git a/lib/seeders/inbox_seeder.rb b/lib/seeders/inbox_seeder.rb index 0c4bca669..9ee750a63 100644 --- a/lib/seeders/inbox_seeder.rb +++ b/lib/seeders/inbox_seeder.rb @@ -10,7 +10,7 @@ class Seeders::InboxSeeder def initialize(account:, company_data:) - raise 'Inbox Seeding is not allowed in production.' if Rails.env.production? + raise 'Inbox Seeding is not allowed in production.' unless ENV.fetch('ENABLE_ACCOUNT_SEEDING', !Rails.env.production?) @account = account @company_data = company_data diff --git a/lib/seeders/seed_data.yml b/lib/seeders/seed_data.yml index 847ba5a8c..5e41e0131 100644 --- a/lib/seeders/seed_data.yml +++ b/lib/seeders/seed_data.yml @@ -351,11 +351,11 @@ contacts: - message_type: incoming content: "Hey, \n My card is not working on your website. Please help" - name: "Candice Matherson" - email: "cmathersonj@va.gov" + email: "cmathersonj@va.test" gender: 'female' conversations: - channel: Channel::Email - source_id: "cmathersonj@va.gov" + source_id: "cmathersonj@va.test" assignee: michael_scott@paperlayer.test messages: - message_type: incoming