3
votes

So I'm trying to run rspec tests with

$ rspec spec/models

but I get this error

/home/kenny/WorkSpace/FeedingForward/app/admin/admin_user.rb:1:in <top (required)>': uninitialized constant AdminUser (NameError) from /home/kenny/.rvm/gems/ruby-1.9.3-p362/gems/backports-2.6.7/lib/backports/tools.rb:314:inrequire' from /home/kenny/.rvm/gems/ruby-1.9.3-p362/gems/backports-2.6.7/lib/backports/tools.rb:314:in require_with_backports' from /home/kenny/.rvm/gems/ruby-1.9.3-p362/gems/activesupport-3.2.13/lib/active_support/inflector/methods.rb:230:inblock in constantize' from /home/kenny/.rvm/gems/ruby-1.9.3-p362/gems/activesupport-3.2.13/lib/active_support/inflector/methods.rb:229:in each' from /home/kenny/.rvm/gems/ruby-1.9.3-p362/gems/activesupport-3.2.13/lib/active_support/inflector/methods.rb:229:inconstantize' from /home/kenny/.rvm/gems/ruby-1.9.3-p362/gems/devise-2.1.3/lib/devise.rb:256:in get' from /home/kenny/.rvm/gems/ruby-1.9.3-p362/gems/devise-2.1.3/lib/devise/mapping.rb:77:into' from /home/kenny/.rvm/gems/ruby-1.9.3-p362/gems/devise-2.1.3/lib/devise/mapping.rb:72:in modules' from /home/kenny/.rvm/gems/ruby-1.9.3-p362/gems/devise-2.1.3/lib/devise/mapping.rb:89:inroutes' from /home/kenny/.rvm/gems/ruby-1.9.3-p362/gems/devise-2.1.3/lib/devise/mapping.rb:156:in default_used_route' from /home/kenny/.rvm/gems/ruby-1.9.3-p362/gems/devise-2.1.3/lib/devise/mapping.rb:66:ininitialize' from /home/kenny/.rvm/gems/ruby-1.9.3-p362/gems/devise-2.1.3/lib/devise.rb:290:in new' from /home/kenny/.rvm/gems/ruby-1.9.3-p362/gems/devise-2.1.3/lib/devise.rb:290:inadd_mapping' from /home/kenny/.rvm/gems/ruby-1.9.3-p362/gems/devise-2.1.3/lib/devise/rails/routes.rb:208:in block in devise_for' from /home/kenny/.rvm/gems/ruby-1.9.3-p362/gems/devise-2.1.3/lib/devise/rails/routes.rb:207:ineach' from /home/kenny/.rvm/gems/ruby-1.9.3-p362/gems/devise-2.1.3/lib/devise/rails/routes.rb:207:in devise_for' from /home/kenny/WorkSpace/FeedingForward/config/routes.rb:41:inblock in ' from /home/kenny/.rvm/gems/ruby-1.9.3-p362/gems/actionpack-3.2.13/lib/action_dispatch/routing/route_set.rb:289:in instance_exec' from /home/kenny/.rvm/gems/ruby-1.9.3-p362/gems/actionpack-3.2.13/lib/action_dispatch/routing/route_set.rb:289:ineval_block' from /home/kenny/.rvm/gems/ruby-1.9.3-p362/gems/actionpack-3.2.13/lib/action_dispatch/routing/route_set.rb:267:in draw' from /home/kenny/WorkSpace/FeedingForward/config/routes.rb:1:in' from /home/kenny/.rvm/gems/ruby-1.9.3-p362/gems/railties-3.2.13/lib/rails/application/routes_reloader.rb:40:in block in load_paths' from /home/kenny/.rvm/gems/ruby-1.9.3-p362/gems/railties-3.2.13/lib/rails/application/routes_reloader.rb:40:ineach' from /home/kenny/.rvm/gems/ruby-1.9.3-p362/gems/railties-3.2.13/lib/rails/application/routes_reloader.rb:40:in load_paths' from /home/kenny/.rvm/gems/ruby-1.9.3-p362/gems/railties-3.2.13/lib/rails/application/routes_reloader.rb:16:inreload!' from /home/kenny/.rvm/gems/ruby-1.9.3-p362/gems/railties-3.2.13/lib/rails/application.rb:108:in reload_routes!' from /home/kenny/.rvm/gems/ruby-1.9.3-p362/gems/activeadmin-0.6.0/lib/active_admin/reloader.rb:34:inreload!' from /home/kenny/.rvm/gems/ruby-1.9.3-p362/gems/activeadmin-0.6.0/lib/active_admin/reloader.rb:61:in block in attach!' from /home/kenny/.rvm/gems/ruby-1.9.3-p362/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:429:inrun_191199301_prepare_874569490__callbacks' from /home/kenny/.rvm/gems/ruby-1.9.3-p362/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:405:in __run_callback' from /home/kenny/.rvm/gems/ruby-1.9.3-p362/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:385:in_run_prepare_callbacks' from /home/kenny/.rvm/gems/ruby-1.9.3-p362/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:81:in run_callbacks' from /home/kenny/.rvm/gems/ruby-1.9.3-p362/gems/actionpack-3.2.13/lib/action_dispatch/middleware/reloader.rb:74:inprepare!' from /home/kenny/.rvm/gems/ruby-1.9.3-p362/gems/actionpack-3.2.13/lib/action_dispatch/middleware/reloader.rb:48:in prepare!' from /home/kenny/.rvm/gems/ruby-1.9.3-p362/gems/railties-3.2.13/lib/rails/application/finisher.rb:47:inblock in ' from /home/kenny/.rvm/gems/ruby-1.9.3-p362/gems/railties-3.2.13/lib/rails/initializable.rb:30:in instance_exec' from /home/kenny/.rvm/gems/ruby-1.9.3-p362/gems/railties-3.2.13/lib/rails/initializable.rb:30:inrun' from /home/kenny/.rvm/gems/ruby-1.9.3-p362/gems/railties-3.2.13/lib/rails/initializable.rb:55:in block in run_initializers' from /home/kenny/.rvm/gems/ruby-1.9.3-p362/gems/railties-3.2.13/lib/rails/initializable.rb:54:ineach' from /home/kenny/.rvm/gems/ruby-1.9.3-p362/gems/railties-3.2.13/lib/rails/initializable.rb:54:in run_initializers' from /home/kenny/.rvm/gems/ruby-1.9.3-p362/gems/railties-3.2.13/lib/rails/application.rb:136:ininitialize!' from /home/kenny/.rvm/gems/ruby-1.9.3-p362/gems/railties-3.2.13/lib/rails/railtie/configurable.rb:30:in method_missing' from /home/kenny/WorkSpace/FeedingForward/config/environment.rb:5:in' from /home/kenny/WorkSpace/FeedingForward/spec/spec_helper.rb:3:in require' from /home/kenny/WorkSpace/FeedingForward/spec/spec_helper.rb:3:in' from /home/kenny/WorkSpace/FeedingForward/spec/models/delivery_spec.rb:1:in require' from /home/kenny/WorkSpace/FeedingForward/spec/models/delivery_spec.rb:1:in' from /home/kenny/.rvm/gems/ruby-1.9.3-p362/gems/rspec-core-2.12.2/lib/rspec/core/configuration.rb:789:in load' from /home/kenny/.rvm/gems/ruby-1.9.3-p362/gems/rspec-core-2.12.2/lib/rspec/core/configuration.rb:789:inblock in load_spec_files' from /home/kenny/.rvm/gems/ruby-1.9.3-p362/gems/rspec-core-2.12.2/lib/rspec/core/configuration.rb:789:in each' from /home/kenny/.rvm/gems/ruby-1.9.3-p362/gems/rspec-core-2.12.2/lib/rspec/core/configuration.rb:789:inload_spec_files' from /home/kenny/.rvm/gems/ruby-1.9.3-p362/gems/rspec-core-2.12.2/lib/rspec/core/command_line.rb:22:in run' from /home/kenny/.rvm/gems/ruby-1.9.3-p362/gems/rspec-core-2.12.2/lib/rspec/core/runner.rb:80:inrun' from /home/kenny/.rvm/gems/ruby-1.9.3-p362/gems/rspec-core-2.12.2/lib/rspec/core/runner.rb:17:in `block in autorun'

Here is the code in admin_user in the admin directory

ActiveAdmin.register AdminUser do     
  index do                            
    column :email
    column :primary_phone

I also have a admin_user class in the models directory

class AdminUser < ActiveRecord::Base
  after_initialize :init

  devise :database_authenticatable, 
         :recoverable, :rememberable, :trackable, :validatable

  # Setup accessible (or protected) attributes for your model
  attr_accessible :email, :primary_phone, :password, :password_confirmation,    :remember_me, :notify_by_sms, :notify_by_email
  # attr_accessible :title, :body

  protected

  def init
    self.notify_by_sms ||= false
    self.notify_by_email ||= true
  end
end
1

1 Answers

0
votes

It looks like the schema is missing from your test database. Make sure you run the migrations for your test environment too.

RAILS_ENV=test be rake db:migrate