mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Merge pull request #4400 from coopdevs/task-to-remove-enterprise-limit
Task to remove limit of ent. that can be created
This commit is contained in:
27
lib/tasks/users.rake
Normal file
27
lib/tasks/users.rake
Normal file
@@ -0,0 +1,27 @@
|
||||
require 'csv'
|
||||
|
||||
namespace :ofn do
|
||||
desc 'remove the limit of enterprises a user can create'
|
||||
task :remove_enterprise_limit, [:user_id] => :environment do |_task, args|
|
||||
RemoveEnterpriseLimit.new(args.user_id).call
|
||||
end
|
||||
|
||||
class RemoveEnterpriseLimit
|
||||
# rubocop:disable Style/NumericLiterals
|
||||
MAX_INTEGER = 2147483647
|
||||
# rubocop:enable Style/NumericLiterals
|
||||
|
||||
def initialize(user_id)
|
||||
@user_id = user_id
|
||||
end
|
||||
|
||||
def call
|
||||
user = Spree::User.find(user_id)
|
||||
user.update_attribute(:enterprise_limit, MAX_INTEGER)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
attr_reader :user_id
|
||||
end
|
||||
end
|
||||
28
spec/lib/tasks/users_rake_spec.rb
Normal file
28
spec/lib/tasks/users_rake_spec.rb
Normal file
@@ -0,0 +1,28 @@
|
||||
require 'spec_helper'
|
||||
require 'rake'
|
||||
|
||||
describe 'users.rake' do
|
||||
describe ':remove_enterprise_limit' do
|
||||
context 'when the user exists' do
|
||||
it 'sets the enterprise_limit to the maximum integer' do
|
||||
Rake.application.rake_require 'tasks/users'
|
||||
Rake::Task.define_task(:environment)
|
||||
|
||||
max_integer = 2147483647
|
||||
user = create(:user)
|
||||
|
||||
Rake.application.invoke_task "ofn:remove_enterprise_limit[#{user.id}]"
|
||||
|
||||
expect(user.reload.enterprise_limit).to eq(max_integer)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the user does not exist' do
|
||||
it 'raises' do
|
||||
expect {
|
||||
RemoveEnterpriseLimit.new(-1).call
|
||||
}.to raise_error(ActiveRecord::RecordNotFound)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user