regex - Rails model validation works, but rake test fail -


currently, i'm learning rails. when build model validation format:

class product < activerecord::base validates :title, :description, :image_url, presence: true validates :price, numericality: {greater_than_or_equal_to: 0.01} validates :title, uniqueness: true validates :image_url, allow_blank: true, format: {     with:   %r{\.(gif|jpg|png)$}i,     message: 'must url gif, jpg or png image.',     multiline: true } end 

this validation test whether image_url has extension gif, jpg or png.

when run server , test myself, work fine. while when try build model test, test not pass.

enter require 'test_helper'       class producttest < activesupport::testcase                                                                              def new_product(image_url)     product.new(title: "bool",             description: "daf",             image_url: image_url) end  test "image url"     ok = %w{fred.gif fred.jpg fred.png red.jpg red.jpg http://a.b.c/x/y/z/fesd.gif}     bad = %w{fred.doc fred.gif/more fred.gif.more}     ok.each |name|         assert new_product(name).valid?, "#{name} shouldn't invalid"     end     bad.each |name|         assert new_product(name).invalid?, "#{name} shouldn't valid"     end end  end 

it through me 1 assert failure:

1) failure:
producttest#test_image_url [/home/clark/desktop/agile_rails/depot/test/models/product_test.rb 38]:
fred.gif shouldn't invalid

can me, testing code wrong?

i don't know if found yet problem not in image_url. validating price numericality letting blank in test product invalid because of price field.


Comments