mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-26 01:33:22 +00:00
Copy admin attribute to users
This commit is contained in:
13
db/migrate/20250107014617_copy_admin_attribute_to_users.rb
Normal file
13
db/migrate/20250107014617_copy_admin_attribute_to_users.rb
Normal 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
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user