Permalink
Browse files

Merge remote branch 'alexbartlow/master'

  • Loading branch information...
2 parents c857542 + 93955e8 commit e6ee667bf680736a90b2fcf6823a03ea48fbf101 bokmann committed Mar 15, 2010
Showing with 35 additions and 3 deletions.
  1. +1 −1 lib/sentient_user.rb
  2. +10 −0 test/helper.rb
  3. +24 −2 test/test_sentient_user.rb
View
2 lib/sentient_user.rb
@@ -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
View
10 test/helper.rb
@@ -8,3 +8,13 @@
class Test::Unit::TestCase
end
+
+class Person
+ include SentientUser
+end
+
+class User
+ include SentientUser
+end
+
+class AnonymousUser < User ; end
View
26 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.