0

I am new to RoR. I have two problems here. ISSUE 1 my rspec is

require 'spec_helper'
describe RefUserCategory do
    describe "validations" do
        it { should validate_presence_of(:user_category_description) }
    end
end

my Ref_User_Category model is

class RefUserCategory < ActiveRecord::Base
    validate :user_category_description , presence: true
    has_many :Users
end

The error I got in Rspec is Expected errors to include /can't be blank/ when user_category_description is set to nil, got no errors

So I decided to to use Pry to check whats happening

ISSUE 2 Im my application folder I do

pry -r ./config/environment

[2] pry(main)> Ref_User_Category.new
LoadError: Unable to autoload constant Ref_User_Category, expected /var/lib/stickshift/52d29d0e5004461024000031/app-root/data/736003/east/app/models/ref_user_category.rb to define it
from /var/lib/stickshift/52d29d0e5004461024000031/app-root/data/lib/ruby/gems/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:464:in `load_missing_constant'

I have user model too I

pry(main)> User.new

gives error

ActiveRecord::StatementInvalid: Could not find table 'users'

/app-root/data/lib/ruby/gems/gems/activerecord-4.0.2/lib/active_record/connection_adapters/sqlite3_adapter.rb:512:in `table_structure'
Rigel
  • 882
  • 1
  • 11
  • 32

1 Answers1

0

Regarding issue 1, you have a typo: change validate to validates.

Regarding issue 2:

You generally start the console from the root of your project like this:

$ rails c

You are doing Ref_User_Category.new when you should do RefUserCategory.new.

About User.new, it looks like you haven't run your database migrations:

$ rake db:migrate
$ rake db:test:prepare
Agis
  • 32,639
  • 3
  • 73
  • 81
  • I have done rake db:migrate. Or else Rspec execution would have suggested me the same . In any case I tried again `rake db:migrate RAILS_ENV=test` still not working – Rigel Jan 15 '14 at 11:10
  • 1
    What does `$ rake db:test:prepare` outputs? Also, do you run `rails console` from the root folder of your project? – Agis Jan 15 '14 at 11:12
  • rake db:test:prepare give no output. Thanks for the pointer it was issue with rails console no executed properly was getting error `config.eager_load is set to nil` got it fixed thanks :) working now – Rigel Jan 15 '14 at 11:25
  • @Rigel also added solution for issue 1 and more solutions for 2. – Agis Jan 15 '14 at 11:39