egonSchiele / contracts.ruby

Contracts for Ruby.
http://egonschiele.github.com/contracts.ruby
BSD 2-Clause "Simplified" License
1.44k stars 82 forks source link

ActiveRecord (3.2.22) shows deprecation warning due to override of .inherited method #223

Closed pavel-manylov closed 8 years ago

pavel-manylov commented 8 years ago

Given some (even empty) model:

class Book < ActiveRecord::Base
  include Contracts::Core
end

ActiveRecord puts warning (not so promising for actual versions of AR…):

DEPRECATION WARNING: It looks like something (probably a gem/plugin) is overriding the ActiveRecord::Base.inherited method. It is important that this hook executes so that your models are set up correctly. A workaround has been added to stop this causing an error in 3.2, but future versions will simply not work if the hook is overridden. If you are using Kaminari, please upgrade as it is known to have had this problem.

The following may help track down the problem: ["/home/rk/.rvm/gems/ruby-2.2.2@soft24/gems/contracts-0.13.0/lib/contracts/decorators.rb", 7]

In contracts/decorators.rb:7 method definition there are actually no call to super.

waterlink commented 8 years ago

@rap-kasta PR to add super there is welcome ;)

eval commented 8 years ago

Ran into the same issue with Rails 4.2.6, though the stacktrace was more cryptic:

/Users/gert/.gem/ruby/2.3.0/gems/activerecord-4.2.6/lib/active_record/relation/delegation.rb:9:in `relation_delegate_class': undefined method `[]' for nil:NilClass (NoMethodError)
        from /Users/gert/.gem/ruby/2.3.0/gems/activerecord-4.2.6/lib/active_record/relation/delegation.rb:112:in `relation_class_for'
        from /Users/gert/.gem/ruby/2.3.0/gems/activerecord-4.2.6/lib/active_record/relation/delegation.rb:106:in `create'
        from /Users/gert/.gem/ruby/2.3.0/gems/activerecord-4.2.6/lib/active_record/core.rb:254:in `relation'
        from /Users/gert/.gem/ruby/2.3.0/gems/activerecord-4.2.6/lib/active_record/scoping/named.rb:33:in `default_scoped'
        from /Users/gert/.gem/ruby/2.3.0/gems/activerecord-4.2.6/lib/active_record/scoping/named.rb:28:in `all'
        from /Users/gert/.gem/ruby/2.3.0/gems/activerecord-4.2.6/lib/active_record/migration.rb:847:in `get_all_versions'
        from /Users/gert/.gem/ruby/2.3.0/gems/activerecord-4.2.6/lib/active_record/migration.rb:858:in `needs_migration?'
        from /Users/gert/.gem/ruby/2.3.0/gems/activerecord-4.2.6/lib/active_record/migration.rb:396:in `load_schema_if_pending!'
        from /Users/gert/.gem/ruby/2.3.0/gems/activerecord-4.2.6/lib/active_record/migration.rb:411:in `block in maintain_test_schema!'
        from /Users/gert/.gem/ruby/2.3.0/gems/activerecord-4.2.6/lib/active_record/migration.rb:642:in `suppress_messages'
        from /Users/gert/.gem/ruby/2.3.0/gems/activerecord-4.2.6/lib/active_record/migration.rb:416:in `method_missing'
        from /Users/gert/.gem/ruby/2.3.0/gems/activerecord-4.2.6/lib/active_record/migration.rb:411:in `maintain_test_schema!'
        from /Users/gert/projects/philips/eit/repository/bpm-api/spec/rails_helper.rb:30:in `<top (required)>'
        from /Users/gert/.gem/ruby/2.3.0/gems/rspec-core-3.4.4/lib/rspec/core/configuration.rb:1295:in `require'
        from /Users/gert/.gem/ruby/2.3.0/gems/rspec-core-3.4.4/lib/rspec/core/configuration.rb:1295:in `block in requires='
        from /Users/gert/.gem/ruby/2.3.0/gems/rspec-core-3.4.4/lib/rspec/core/configuration.rb:1295:in `each'
        from /Users/gert/.gem/ruby/2.3.0/gems/rspec-core-3.4.4/lib/rspec/core/configuration.rb:1295:in `requires='
        from /Users/gert/.gem/ruby/2.3.0/gems/rspec-core-3.4.4/lib/rspec/core/configuration_options.rb:109:in `block in process_options_into'
        from /Users/gert/.gem/ruby/2.3.0/gems/rspec-core-3.4.4/lib/rspec/core/configuration_options.rb:108:in `each'
        from /Users/gert/.gem/ruby/2.3.0/gems/rspec-core-3.4.4/lib/rspec/core/configuration_options.rb:108:in `process_options_into'
        from /Users/gert/.gem/ruby/2.3.0/gems/rspec-core-3.4.4/lib/rspec/core/configuration_options.rb:21:in `configure'
        from /Users/gert/.gem/ruby/2.3.0/gems/rspec-core-3.4.4/lib/rspec/core/runner.rb:105:in `setup'
        from /Users/gert/.gem/ruby/2.3.0/gems/rspec-core-3.4.4/lib/rspec/core/runner.rb:92:in `run'
        from /Users/gert/.gem/ruby/2.3.0/gems/rspec-core-3.4.4/lib/rspec/core/runner.rb:78:in `run'
        from /Users/gert/.gem/ruby/2.3.0/gems/rspec-core-3.4.4/lib/rspec/core/runner.rb:45:in `invoke'
        from /Users/gert/.gem/ruby/2.3.0/gems/rspec-core-3.4.4/exe/rspec:4:in `<top (required)>'
        from /Users/gert/.gem/ruby/2.3.0/bin/rspec:23:in `load'
        from /Users/gert/.gem/ruby/2.3.0/bin/rspec:23:in `<main>'

Patch in the making.