rails_inheritable_attributes_manager 0.3.0 → 0.3.1
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/RELEASE_NOTES +3 -0
- data/VERSION +1 -1
- data/lib/models/reflection.rb +27 -0
- data/lib/rails_inheritable_attributes_manager.rb +3 -0
- data/tests/models/accepts_nested_attributes_for_test.rb +0 -5
- data/tests/models/config.rb +7 -1
- data/tests/models/reflections_test.rb +26 -0
- metadata +21 -19
data/RELEASE_NOTES
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.1
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'active_record'
|
2
|
+
|
3
|
+
module ActiveRecord
|
4
|
+
|
5
|
+
class Base
|
6
|
+
class << self
|
7
|
+
def create_reflection_with_inheritance_management(macro, name, options, active_record)
|
8
|
+
reflection = create_reflection_without_inheritance_management(macro, name, options, active_record)
|
9
|
+
alert_subclasses_of_new_reflection(name, reflection)
|
10
|
+
reflection
|
11
|
+
end
|
12
|
+
alias_method_chain :create_reflection, :inheritance_management
|
13
|
+
|
14
|
+
def alert_subclasses_of_new_reflection(name, reflection)
|
15
|
+
subclasses.each do |subclass|
|
16
|
+
subclass.superclass_created_new_reflection(name, reflection)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def superclass_created_new_reflection(name, reflection)
|
21
|
+
return if reflections[name]
|
22
|
+
write_inheritable_hash :reflections, name => reflection
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
@@ -9,11 +9,6 @@ class AcceptsNestedAttributesForTest < Test::Unit::TestCase
|
|
9
9
|
initialize_db
|
10
10
|
create_mammals
|
11
11
|
create_legs
|
12
|
-
|
13
|
-
Mammal.class_eval do
|
14
|
-
has_many :legs
|
15
|
-
accepts_nested_attributes_for :legs, :reject_if => :all_blank
|
16
|
-
end
|
17
12
|
end
|
18
13
|
|
19
14
|
should "not fail if legs association added to re-opened Mammal class" do
|
data/tests/models/config.rb
CHANGED
@@ -16,6 +16,11 @@ module MammalSample
|
|
16
16
|
class Beagle < Dog
|
17
17
|
end
|
18
18
|
|
19
|
+
Mammal.class_eval do
|
20
|
+
has_many :legs
|
21
|
+
accepts_nested_attributes_for :legs, :reject_if => :all_blank
|
22
|
+
end
|
23
|
+
|
19
24
|
def initialize_db
|
20
25
|
SQLite3::Database.new(DATABASE_NAME)
|
21
26
|
ActiveRecord::Base.establish_connection(:adapter => 'sqlite3',
|
@@ -31,8 +36,9 @@ module MammalSample
|
|
31
36
|
end
|
32
37
|
|
33
38
|
def create_legs
|
34
|
-
|
39
|
+
ActiveRecord::Base.connection.drop_table :legs if Leg.table_exists?
|
35
40
|
ActiveRecord::Base.connection.create_table :legs do |t|
|
41
|
+
t.integer :mammal_id
|
36
42
|
t.string :length
|
37
43
|
t.timestamps
|
38
44
|
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'models/config'
|
3
|
+
|
4
|
+
class ReflectionsTest < Test::Unit::TestCase
|
5
|
+
include MammalSample
|
6
|
+
|
7
|
+
context "including associations in #find calls" do
|
8
|
+
setup do
|
9
|
+
initialize_db
|
10
|
+
create_mammals
|
11
|
+
create_legs
|
12
|
+
end
|
13
|
+
|
14
|
+
should "not fail if re-opened association is included in #find call" do
|
15
|
+
assert_nothing_raised do
|
16
|
+
Dog.find :all, :conditions => {:legs => {:length => :reaches_the_ground}}, :include => :legs
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
should "not fail if re-opened association is included in a deeper subclass #find call" do
|
21
|
+
assert_nothing_raised do
|
22
|
+
Beagle.find :all, :conditions => {:legs => {:length => :reaches_the_ground}}, :include => :legs
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_inheritable_attributes_manager
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 17
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 3
|
9
|
-
-
|
10
|
-
version: 0.3.
|
9
|
+
- 1
|
10
|
+
version: 0.3.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Ryan L. Bell
|
@@ -19,7 +19,9 @@ date: 2010-08-07 00:00:00 -04:00
|
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
|
-
|
22
|
+
name: shoulda
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
23
25
|
none: false
|
24
26
|
requirements:
|
25
27
|
- - "="
|
@@ -30,12 +32,12 @@ dependencies:
|
|
30
32
|
- 10
|
31
33
|
- 2
|
32
34
|
version: 2.10.2
|
33
|
-
requirement: *id001
|
34
|
-
name: shoulda
|
35
|
-
prerelease: false
|
36
35
|
type: :development
|
36
|
+
version_requirements: *id001
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
|
-
|
38
|
+
name: redgreen
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
41
|
none: false
|
40
42
|
requirements:
|
41
43
|
- - "="
|
@@ -46,12 +48,12 @@ dependencies:
|
|
46
48
|
- 2
|
47
49
|
- 2
|
48
50
|
version: 1.2.2
|
49
|
-
requirement: *id002
|
50
|
-
name: redgreen
|
51
|
-
prerelease: false
|
52
51
|
type: :development
|
52
|
+
version_requirements: *id002
|
53
53
|
- !ruby/object:Gem::Dependency
|
54
|
-
|
54
|
+
name: actionpack
|
55
|
+
prerelease: false
|
56
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
55
57
|
none: false
|
56
58
|
requirements:
|
57
59
|
- - ">="
|
@@ -62,12 +64,12 @@ dependencies:
|
|
62
64
|
- 3
|
63
65
|
- 0
|
64
66
|
version: 2.3.0
|
65
|
-
requirement: *id003
|
66
|
-
name: actionpack
|
67
|
-
prerelease: false
|
68
67
|
type: :development
|
68
|
+
version_requirements: *id003
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
|
70
|
+
name: activerecord
|
71
|
+
prerelease: false
|
72
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
71
73
|
none: false
|
72
74
|
requirements:
|
73
75
|
- - ">="
|
@@ -78,10 +80,8 @@ dependencies:
|
|
78
80
|
- 3
|
79
81
|
- 0
|
80
82
|
version: 2.3.0
|
81
|
-
requirement: *id004
|
82
|
-
name: activerecord
|
83
|
-
prerelease: false
|
84
83
|
type: :development
|
84
|
+
version_requirements: *id004
|
85
85
|
description: Enhances Rails inheritable attributes to ensure that changes to super classes are passed on to the subclasses
|
86
86
|
email: ryan.l.bell@gmail.com
|
87
87
|
executables: []
|
@@ -99,10 +99,12 @@ files:
|
|
99
99
|
- RELEASE_NOTES
|
100
100
|
- Gemfile
|
101
101
|
- init.rb
|
102
|
+
- lib/models/reflection.rb
|
102
103
|
- lib/models/nested_attributes.rb
|
103
104
|
- lib/controllers/controller_filters.rb
|
104
105
|
- lib/rails_inheritable_attributes_manager.rb
|
105
106
|
- tests/models/accepts_nested_attributes_for_test.rb
|
107
|
+
- tests/models/reflections_test.rb
|
106
108
|
- tests/models/config.rb
|
107
109
|
- tests/test_helper.rb
|
108
110
|
- tests/controllers/normal_filter_chain_test.rb
|