Plugins - TestInjector

StarAdd to favorites

Tests performed

The automatically injected tests are currently limited to tests against ActiveRecord models. However, there is nothing stopping you from adding tests for other portions of the framework.

ActiveRecord tests

Every association defined in the ActiveRecord model. A common model might look like:

        class User < ActiveRecord::Base
                has_and_belongs_to_many :groups
                belongs_to :company
                has_many :purchases, :class_name => "Order", :dependent => :nullify
                has_many :subscriptions, :dependent => :destroy
                has_many :newspapers, :through => subscriptions
        end

        By calling inject_activerecord_tests some here in the class definition, several test will be injected into
        the unit test at runtime.

        class UserTest < Test::Unit::TestCase
                fixtures :groups, :companies, :orders, :subscriptions, :newspapers
                inject_activerecord_tests
        end

        Based on the example User class, the following tests will be run (notice that we didn't have to define any test
        methods in the test class):

        def test_has_and_belongs_to_many_groups
                # asserts that groups is an Array of Groups
        end

        def test_belongs_to_company
                # asserts that company return an instance of Company
        end

        def test_has_many_purchases
                # asserts that purchases is an Array of Purchases
                # asserts that associated purchases's user_id column is nullified when the user is deleted
        end

        def test_has_many_subscriptions
                # asserts that subscriptions is an array of Subscriptions
                # asserts that all subscriptions are destroyed when a User is deleted
        end

        def test_has_many_newspapers_through_subscriptions
                # asserts that newspapers is an array of Newspapers
        end

        def test_fixture_defined_for_companies
                # tests to see if a fixture called 'companies' is defined in the unit test
        end

        def test_fixture_defined_for_purchases
          # tests to see if a fixture called 'orders' is defined in the unit test
        end

        def test_fixture_defined_for_subscriptions
          # tests to see if a fixture called 'subscriptions' is defined in the unit test
        end

        def test_fixture_defined_for_newspapers
                # tests to see if a fixture called 'newspapers' is defined in the unit test
        end

        # if the users table has a 'lock_version' column, one test will be defined
        def test_optimistic_locking
                # forces a StaleObjectError in order to test that optimisic locking is functioning correctly
        end

        # if the users table is using the acts_as_versioned plugin by technoweenie, one test will be defined
        def test_acts_as_versioned
                # tests that the versioned table is set up correctly by exercising the versioning system
        end

Keith Morrison

http://wiki.rubyonrails.org/rails/pages/TestInjector

http://www.infused.org/svn/plugins/test_injector

Rails' (MIT)

  • Currently 1.0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Testing

Tags

Comments

Add a comment
rabble 7 Dec 2006

What exactly is the point of this? I mean AR relationships are already tested in ActiveRecord.

Search Plugins

Query syntax

Plugins by Category

Sponsors

Rails Kits: Get Code. Get Moving.

Have a comment?