Sha256: e034f81ef961e51b466a662d68e45ec0a2183c4dc85462e58f9fe1bf7f800ded

Contents?: true

Size: 1.64 KB

Versions: 29

Compression:

Stored size: 1.64 KB

Contents

# frozen_string_literal: true

require 'eac_ruby_utils/core_ext'
require 'factory_bot'

module EacRailsBase0
  module Rspec
    module Setup
      def self.extended(obj)
        return unless obj.rails_app_path

        %w[engines admin_user non_admin_user admin_example non_admin_example
           anonymous_example].each do |m|
          obj.send("setup_#{m}")
        end
      end

      private

      def setup_engines
        ::FactoryBot.definition_file_paths += ::EacRailsBase0::XEngine.local.flat_map do |engine|
          %w[factories test/factories spec/factories].map do |subpath|
            engine.config.root.join(subpath).to_path
          end
        end
        ::FactoryBot.find_definitions
      end

      def setup_admin_user
        ::FactoryBot.define do
          factory :admin_user, class: ::EacUsersSupport::User do
            email { 'admin@example.com' }
            password { 'mysecret' }
            confirmed_at { ::Time.zone.now }
          end
        end
      end

      def setup_non_admin_user
        ::FactoryBot.define do
          factory :non_admin_user, class: ::EacUsersSupport::User do
            email { 'nonadmin@example.com' }
            password { 'mysecret' }
            confirmed_at { ::Time.zone.now }
          end
        end
      end

      def setup_admin_example
        require 'eac_rails_base0/rspec/shared_contexts/when_user_is_admin'
      end

      def setup_non_admin_example
        require 'eac_rails_base0/rspec/shared_contexts/when_user_is_non_admin'
      end

      def setup_anonymous_example
        require 'eac_rails_base0/rspec/shared_contexts/when_user_is_anonymous'
      end
    end
  end
end

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
eac_rails_base0-0.69.0 lib/eac_rails_base0/rspec/setup.rb
eac_rails_base0-0.68.7 lib/eac_rails_base0/rspec/setup.rb
eac_rails_base0-0.68.6 lib/eac_rails_base0/rspec/setup.rb
eac_rails_base0-0.68.5 lib/eac_rails_base0/rspec/setup.rb
eac_rails_base0-0.68.4 lib/eac_rails_base0/rspec/setup.rb
eac_rails_base0-0.68.3 lib/eac_rails_base0/rspec/setup.rb
eac_rails_base0-0.68.2 lib/eac_rails_base0/rspec/setup.rb
eac_rails_base0-0.68.1 lib/eac_rails_base0/rspec/setup.rb
eac_rails_base0-0.68.0 lib/eac_rails_base0/rspec/setup.rb
eac_rails_base0-0.67.0 lib/eac_rails_base0/rspec/setup.rb
eac_rails_base0-0.66.0 lib/eac_rails_base0/rspec/setup.rb
eac_rails_base0-0.65.0 lib/eac_rails_base0/rspec/setup.rb
eac_rails_base0-0.64.0 lib/eac_rails_base0/rspec/setup.rb
eac_rails_base0-0.63.1 lib/eac_rails_base0/rspec/setup.rb
eac_rails_base0-0.63.0 lib/eac_rails_base0/rspec/setup.rb
eac_rails_base0-0.62.0 lib/eac_rails_base0/rspec/setup.rb
eac_rails_base0-0.61.1 lib/eac_rails_base0/rspec/setup.rb
eac_rails_base0-0.61.0 lib/eac_rails_base0/rspec/setup.rb
eac_rails_base0-0.60.4 lib/eac_rails_base0/rspec/setup.rb
eac_rails_base0-0.60.3 lib/eac_rails_base0/rspec/setup.rb