Created
November 19, 2008 07:53
-
-
Save Roman2K/26449 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Post < ActiveRecord::Base | |
validates_length_of :title, :minimum => 4 | |
def custom_method | |
title.scan(/./).join(' ').upcase | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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