Sha256: acada10405d5807eaafced8b83414b7b3c42dc4629ec7dc345666892e3cd1871

Contents?: true

Size: 1.58 KB

Versions: 13

Compression:

Stored size: 1.58 KB

Contents

require 'test_helper'

describe "Surrounded", 'without context' do

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

  it "never has context roles" do
    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
    jim.store_context(context)
    guille.store_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)

    jim.remove_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

describe "Surrounded", "added to an existing object" do
  it "allows the object to store its context" do
    object = Object.new
    assert_raises(NoMethodError){
      object.store_context(self)
    }
    object.extend(Surrounded)
    assert object.store_context(self)
    assert object.remove_context
  end
end

module SpecialSurrounding
  include Surrounded
end

describe "Surrounded", "added to an object through another module" do
  it "allows the object to store its context" do
    object = Array.new
    assert_raises(NoMethodError){
      object.store_context(self)
    }
    object.extend(SpecialSurrounding)
    assert object.store_context(self)
    assert object.remove_context
    assert object.send(:context)
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
surrounded-0.7.3 test/surrounded_test.rb
surrounded-0.7.2 test/surrounded_test.rb
surrounded-0.7.1 test/surrounded_test.rb
surrounded-0.7.0 test/surrounded_test.rb
surrounded-0.6.0 test/surrounded_test.rb
surrounded-0.5.1 test/surrounded_test.rb
surrounded-0.5.0 test/surrounded_test.rb
surrounded-0.4.1 test/surrounded_test.rb
surrounded-0.4.0 test/surrounded_test.rb
surrounded-0.3.1 test/surrounded_test.rb
surrounded-0.3.0 test/surrounded_test.rb
surrounded-0.2.1 test/surrounded_test.rb
surrounded-0.2.0 test/surrounded_test.rb