multiple_table_inheritance 0.1.9 → 0.1.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.md +9 -1
- data/README.md +2 -2
- data/lib/multiple_table_inheritance/child/sanitizer.rb +10 -2
- data/lib/multiple_table_inheritance/version.rb +1 -1
- data/spec/active_record/child_spec.rb +24 -0
- data/spec/support/models.rb +31 -0
- data/spec/support/tables.rb +26 -0
- metadata +13 -13
data/CHANGELOG.md
CHANGED
@@ -1,9 +1,15 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.11
|
2
2
|
|
3
3
|
* Child model records can now inherit parent model methods via the :methods
|
4
4
|
option when calling :inherits_from.
|
5
5
|
* Added several unit tests.
|
6
6
|
|
7
|
+
0.1.10
|
8
|
+
|
9
|
+
* Fix issue with sanitizer not allowing relationships to be set when mass
|
10
|
+
assignment security is not specified.
|
11
|
+
* Added unit tests specific to the above issue.
|
12
|
+
|
7
13
|
0.1.9
|
8
14
|
|
9
15
|
* Remove broken code accidentally included during testing.
|
@@ -13,6 +19,8 @@
|
|
13
19
|
* Fix bug where rake commands cannot be run if `inherits_from` or
|
14
20
|
`acts_as_superclass` have been called within an ActiveRecord model and the
|
15
21
|
model's tables do not already exist.
|
22
|
+
* Update order of loading test to ensure models can be loaded before tables
|
23
|
+
exist.
|
16
24
|
|
17
25
|
0.1.7
|
18
26
|
|
data/README.md
CHANGED
@@ -25,7 +25,7 @@ From the command line:
|
|
25
25
|
|
26
26
|
From your Gemfile:
|
27
27
|
|
28
|
-
gem 'multiple_table_inheritance', '~> 0.1.
|
28
|
+
gem 'multiple_table_inheritance', '~> 0.1.10'
|
29
29
|
|
30
30
|
Usage
|
31
31
|
=====
|
@@ -236,7 +236,7 @@ When inheriting from another parent model, methods can optionally be called on
|
|
236
236
|
the parent model automatically as well. To do so, specify the `:methods`
|
237
237
|
option when calling `inherits_from`.
|
238
238
|
|
239
|
-
NOTE: This is not fully implemented yet as of version 0.1.
|
239
|
+
NOTE: This is not fully implemented yet as of version 0.1.10. Please wait until
|
240
240
|
a future release to prior to using this feature.
|
241
241
|
|
242
242
|
class Employee < ActiveRecord::Base
|
@@ -73,11 +73,19 @@ module MultipleTableInheritance
|
|
73
73
|
end
|
74
74
|
|
75
75
|
def child_attribute_names
|
76
|
-
@child_attribute_names ||=
|
76
|
+
@child_attribute_names ||= begin
|
77
|
+
columns = @target.attribute_names
|
78
|
+
associations = @target.reflections.map { |key, value| key.to_s }
|
79
|
+
columns + associations
|
80
|
+
end
|
77
81
|
end
|
78
82
|
|
79
83
|
def parent_attribute_names
|
80
|
-
@parent_attribute_names ||=
|
84
|
+
@parent_attribute_names ||= begin
|
85
|
+
columns = @target.parent_association_class.attribute_names
|
86
|
+
associations = @target.parent_association_class.reflections.map { |key, value| key.to_s }
|
87
|
+
columns + associations
|
88
|
+
end
|
81
89
|
end
|
82
90
|
end
|
83
91
|
end
|
@@ -147,6 +147,30 @@ describe MultipleTableInheritance::Child do
|
|
147
147
|
@pants.should_not be_new_record
|
148
148
|
end
|
149
149
|
end
|
150
|
+
|
151
|
+
context 'with relationships' do
|
152
|
+
before(:each) do
|
153
|
+
@user = User.create!(:username => 'bob')
|
154
|
+
@image = Image.create(:url => 'https://www.google.com/images/srpr/logo3w.png')
|
155
|
+
@advertisement = ImageAdvertisement.create(:user => @user, :image => @image)
|
156
|
+
end
|
157
|
+
|
158
|
+
it 'should not have errors' do
|
159
|
+
@advertisement.errors.messages.should be_empty
|
160
|
+
end
|
161
|
+
|
162
|
+
it 'should have been saved' do
|
163
|
+
@advertisement.should_not be_new_record
|
164
|
+
end
|
165
|
+
|
166
|
+
it 'should have correct user_id' do
|
167
|
+
@advertisement.user_id.should == @user.id
|
168
|
+
end
|
169
|
+
|
170
|
+
it 'should have correct image_id' do
|
171
|
+
@advertisement.image_id.should == @image.id
|
172
|
+
end
|
173
|
+
end
|
150
174
|
end
|
151
175
|
end
|
152
176
|
|
data/spec/support/models.rb
CHANGED
@@ -143,3 +143,34 @@ module Store
|
|
143
143
|
validates :color, :presence => true
|
144
144
|
end
|
145
145
|
end
|
146
|
+
|
147
|
+
#########################################################
|
148
|
+
# Model that includes relationships on both child and
|
149
|
+
# parent with no mass assignment security defined.
|
150
|
+
#########################################################
|
151
|
+
|
152
|
+
class User < ActiveRecord::Base
|
153
|
+
validates :username, :presence => true, :uniqueness => true
|
154
|
+
end
|
155
|
+
|
156
|
+
class Image < ActiveRecord::Base
|
157
|
+
validates :url, :presence => true
|
158
|
+
end
|
159
|
+
|
160
|
+
class Advertisement < ActiveRecord::Base
|
161
|
+
acts_as_superclass
|
162
|
+
belongs_to :user
|
163
|
+
validates :user, :presence => true
|
164
|
+
end
|
165
|
+
|
166
|
+
class ImageAdvertisement < ActiveRecord::Base
|
167
|
+
inherits_from :advertisement
|
168
|
+
belongs_to :image
|
169
|
+
validates :image, :presence => true
|
170
|
+
end
|
171
|
+
|
172
|
+
class TextAdvertisement < ActiveRecord::Base
|
173
|
+
inherits_from :advertisement
|
174
|
+
validates :title, :presence => true
|
175
|
+
validates :body, :presence => true
|
176
|
+
end
|
data/spec/support/tables.rb
CHANGED
@@ -97,3 +97,29 @@ conn.create_table :store_tables, :inherits => :furniture do |t|
|
|
97
97
|
t.integer :chairs, :null => false
|
98
98
|
t.string :color, :null => false
|
99
99
|
end
|
100
|
+
|
101
|
+
#########################################################
|
102
|
+
# Store entities
|
103
|
+
#########################################################
|
104
|
+
|
105
|
+
conn.create_table :users do |t|
|
106
|
+
t.string :username, :null => false
|
107
|
+
end
|
108
|
+
|
109
|
+
conn.create_table :images do |t|
|
110
|
+
t.string :url, :null => false
|
111
|
+
end
|
112
|
+
|
113
|
+
conn.create_table :advertisements do |t|
|
114
|
+
t.string :subtype, :null => false
|
115
|
+
t.integer :user_id, :null => false
|
116
|
+
end
|
117
|
+
|
118
|
+
conn.create_table :image_advertisements, :inherits => :advertisement do |t|
|
119
|
+
t.integer :image_id, :null => false
|
120
|
+
end
|
121
|
+
|
122
|
+
conn.create_table :text_advertisements, :inherits => :advertisement do |t|
|
123
|
+
t.string :title, :null => false
|
124
|
+
t.string :body, :null => false
|
125
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: multiple_table_inheritance
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.10
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2012-03-24 00:00:00.000000000Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|
16
|
-
requirement: &
|
16
|
+
requirement: &2156165380 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 3.0.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2156165380
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: activesupport
|
27
|
-
requirement: &
|
27
|
+
requirement: &2156164800 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 3.0.0
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *2156164800
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rspec-rails
|
38
|
-
requirement: &
|
38
|
+
requirement: &2156164220 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: 2.8.0
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *2156164220
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rspec_tag_matchers
|
49
|
-
requirement: &
|
49
|
+
requirement: &2156163640 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: 1.0.0
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *2156163640
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: sqlite3-ruby
|
60
|
-
requirement: &
|
60
|
+
requirement: &2156163060 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: 1.3.3
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *2156163060
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: database_cleaner
|
71
|
-
requirement: &
|
71
|
+
requirement: &2156141780 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ! '>='
|
@@ -76,7 +76,7 @@ dependencies:
|
|
76
76
|
version: 0.7.1
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *2156141780
|
80
80
|
description: ActiveRecord plugin designed to allow simple multiple table inheritance.
|
81
81
|
email:
|
82
82
|
- matt@matthuggins.com
|