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

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/412ab655-42c4-4287-825a-5cb913242a3b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

  • Colin Law at Dec 6, 2015 at 2:42 pm

    On 6 December 2015 at 13:19, Martin wrote:
    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?
    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

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLuGeL7o5Av9oh9NKDm1cRBw%3D7whXhqQS0sTzB9K%3DiJTZw%40mail.gmail.com.
    For more options, visit https://groups.google.com/d/optout.
  • Martin at Dec 6, 2015 at 6:48 pm
    Ok, thanks

    Am Sonntag, 6. Dezember 2015 15:43:21 UTC+1 schrieb Colin Law:
    On 6 December 2015 at 13:19, Martin <m.kaf...@gmail.com <javascript:>>
    wrote:
    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?
    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
    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/e655f49c-a9cb-41f9-956a-c4820df82dc3%40googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedDec 6, '15 at 1:19p
activeDec 6, '15 at 6:48p
posts3
users2
websiterubyonrails.org
irc#RubyOnRails

2 users in discussion

Martin: 2 posts Colin Law: 1 post

People

Translate

site design / logo © 2022 Grokbase