Sha256: 153cef87e29854a5dbdae5d0c8f41fd3fc55eb4bb3c584658691e7a99631edb8

Contents?: true

Size: 1.79 KB

Versions: 4

Compression:

Stored size: 1.79 KB

Contents

require 'spec_helper'

describe Kindergarten::HeadGoverness do
  before(:each) do
    @governess = Kindergarten::HeadGoverness.new("child")
  end

  it "should include CanCan ability" do
    @governess.should be_kind_of(CanCan::Ability)
  end

  describe :governing do
    it "should guard the child" do
      expect {
        @governess.guard(:free, "Willy")
      }.to raise_error(Kindergarten::AccessDenied)
    end

    it "should keep a closed eye" do
      expect {
        @governess.unguarded do
          @governess.guard(:free, "Willy")
        end
      }.to_not raise_error(Kindergarten::AccessDenied)
    end
  end

  describe :washing do
    it "should scrub attributes" do
      attr     = { :a => 1, :b => 2, :c => 3 }

      scrubbed = @governess.scrub(attr, :a, :c)
      scrubbed.should_not be_has_key(:b)
    end

    it "should return a ScrubbedHash after scrubbing" do
      attr     = { :a => 1, :b => 2, :c => 3 }

      scrubbed = @governess.scrub(attr, :a, :c)
      scrubbed.should be_kind_of(Kindergarten::ScrubbedHash)
    end

    it "should rinse attributes" do
      attr   = { :a => 1, :b => "2a", :c => 3 }
      rinsed = @governess.rinse(attr, :a => /(\d+)/, :b => /(\D+)/)

      rinsed.should_not be_has_key(:c)
      rinsed[:a].should eq "1"
      rinsed[:b].should eq "a"
    end

    it "should pass attributes" do
      attr   = { :a => "1", :b => "2a", :c => "3" }
      rinsed = @governess.rinse(attr, :a => :pass, :c => :pass)

      rinsed.should_not be_has_key(:b)
      rinsed[:a].should eq "1"
      rinsed[:c].should eq "3"
    end
    it "should return a RinsedHash after rinsing" do
      attr   = { :a => "1", :b => "2a", :c => "3" }
      rinsed = @governess.rinse(attr, :a => /(\d+)/, :b => /(\d+)/)

      rinsed.should be_kind_of(Kindergarten::RinsedHash)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
kindergarten-0.2.1 spec/kindergarten/governess_spec.rb
kindergarten-0.2.0 spec/kindergarten/governess_spec.rb
kindergarten-0.1.1 spec/kindergarten/governess_spec.rb
kindergarten-0.1.0 spec/kindergarten/governess_spec.rb