<commit_before>require 'spec_helper'
require 'support/ability_model'
require 'support/user'

describe Authority do

  it "should have a default list of abilities" do
    Authority.abilities.should be_a(Hash)
  end

  it "should not allow modification of the Authority.abilities hash directly" do
    expect { Authority.abilities[:exchange] = 'fungible' }.to raise_error(RuntimeError, "can't modify frozen Hash")
  end

  it "should have a convenience accessor for the ability verbs" do
    Authority.verbs.sort.should eq([:create, :delete, :read, :update])
  end

  it "should have a convenience accessor for the ability adjectives" do
    Authority.adjectives.sort.should eq(%w[creatable deletable readable updatable])
  end

  describe "configuring Authority" do

    it "should have a configuration accessor" do
      Authority.should respond_to(:configuration)
    end

    it "should have a `configure` method" do
      Authority.should respond_to(:configure)
    end

    it "should require the remainder of library internals after configuration" do
      Authority.should_receive(:require_authority_internals!)
      Authority.configure
    end
  end

  describe "enforcement" do

    before :each do
      @user = User.new
    end

    it "should raise a SecurityTransgression if the action is unauthorized" do
      expect { Authority.enforce(:update, AbilityModel, @user) }.to raise_error(Authority::SecurityTransgression)
    end

    it "should not raise a SecurityTransgression if the action is authorized" do
      expect { Authority.enforce(:read, AbilityModel, @user) }.not_to raise_error(Authority::SecurityTransgression)
    end

  end

end
<commit_msg>Fix specs for 1.8.7<commit_after>require 'spec_helper'
require 'support/ability_model'
require 'support/user'

describe Authority do

  it "should have a default list of abilities" do
    Authority.abilities.should be_a(Hash)
  end

  it "should not allow modification of the Authority.abilities hash directly" do
    case RUBY_VERSION
    when "1.8.7"
      expect { Authority.abilities[:exchange] = 'fungible' }.to raise_error(TypeError, "can't modify frozen hash")
    when "1.9.3"
      expect { Authority.abilities[:exchange] = 'fungible' }.to raise_error(RuntimeError, "can't modify frozen Hash")
    end
  end

  it "should have a convenience accessor for the ability verbs" do
    Authority.verbs.map(&:to_s).sort.should eq(['create', 'delete', 'read', 'update'])
  end

  it "should have a convenience accessor for the ability adjectives" do
    Authority.adjectives.sort.should eq(%w[creatable deletable readable updatable])
  end

  describe "configuring Authority" do

    it "should have a configuration accessor" do
      Authority.should respond_to(:configuration)
    end

    it "should have a `configure` method" do
      Authority.should respond_to(:configure)
    end

    it "should require the remainder of library internals after configuration" do
      Authority.should_receive(:require_authority_internals!)
      Authority.configure
    end
  end

  describe "enforcement" do

    before :each do
      @user = User.new
    end

    it "should raise a SecurityTransgression if the action is unauthorized" do
      expect { Authority.enforce(:update, AbilityModel, @user) }.to raise_error(Authority::SecurityTransgression)
    end

    it "should not raise a SecurityTransgression if the action is authorized" do
      expect { Authority.enforce(:read, AbilityModel, @user) }.not_to raise_error(Authority::SecurityTransgression)
    end

  end

end

{'fraction_non_alphanumeric': 0.07983074753173484, 'fraction_numerical': 0.002538787023977433, 'mean_word_length': 3.8910344827586205, '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': '3912313', 'n_tokens_mistral': 1030, 'n_tokens_neox': 986, 'n_words': 345}