active_mongoid 0.1.0
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.
- checksums.yaml +7 -0
- data/.DS_Store +0 -0
- data/.coveralls.yml +1 -0
- data/.gitignore +22 -0
- data/.ruby_gemset +1 -0
- data/.ruby_version +1 -0
- data/.travis.yml +11 -0
- data/Appraisals +7 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +198 -0
- data/Rakefile +7 -0
- data/active_mongoid.gemspec +36 -0
- data/gemfiles/mongoid_2.8.gemfile +7 -0
- data/gemfiles/mongoid_2.8.gemfile.lock +105 -0
- data/gemfiles/mongoid_3.1.gemfile +7 -0
- data/gemfiles/mongoid_3.1.gemfile.lock +108 -0
- data/lib/active_mongoid.rb +8 -0
- data/lib/active_mongoid/associations.rb +82 -0
- data/lib/active_mongoid/associations/binding.rb +77 -0
- data/lib/active_mongoid/associations/builder.rb +26 -0
- data/lib/active_mongoid/associations/builders/in.rb +17 -0
- data/lib/active_mongoid/associations/builders/many.rb +15 -0
- data/lib/active_mongoid/associations/builders/one.rb +15 -0
- data/lib/active_mongoid/associations/document_relation/accessors.rb +100 -0
- data/lib/active_mongoid/associations/document_relation/associations.rb +33 -0
- data/lib/active_mongoid/associations/document_relation/auto_save.rb +31 -0
- data/lib/active_mongoid/associations/document_relation/bindings/in.rb +48 -0
- data/lib/active_mongoid/associations/document_relation/bindings/many.rb +19 -0
- data/lib/active_mongoid/associations/document_relation/bindings/one.rb +19 -0
- data/lib/active_mongoid/associations/document_relation/builders.rb +31 -0
- data/lib/active_mongoid/associations/document_relation/dependent.rb +26 -0
- data/lib/active_mongoid/associations/document_relation/macros.rb +51 -0
- data/lib/active_mongoid/associations/document_relation/referenced/in.rb +72 -0
- data/lib/active_mongoid/associations/document_relation/referenced/many.rb +125 -0
- data/lib/active_mongoid/associations/document_relation/referenced/one.rb +75 -0
- data/lib/active_mongoid/associations/many.rb +211 -0
- data/lib/active_mongoid/associations/metadata.rb +229 -0
- data/lib/active_mongoid/associations/one.rb +21 -0
- data/lib/active_mongoid/associations/proxy.rb +38 -0
- data/lib/active_mongoid/associations/record_relation/accessors.rb +80 -0
- data/lib/active_mongoid/associations/record_relation/associations.rb +33 -0
- data/lib/active_mongoid/associations/record_relation/auto_save.rb +43 -0
- data/lib/active_mongoid/associations/record_relation/bindings/in.rb +48 -0
- data/lib/active_mongoid/associations/record_relation/bindings/many.rb +19 -0
- data/lib/active_mongoid/associations/record_relation/bindings/one.rb +19 -0
- data/lib/active_mongoid/associations/record_relation/builders.rb +31 -0
- data/lib/active_mongoid/associations/record_relation/dependent.rb +26 -0
- data/lib/active_mongoid/associations/record_relation/macros.rb +65 -0
- data/lib/active_mongoid/associations/record_relation/referenced/in.rb +72 -0
- data/lib/active_mongoid/associations/record_relation/referenced/many.rb +128 -0
- data/lib/active_mongoid/associations/record_relation/referenced/one.rb +75 -0
- data/lib/active_mongoid/associations/targets/enumerable.rb +161 -0
- data/lib/active_mongoid/bson_id.rb +44 -0
- data/lib/active_mongoid/finder_proxy.rb +55 -0
- data/lib/active_mongoid/finders.rb +60 -0
- data/lib/active_mongoid/version.rb +3 -0
- data/spec/lib/associations/document_relation/accessors_spec.rb +330 -0
- data/spec/lib/associations/document_relation/auto_save_spec.rb +157 -0
- data/spec/lib/associations/document_relation/bindings/in_spec.rb +39 -0
- data/spec/lib/associations/document_relation/bindings/many_spec.rb +36 -0
- data/spec/lib/associations/document_relation/bindings/one_spec.rb +39 -0
- data/spec/lib/associations/document_relation/builders_spec.rb +117 -0
- data/spec/lib/associations/document_relation/dependent_spec.rb +87 -0
- data/spec/lib/associations/document_relation/macros_spec.rb +68 -0
- data/spec/lib/associations/document_relation/referenced/in_spec.rb +27 -0
- data/spec/lib/associations/document_relation/referenced/many_spec.rb +32 -0
- data/spec/lib/associations/document_relation/referenced/one_spec.rb +28 -0
- data/spec/lib/associations/metadata_spec.rb +157 -0
- data/spec/lib/associations/record_relation/accessors_spec.rb +328 -0
- data/spec/lib/associations/record_relation/auto_save_spec.rb +157 -0
- data/spec/lib/associations/record_relation/bindings/in_spec.rb +39 -0
- data/spec/lib/associations/record_relation/bindings/many_spec.rb +39 -0
- data/spec/lib/associations/record_relation/bindings/one_spec.rb +57 -0
- data/spec/lib/associations/record_relation/builders_spec.rb +118 -0
- data/spec/lib/associations/record_relation/dependent_spec.rb +87 -0
- data/spec/lib/associations/record_relation/macros_spec.rb +73 -0
- data/spec/lib/associations/record_relation/referenced/in_spec.rb +27 -0
- data/spec/lib/associations/record_relation/referenced/many_spec.rb +32 -0
- data/spec/lib/associations/record_relation/referenced/one_spec.rb +27 -0
- data/spec/lib/bson_id_spec.rb +48 -0
- data/spec/lib/finders_spec.rb +105 -0
- data/spec/spec_helper.rb +89 -0
- data/spec/support/models/active_record/address.rb +6 -0
- data/spec/support/models/active_record/division.rb +16 -0
- data/spec/support/models/active_record/division_setting.rb +9 -0
- data/spec/support/models/active_record/player.rb +12 -0
- data/spec/support/models/mongoid/league.rb +10 -0
- data/spec/support/models/mongoid/person.rb +9 -0
- data/spec/support/models/mongoid/post.rb +9 -0
- data/spec/support/models/mongoid/stat.rb +8 -0
- data/spec/support/models/mongoid/team.rb +9 -0
- data/spec/support/shared_examples/shared_many_spec.rb +411 -0
- metadata +370 -0
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
require "spec_helper"
|
|
2
|
+
|
|
3
|
+
describe ActiveMongoid::Associations::RecordRelation::AutoSave do
|
|
4
|
+
|
|
5
|
+
describe ".autosave_documents" do
|
|
6
|
+
|
|
7
|
+
describe "when relation is has_one" do
|
|
8
|
+
|
|
9
|
+
before(:all) do
|
|
10
|
+
League.autosave_records(League.am_relations["division"].merge!(autosave: true))
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
after(:all) do
|
|
14
|
+
League.reset_callbacks(:save)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
let(:league) do
|
|
18
|
+
League.new
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
context "when the option is provided" do
|
|
22
|
+
|
|
23
|
+
let(:division) do
|
|
24
|
+
Division.new(name: "Foo")
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
before do
|
|
28
|
+
league.division = division
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
context "when saving the parent document" do
|
|
32
|
+
|
|
33
|
+
before do
|
|
34
|
+
league.save
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
it "does save self" do
|
|
38
|
+
expect(league).to be_persisted
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
it "does save the relation" do
|
|
42
|
+
expect(division).to be_persisted
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
it "does save the relation id" do
|
|
46
|
+
expect(league.id).to_not be_nil
|
|
47
|
+
expect(division.league_id).to eq(league.id)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
describe "when relation is a belongs_to" do
|
|
57
|
+
|
|
58
|
+
before(:all) do
|
|
59
|
+
Person.autosave_records(Person.am_relations["player"].merge!(autosave: true))
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
after(:all) do
|
|
63
|
+
Person.reset_callbacks(:save)
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
let(:person) do
|
|
67
|
+
Person.new
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
context "when the option is provided" do
|
|
71
|
+
|
|
72
|
+
let(:player) do
|
|
73
|
+
Player.new(name: "Foo")
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
before do
|
|
77
|
+
person.player = player
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
context "when saving the parent document" do
|
|
81
|
+
|
|
82
|
+
before do
|
|
83
|
+
person.save
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
it "does save self" do
|
|
87
|
+
expect(person).to be_persisted
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
it "does save the relation" do
|
|
91
|
+
expect(player).to be_persisted
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
xit "does save the relation id" do
|
|
95
|
+
expect(player.id).to_not be_nil
|
|
96
|
+
expect(person.player_id).to eq(player.id)
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
describe "when relation is a has_many" do
|
|
106
|
+
|
|
107
|
+
before(:all) do
|
|
108
|
+
Team.autosave_records(Team.am_relations["players"].merge!(autosave: true))
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
after(:all) do
|
|
112
|
+
Team.reset_callbacks(:save)
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
let(:team) do
|
|
116
|
+
Team.new(name: "Foo")
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
let(:player) do
|
|
120
|
+
Player.new(name: "Foo")
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
context "when the option is provided" do
|
|
124
|
+
|
|
125
|
+
before do
|
|
126
|
+
team.players << player
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
context "when saving the parent document" do
|
|
130
|
+
|
|
131
|
+
before do
|
|
132
|
+
team.save
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
it "does save self" do
|
|
136
|
+
expect(team).to be_persisted
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
it "does save the relation" do
|
|
140
|
+
expect(player).to be_persisted
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
it "does save the relation id" do
|
|
144
|
+
expect(team.id).to_not be_nil
|
|
145
|
+
expect(player.team_id).to eq(team.id)
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
end
|
|
157
|
+
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
require "spec_helper"
|
|
2
|
+
|
|
3
|
+
describe ActiveMongoid::Associations::RecordRelation::Bindings::In do
|
|
4
|
+
|
|
5
|
+
let(:person) do
|
|
6
|
+
Person.new
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
let(:player) do
|
|
10
|
+
Player.new
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
let(:person_metadata) do
|
|
14
|
+
Person.am_relations["player"]
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
describe "#bind_one" do
|
|
18
|
+
|
|
19
|
+
context "when the child of a references one" do
|
|
20
|
+
|
|
21
|
+
let(:binder) do
|
|
22
|
+
described_class.new(person, player, person_metadata)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
context "when the document is bindable with default" do
|
|
26
|
+
|
|
27
|
+
before do
|
|
28
|
+
binder.bind_one
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
it "sets the inverse relation" do
|
|
32
|
+
expect(player.person).to eq(person)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
require "spec_helper"
|
|
2
|
+
|
|
3
|
+
describe ActiveMongoid::Associations::DocumentRelation::Bindings::Many do
|
|
4
|
+
|
|
5
|
+
let(:team) do
|
|
6
|
+
Team.new
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
let(:player) do
|
|
10
|
+
Player.new
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
let(:team_metadata) do
|
|
14
|
+
Team.am_relations["players"]
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
describe "#bind_one" do
|
|
18
|
+
|
|
19
|
+
context "when the child of a references many" do
|
|
20
|
+
|
|
21
|
+
let(:binder) do
|
|
22
|
+
described_class.new(team, player, team_metadata)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
context "when the document is bindable with default" do
|
|
26
|
+
|
|
27
|
+
before do
|
|
28
|
+
binder.bind_one(player)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
it "sets the inverse relation" do
|
|
32
|
+
expect(player.team).to eq(team)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
require "spec_helper"
|
|
2
|
+
|
|
3
|
+
describe ActiveMongoid::Associations::RecordRelation::Bindings::One do
|
|
4
|
+
|
|
5
|
+
let(:league){ League.new }
|
|
6
|
+
|
|
7
|
+
let(:division){ Division.new }
|
|
8
|
+
|
|
9
|
+
let(:division_setting){ Settings::DivisionSetting.new }
|
|
10
|
+
|
|
11
|
+
let(:league_metadata){ League.am_relations["division"] }
|
|
12
|
+
|
|
13
|
+
describe "#bind_one" do
|
|
14
|
+
|
|
15
|
+
context "when the child of a references belongs_to" do
|
|
16
|
+
|
|
17
|
+
let(:binder) do
|
|
18
|
+
described_class.new(league, division, league_metadata)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
context "when the document is bindable with default" do
|
|
22
|
+
|
|
23
|
+
before do
|
|
24
|
+
binder.bind_one
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it "sets the inverse relation" do
|
|
28
|
+
expect(division.league).to eq(league)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
context "when the child of a references belongs_to with class_name" do
|
|
36
|
+
|
|
37
|
+
let(:binder) do
|
|
38
|
+
described_class.new(league, division_setting, league_metadata)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
context "when the document is bindable with default" do
|
|
42
|
+
|
|
43
|
+
before do
|
|
44
|
+
binder.bind_one
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
it "sets the inverse relation" do
|
|
48
|
+
expect(division_setting.league).to eq(league)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
end
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe ActiveMongoid::Associations::RecordRelation::Builders do
|
|
4
|
+
|
|
5
|
+
describe "#build_#\{name}" do
|
|
6
|
+
|
|
7
|
+
context "when the relation is a has_one" do
|
|
8
|
+
|
|
9
|
+
let(:league) do
|
|
10
|
+
League.new
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
let!(:division) do
|
|
14
|
+
league.build_division
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it "builds the document" do
|
|
18
|
+
expect(league.division).to eq(division)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
it "sets the inverse" do
|
|
22
|
+
expect(division.league).to eq(league)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
it "does not save the document" do
|
|
26
|
+
expect(division).to_not be_persisted
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
context "when the relation is a belongs to" do
|
|
32
|
+
|
|
33
|
+
context "when the inverse is a has one" do
|
|
34
|
+
|
|
35
|
+
let(:person) do
|
|
36
|
+
Person.new
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
let!(:player) do
|
|
40
|
+
person.build_player
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
it "builds the record" do
|
|
44
|
+
expect(person.player).to eq(player)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
it "sets the inverse" do
|
|
48
|
+
expect(player.person).to eq(person)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
it "does not save the document" do
|
|
52
|
+
expect(person).to_not be_persisted
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
describe "#create_#\{name}" do
|
|
62
|
+
|
|
63
|
+
context "when the relation is a has_one" do
|
|
64
|
+
|
|
65
|
+
let(:league) do
|
|
66
|
+
League.create
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
let!(:division) do
|
|
70
|
+
league.create_division
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
it "create the record" do
|
|
74
|
+
expect(league.division).to eq(division)
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
it "sets the inverse" do
|
|
78
|
+
expect(division.league).to eq(league)
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
it "does save the record" do
|
|
82
|
+
expect(division).to be_persisted
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
context "when the relation is a belongs to" do
|
|
88
|
+
|
|
89
|
+
context "when the inverse is a has one" do
|
|
90
|
+
|
|
91
|
+
let(:person) do
|
|
92
|
+
Person.create
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
let!(:player) do
|
|
96
|
+
person.create_player
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
it "creates the record" do
|
|
100
|
+
expect(person.player).to eq(player)
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
it "sets the inverse" do
|
|
104
|
+
expect(player.person).to eq(person)
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
it "does save the record" do
|
|
108
|
+
expect(player).to be_persisted
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
end
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
require "spec_helper"
|
|
2
|
+
|
|
3
|
+
describe ActiveMongoid::Associations::RecordRelation::Dependent do
|
|
4
|
+
|
|
5
|
+
describe ".dependent_records" do
|
|
6
|
+
|
|
7
|
+
context "relation is a has_one" do
|
|
8
|
+
|
|
9
|
+
let(:base_class) { League }
|
|
10
|
+
let(:target_class) { Division }
|
|
11
|
+
let(:relation_name) { :division }
|
|
12
|
+
let(:persisted_base) { base_class.create }
|
|
13
|
+
let(:new_target) { target_class.new }
|
|
14
|
+
let(:metadata) { base_class.am_relations[relation_name.to_s] }
|
|
15
|
+
|
|
16
|
+
before do
|
|
17
|
+
base_class.dependent_records(metadata.merge!(dependent: :destroy))
|
|
18
|
+
persisted_base.division = new_target
|
|
19
|
+
new_target.save!
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
after do
|
|
23
|
+
base_class.reset_callbacks(:destroy)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
it "destroys dependent" do
|
|
27
|
+
persisted_base.destroy
|
|
28
|
+
expect { new_target.reload }.to raise_error(ActiveRecord::RecordNotFound)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
context "relation is a belongs_to" do
|
|
34
|
+
|
|
35
|
+
let(:base_class) { Person }
|
|
36
|
+
let(:target_class) { Player }
|
|
37
|
+
let(:relation_name) { :player }
|
|
38
|
+
let(:new_base) { base_class.new }
|
|
39
|
+
let(:persisted_target) { target_class.create }
|
|
40
|
+
let(:metadata) { base_class.am_relations[relation_name.to_s] }
|
|
41
|
+
|
|
42
|
+
before do
|
|
43
|
+
base_class.dependent_records(metadata.merge!(dependent: :destroy))
|
|
44
|
+
new_base.player = persisted_target
|
|
45
|
+
new_base.save!
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
after do
|
|
49
|
+
base_class.reset_callbacks(:destroy)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
it "destroys dependent" do
|
|
53
|
+
new_base.destroy
|
|
54
|
+
expect { persisted_target.reload }.to raise_error(ActiveRecord::RecordNotFound)
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
context "relation is a has_many" do
|
|
60
|
+
|
|
61
|
+
let(:base_class) { Team }
|
|
62
|
+
let(:target_class) { Player }
|
|
63
|
+
let(:relation_name) { :players }
|
|
64
|
+
let(:persisted_base) { base_class.create }
|
|
65
|
+
let(:new_target) { target_class.new }
|
|
66
|
+
let(:metadata) { base_class.am_relations[relation_name.to_s] }
|
|
67
|
+
|
|
68
|
+
before do
|
|
69
|
+
base_class.dependent_records(metadata.merge!(dependent: :destroy))
|
|
70
|
+
persisted_base.players << new_target
|
|
71
|
+
new_target.save!
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
after do
|
|
75
|
+
base_class.reset_callbacks(:destroy)
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
it "destroys dependents" do
|
|
79
|
+
persisted_base.destroy
|
|
80
|
+
expect { new_target.reload }.to raise_error(ActiveRecord::RecordNotFound)
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
end
|