Copy admin attribute to users

This commit is contained in:
Maikel Linke
2025-01-07 13:37:46 +11:00
parent 698d1daa57
commit 920002e084
2 changed files with 34 additions and 0 deletions

View File

@@ -0,0 +1,13 @@
# frozen_string_literal: true
class CopyAdminAttributeToUsers < ActiveRecord::Migration[7.0]
def up
execute <<~SQL.squish
UPDATE spree_users SET admin = true WHERE id IN (
SELECT user_id FROM spree_roles_users WHERE role_id IN (
SELECT id FROM spree_roles WHERE name = 'admin'
)
)
SQL
end
end

View File

@@ -0,0 +1,21 @@
# frozen_string_literal: true
require 'spec_helper'
require_relative "../../db/migrate/#{File.basename(__FILE__, '_spec.rb')}"
RSpec.describe CopyAdminAttributeToUsers do
describe "#up" do
it "marks current admins as admin" do
admin = create(:admin_user)
enterprise_user = create(:enterprise_user)
customer = create(:user)
expect { subject.up }.to change {
admin.reload.admin
}.from(false).to(true)
expect(enterprise_user.reload.admin).to eq false
expect(customer.reload.admin).to eq false
end
end
end