Sha256: 582b93c75db3a77a5af7e8944c338d524f96d91c9cd6c8042c06d8255a70a4e3

Contents?: true

Size: 1.34 KB

Versions: 10

Compression:

Stored size: 1.34 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)
  }

  it "has access to objects in the context" do
    assert context.access_other_object
  end

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

class UnsurroundedObject
  attr_accessor :name
end

describe "Surrounded", "added to an existing object" do
  it "allows the object to store its context" do
    thing = UnsurroundedObject.new
    thing.name = 'Jim'

    assert_raises(NoMethodError){
      thing.__send__(:store_context)
    }
    thing.extend(Surrounded)

    other = User.new('Guille')

    context = TestContext.new(thing, other)
    assert context.access_other_object
  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
    object.extend(SpecialSurrounding)
    assert object.respond_to?(:context, true)
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
surrounded-0.9.11 test/surrounded_test.rb
surrounded-0.9.10 test/surrounded_test.rb
surrounded-0.9.9 test/surrounded_test.rb
surrounded-0.9.8 test/surrounded_test.rb
surrounded-0.9.7 test/surrounded_test.rb
surrounded-0.9.6 test/surrounded_test.rb
surrounded-0.9.5 test/surrounded_test.rb
surrounded-0.9.4 test/surrounded_test.rb
surrounded-0.9.3 test/surrounded_test.rb
surrounded-0.9.2 test/surrounded_test.rb