Sha256: 2dcca105388bbc8d91ec4c7beb79b1baab9921de0e1a54bcf6f16d1706cbc06d

Contents?: true

Size: 904 Bytes

Versions: 1

Compression:

Stored size: 904 Bytes

Contents

require 'test_helper'

describe "Surrounded", 'without context' do

  let(:jim){ User.new("Jim") }

  it "never has context roles" do
    Thread.current[:context] = []
    assert_nil jim.send(:context).role?('anything')
  end

end

describe "Surrounded" do
  let(:jim){ User.new("Jim") }
  let(:guille){ User.new("Guille") }
  let(:external_user){ User.new("External User") }

  let(:context){
    TestContext.new(jim, guille)
  }

  before do
    Thread.current[:context] = [context]
  end

  it "has access to objects in the context" do
    assert_equal jim.other_user, guille
  end
  it "responds to messages for roles on the context" do
    assert jim.respond_to?(:other_user)

    Thread.current[:context] = []

    refute jim.respond_to?(:other_user)
  end

  it "prevents access to context objects for external objects" do
    assert_raises(NoMethodError){
      external_user.user
    }
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
surrounded-0.1.0 test/surrounded_test.rb