Module: Virtuatable::Specs::Factories::Applications

Extended by:
ActiveSupport::Concern
Included in:
Builders::Tests
Defined in:
lib/virtuatable/specs/factories/applications.rb

Overview

Factories concerning applications used in shared examples

Author:

Instance Method Summary collapse

Instance Method Details

#load_applications_factory!Object

rubocop:disable Metrics/MethodLength



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/virtuatable/specs/factories/applications.rb', line 16

def load_applications_factory!
  # This avoids multiple re-declarations by setting a flag.
  return if self.class.class_variable_defined?(:@@apps_declared)

  FactoryBot.define do
    factory :vt_empty_application, class: Arkaan::OAuth::Application do
      # This factory creates an application with random value, useful
      # to make simple requests on any route as all routes require
      # the use of a valid application to be correctly called.
      factory :random_application do
        name { Faker::Alphanumeric.unique.alphanumeric(number: 16) }
        app_key { BSON::ObjectId.new }
        creator { association(:random_administrator) }
        premium { false }

        # This factory creates a premium application, mainly used for
        # registration and authentication purpose.
        factory :random_premium_app do
          premium { true }
        end
      end
    end
  end

  # rubocop:disable Style/ClassVars
  @@apps_declared = true
  # rubocop:enable Style/ClassVars
end