Postgresql tests fixed

Antonio Terceiro terceiro at colivre.coop.br
Tue Sep 17 16:23:22 BRT 2013


On Tue, Sep 17, 2013 at 12:16:59PM -0300, Rodrigo Souto wrote:
> Bráulio Bhavamitra escreveu isso ai:
> > Hello Rodrigo,
> > 
> > I've pulled noosfero stable branch and still I've got 4 unit tests failing.
> > https://travis-ci.org/coletivoEITA/noosfero-ecosol/jobs/11333500
> > 
> > Do they pass to you?
> 
> Yeah man. I'm kind of trying to fix them based on the failures that are
> happening on your ci. See this error here:
> 
> test_should_deliver_activation_email_notify(UserMailerTest):
> 
>   NoMethodError: undefined method `environment=' for nil:NilClass
>   /test/unit/user_mailer_test.rb:18:in `test_should_deliver_activation_email_notify'
>   lib/authenticated_test_helper.rb:42:in `assert_difference'
>   /test/unit/user_mailer_test.rb:16:in `test_should_deliver_activation_email_notify'
> 
> It's passing here, but I guess it's breaking on your server because due
> to some reason there is no user before the test is ran:
> 
>   should 'deliver activation email notify' do
>     assert_difference ActionMailer::Base.deliveries, :size do
>       u = Person.find(:first).user
>       u.environment = Environment.default
>       User::Mailer.deliver_activation_email_notify(u)
>     end
>   end

> 
> So I did this to avoid this problem:
> 
>    should 'deliver activation email notify' do
>      assert_difference ActionMailer::Base.deliveries, :size do
> -      u = Person.find(:first).user
> -      u.environment = Environment.default
> +      u = create_user('some_user')
>        User::Mailer.deliver_activation_email_notify(u)
>      end
>    end

the original test was wrong. Tests must be self-contained and *cannot*
assume anything of the external environment.

the only case where that Person.find(:first) should be expeceted to work
was if that first user it assumes to exist is actually created in the
setup method of the test class.

-- 
Antonio Terceiro <terceiro at colivre.coop.br>
Colivre - Cooperativa de Tecnologias Livres
http://www.colivre.coop.br/


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20130917/02c3be7d/attachment.pgp>


More information about the Noosfero-dev mailing list