Advertisement
Guest User

Untitled

a guest
Nov 19th, 2011
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.61 KB | None | 0 0
  1. # Entry model
  2.  
  3. class Entry < ActiveRecord::Base
  4.   validates :title, :description, presence: true
  5.   validates :title, uniqueness: true
  6.   validates :image_url, allow_blank: true, format: {
  7.     with:    %r{\.(gif|jpg|png)$}i,
  8.     message: 'must be a URL for GIF, JPG or PNG image.'
  9.   }
  10.  
  11. end
  12.  
  13. # Entry test
  14.  
  15. require 'test_helper'
  16.  
  17. class EntryTest < ActiveSupport::TestCase
  18.   test 'entry attributes must not be empty' do
  19.     entry = Entry.new
  20.     assert entry.invalid?
  21.     assert entry.errors[:title].any?
  22.     assert entry.errors[:description].any?
  23.     assert entry.errors[:image_url].any?
  24.   end
  25. end
  26.  
  27.  
  28.  
  29.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement