rails/rails — Issue #4994: include AR::Validations and AR::AttributeMethods fails on `abstract_class?' undefined
Author: petervandenabeele
Created: 2012-02-10 20:01:39+00:00
State: open

Working on Rails 4.0.0.beta

```
$ git log -1 | cat
commit 3092324ef4e2f6f096adfbcf92597502b3ce91aa
Merge: fc3fad8 aaffc2a
Author: Aaron Patterson
Date: Fri Feb 10 10:23:42 2012 -0800
```

I presumed I could include (cherry pick) certain modules out of ActiveRecord (not inheriting from ActiveRecord::Base
or include _all_ functionality)

I tried:

```ruby
class EventOrganizer
include ActiveRecord::Validations
include ActiveRecord::AttributeMethods
end
```

And a test creating my initial factory yielded the error below.

I tried to include `ActiveRecord::Model` where `abstract_class` is defined on line 76 back into AttributesMethod

```ruby
module AttributeMethods #:nodoc:
extend ActiveSupport::Concern
include ActiveModel::AttributeMethods
+ include ActiveRecord::Model
```

but failed miserably, because after a lot of fiddling with requires it turns out this is cyclic include.

Is it the intention to be able to _only_ include AR::Validations and AR::AttributeMethods and
get sensible results or do I need to include more to get a functional system ?

Actually, if I also include ActiveRecord::Model in the project, it works again (but have I than not
essentially include everything, including ActiveRecord::Base given the last line of the
ActiveRecord::Model file?)

```
module ActiveRecord
# ActiveRecord::Model can be included into a class to add Active Record persistence.
# This is an alternative to inheriting from ActiveRecord::Base. Example:
#
# class Post
# include ActiveRecord::Model
# end
#
module Model
...
# Load Base at this point, because the active_record load hook is run in that file.
Base
end
```

Full trace is below.

Thanks (I hope this makes sense, sorry upfront if not ...)

```
$ bundle exec rspec spec/models/event_organizer/factory_spec.rb
DEPRECATION WARNING: config.whiny_nils option is deprecated and no longer works. (called from block in at /home/peterv/data/backed_up/projects/.../config/environments/test.rb:15)
/home/peterv/b/github/petervandenabeele/rails/activerecord/lib/active_record/attribute_methods.rb:105:in `attribute_names': undefined method `abstract_class?' for EventOrganizer:Class (NoMethodError)
from /home/peterv/b/github/petervandenabeele/rails/actionpack/lib/action_controller/metal/params_wrapper.rb:171:in `_set_wrapper_defaults'
from /home/peterv/b/github/petervandenabeele/rails/actionpack/lib/action_controller/metal/params_wrapper.rb:132:in `inherited'
from /home/peterv/b/github/petervandenabeele/rails/actionpack/lib/abstract_controller/railties/routes_helpers.rb:7:in `block (2 levels) in with'
from /home/peterv/b/github/petervandenabeele/rails/actionpack/lib/action_controller/railties/paths.rb:7:in `block (2 levels) in with'
from /home/peterv/data/backed_up/projects/.../app/controllers/event_organizers_controller.rb:1:in `'
from /home/peterv/b/github/petervandenabeele/rails/activesupport/lib/active_support/dependencies.rb:251:in `require'
from /home/peterv/b/github/petervandenabeele/rails/activesupport/lib/active_support/dependencies.rb:251:in `block in require'
from /home/peterv/b/github/petervandenabeele/rails/activesupport/lib/active_support/dependencies.rb:236:in `load_dependency'
from /home/peterv/b/github/petervandenabeele/rails/activesupport/lib/active_support/dependencies.rb:251:in `require'
from /home/peterv/b/github/petervandenabeele/rails/activesupport/lib/active_support/dependencies.rb:359:in `require_or_load'
from /home/peterv/b/github/petervandenabeele/rails/activesupport/lib/active_support/dependencies.rb:313:in `depend_on'
from /home/peterv/b/github/petervandenabeele/rails/activesupport/lib/active_support/dependencies.rb:225:in `require_dependency'
from /home/peterv/b/github/petervandenabeele/rails/railties/lib/rails/engine.rb:439:in `block (2 levels) in eager_load!'
from /home/peterv/b/github/petervandenabeele/rails/railties/lib/rails/engine.rb:438:in `each'
from /home/peterv/b/github/petervandenabeele/rails/railties/lib/rails/engine.rb:438:in `block in eager_load!'
from /home/peterv/b/github/petervandenabeele/rails/railties/lib/rails/engine.rb:436:in `each'
from /home/peterv/b/github/petervandenabeele/rails/railties/lib/rails/engine.rb:436:in `eager_load!'
from /home/peterv/b/github/petervandenabeele/rails/railties/lib/rails/application/finisher.rb:53:in `block in '
from /home/peterv/b/github/petervandenabeele/rails/railties/lib/rails/initializable.rb:30:in `instance_exec'
from /home/peterv/b/github/petervandenabeele/rails/railties/lib/rails/initializable.rb:30:in `run'
from /home/peterv/b/github/petervandenabeele/rails/railties/lib/rails/initializable.rb:55:in `block in run_initializers'
from /home/peterv/b/github/petervandenabeele/rails/railties/lib/rails/initializable.rb:54:in `each'
from /home/peterv/b/github/petervandenabeele/rails/railties/lib/rails/initializable.rb:54:in `run_initializers'
from /home/peterv/b/github/petervandenabeele/rails/railties/lib/rails/application.rb:132:in `initialize!'
from /home/peterv/b/github/petervandenabeele/rails/railties/lib/rails/railtie/configurable.rb:30:in `method_missing'
from /home/peterv/data/backed_up/projects/.../config/environment.rb:5:in `'
from /home/peterv/data/backed_up/projects/.../spec/spec_helper.rb:3:in `require'
from /home/peterv/data/backed_up/projects/.../spec/spec_helper.rb:3:in `'
from /home/peterv/data/backed_up/projects/.../spec/models/event_organizer/factory_spec.rb:1:in `require'
from /home/peterv/data/backed_up/projects/.../spec/models/event_organizer/factory_spec.rb:1:in `'
from /home/peterv/.rvm/gems/ruby-1.9.3-p0@.../gems/rspec-core-2.8.0/lib/rspec/core/configuration.rb:698:in `load'
from /home/peterv/.rvm/gems/ruby-1.9.3-p0@.../gems/rspec-core-2.8.0/lib/rspec/core/configuration.rb:698:in `block in load_spec_files'
from /home/peterv/.rvm/gems/ruby-1.9.3-p0@.../gems/rspec-core-2.8.0/lib/rspec/core/configuration.rb:698:in `map'
from /home/peterv/.rvm/gems/ruby-1.9.3-p0@.../gems/rspec-core-2.8.0/lib/rspec/core/configuration.rb:698:in `load_spec_files'
from /home/peterv/.rvm/gems/ruby-1.9.3-p0@.../gems/rspec-core-2.8.0/lib/rspec/core/command_line.rb:22:in `run'
from /home/peterv/.rvm/gems/ruby-1.9.3-p0@.../gems/rspec-core-2.8.0/lib/rspec/core/runner.rb:80:in `run_in_process'
from /home/peterv/.rvm/gems/ruby-1.9.3-p0@.../gems/rspec-core-2.8.0/lib/rspec/core/runner.rb:69:in `run'
from /home/peterv/.rvm/gems/ruby-1.9.3-p0@.../gems/rspec-core-2.8.0/lib/rspec/core/runner.rb:10:in `block in autorun'
```