Class: Railscheck::Test::Models

Inherits:
Railscheck::TestCase show all
Defined in:
lib/test/tc_models.rb

Instance Method Summary collapse

Methods inherited from Railscheck::TestCase

#default_test

Instance Method Details

#test_associations_pluralizationObject

Test that associations uses the correct pluralization.



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/test/tc_models.rb', line 14

def test_associations_pluralization
  lookup_active_record_models_classes.each do |clazz|
    clazz.reflect_on_all_associations.each do |a|
      #puts "Checking associations #{a.macro} #{a.name} for #{clazz}"
      if a.macro==:has_many || a.macro==:has_and_belongs_to_many 
         assert plural?(a.name), "#{a.macro} association #{a.name} in model class #{clazz} should be be a plural name (as known by rails pluralizer)"
      elsif a.macro==:has_one || a.macro==:belongs_to
         assert singular?(a.name), "#{a.macro} association #{a.name} in model class #{clazz} should be be a singular name (as known by rails pluralizer)"                    
      end
    end
  end
end

#test_database_tables_and_models_consistencyObject

Check that correctly named database tables exist for each rails model



7
8
9
10
11
# File 'lib/test/tc_models.rb', line 7

def test_database_tables_and_models_consistency      
  lookup_active_record_models_classes.each do |clazz|
    assert clazz.table_exists?, "Error - Could not find  database table #{clazz.table_name} corresponding to rails model #{clazz.name}"
  end
end