<commit_before>var expect    = require('chai').expect;
var _         = require('lodash');
var UserBase  = require('../mocks/user');
var ModelBase = require('../mocks/model');

describe('Integration: Configuration API', function () {

  var Model, User, fn;
  beforeEach(function () {
    Model = ModelBase.extend();
    User = UserBase.extend();
    fn = function () {};
  });

  var rules;
  beforeEach(function () {
    rules = function () {
      return Model.authorization.rules;
    };

    rules.ensureOne = function () {
      expect(rules()).to.have.length(1);
    };

    Object.defineProperty(rules, 'first', {
      enumerable: true,
      get: function () {
        return rules()[0];
      }
    });
  });

  afterEach(function () {
    rules.ensureOne();
  });

  describe('Top Level', function () {

    it('can authorize everything', function () {
      Model.authorize.always();
      expect(rules.first).to.have.property('test', true);
    });

    it('can prevent everything', function () {
      Model.authorize.never();
      expect(rules.first).to.have.property('test', false);
    });

    it('can validate everything with a function', function () {
      Model.authorize.when(fn);
      expect(rules.first).to.have.property('test', fn);
    });

  });

  describe('User', function () {

    afterEach(function () {
      expect(rules.first).to.have.property('user', User);
    });

    it('can allow a user to do anything', function () {
      Model.authorize.a(User).always();
      expect(rules.first).to.have.property('test', true);
    });

    it('can prevent a user from doing anything', function () {
      Model.authorize.a(User).never();
      expect(rules.first).to.have.property('test', false);
    });

    it('can validate user actions with a function', function () {
      Model.authorize.a(User).when(fn);
      expect(rules.first).to.have.property('test', fn);
    });

  });

  describe('Method', function () {

    afterEach(function () {
      expect(rules.first).to.have.property('method', 'write');
    });

    it('can validate all uses of any method', function () {
      Model.authorize.anyone.to('write').always();
      expect(rules.first).to.have.property('test', true);
    });

    it('can prevent all uses of a method', function () {
      Model.authorize.anyone.to('write').never();
      expect(rules.first).to.have.property('test', false);
    });

    it('can validate uses of a method with a function', function () {
      Model.authorize.anyone.to('write').when(fn);
      expect(rules.first).to.have.property('test', fn);
    });

    it('can use the chained syntax for registered methods', function () {
      Model.authorize.anyone.to.write.when(fn);
      expect(rules.first).to.have.property('test', fn);
    });

  });

});<commit_msg>Slim down repetitive tests and more thoroughly test getter syntaxes<commit_after>var expect    = require('chai').expect;
var _         = require('lodash');
var UserBase  = require('../mocks/user');
var ModelBase = require('../mocks/model');

describe('Integration: Configuration API', function () {

  var Model, User, fn;
  beforeEach(function () {
    Model = ModelBase.extend();
    User = UserBase.extend();
    fn = function () {};
  });

  var rules;
  beforeEach(function () {
    rules = function () {
      return Model.authorization.rules;
    };

    rules.ensureOne = function () {
      expect(rules()).to.have.length(1);
    };

    Object.defineProperty(rules, 'first', {
      enumerable: true,
      get: function () {
        return rules()[0];
      }
    });
  });

  afterEach(function () {
    rules.ensureOne();
  });

  describe('Top Level', function () {

    it('can authorize everything', function () {
      Model.authorize.always();
      expect(rules.first).to.have.property('test', true);
    });

    it('can prevent everything', function () {
      Model.authorize.never();
      expect(rules.first).to.have.property('test', false);
    });

    it('can validate everything with a function', function () {
      Model.authorize.when(fn);
      expect(rules.first).to.have.property('test', fn);
    });

  });

  describe('User', function () {

    afterEach(function () {
      expect(rules.first).to.have.property('user', User);
    });

    it('can allow a user to do anything', function () {
      Model.authorize.a(User).always();
      expect(rules.first).to.have.property('test', true);
    });

    it('has an alternate "an" syntax for grammar', function () {
      Model.authorize.an(User).always();
      expect(rules.first).to.have.property('test', true);
    });

  });

  describe('Method', function () {

    afterEach(function () {
      expect(rules.first).to.have.property('test', fn);
    });

    it('can validate all uses of any method', function () {
      Model.authorize.anyone.to('say').when(fn);
      expect(rules.first).to.have.property('method', 'say');
    });

    it('can use the chained syntax for write', function () {
      Model.authorize.anyone.to.write.when(fn);
      expect(rules.first).to.have.property('method', 'write');
    });

    it('can use the chained syntax for read', function () {
      Model.authorize.anyone.to.read.when(fn);
      expect(rules.first).to.have.property('method', 'read');
    });

  });

  describe('User + Method', function () {

    afterEach(function () {
      expect(rules.first).to.have.property('user', User);
      expect(rules.first).to.have.property('method', 'write');
    });

    it('can validate all method calls by a specific user', function () {
      Model.authorize.a(User).to.write.when(fn);
      expect(rules.first).to.have.property('test', fn);
    });

  });

});
{'fraction_non_alphanumeric': 0.18213783403656822, 'fraction_numerical': 0.0007032348804500703, 'mean_word_length': 2.9424809424809424, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, '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': '7200813', 'n_tokens_mistral': 1743, 'n_tokens_neox': 1686, 'n_words': 331}