Skip to content

Instantly share code, notes, and snippets.

@Roman2K
Created November 19, 2008 07:53
Show Gist options
  • Save Roman2K/26449 to your computer and use it in GitHub Desktop.
Save Roman2K/26449 to your computer and use it in GitHub Desktop.
class Post < ActiveRecord::Base
validates_length_of :title, :minimum => 4
def custom_method
title.scan(/./).join(' ').upcase
end
end
require 'test_helper'
class PostTest < ActiveSupport::TestCase
# setup do
# if Object.const_defined?(:Fixtures) && Fixtures.respond_to?(:reset_cache)
# Fixtures.reset_cache
# end
# end
should_ensure_length_at_least :title, 4
def test_title
p = Post.create :title => "test"
assert_equal "test", p.reload.title
# Method that is not an attribute
assert_equal "T E S T", p.custom_method
# Use fixtures
assert_equal Post, posts(:one).class
assert_equal "title from fixture", posts(:one).title
end
context "in shoulda context" do
setup do
@post = posts(:one)
end
should "respond to title" do
assert_equal "title from fixture", @post.title
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment