Sha256: 0cc67f295638305a334c7c2fefb4ef97cedbb39b4751fd1fa06f2aa0c9b0fbcb

Contents?: true

Size: 1.33 KB

Versions: 7

Compression:

Stored size: 1.33 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

7 entries across 7 versions & 1 rubygems

Version Path
surrounded-0.9.1 test/surrounded_test.rb
surrounded-0.9.0 test/surrounded_test.rb
surrounded-0.8.4 test/surrounded_test.rb
surrounded-0.8.3 test/surrounded_test.rb
surrounded-0.8.2 test/surrounded_test.rb
surrounded-0.8.1 test/surrounded_test.rb
surrounded-0.8.0 test/surrounded_test.rb