Sha256: 2a62e15f94efb866127f4ff73d29874d32c8e06f643365ba0f5b73943dce023f
Contents?: true
Size: 1.37 KB
Versions: 2
Compression:
Stored size: 1.37 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(user: jim, other_user: 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(user: thing, other_user: 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
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
surrounded-1.1.0 | test/surrounded_test.rb |
surrounded-1.0.0 | test/surrounded_test.rb |