bullet 7.0.3 → 7.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +39 -1
- data/MIT-LICENSE +1 -1
- data/README.md +7 -2
- data/lib/bullet/active_record4.rb +9 -0
- data/lib/bullet/active_record41.rb +9 -0
- data/lib/bullet/active_record42.rb +9 -0
- data/lib/bullet/active_record5.rb +24 -8
- data/lib/bullet/active_record52.rb +23 -7
- data/lib/bullet/active_record60.rb +22 -6
- data/lib/bullet/active_record61.rb +22 -6
- data/lib/bullet/active_record70.rb +43 -14
- data/lib/bullet/active_record71.rb +304 -0
- data/lib/bullet/dependency.rb +12 -0
- data/lib/bullet/detector/association.rb +8 -0
- data/lib/bullet/detector/n_plus_one_query.rb +17 -9
- data/lib/bullet/detector/unused_eager_loading.rb +6 -3
- data/lib/bullet/ext/object.rb +13 -3
- data/lib/bullet/mongoid7x.rb +8 -10
- data/lib/bullet/mongoid8x.rb +59 -0
- data/lib/bullet/notification/base.rb +9 -8
- data/lib/bullet/notification/counter_cache.rb +1 -1
- data/lib/bullet/rack.rb +41 -7
- data/lib/bullet/registry/association.rb +2 -1
- data/lib/bullet/registry/call_stack.rb +12 -0
- data/lib/bullet/registry.rb +1 -0
- data/lib/bullet/stack_trace_filter.rb +13 -10
- data/lib/bullet/version.rb +1 -1
- data/lib/bullet.rb +13 -3
- metadata +8 -153
- data/.github/workflows/main.yml +0 -82
- data/.gitignore +0 -15
- data/.rspec +0 -2
- data/Gemfile +0 -24
- data/Gemfile.mongoid +0 -12
- data/Gemfile.mongoid-4.0 +0 -15
- data/Gemfile.mongoid-5.0 +0 -15
- data/Gemfile.mongoid-6.0 +0 -15
- data/Gemfile.mongoid-7.0 +0 -15
- data/Gemfile.rails-4.0 +0 -16
- data/Gemfile.rails-4.1 +0 -16
- data/Gemfile.rails-4.2 +0 -16
- data/Gemfile.rails-5.0 +0 -15
- data/Gemfile.rails-5.1 +0 -15
- data/Gemfile.rails-5.2 +0 -15
- data/Gemfile.rails-6.0 +0 -15
- data/Gemfile.rails-6.1 +0 -15
- data/Gemfile.rails-7.0 +0 -10
- data/Guardfile +0 -8
- data/Hacking.md +0 -75
- data/Rakefile +0 -51
- data/bullet.gemspec +0 -33
- data/perf/benchmark.rb +0 -118
- data/rails/init.rb +0 -3
- data/spec/bullet/detector/association_spec.rb +0 -28
- data/spec/bullet/detector/base_spec.rb +0 -10
- data/spec/bullet/detector/counter_cache_spec.rb +0 -58
- data/spec/bullet/detector/n_plus_one_query_spec.rb +0 -182
- data/spec/bullet/detector/unused_eager_loading_spec.rb +0 -121
- data/spec/bullet/ext/object_spec.rb +0 -44
- data/spec/bullet/ext/string_spec.rb +0 -15
- data/spec/bullet/notification/base_spec.rb +0 -94
- data/spec/bullet/notification/counter_cache_spec.rb +0 -14
- data/spec/bullet/notification/n_plus_one_query_spec.rb +0 -29
- data/spec/bullet/notification/unused_eager_loading_spec.rb +0 -18
- data/spec/bullet/notification_collector_spec.rb +0 -34
- data/spec/bullet/rack_spec.rb +0 -279
- data/spec/bullet/registry/association_spec.rb +0 -28
- data/spec/bullet/registry/base_spec.rb +0 -46
- data/spec/bullet/registry/object_spec.rb +0 -26
- data/spec/bullet_spec.rb +0 -136
- data/spec/integration/active_record/association_spec.rb +0 -793
- data/spec/integration/counter_cache_spec.rb +0 -68
- data/spec/integration/mongoid/association_spec.rb +0 -246
- data/spec/models/address.rb +0 -5
- data/spec/models/attachment.rb +0 -5
- data/spec/models/author.rb +0 -5
- data/spec/models/base_user.rb +0 -7
- data/spec/models/category.rb +0 -12
- data/spec/models/city.rb +0 -5
- data/spec/models/client.rb +0 -8
- data/spec/models/comment.rb +0 -8
- data/spec/models/company.rb +0 -5
- data/spec/models/country.rb +0 -5
- data/spec/models/deal.rb +0 -5
- data/spec/models/document.rb +0 -7
- data/spec/models/entry.rb +0 -5
- data/spec/models/firm.rb +0 -7
- data/spec/models/folder.rb +0 -4
- data/spec/models/group.rb +0 -4
- data/spec/models/mongoid/address.rb +0 -9
- data/spec/models/mongoid/category.rb +0 -10
- data/spec/models/mongoid/comment.rb +0 -9
- data/spec/models/mongoid/company.rb +0 -9
- data/spec/models/mongoid/entry.rb +0 -9
- data/spec/models/mongoid/post.rb +0 -14
- data/spec/models/mongoid/user.rb +0 -7
- data/spec/models/newspaper.rb +0 -5
- data/spec/models/page.rb +0 -4
- data/spec/models/person.rb +0 -5
- data/spec/models/pet.rb +0 -5
- data/spec/models/post.rb +0 -34
- data/spec/models/relationship.rb +0 -6
- data/spec/models/reply.rb +0 -5
- data/spec/models/role.rb +0 -7
- data/spec/models/student.rb +0 -5
- data/spec/models/submission.rb +0 -7
- data/spec/models/teacher.rb +0 -5
- data/spec/models/user.rb +0 -8
- data/spec/models/writer.rb +0 -4
- data/spec/spec_helper.rb +0 -97
- data/spec/support/bullet_ext.rb +0 -56
- data/spec/support/mongo_seed.rb +0 -59
- data/spec/support/rack_double.rb +0 -49
- data/spec/support/sqlite_seed.rb +0 -284
- data/test.sh +0 -15
- data/update.sh +0 -10
@@ -1,68 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
if !mongoid? && active_record?
|
6
|
-
describe Bullet::Detector::CounterCache do
|
7
|
-
before(:each) { Bullet.start_request }
|
8
|
-
|
9
|
-
after(:each) { Bullet.end_request }
|
10
|
-
|
11
|
-
it 'should need counter cache with all cities' do
|
12
|
-
Country.all.each { |country| country.cities.size }
|
13
|
-
expect(Bullet.collected_counter_cache_notifications).not_to be_empty
|
14
|
-
end
|
15
|
-
|
16
|
-
it 'should not need counter cache if already define counter_cache' do
|
17
|
-
Person.all.each { |person| person.pets.size }
|
18
|
-
expect(Bullet.collected_counter_cache_notifications).to be_empty
|
19
|
-
end
|
20
|
-
|
21
|
-
it 'should not need counter cache with only one object' do
|
22
|
-
Country.first.cities.size
|
23
|
-
expect(Bullet.collected_counter_cache_notifications).to be_empty
|
24
|
-
end
|
25
|
-
|
26
|
-
it 'should not need counter cache without size' do
|
27
|
-
Country.includes(:cities).each { |country| country.cities.empty? }
|
28
|
-
expect(Bullet.collected_counter_cache_notifications).to be_empty
|
29
|
-
end
|
30
|
-
|
31
|
-
if ActiveRecord::VERSION::MAJOR > 4
|
32
|
-
it 'should not need counter cache for has_many through' do
|
33
|
-
Client.all.each { |client| client.firms.size }
|
34
|
-
expect(Bullet.collected_counter_cache_notifications).to be_empty
|
35
|
-
end
|
36
|
-
else
|
37
|
-
it 'should need counter cache for has_many through' do
|
38
|
-
Client.all.each { |client| client.firms.size }
|
39
|
-
expect(Bullet.collected_counter_cache_notifications).not_to be_empty
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
it 'should not need counter cache with part of cities' do
|
44
|
-
Country.all.each { |country| country.cities.where(name: 'first').size }
|
45
|
-
expect(Bullet.collected_counter_cache_notifications).to be_empty
|
46
|
-
end
|
47
|
-
|
48
|
-
context 'disable' do
|
49
|
-
before { Bullet.counter_cache_enable = false }
|
50
|
-
after { Bullet.counter_cache_enable = true }
|
51
|
-
|
52
|
-
it 'should not detect counter cache' do
|
53
|
-
Country.all.each { |country| country.cities.size }
|
54
|
-
expect(Bullet.collected_counter_cache_notifications).to be_empty
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
context 'safelist' do
|
59
|
-
before { Bullet.add_safelist type: :counter_cache, class_name: 'Country', association: :cities }
|
60
|
-
after { Bullet.clear_safelist }
|
61
|
-
|
62
|
-
it 'should not detect counter cache' do
|
63
|
-
Country.all.each { |country| country.cities.size }
|
64
|
-
expect(Bullet.collected_counter_cache_notifications).to be_empty
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
@@ -1,246 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
if mongoid?
|
6
|
-
describe Bullet::Detector::Association do
|
7
|
-
context 'embeds_many' do
|
8
|
-
context 'posts => users' do
|
9
|
-
it 'should detect nothing' do
|
10
|
-
Mongoid::Post.all.each { |post| post.users.map(&:name) }
|
11
|
-
Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
|
12
|
-
expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
|
13
|
-
|
14
|
-
expect(Bullet::Detector::Association).to be_completely_preloading_associations
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
context 'has_many' do
|
20
|
-
context 'posts => comments' do
|
21
|
-
it 'should detect non preload posts => comments' do
|
22
|
-
Mongoid::Post.all.each { |post| post.comments.map(&:name) }
|
23
|
-
Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
|
24
|
-
expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
|
25
|
-
|
26
|
-
expect(Bullet::Detector::Association).to be_detecting_unpreloaded_association_for(Mongoid::Post, :comments)
|
27
|
-
end
|
28
|
-
|
29
|
-
it 'should detect preload post => comments' do
|
30
|
-
Mongoid::Post.includes(:comments).each { |post| post.comments.map(&:name) }
|
31
|
-
Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
|
32
|
-
expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
|
33
|
-
|
34
|
-
expect(Bullet::Detector::Association).to be_completely_preloading_associations
|
35
|
-
end
|
36
|
-
|
37
|
-
it 'should detect unused preload post => comments' do
|
38
|
-
Mongoid::Post.includes(:comments).map(&:name)
|
39
|
-
Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
|
40
|
-
expect(Bullet::Detector::Association).to be_unused_preload_associations_for(Mongoid::Post, :comments)
|
41
|
-
|
42
|
-
expect(Bullet::Detector::Association).to be_completely_preloading_associations
|
43
|
-
end
|
44
|
-
|
45
|
-
it 'should not detect unused preload post => comments' do
|
46
|
-
Mongoid::Post.all.map(&:name)
|
47
|
-
Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
|
48
|
-
expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
|
49
|
-
|
50
|
-
expect(Bullet::Detector::Association).to be_completely_preloading_associations
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
context 'category => posts, category => entries' do
|
55
|
-
it 'should detect non preload with category => [posts, entries]' do
|
56
|
-
Mongoid::Category.all.each do |category|
|
57
|
-
category.posts.map(&:name)
|
58
|
-
category.entries.map(&:name)
|
59
|
-
end
|
60
|
-
Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
|
61
|
-
expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
|
62
|
-
|
63
|
-
expect(Bullet::Detector::Association).to be_detecting_unpreloaded_association_for(Mongoid::Category, :posts)
|
64
|
-
expect(Bullet::Detector::Association).to be_detecting_unpreloaded_association_for(Mongoid::Category, :entries)
|
65
|
-
end
|
66
|
-
|
67
|
-
it 'should detect preload with category => posts, but not with category => entries' do
|
68
|
-
Mongoid::Category.includes(:posts).each do |category|
|
69
|
-
category.posts.map(&:name)
|
70
|
-
category.entries.map(&:name)
|
71
|
-
end
|
72
|
-
Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
|
73
|
-
expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
|
74
|
-
|
75
|
-
expect(Bullet::Detector::Association).not_to be_detecting_unpreloaded_association_for(
|
76
|
-
Mongoid::Category,
|
77
|
-
:posts
|
78
|
-
)
|
79
|
-
expect(Bullet::Detector::Association).to be_detecting_unpreloaded_association_for(Mongoid::Category, :entries)
|
80
|
-
end
|
81
|
-
|
82
|
-
it 'should detect preload with category => [posts, entries]' do
|
83
|
-
Mongoid::Category.includes(:posts, :entries).each do |category|
|
84
|
-
category.posts.map(&:name)
|
85
|
-
category.entries.map(&:name)
|
86
|
-
end
|
87
|
-
Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
|
88
|
-
expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
|
89
|
-
|
90
|
-
expect(Bullet::Detector::Association).to be_completely_preloading_associations
|
91
|
-
end
|
92
|
-
|
93
|
-
it 'should detect unused preload with category => [posts, entries]' do
|
94
|
-
Mongoid::Category.includes(:posts, :entries).map(&:name)
|
95
|
-
Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
|
96
|
-
expect(Bullet::Detector::Association).to be_unused_preload_associations_for(Mongoid::Category, :posts)
|
97
|
-
expect(Bullet::Detector::Association).to be_unused_preload_associations_for(Mongoid::Category, :entries)
|
98
|
-
|
99
|
-
expect(Bullet::Detector::Association).to be_completely_preloading_associations
|
100
|
-
end
|
101
|
-
|
102
|
-
it 'should detect unused preload with category => entries, but not with category => posts' do
|
103
|
-
Mongoid::Category.includes(:posts, :entries).each { |category| category.posts.map(&:name) }
|
104
|
-
Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
|
105
|
-
expect(Bullet::Detector::Association).not_to be_unused_preload_associations_for(Mongoid::Category, :posts)
|
106
|
-
expect(Bullet::Detector::Association).to be_unused_preload_associations_for(Mongoid::Category, :entries)
|
107
|
-
|
108
|
-
expect(Bullet::Detector::Association).to be_completely_preloading_associations
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
|
-
context 'post => comment' do
|
113
|
-
it 'should detect unused preload with post => comments' do
|
114
|
-
Mongoid::Post.includes(:comments).each { |post| post.comments.first.name }
|
115
|
-
Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
|
116
|
-
expect(Bullet::Detector::Association).not_to be_unused_preload_associations_for(Mongoid::Post, :comments)
|
117
|
-
|
118
|
-
expect(Bullet::Detector::Association).to be_completely_preloading_associations
|
119
|
-
end
|
120
|
-
|
121
|
-
it 'should detect preload with post => comments' do
|
122
|
-
Mongoid::Post.first.comments.map(&:name)
|
123
|
-
Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
|
124
|
-
expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
|
125
|
-
|
126
|
-
expect(Bullet::Detector::Association).to be_completely_preloading_associations
|
127
|
-
end
|
128
|
-
end
|
129
|
-
|
130
|
-
context 'scope preload_comments' do
|
131
|
-
it 'should detect preload post => comments with scope' do
|
132
|
-
Mongoid::Post.preload_comments.each { |post| post.comments.map(&:name) }
|
133
|
-
Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
|
134
|
-
expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
|
135
|
-
|
136
|
-
expect(Bullet::Detector::Association).to be_completely_preloading_associations
|
137
|
-
end
|
138
|
-
|
139
|
-
it 'should detect unused preload with scope' do
|
140
|
-
Mongoid::Post.preload_comments.map(&:name)
|
141
|
-
Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
|
142
|
-
expect(Bullet::Detector::Association).to be_unused_preload_associations_for(Mongoid::Post, :comments)
|
143
|
-
|
144
|
-
expect(Bullet::Detector::Association).to be_completely_preloading_associations
|
145
|
-
end
|
146
|
-
end
|
147
|
-
end
|
148
|
-
|
149
|
-
context 'belongs_to' do
|
150
|
-
context 'comment => post' do
|
151
|
-
it 'should detect non preload with comment => post' do
|
152
|
-
Mongoid::Comment.all.each { |comment| comment.post.name }
|
153
|
-
Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
|
154
|
-
expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
|
155
|
-
|
156
|
-
expect(Bullet::Detector::Association).to be_detecting_unpreloaded_association_for(Mongoid::Comment, :post)
|
157
|
-
end
|
158
|
-
|
159
|
-
it 'should detect preload with one comment => post' do
|
160
|
-
Mongoid::Comment.first.post.name
|
161
|
-
Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
|
162
|
-
expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
|
163
|
-
|
164
|
-
expect(Bullet::Detector::Association).to be_completely_preloading_associations
|
165
|
-
end
|
166
|
-
|
167
|
-
it 'should detect preload with comment => post' do
|
168
|
-
Mongoid::Comment.includes(:post).each { |comment| comment.post.name }
|
169
|
-
Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
|
170
|
-
expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
|
171
|
-
|
172
|
-
expect(Bullet::Detector::Association).to be_completely_preloading_associations
|
173
|
-
end
|
174
|
-
|
175
|
-
it 'should not detect preload with comment => post' do
|
176
|
-
Mongoid::Comment.all.map(&:name)
|
177
|
-
Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
|
178
|
-
expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
|
179
|
-
|
180
|
-
expect(Bullet::Detector::Association).to be_completely_preloading_associations
|
181
|
-
end
|
182
|
-
|
183
|
-
it 'should detect unused preload with comments => post' do
|
184
|
-
Mongoid::Comment.includes(:post).map(&:name)
|
185
|
-
Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
|
186
|
-
expect(Bullet::Detector::Association).to be_unused_preload_associations_for(Mongoid::Comment, :post)
|
187
|
-
|
188
|
-
expect(Bullet::Detector::Association).to be_completely_preloading_associations
|
189
|
-
end
|
190
|
-
end
|
191
|
-
end
|
192
|
-
|
193
|
-
context 'has_one' do
|
194
|
-
context 'company => address' do
|
195
|
-
if Mongoid::VERSION !~ /\A3.0/
|
196
|
-
it 'should detect non preload association' do
|
197
|
-
Mongoid::Company.all.each { |company| company.address.name }
|
198
|
-
Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
|
199
|
-
expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
|
200
|
-
|
201
|
-
expect(Bullet::Detector::Association).to be_detecting_unpreloaded_association_for(
|
202
|
-
Mongoid::Company,
|
203
|
-
:address
|
204
|
-
)
|
205
|
-
end
|
206
|
-
end
|
207
|
-
|
208
|
-
it 'should detect preload association' do
|
209
|
-
Mongoid::Company.includes(:address).each { |company| company.address.name }
|
210
|
-
Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
|
211
|
-
expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
|
212
|
-
|
213
|
-
expect(Bullet::Detector::Association).to be_completely_preloading_associations
|
214
|
-
end
|
215
|
-
|
216
|
-
it 'should not detect preload association' do
|
217
|
-
Mongoid::Company.all.map(&:name)
|
218
|
-
Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
|
219
|
-
expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
|
220
|
-
|
221
|
-
expect(Bullet::Detector::Association).to be_completely_preloading_associations
|
222
|
-
end
|
223
|
-
|
224
|
-
it 'should detect unused preload association' do
|
225
|
-
criteria = Mongoid::Company.includes(:address)
|
226
|
-
criteria.map(&:name)
|
227
|
-
Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
|
228
|
-
expect(Bullet::Detector::Association).to be_unused_preload_associations_for(Mongoid::Company, :address)
|
229
|
-
|
230
|
-
expect(Bullet::Detector::Association).to be_completely_preloading_associations
|
231
|
-
end
|
232
|
-
end
|
233
|
-
end
|
234
|
-
|
235
|
-
context 'call one association that in possible objects' do
|
236
|
-
it 'should not detect preload association' do
|
237
|
-
Mongoid::Post.all
|
238
|
-
Mongoid::Post.first.comments.map(&:name)
|
239
|
-
Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
|
240
|
-
expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
|
241
|
-
|
242
|
-
expect(Bullet::Detector::Association).to be_completely_preloading_associations
|
243
|
-
end
|
244
|
-
end
|
245
|
-
end
|
246
|
-
end
|
data/spec/models/address.rb
DELETED
data/spec/models/attachment.rb
DELETED
data/spec/models/author.rb
DELETED
data/spec/models/base_user.rb
DELETED
data/spec/models/category.rb
DELETED
data/spec/models/city.rb
DELETED
data/spec/models/client.rb
DELETED
data/spec/models/comment.rb
DELETED
data/spec/models/company.rb
DELETED
data/spec/models/country.rb
DELETED
data/spec/models/deal.rb
DELETED
data/spec/models/document.rb
DELETED
data/spec/models/entry.rb
DELETED
data/spec/models/firm.rb
DELETED
data/spec/models/folder.rb
DELETED
data/spec/models/group.rb
DELETED
data/spec/models/mongoid/post.rb
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
class Mongoid::Post
|
4
|
-
include Mongoid::Document
|
5
|
-
|
6
|
-
field :name
|
7
|
-
|
8
|
-
has_many :comments, class_name: 'Mongoid::Comment'
|
9
|
-
belongs_to :category, class_name: 'Mongoid::Category'
|
10
|
-
|
11
|
-
embeds_many :users, class_name: 'Mongoid::User'
|
12
|
-
|
13
|
-
scope :preload_comments, -> { includes(:comments) }
|
14
|
-
end
|
data/spec/models/mongoid/user.rb
DELETED
data/spec/models/newspaper.rb
DELETED
data/spec/models/page.rb
DELETED
data/spec/models/person.rb
DELETED
data/spec/models/pet.rb
DELETED
data/spec/models/post.rb
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
class Post < ActiveRecord::Base
|
4
|
-
belongs_to :category, inverse_of: :posts
|
5
|
-
belongs_to :writer
|
6
|
-
has_many :comments, inverse_of: :post
|
7
|
-
has_and_belongs_to_many :deals
|
8
|
-
|
9
|
-
validates :category, presence: true
|
10
|
-
|
11
|
-
scope :preload_comments, -> { includes(:comments) }
|
12
|
-
scope :in_category_name, ->(name) { where(['categories.name = ?', name]).includes(:category) }
|
13
|
-
scope :draft, -> { where(active: false) }
|
14
|
-
|
15
|
-
def link=(*)
|
16
|
-
comments.new
|
17
|
-
end
|
18
|
-
|
19
|
-
# see association_spec.rb 'should not detect newly assigned object in an after_save'
|
20
|
-
attr_accessor :trigger_after_save
|
21
|
-
after_save do
|
22
|
-
next unless trigger_after_save
|
23
|
-
|
24
|
-
temp_comment = Comment.new(post: self)
|
25
|
-
|
26
|
-
# this triggers self to be "possible", even though it's
|
27
|
-
# not saved yet
|
28
|
-
temp_comment.post
|
29
|
-
|
30
|
-
# category should NOT whine about not being pre-loaded, because
|
31
|
-
# it's obviously attached to a new object
|
32
|
-
category
|
33
|
-
end
|
34
|
-
end
|
data/spec/models/relationship.rb
DELETED
data/spec/models/reply.rb
DELETED
data/spec/models/role.rb
DELETED
data/spec/models/student.rb
DELETED
data/spec/models/submission.rb
DELETED
data/spec/models/teacher.rb
DELETED
data/spec/models/user.rb
DELETED
data/spec/models/writer.rb
DELETED