Module: Shoulda::Matchers::ActiveRecord::Uniqueness::TestModels

Defined in:
lib/shoulda/matchers/active_record/uniqueness/test_models.rb

Defined Under Namespace

Modules: DescendantsFiltering

Class Method Summary collapse

Class Method Details

.contains?(klass) ⇒ Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/shoulda/matchers/active_record/uniqueness/test_models.rb', line 38

def self.contains?(klass)
  !klass.name.nil? && klass.name.start_with?(name_prefix)
end

.create(model_name) ⇒ Object



25
26
27
28
# File 'lib/shoulda/matchers/active_record/uniqueness/test_models.rb', line 25

def self.create(model_name)
  hide_from_descendants
  TestModelCreator.create(model_name, root_namespace)
end

.hide_from_descendantsObject



46
47
48
49
50
# File 'lib/shoulda/matchers/active_record/uniqueness/test_models.rb', line 46

def self.hide_from_descendants
  @_hide_from_descendants ||=
    ::ActiveRecord::Base.singleton_class.
      prepend(DescendantsFiltering) && true
end

.name_prefixObject



42
43
44
# File 'lib/shoulda/matchers/active_record/uniqueness/test_models.rb', line 42

def self.name_prefix
  @_name_prefix ||= "#{name}::"
end

.remove_allObject



30
31
32
# File 'lib/shoulda/matchers/active_record/uniqueness/test_models.rb', line 30

def self.remove_all
  root_namespace.clear
end

.root_namespaceObject



34
35
36
# File 'lib/shoulda/matchers/active_record/uniqueness/test_models.rb', line 34

def self.root_namespace
  @_root_namespace ||= Namespace.new(self)
end