Testing Rails with changed model

7 views
Skip to first unread message

Martin

unread,
Dec 6, 2015, 8:19:23 AM12/6/15
to Ruby on Rails: Talk
Hi there,

I have a model with following methods:

  # Permalink instead of ID
  before_create do |article|
    article.permalink = _permalink
  end
 
  def to_param
    permalink
  end

- permalink is a field in the database

Ok, but when i try to run tests the permalink is not created, but my controllers find the object by the permalink attribute, and this is nil in the tests
maybe the

@article = articles(:one)

does not create the permalink because it is not in the fixtures, and I do not want to have it there.

How can I deal with that?

Thanks,
Martin

Colin Law

unread,
Dec 6, 2015, 9:43:21 AM12/6/15
to Ruby on Rails: Talk
Callbacks are not called when fixtures are saved (which is before the
test is run) and @article=articles(:one) does not create the record so
it is not called then either. If you don't want to put it in the
fixtures then you could put something in setup() in the test class, or
before the specific tests that require it.

Colin
Reply all
Reply to author
Forward
Message has been deleted
0 new messages