diff --git nodeapi_example/nodeapi_example.install nodeapi_example/nodeapi_example.install
index 83539ab..41fa79b 100644
--- nodeapi_example/nodeapi_example.install
+++ nodeapi_example/nodeapi_example.install
@@ -25,13 +25,36 @@ function nodeapi_example_uninstall() {
  */
 function nodeapi_example_schema() {
   $schema['nodeapi_example'] = array(
-    'fields' => array(
-      'nid'    => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
-      'rating' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
+  'fields' => array(
+      'id' => array(
+      'type' => 'serial',
+      'not null' => TRUE,
+      'description' => t('Primary Key: Unique ID.'),
     ),
-    'primary key' => array('nid'),
+    'nid' => array(
+      'type' => 'int',
+      'unsigned' => TRUE,
+      'not null' => TRUE,
+      'default' => 0,
+      'description' => t('node id for the rating'),
+    ),
+    'vid' => array(
+      'type' => 'int',
+      'unsigned' => TRUE,
+      'not null' => TRUE,
+      'default' => 0,
+      'description' => t('version id for rating'),
+    ),
+    'rating' => array(
+      'type' => 'int',
+      'unsigned' => TRUE,
+      'not null' => TRUE,
+      'default' => 0,
+      'description' => t('rating for this node'),
+    ),
+  ),
+  'primary key' => array('id'),
   );
-
   return $schema;
 }
 
diff --git nodeapi_example/nodeapi_example.module nodeapi_example/nodeapi_example.module
index ff98342..0b477f6 100755
--- nodeapi_example/nodeapi_example.module
+++ nodeapi_example/nodeapi_example.module
@@ -78,7 +78,8 @@ function nodeapi_example_nodeapi(&$node, $op, $teaser, $page) {
     // Now we need to take care of loading one of the extended nodes from the
     // database. An array containing our extra field needs to be returned.
     case 'load':
-      $rating = db_result(db_query('SELECT rating FROM {nodeapi_example} WHERE nid = %d', $node->nid));
+      // we match against vid in order to keep up with the current revision
+      $rating = db_result(db_query('SELECT rating FROM {nodeapi_example} WHERE vid = %d', $node->vid));
       return array('nodeapi_example_rating' => $rating);
       break;
 
@@ -86,7 +87,7 @@ function nodeapi_example_nodeapi(&$node, $op, $teaser, $page) {
     // database. It gives us a chance to create our own record in the database.
     case 'insert':
       if (variable_get('nodeapi_example_'. $node->type, 0)) {
-        db_query('INSERT INTO {nodeapi_example} (nid, rating) VALUES (%d, %d)', $node->nid, $node->nodeapi_example_rating);
+        db_query('INSERT INTO {nodeapi_example} (nid, vid, rating) VALUES (%d, %d, %d)', $node->nid, $node->vid, $node->nodeapi_example_rating);
       }
       break;
 
@@ -96,17 +97,26 @@ function nodeapi_example_nodeapi(&$node, $op, $teaser, $page) {
     // saved so there would be nothing to update.
     case 'update':
       if (variable_get('nodeapi_example_'. $node->type, 0)) {
-        db_query('DELETE FROM {nodeapi_example} WHERE nid = %d', $node->nid);
-        db_query('INSERT INTO {nodeapi_example} (nid, rating) VALUES (%d, %d)', $node->nid, $node->nodeapi_example_rating);
+        db_query('DELETE FROM {nodeapi_example} WHERE vid = %d', $node->vid);
+        db_query('INSERT INTO {nodeapi_example} (nid, vid, rating) VALUES (%d, %d, %d)', $node->nid, $node->vid, $node->nodeapi_example_rating);
       }
       break;
 
-    // Delete is called whn the node is being deleted, it gives us a chance
+    // Delete is called when the node is being deleted, it gives us a chance
     // to delete the rating too.
+    // This will delete all revisions as well.
     case 'delete':
       db_query('DELETE FROM {nodeapi_example} WHERE nid = %d', $node->nid);
       break;
 
+    // When a node revision is deleted, we need to remove the corresponding
+    // record from our table. The only way to handle revision deletion is by
+    // implementing hook_nodeapi().
+    case 'delete revision':
+      // Notice that we're matching a single revision based on the node's vid.
+      db_query('DELETE FROM {nodeapi_example} WHERE vid = %d', $node->vid);
+      break;
+
     // Finally, we need to take care of displaying our rating when the node is
     // viewed. This operation is called after the node has already been prepared
     // into HTML and filtered as necessary, so we know we are dealing with an
diff --git nodeapi_example/nodeapi_example.test nodeapi_example/nodeapi_example.test
new file mode 100644
index 0000000..44adc61
--- /dev/null
+++ nodeapi_example/nodeapi_example.test
@@ -0,0 +1,203 @@
+<?php
+// $Id: nodeapi_example.test,v 1.2 2010/12/10 06:49:28 rfay Exp $
+
+/**
+ * @file
+ * Test case for Testing the node API example module.
+ *
+ * This file contains the test cases to check if module is performing as
+ * expected.
+ *
+ */
+
+class NodeApiExampleTestCase extends DrupalWebTestCase {
+  /**
+   * User object to perform site browsing
+   * @var object
+   */
+  protected $web_user;
+
+  /**
+   * Content type to attach the rating system
+   * @var string
+   */
+  protected $type;
+
+  public static function getInfo() {
+    return array(
+      'name' => 'Node API example functionality',
+      'description' => 'Demonstrate Node API hook that allow altering a node.',
+      'group' => 'Examples',
+    );
+  }
+
+  /**
+   * Enable modules and create user with specific permissions.
+   */
+  function setUp() {
+    parent::setUp('nodeapi_example');
+
+    // Create admin user. This module has no access control, so we can use a
+    // trusted user. Revision access and revert permissions are required too.
+    $this->web_user = $this->drupalCreateUser(array(
+      'administer nodes', // Required to set revision checkbox
+      'administer content types',
+    //  'bypass node access',
+      'view revisions',
+      'revert revisions'
+    ));
+    // Login the admin user.
+    $this->drupalLogin($this->web_user);
+  }
+
+  /**
+   * Login user, create an example node, and use the rating system
+   */
+  function testNodeExampleBasic() {
+
+    // Login the user.
+    $this->drupalLogin($this->web_user);
+
+    // Create custom content type
+    $content_type = $this->drupalCreateContentType();
+    $type = $content_type->type;
+
+    // Disable the rating for this content type: 0 for Disabled, 1 for Enabled.
+    $content_settings = array(
+      'nodeapi_example' => 0,
+    );
+    $this->drupalPost('admin/content/node-type/' . $type, $content_settings, t('Save content type'));
+    $this->assertResponse(200);
+    $this->assertRaw(' has been updated.', t('Settings modified successfully for content type.'));
+
+    // Create an example node
+    $edit = array(
+      "title" => $this->randomName(),
+    );
+    $this->drupalPost('node/add/' . $type, $edit, t('Save'));
+    $this->assertResponse(200);
+
+    // Check that the rating is not shown, as we have not yet enabled it
+    $this->assertNoRaw('Rating: <em>', t('Extended rating information is not shown.'));
+
+    // Save current current url (we are viewing the new node)
+    $node_url = $this->getUrl();
+
+    // Enable the rating for this content type: 0 for Disabled, 1 for Enabled.
+    $content_settings = array(
+      'nodeapi_example' => TRUE,
+    );
+    $this->drupalPost('admin/content/node-type/' . $type, $content_settings, t('Save content type'));
+    $this->assertResponse(200);
+    $this->assertRaw(' has been updated.', t('Settings modified successfully for content type.'));
+
+    // Check previously create node. It should be not rated
+    $this->drupalGet($node_url);
+    $this->assertResponse(200);
+    $this->assertRaw(t('Rating: %rating', array('%rating' => t('Unrated'))), t('Content is not rated.'));
+
+    // Rate the content, 4 is for "Good"
+    $rate = array(
+      'nodeapi_example_rating' => 4,
+    );
+    $this->drupalPost($node_url . '/edit', $rate, t('Save'));
+    $this->assertResponse(200);
+
+    // Check that content has been rated
+    $this->assertRaw(t('Rating: %rating', array('%rating' => t('Good'))), t('Content is successfully rated.'));
+
+  }
+
+  /**
+   * Login user, create an example node, and test rating functionality with
+   * a node using revisions.
+   */
+  function testNodeExampleRevision() {
+
+    // Login the user.
+    $this->drupalLogin($this->web_user);
+
+    // Create custom content type
+    $content_type = $this->drupalCreateContentType();
+    $type = $content_type->type;
+
+    // Go to edit the settings of this content type
+    $this->drupalGet('admin/content/node-type/' . $type);
+    $this->assertResponse(200);
+
+    // Check if the new Rating options appear in the settings page
+    $this->assertText(t('NodeAPI Example Rating'), t('Rating options found in content type.'));
+    $this->assertFieldByName('nodeapi_example', 1, t('Rating is Disabled by default.'));
+
+    // Disable the rating for this content type: 0 for Disabled, 1 for Enabled.
+    $content_settings = array(
+      'nodeapi_example' => 0,
+    );
+    $this->drupalPost('admin/content/node-type/' . $type, $content_settings, t('Save content type'));
+    $this->assertResponse(200);
+    $this->assertRaw(' has been updated.', t('Settings modified successfully for content type.'));
+
+    // Create an example node
+    $edit = array(
+      "title" => $this->randomName(),
+    );
+    $this->drupalPost('node/add/' . $type, $edit, t('Save'));
+    $this->assertResponse(200);
+
+    // Check that the rating is not shown, as we have not yet enabled it
+    $this->assertNoRaw('Rating: <em>', t('Extended rating information is not shown.'));
+
+    // Save current current url (we are viewing the new node)
+    $node_url = $this->getUrl();
+
+    // Enable the rating for this content type: 0 for Disabled, 1 for Enabled.
+    $content_settings = array(
+      'nodeapi_example' => TRUE,
+    );
+    $this->drupalPost('admin/content/node-type/' . $type, $content_settings, t('Save content type'));
+    $this->assertResponse(200);
+    $this->assertRaw(' has been updated.', t('Settings modified successfully for content type.'));
+
+    // Check previously create node. It should be not rated
+    $this->drupalGet($node_url);
+    $this->assertResponse(200);
+    $this->assertRaw(t('Rating: %rating', array('%rating' => t('Unrated'))), t('Content is not rated.'));
+
+    // Rate the content, 4 is for "Good"
+    $rate = array(
+      'nodeapi_example_rating' => 4,
+    );
+    $this->drupalPost($node_url . '/edit', $rate, t('Save'));
+    $this->assertResponse(200);
+
+    // Check that content has been rated
+    $this->assertRaw(t('Rating: %rating', array('%rating' => t('Good'))), t('Content is successfully rated.'));
+
+    // Rate the content to poor using a new revision, 1 is for "Poor"
+    $rate = array(
+      'nodeapi_example_rating' => 1,
+      'revision'               => 1,
+    );
+    $this->drupalPost($node_url . '/edit', $rate, t('Save'));
+    $this->assertResponse(200);
+
+    // Check that content has been rated
+    $this->assertRaw(t('Rating: %rating', array('%rating' => t('Poor'))), t('Content is successfully rated.'));
+
+    //Now switch back to previous revision of the node.
+    $this->drupalGet($node_url . '/revisions');
+    // There is only a revision, so it must work just clicking the first link..
+    $this->clickLink('revert');
+    $revert_form = $this->getUrl();
+    $this->drupalPost($revert_form, array(), t('Revert'));
+
+    // Go back to the node page.
+    $this->drupalGet($node_url);
+    $this->assertResponse(200);
+
+    // Check that content has been rated
+    $this->assertRaw(t('Rating: %rating', array('%rating' => t('Good'))), t('Content rating matches reverted revision.'));
+
+  }
+
+}
