Sha256: 05e02c10548efce18093b0503007a123da2fa43aad080a4780257dcaacf2e1e7

Contents?: true

Size: 1.4 KB

Versions: 7

Compression:

Stored size: 1.4 KB

Contents

require 'spec_helper'

describe AuthorizationHelper do
  describe "#guard" do
    let(:current_user) { create :user, is_superuser: false }
    let(:permission) { create :permission, resource: "Post" }

    before :each do
      helper.stub(:current_user) { current_user }
    end

    it "returns the block if user has permission to manage the resource" do
      current_user.permissions.push permission
      helper.guard(Post) { "hello" }.should eq "hello"
    end

    it "returns nil if permission not granted and no message specified" do
      helper.guard(Post) { "hello" }.should eq ""
    end

    it "returns message if permission not granted and message specified" do
      helper.guard(Post, "Not Allowed") { "hello" }.should eq "Not Allowed"
    end
  end

  #-----------------

  describe "#guarded_link_to" do
    let(:current_user) { create :user, is_superuser: false }
    let(:permission) { create :permission, resource: "Post" }

    before :each do
      helper.stub(:current_user) { current_user }
    end

    it "sends to link_to if the user has permission" do
      current_user.permissions.push permission
      link = helper.guarded_link_to Post, "Title", "/some/path"
      link.should eq helper.link_to("Title", "/some/path")
    end

    it "shows only the title if permission is not granted" do
      link = helper.guarded_link_to Post, "Title", "/some/path"
      link.should eq "Title"
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
outpost-cms-0.1.4 spec/helpers/authorization_helper_spec.rb
outpost-cms-0.1.3 spec/helpers/authorization_helper_spec.rb
outpost-cms-0.1.2 spec/helpers/authorization_helper_spec.rb
outpost-cms-0.1.1 spec/helpers/authorization_helper_spec.rb
outpost-cms-0.1.0 spec/helpers/authorization_helper_spec.rb
outpost-cms-0.0.5 spec/helpers/authorization_helper_spec.rb
outpost-cms-0.0.4 spec/helpers/authorization_helper_spec.rb