inherits_from 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -0
- data/README.rdoc +1 -1
- data/lib/inherits_from.rb +4 -0
- data/lib/inherits_from/version.rb +1 -1
- data/spec/inherits_from/inherits_from_spec.rb +34 -1
- metadata +1 -1
data/Gemfile
CHANGED
data/README.rdoc
CHANGED
data/lib/inherits_from.rb
CHANGED
@@ -5,10 +5,14 @@ class User
|
|
5
5
|
def initialize
|
6
6
|
self.user_field = "User Field"
|
7
7
|
end
|
8
|
+
|
9
|
+
def user_instance_method
|
10
|
+
true
|
11
|
+
end
|
8
12
|
end
|
9
13
|
|
10
14
|
class Profile
|
11
|
-
|
15
|
+
include InheritsFrom
|
12
16
|
# rewrite inherits_from to not use belongs_to
|
13
17
|
def self.inherits_from(inheriter, args={})
|
14
18
|
inherited_methods(inheriter)
|
@@ -22,6 +26,10 @@ class Profile
|
|
22
26
|
self.user = User.new
|
23
27
|
self.profile_field = "Profile Field"
|
24
28
|
end
|
29
|
+
|
30
|
+
def profile_instance_method
|
31
|
+
true
|
32
|
+
end
|
25
33
|
end
|
26
34
|
|
27
35
|
|
@@ -52,4 +60,29 @@ describe Profile do
|
|
52
60
|
@p.user.tainted?.should be_true
|
53
61
|
end
|
54
62
|
|
63
|
+
it "should call save on user if it is saved and user is tainted" do
|
64
|
+
@p.user.taint
|
65
|
+
@p.user.should_receive(:save).and_return(true)
|
66
|
+
@p.save
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should call save! on user if it is saved! and user is tainted" do
|
70
|
+
@p.user.taint
|
71
|
+
@p.user.should_receive(:save!).and_return(true)
|
72
|
+
@p.save!
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should respond to methods it has" do
|
76
|
+
@p.respond_to?(:profile_field).should be_true
|
77
|
+
@p.respond_to?(:profile_instance_method).should be_true
|
78
|
+
end
|
79
|
+
|
80
|
+
it "should respond to methods user has" do
|
81
|
+
@p.respond_to?(:user_field).should be_true
|
82
|
+
@p.respond_to?(:user_instance_method).should be_true
|
83
|
+
end
|
84
|
+
|
85
|
+
it "should NOT respond to methods in neither user nor profile has" do
|
86
|
+
@p.respond_to?(:not_me).should be_false
|
87
|
+
end
|
55
88
|
end
|