Sha256: 2efc232170b105e4955b49d93818abe1ff2c9d9ec93f5eff839ae8e5c1710734

Contents?: true

Size: 1006 Bytes

Versions: 3

Compression:

Stored size: 1006 Bytes

Contents

# Routine for creating an account, only for use when stubbing and
# not on production.

module OpenStax
  module Accounts
    module Dev
      class CreateAccount
        lev_routine

        protected

        def exec(inputs={})
          fatal_error(code: :cannot_create_account_in_production) if Rails.env.production?
          fatal_error(code: :can_only_create_account_when_stubbing) if !OpenStax::Accounts.configuration.enable_stubbing?

          username = inputs[:username]
          while username.nil? || Account.where(username: username).exists? do
            username = SecureRandom.hex(3).to_s
          end

          account = OpenStax::Accounts::Account.new

          account.openstax_uid = -SecureRandom.hex(4).to_i(16)/2
          account.access_token = SecureRandom.hex.to_s
          account.username = username

          account.save

          transfer_errors_from(account, {type: :verbatim}, true)

          outputs[:account] = account
        end

      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
openstax_accounts-7.5.0 app/routines/openstax/accounts/dev/create_account.rb
openstax_accounts-7.4.0 app/routines/openstax/accounts/dev/create_account.rb
openstax_accounts-7.3.0 app/routines/openstax/accounts/dev/create_account.rb