Skip to content

Commit

Permalink
Merge remote branch 'alexbartlow/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
bokmann committed Mar 15, 2010
2 parents c857542 + 93955e8 commit e6ee667
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/sentient_user.rb
Expand Up @@ -8,7 +8,7 @@ def self.current

def self.current=(o)
raise(ArgumentError,
"Expected an object of class 'User', got #{o.inspect}") unless (o.is_a?(User) || o.nil?)
"Expected an object of class '#{self}', got #{o.inspect}") unless (o.is_a?(self) || o.nil?)
Thread.current[:user] = o
end

Expand Down
10 changes: 10 additions & 0 deletions test/helper.rb
Expand Up @@ -8,3 +8,13 @@

class Test::Unit::TestCase
end

class Person
include SentientUser
end

class User
include SentientUser
end

class AnonymousUser < User ; end
26 changes: 24 additions & 2 deletions test/test_sentient_user.rb
@@ -1,7 +1,29 @@
require 'helper'

class TestSentientUser < Test::Unit::TestCase
should "probably rename this file and start testing for real" do
flunk "hey buddy, you should probably rename this file and start testing for real"
should "allow making the 'person' class sentient" do
p = Person.new
p.make_current
assert_equal Person.current, p
end

should "allow making the 'user' class sentient" do
u = User.new
u.make_current
assert_equal User.current, u
end

should "not allow making Person.current a user" do
assert_raise ArgumentError do
Person.current = User.new
end
end

should "allow making person.current a person" do
Person.current = Person.new
end

should "allow subclasses of user to be assigned to user.current" do
User.current = AnonymousUser.new
end
end

0 comments on commit e6ee667

Please sign in to comment.