jeudi 29 octobre 2015

RoR: Model test looks for nonexistent table then gives an error

I have a rails test

class OrganizerTest < ActiveSupport::TestCase

def setup
  @organizer = Organizer.new(name: "Example Organizer", email: "organizer@example.com")
end

test "should be valid" do
  assert @organizer.valid?
end

end

and the model looks like

class Organizer < ActiveRecord::Base
  validates :name,  presence: true, length: { maximum: 50 }
  VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i    
  validates :email, presence: true, length: { maximum: 255 },
                format: { with: VALID_EMAIL_REGEX }
end

Now, when I run `rake test:models' I get the output:

Run options: --seed 41657

# Running:

[DEPRECATION] requiring "RMagick" is deprecated. Use "rmagick" instead
E

Finished in 0.119294s, 8.3826 runs/s, 0.0000 assertions/s.

  1) Error:
OrganizerTest#test_should_be_valid:
ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR:  relation "sessions" does not exist
LINE 1: DELETE FROM "sessions"
                    ^
: DELETE FROM "sessions"


1 runs, 0 assertions, 0 failures, 1 errors, 0 skips

But this is sooo confusing! I have no clue why the test is looking for a table called "sessions". I have a sessions controller, but no model or db table. Been playing with this for a while but google doesn't return great results for the error message so I would appreciate if anyone can explain what's going on!

Aucun commentaire:

Enregistrer un commentaire