Montag, 13. Juli 2009
Running one of my test classes using multiparameter attributes (date column in the database) I got a lot of warnings saying:
vendor/rails/activerecord/lib/active_record/attribute_methods.rb:142: warning: Object#type is deprecated; use Object#class

Here's the code where type is called:
def create_time_zone_conversion_attribute?(name, column)
  time_zone_aware_attributes && !skip_time_zone_conversion_for_attributes.include?(name.to_sym) && [:datetime, :timestamp].include?(column.type)
end

Normally, type should be called on a Column object, which provides a type (see vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb), but in my case, column was nil and the method type was called for Object.

I don't fully understand what's going on (why is column nil?), but as a quickfix to silence the annoying warning you can change the method in attribute_methods.rb to handle this as a special case:
def create_time_zone_conversion_attribute?(name, column)
  if column.nil?
    true
  else
    time_zone_aware_attributes && !skip_time_zone_conversion_for_attributes.include?(name.to_sym) && [:datetime, :timestamp].include?(column.type)
  end
end




Today, I had the problem that rcov on one machine produced outputs like 50% or 48% for some files while on some other machine the coverage was 100% or at least >95%. When looking at the rcov output, I noticed that the contents of the files that made problems were duplicated, first the correct results and then again the whole class, this time with every single line marked as being not covered.

The affected files were sessions_controller.rb, user_controller.rb and user_mailer.rb. This made me think of where those files came originally from: The restful authentication plugin. I had a look on the test files for these and their beginning looked like this (test/functional/sessions_controller_test.rb here):
require 'test_helper'
require 'sessions_controller'

# Re-raise errors caught by the controller.
class SessionsController; def rescue_action(e) raise e end; end

Why is sessions_controller included/required there? I don't know why the restful authentication plugin put those instructions there, but you can just remove them from the affected files and you will be fine.

I suspect that this issue only comes up with older rcov versions, because my development machine with current rcov does not have a problem with the require instructions.