Hi, I wonder why this unit test fails. The model : class Article < ActiveRecord::Base set_table_name "publish_articles" belongs_to :category validates_presence_of :title, :excerpt #snip end The test : def test_validate @article.title = nil @article.excerpt = nil assert !@article.save assert_equal 2, !@article.errors.count end !@article.errors.count returns ''false'' instead of 2 I tried also with @article.title = '''' Any idea ? -- Posted via http://www.ruby-forum.com/.
try changing assert_equal 2, !@article.errors.count to be assert_equal 2, @article.errors.count The bang(!) means not and when you place it in front of !@ article.errors.count it''s returning the opposite of whether there is an @ articles.errors.count value returned, which in this case is false. On 3/25/06, Christophe Gimenez <kandjidev@yahoo.fr> wrote:> > Hi, I wonder why this unit test fails. > > The model : > class Article < ActiveRecord::Base > set_table_name "publish_articles" > belongs_to :category > > validates_presence_of :title, :excerpt > #snip > end > > The test : > def test_validate > @article.title = nil > @article.excerpt = nil > assert !@article.save > assert_equal 2, !@article.errors.count > end > > !@article.errors.count returns ''false'' instead of 2 > I tried also with @article.title = '''' > > Any idea ? > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060326/766da8a5/attachment.html
On 3/25/06, Christophe Gimenez <kandjidev@yahoo.fr> wrote:> Hi, I wonder why this unit test fails. > > The model : > class Article < ActiveRecord::Base > set_table_name "publish_articles" > belongs_to :category > > validates_presence_of :title, :excerpt > #snip > end > > The test : > def test_validate > @article.title = nil > @article.excerpt = nil > assert !@article.save > assert_equal 2, !@article.errors.count > end > > !@article.errors.count returns ''false'' instead of 2 > I tried also with @article.title = '''' >Shouldn''t that be?: assert_equal 2, @article.errors.count
Where is "@article" getting created? Also, what if you put your validation statements in the model on two seperate lines? On 3/25/06, Christophe Gimenez <kandjidev@yahoo.fr> wrote:> Hi, I wonder why this unit test fails. > > The model : > class Article < ActiveRecord::Base > set_table_name "publish_articles" > belongs_to :category > > validates_presence_of :title, :excerpt > #snip > end > > The test : > def test_validate > @article.title = nil > @article.excerpt = nil > assert !@article.save > assert_equal 2, !@article.errors.count > end > > !@article.errors.count returns ''false'' instead of 2 > I tried also with @article.title = '''' > > Any idea ? > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >