Sha256: 239095e502be3dd2f79bd83648cb09e138cd27c24eff116133e5e1ba15e3557a

Contents?: true

Size: 1.08 KB

Versions: 19

Compression:

Stored size: 1.08 KB

Contents

require 'thread'

module Shoulda
  module Matchers
    module ActiveRecord
      # @private
      module Uniqueness
        # @private
        class TestModelCreator
          def self.create(model_name, namespace)
            Mutex.new.synchronize do
              new(model_name, namespace).create
            end
          end

          def initialize(model_name, namespace)
            @model_name = model_name
            @namespace = namespace
          end

          def create
            new_model.tap do |new_model|
              new_model.symlink_to(existing_model)
            end
          end

          protected

          attr_reader :model_name, :namespace

          private

          def model_name_without_namespace
            model_name.demodulize
          end

          def new_model
            @_new_model ||= Model.next_unique_copy_of(
              model_name_without_namespace,
              namespace
            )
          end

          def existing_model
            @_existing_model ||= model_name.constantize
          end
        end
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 2 rubygems

Version Path
shoulda-matchers-4.4.1 lib/shoulda/matchers/active_record/uniqueness/test_model_creator.rb
shoulda-matchers-4.4.0 lib/shoulda/matchers/active_record/uniqueness/test_model_creator.rb
shoulda-matchers-4.3.0 lib/shoulda/matchers/active_record/uniqueness/test_model_creator.rb
shoulda-matchers-4.2.0 lib/shoulda/matchers/active_record/uniqueness/test_model_creator.rb
shoulda-matchers-4.1.2 lib/shoulda/matchers/active_record/uniqueness/test_model_creator.rb
shoulda-matchers-4.1.1 lib/shoulda/matchers/active_record/uniqueness/test_model_creator.rb
shoulda-matchers-4.1.0 lib/shoulda/matchers/active_record/uniqueness/test_model_creator.rb
shoulda-matchers-4.0.1 lib/shoulda/matchers/active_record/uniqueness/test_model_creator.rb
shoulda-matchers-3.1.3 lib/shoulda/matchers/active_record/uniqueness/test_model_creator.rb
shoulda-matchers-4.0.0.rc1 lib/shoulda/matchers/active_record/uniqueness/test_model_creator.rb
shoulda-matchers-3.1.2 lib/shoulda/matchers/active_record/uniqueness/test_model_creator.rb
ish_lib_manager-0.0.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/shoulda-matchers-2.8.0/lib/shoulda/matchers/active_record/uniqueness/test_model_creator.rb
shoulda-matchers-3.1.1 lib/shoulda/matchers/active_record/uniqueness/test_model_creator.rb
shoulda-matchers-3.1.0 lib/shoulda/matchers/active_record/uniqueness/test_model_creator.rb
shoulda-matchers-3.0.1 lib/shoulda/matchers/active_record/uniqueness/test_model_creator.rb
shoulda-matchers-3.0.0 lib/shoulda/matchers/active_record/uniqueness/test_model_creator.rb
shoulda-matchers-3.0.0.rc1 lib/shoulda/matchers/active_record/uniqueness/test_model_creator.rb
shoulda-matchers-2.8.0 lib/shoulda/matchers/active_record/uniqueness/test_model_creator.rb
shoulda-matchers-2.8.0.rc2 lib/shoulda/matchers/active_record/uniqueness/test_model_creator.rb