Sha256: ee36b73914a2bb5217572b299f526e1c1ac9e72b223422f1404754d1f33f01f1

Contents?: true

Size: 1.18 KB

Versions: 8

Compression:

Stored size: 1.18 KB

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.role = inputs[:role] || :unknown_role
          account.uuid = SecureRandom.uuid
          account.support_identifier = "cs_#{SecureRandom.hex(4)}"
          account.is_test = true

          account.save

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

          outputs[:account] = account
        end

      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
openstax_accounts-9.0.0 app/routines/openstax/accounts/dev/create_account.rb
openstax_accounts-8.1.1 app/routines/openstax/accounts/dev/create_account.rb
openstax_accounts-8.1.0 app/routines/openstax/accounts/dev/create_account.rb
openstax_accounts-8.0.1 app/routines/openstax/accounts/dev/create_account.rb
openstax_accounts-8.0.0 app/routines/openstax/accounts/dev/create_account.rb
openstax_accounts-7.13.1 app/routines/openstax/accounts/dev/create_account.rb
openstax_accounts-7.13.0 app/routines/openstax/accounts/dev/create_account.rb
openstax_accounts-7.12.0 app/routines/openstax/accounts/dev/create_account.rb