Book Image

Redmine Plugin Extension and Development

By : Alex Bevilacqua
Book Image

Redmine Plugin Extension and Development

By: Alex Bevilacqua

Overview of this book

Table of Contents (16 chapters)
Redmine Plugin Extension and Development
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Writing unit tests


Unit tests within Ruby on Rails applications tend to involve writing tests for models. A good practice is to include tests for all validations, and at least one test per method. Ideally though, tests should be written for anything that could possibly break.

If we were writing the tests first, we would start with something like the following code:

require File.dirname(__FILE__) + '/../test_helper'

class CategoryTest < ActiveSupport::TestCase
  plugin_fixtures :kb_categories

  test "should not save category without title" do
    category = KbCategory.new
    assert !category.save, "Saved the category without a title"
  end
end

If we had yet to configure our model, this test would fail until we added a presence validation to our category model.