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 CHANGED
@@ -4,6 +4,7 @@ source "http://rubygems.org"
4
4
  gemspec
5
5
 
6
6
  gem 'rake'
7
+ gem 'activerecord'
7
8
 
8
9
  group :test do
9
10
  gem 'rspec', '2.8.0'
@@ -31,7 +31,7 @@ in a normalized RDBMS.
31
31
  end
32
32
 
33
33
  class Profile < ActiveRecord::Base
34
- extend InheritsFrom::ClassMethods
34
+ include InheritsFrom
35
35
  inherits_from :user # this would be belongs_to if not using inherits_from
36
36
  end
37
37
 
@@ -1,6 +1,10 @@
1
1
  require "inherits_from/version"
2
2
 
3
3
  module InheritsFrom
4
+ def self.included(base)
5
+ base.extend ClassMethods
6
+ end
7
+
4
8
  module ClassMethods
5
9
  def inherits_from(inheriter, args={})
6
10
  belongs_to inheriter, args
@@ -1,3 +1,3 @@
1
1
  module InheritsFrom
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -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
- extend InheritsFrom::ClassMethods
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
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: inherits_from
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.1
5
+ version: 0.0.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - Scott Johnson