<commit_before># chai-bookshelf

Assertions for bookshelf-based models

[![Build Status](https://travis-ci.org/elliotf/chai-bookshelf.png)](https://travis-ci.org/elliotf/chai-bookshelf)<commit_msg>Light documentation<commit_after># chai-bookshelf

Make assertions on your [bookshelf.js](http://bookshelfjs.org) models.

[![Build Status](https://travis-ci.org/elliotf/chai-bookshelf.png)](https://travis-ci.org/elliotf/chai-bookshelf)

## Install

`npm install chai-bookshelf`

## Using

    var chai = require('chai');
    chai.use(require('chai-bookshelf'));

## Assertions

Right now, only basic assertions on relations are supported.

### Relations

Remove boiler plate from your code by making straightforward assertions

Supported Relationships include:

* hasOne `expect(ClassA).to.haveOne(ClassB)`
* hasMany `expect(ClassA).to.haveMany(ClassB)`
* belongsTo `expect(ClassA).to.belongTo(ClassB)`
* belongsToMany `expect(ClassA).to.belongToMany(ClassB)`

Note that "through" is not supported yet.

#### Basic Example

A basic example showing a test of a relationship

    describe('User model', function() {
      var User
        , Thing
      ;

      beforeEach(function() {
        Thing = db.Model.extend({
          tableName: 'things'
        });

        User = db.Model.extend({
          things: function() {
            return this.hasMany(Thing);
          }
        });
      });

      describe('Relationships', function() {
        it('has many things', function() {
          expect(User).to.haveMany(Thing);
        })
      });
    });

#### Specifying the attribute name example

By default, the assertion will use the singular form of the tablename.  If the attribute is named something other than the target model's class (for example, to be plural) you will need to specify the name of the attribute that represents the relationship.

    describe('User model', function() {
      var User
        , Thing
      ;

      beforeEach(function() {
        User = db.Model.extend({});

        Thing = db.Model.extend({
          owner: function() {
            this.belongsTo(User);
          }
        });
      });

      describe('Relationships', function() {
        it('has many things', function() {
          expect(Thing).to.belongTo(User, 'owner');
        })
      });
    });
{'fraction_non_alphanumeric': 0.13122563880467736, 'fraction_numerical': 0.0, 'mean_word_length': 2.8372093023255816, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2415678', 'n_tokens_mistral': 708, 'n_tokens_neox': 674, 'n_words': 171}