Commit 314fe766b166520728a9bbd050727f3f2c4ca5a2
1 parent
2f20b79b
Exists in
master
and in
1 other branch
fix spec/model/problem with fabrication_gem
Showing
3 changed files
with
55 additions
and
57 deletions
Show diff stats
spec/fabricators/app_fabricator.rb
spec/fabricators/sequences_fabricator.rb
1 | Fabricate.sequence(:name) {|n| "John #{n} Doe"} | 1 | Fabricate.sequence(:name) {|n| "John #{n} Doe"} |
2 | Fabricate.sequence(:word) {|n| "word#{n}"} | 2 | Fabricate.sequence(:word) {|n| "word#{n}"} |
3 | -Fabricate.sequence(:app_name) {|n| "App ##{n}"} | ||
4 | Fabricate.sequence(:email) {|n| "email#{n}@example.com"} | 3 | Fabricate.sequence(:email) {|n| "email#{n}@example.com"} |
5 | Fabricate.sequence(:user_email) {|n| "user.#{n}@example.com"} | 4 | Fabricate.sequence(:user_email) {|n| "user.#{n}@example.com"} |
6 | 5 |
spec/models/problem_spec.rb
@@ -3,16 +3,16 @@ require 'spec_helper' | @@ -3,16 +3,16 @@ require 'spec_helper' | ||
3 | describe Problem do | 3 | describe Problem do |
4 | context '#last_notice_at' do | 4 | context '#last_notice_at' do |
5 | it "returns the created_at timestamp of the latest notice" do | 5 | it "returns the created_at timestamp of the latest notice" do |
6 | - err = Factory(:err) | 6 | + err = Fabricate(:err) |
7 | problem = err.problem | 7 | problem = err.problem |
8 | problem.should_not be_nil | 8 | problem.should_not be_nil |
9 | 9 | ||
10 | problem.last_notice_at.should be_nil | 10 | problem.last_notice_at.should be_nil |
11 | 11 | ||
12 | - notice1 = Factory(:notice, :err => err) | 12 | + notice1 = Fabricate(:notice, :err => err) |
13 | problem.last_notice_at.should == notice1.created_at | 13 | problem.last_notice_at.should == notice1.created_at |
14 | 14 | ||
15 | - notice2 = Factory(:notice, :err => err) | 15 | + notice2 = Fabricate(:notice, :err => err) |
16 | problem.last_notice_at.should == notice2.created_at | 16 | problem.last_notice_at.should == notice2.created_at |
17 | end | 17 | end |
18 | end | 18 | end |
@@ -20,10 +20,10 @@ describe Problem do | @@ -20,10 +20,10 @@ describe Problem do | ||
20 | 20 | ||
21 | context '#message' do | 21 | context '#message' do |
22 | it "adding a notice caches its message" do | 22 | it "adding a notice caches its message" do |
23 | - err = Factory(:err) | 23 | + err = Fabricate(:err) |
24 | problem = err.problem | 24 | problem = err.problem |
25 | lambda { | 25 | lambda { |
26 | - Factory(:notice, :err => err, :message => 'ERR 1') | 26 | + Fabricate(:notice, :err => err, :message => 'ERR 1') |
27 | }.should change(problem, :message).from(nil).to('ERR 1') | 27 | }.should change(problem, :message).from(nil).to('ERR 1') |
28 | end | 28 | end |
29 | end | 29 | end |
@@ -32,9 +32,9 @@ describe Problem do | @@ -32,9 +32,9 @@ describe Problem do | ||
32 | context 'being created' do | 32 | context 'being created' do |
33 | context 'when the app has err notifications set to false' do | 33 | context 'when the app has err notifications set to false' do |
34 | it 'should not send an email notification' do | 34 | it 'should not send an email notification' do |
35 | - app = Factory(:app_with_watcher, :notify_on_errs => false) | 35 | + app = Fabricate(:app_with_watcher, :notify_on_errs => false) |
36 | Mailer.should_not_receive(:err_notification) | 36 | Mailer.should_not_receive(:err_notification) |
37 | - Factory(:problem, :app => app) | 37 | + Fabricate(:problem, :app => app) |
38 | end | 38 | end |
39 | end | 39 | end |
40 | end | 40 | end |
@@ -48,7 +48,7 @@ describe Problem do | @@ -48,7 +48,7 @@ describe Problem do | ||
48 | end | 48 | end |
49 | 49 | ||
50 | it "should be able to be resolved" do | 50 | it "should be able to be resolved" do |
51 | - problem = Factory(:problem) | 51 | + problem = Fabricate(:problem) |
52 | problem.should_not be_resolved | 52 | problem.should_not be_resolved |
53 | problem.resolve! | 53 | problem.resolve! |
54 | problem.reload.should be_resolved | 54 | problem.reload.should be_resolved |
@@ -58,14 +58,14 @@ describe Problem do | @@ -58,14 +58,14 @@ describe Problem do | ||
58 | 58 | ||
59 | context "resolve!" do | 59 | context "resolve!" do |
60 | it "marks the problem as resolved" do | 60 | it "marks the problem as resolved" do |
61 | - problem = Factory(:problem) | 61 | + problem = Fabricate(:problem) |
62 | problem.should_not be_resolved | 62 | problem.should_not be_resolved |
63 | problem.resolve! | 63 | problem.resolve! |
64 | problem.should be_resolved | 64 | problem.should be_resolved |
65 | end | 65 | end |
66 | 66 | ||
67 | it "should throw an err if it's not successful" do | 67 | it "should throw an err if it's not successful" do |
68 | - problem = Factory(:problem) | 68 | + problem = Fabricate(:problem) |
69 | problem.should_not be_resolved | 69 | problem.should_not be_resolved |
70 | problem.stub!(:valid?).and_return(false) | 70 | problem.stub!(:valid?).and_return(false) |
71 | problem.should_not be_valid | 71 | problem.should_not be_valid |
@@ -78,8 +78,8 @@ describe Problem do | @@ -78,8 +78,8 @@ describe Problem do | ||
78 | 78 | ||
79 | context ".merge!" do | 79 | context ".merge!" do |
80 | it "collects the Errs from several problems into one and deletes the other problems" do | 80 | it "collects the Errs from several problems into one and deletes the other problems" do |
81 | - problem1 = Factory(:err).problem | ||
82 | - problem2 = Factory(:err).problem | 81 | + problem1 = Fabricate(:err).problem |
82 | + problem2 = Fabricate(:err).problem | ||
83 | problem1.errs.length.should == 1 | 83 | problem1.errs.length.should == 1 |
84 | problem2.errs.length.should == 1 | 84 | problem2.errs.length.should == 1 |
85 | 85 | ||
@@ -93,8 +93,8 @@ describe Problem do | @@ -93,8 +93,8 @@ describe Problem do | ||
93 | 93 | ||
94 | context "#unmerge!" do | 94 | context "#unmerge!" do |
95 | it "creates a separate problem for each err" do | 95 | it "creates a separate problem for each err" do |
96 | - problem1 = Factory(:notice).problem | ||
97 | - problem2 = Factory(:notice).problem | 96 | + problem1 = Fabricate(:notice).problem |
97 | + problem2 = Fabricate(:notice).problem | ||
98 | merged_problem = Problem.merge!(problem1, problem2) | 98 | merged_problem = Problem.merge!(problem1, problem2) |
99 | merged_problem.errs.length.should == 2 | 99 | merged_problem.errs.length.should == 2 |
100 | 100 | ||
@@ -103,7 +103,7 @@ describe Problem do | @@ -103,7 +103,7 @@ describe Problem do | ||
103 | end | 103 | end |
104 | 104 | ||
105 | it "runs smoothly for problem without errs" do | 105 | it "runs smoothly for problem without errs" do |
106 | - expect { Factory(:problem).unmerge! }.not_to raise_error | 106 | + expect { Fabricate(:problem).unmerge! }.not_to raise_error |
107 | end | 107 | end |
108 | end | 108 | end |
109 | 109 | ||
@@ -111,8 +111,8 @@ describe Problem do | @@ -111,8 +111,8 @@ describe Problem do | ||
111 | context "Scopes" do | 111 | context "Scopes" do |
112 | context "resolved" do | 112 | context "resolved" do |
113 | it 'only finds resolved Problems' do | 113 | it 'only finds resolved Problems' do |
114 | - resolved = Factory(:problem, :resolved => true) | ||
115 | - unresolved = Factory(:problem, :resolved => false) | 114 | + resolved = Fabricate(:problem, :resolved => true) |
115 | + unresolved = Fabricate(:problem, :resolved => false) | ||
116 | Problem.resolved.all.should include(resolved) | 116 | Problem.resolved.all.should include(resolved) |
117 | Problem.resolved.all.should_not include(unresolved) | 117 | Problem.resolved.all.should_not include(unresolved) |
118 | end | 118 | end |
@@ -120,8 +120,8 @@ describe Problem do | @@ -120,8 +120,8 @@ describe Problem do | ||
120 | 120 | ||
121 | context "unresolved" do | 121 | context "unresolved" do |
122 | it 'only finds unresolved Problems' do | 122 | it 'only finds unresolved Problems' do |
123 | - resolved = Factory(:problem, :resolved => true) | ||
124 | - unresolved = Factory(:problem, :resolved => false) | 123 | + resolved = Fabricate(:problem, :resolved => true) |
124 | + unresolved = Fabricate(:problem, :resolved => false) | ||
125 | Problem.unresolved.all.should_not include(resolved) | 125 | Problem.unresolved.all.should_not include(resolved) |
126 | Problem.unresolved.all.should include(unresolved) | 126 | Problem.unresolved.all.should include(unresolved) |
127 | end | 127 | end |
@@ -131,9 +131,9 @@ describe Problem do | @@ -131,9 +131,9 @@ describe Problem do | ||
131 | 131 | ||
132 | context "notice counter cache" do | 132 | context "notice counter cache" do |
133 | before do | 133 | before do |
134 | - @app = Factory(:app) | ||
135 | - @problem = Factory(:problem, :app => @app) | ||
136 | - @err = Factory(:err, :problem => @problem) | 134 | + @app = Fabricate(:app) |
135 | + @problem = Fabricate(:problem, :app => @app) | ||
136 | + @err = Fabricate(:err, :problem => @problem) | ||
137 | end | 137 | end |
138 | 138 | ||
139 | it "#notices_count returns 0 by default" do | 139 | it "#notices_count returns 0 by default" do |
@@ -142,12 +142,12 @@ describe Problem do | @@ -142,12 +142,12 @@ describe Problem do | ||
142 | 142 | ||
143 | it "adding a notice increases #notices_count by 1" do | 143 | it "adding a notice increases #notices_count by 1" do |
144 | lambda { | 144 | lambda { |
145 | - Factory(:notice, :err => @err, :message => 'ERR 1') | 145 | + Fabricate(:notice, :err => @err, :message => 'ERR 1') |
146 | }.should change(@problem, :notices_count).from(0).to(1) | 146 | }.should change(@problem, :notices_count).from(0).to(1) |
147 | end | 147 | end |
148 | 148 | ||
149 | it "removing a notice decreases #notices_count by 1" do | 149 | it "removing a notice decreases #notices_count by 1" do |
150 | - notice1 = Factory(:notice, :err => @err, :message => 'ERR 1') | 150 | + notice1 = Fabricate(:notice, :err => @err, :message => 'ERR 1') |
151 | lambda { | 151 | lambda { |
152 | @err.notices.first.destroy | 152 | @err.notices.first.destroy |
153 | @problem.reload | 153 | @problem.reload |
@@ -157,19 +157,18 @@ describe Problem do | @@ -157,19 +157,18 @@ describe Problem do | ||
157 | 157 | ||
158 | 158 | ||
159 | context "#app_name" do | 159 | context "#app_name" do |
160 | - before do | ||
161 | - @app = Factory(:app) | ||
162 | - end | 160 | + let!(:app) { Fabricate(:app) } |
161 | + let!(:problem) { Fabricate(:problem, :app => app) } | ||
162 | + | ||
163 | + before { app.reload } | ||
163 | 164 | ||
164 | it "is set when a problem is created" do | 165 | it "is set when a problem is created" do |
165 | - problem = Factory(:problem, :app => @app) | ||
166 | - assert_equal @app.name, problem.app_name | 166 | + assert_equal app.name, problem.app_name |
167 | end | 167 | end |
168 | 168 | ||
169 | it "is updated when an app is updated" do | 169 | it "is updated when an app is updated" do |
170 | - problem = Factory(:problem, :app => @app) | ||
171 | lambda { | 170 | lambda { |
172 | - @app.update_attributes!(:name => "Bar App") | 171 | + app.update_attributes!(:name => "Bar App") |
173 | problem.reload | 172 | problem.reload |
174 | }.should change(problem, :app_name).to("Bar App") | 173 | }.should change(problem, :app_name).to("Bar App") |
175 | end | 174 | end |
@@ -178,21 +177,21 @@ describe Problem do | @@ -178,21 +177,21 @@ describe Problem do | ||
178 | 177 | ||
179 | context "#last_deploy_at" do | 178 | context "#last_deploy_at" do |
180 | before do | 179 | before do |
181 | - @app = Factory(:app) | 180 | + @app = Fabricate(:app) |
182 | @last_deploy = 10.days.ago.localtime.round(0) | 181 | @last_deploy = 10.days.ago.localtime.round(0) |
183 | - deploy = Factory(:deploy, :app => @app, :created_at => @last_deploy, :environment => "production") | 182 | + deploy = Fabricate(:deploy, :app => @app, :created_at => @last_deploy, :environment => "production") |
184 | end | 183 | end |
185 | 184 | ||
186 | it "is set when a problem is created" do | 185 | it "is set when a problem is created" do |
187 | - problem = Factory(:problem, :app => @app, :environment => "production") | 186 | + problem = Fabricate(:problem, :app => @app, :environment => "production") |
188 | assert_equal @last_deploy, problem.last_deploy_at | 187 | assert_equal @last_deploy, problem.last_deploy_at |
189 | end | 188 | end |
190 | 189 | ||
191 | it "is updated when a deploy is created" do | 190 | it "is updated when a deploy is created" do |
192 | - problem = Factory(:problem, :app => @app, :environment => "production") | 191 | + problem = Fabricate(:problem, :app => @app, :environment => "production") |
193 | next_deploy = 5.minutes.ago.localtime.round(0) | 192 | next_deploy = 5.minutes.ago.localtime.round(0) |
194 | lambda { | 193 | lambda { |
195 | - @deploy = Factory(:deploy, :app => @app, :created_at => next_deploy) | 194 | + @deploy = Fabricate(:deploy, :app => @app, :created_at => next_deploy) |
196 | problem.reload | 195 | problem.reload |
197 | }.should change(problem, :last_deploy_at).from(@last_deploy).to(next_deploy) | 196 | }.should change(problem, :last_deploy_at).from(@last_deploy).to(next_deploy) |
198 | end | 197 | end |
@@ -200,9 +199,9 @@ describe Problem do | @@ -200,9 +199,9 @@ describe Problem do | ||
200 | 199 | ||
201 | context "notice messages cache" do | 200 | context "notice messages cache" do |
202 | before do | 201 | before do |
203 | - @app = Factory(:app) | ||
204 | - @problem = Factory(:problem, :app => @app) | ||
205 | - @err = Factory(:err, :problem => @problem) | 202 | + @app = Fabricate(:app) |
203 | + @problem = Fabricate(:problem, :app => @app) | ||
204 | + @err = Fabricate(:err, :problem => @problem) | ||
206 | end | 205 | end |
207 | 206 | ||
208 | it "#messages should be empty by default" do | 207 | it "#messages should be empty by default" do |
@@ -211,12 +210,12 @@ describe Problem do | @@ -211,12 +210,12 @@ describe Problem do | ||
211 | 210 | ||
212 | it "adding a notice adds a string to #messages" do | 211 | it "adding a notice adds a string to #messages" do |
213 | lambda { | 212 | lambda { |
214 | - Factory(:notice, :err => @err, :message => 'ERR 1') | 213 | + Fabricate(:notice, :err => @err, :message => 'ERR 1') |
215 | }.should change(@problem, :messages).from({}).to({Digest::MD5.hexdigest('ERR 1') => {'value' => 'ERR 1', 'count' => 1}}) | 214 | }.should change(@problem, :messages).from({}).to({Digest::MD5.hexdigest('ERR 1') => {'value' => 'ERR 1', 'count' => 1}}) |
216 | end | 215 | end |
217 | 216 | ||
218 | it "removing a notice removes string from #messages" do | 217 | it "removing a notice removes string from #messages" do |
219 | - notice1 = Factory(:notice, :err => @err, :message => 'ERR 1') | 218 | + notice1 = Fabricate(:notice, :err => @err, :message => 'ERR 1') |
220 | lambda { | 219 | lambda { |
221 | @err.notices.first.destroy | 220 | @err.notices.first.destroy |
222 | @problem.reload | 221 | @problem.reload |
@@ -226,9 +225,9 @@ describe Problem do | @@ -226,9 +225,9 @@ describe Problem do | ||
226 | 225 | ||
227 | context "notice hosts cache" do | 226 | context "notice hosts cache" do |
228 | before do | 227 | before do |
229 | - @app = Factory(:app) | ||
230 | - @problem = Factory(:problem, :app => @app) | ||
231 | - @err = Factory(:err, :problem => @problem) | 228 | + @app = Fabricate(:app) |
229 | + @problem = Fabricate(:problem, :app => @app) | ||
230 | + @err = Fabricate(:err, :problem => @problem) | ||
232 | end | 231 | end |
233 | 232 | ||
234 | it "#hosts should be empty by default" do | 233 | it "#hosts should be empty by default" do |
@@ -237,12 +236,12 @@ describe Problem do | @@ -237,12 +236,12 @@ describe Problem do | ||
237 | 236 | ||
238 | it "adding a notice adds a string to #hosts" do | 237 | it "adding a notice adds a string to #hosts" do |
239 | lambda { | 238 | lambda { |
240 | - Factory(:notice, :err => @err, :request => {'url' => "http://example.com/resource/12"}) | 239 | + Fabricate(:notice, :err => @err, :request => {'url' => "http://example.com/resource/12"}) |
241 | }.should change(@problem, :hosts).from({}).to({Digest::MD5.hexdigest('example.com') => {'value' => 'example.com', 'count' => 1}}) | 240 | }.should change(@problem, :hosts).from({}).to({Digest::MD5.hexdigest('example.com') => {'value' => 'example.com', 'count' => 1}}) |
242 | end | 241 | end |
243 | 242 | ||
244 | it "removing a notice removes string from #hosts" do | 243 | it "removing a notice removes string from #hosts" do |
245 | - notice1 = Factory(:notice, :err => @err, :request => {'url' => "http://example.com/resource/12"}) | 244 | + notice1 = Fabricate(:notice, :err => @err, :request => {'url' => "http://example.com/resource/12"}) |
246 | lambda { | 245 | lambda { |
247 | @err.notices.first.destroy | 246 | @err.notices.first.destroy |
248 | @problem.reload | 247 | @problem.reload |
@@ -252,9 +251,9 @@ describe Problem do | @@ -252,9 +251,9 @@ describe Problem do | ||
252 | 251 | ||
253 | context "notice user_agents cache" do | 252 | context "notice user_agents cache" do |
254 | before do | 253 | before do |
255 | - @app = Factory(:app) | ||
256 | - @problem = Factory(:problem, :app => @app) | ||
257 | - @err = Factory(:err, :problem => @problem) | 254 | + @app = Fabricate(:app) |
255 | + @problem = Fabricate(:problem, :app => @app) | ||
256 | + @err = Fabricate(:err, :problem => @problem) | ||
258 | end | 257 | end |
259 | 258 | ||
260 | it "#user_agents should be empty by default" do | 259 | it "#user_agents should be empty by default" do |
@@ -263,12 +262,12 @@ describe Problem do | @@ -263,12 +262,12 @@ describe Problem do | ||
263 | 262 | ||
264 | it "adding a notice adds a string to #user_agents" do | 263 | it "adding a notice adds a string to #user_agents" do |
265 | lambda { | 264 | lambda { |
266 | - Factory(:notice, :err => @err, :request => {'cgi-data' => {'HTTP_USER_AGENT' => 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_7; en-US) AppleWebKit/534.16 (KHTML, like Gecko) Chrome/10.0.648.204 Safari/534.16'}}) | 265 | + Fabricate(:notice, :err => @err, :request => {'cgi-data' => {'HTTP_USER_AGENT' => 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_7; en-US) AppleWebKit/534.16 (KHTML, like Gecko) Chrome/10.0.648.204 Safari/534.16'}}) |
267 | }.should change(@problem, :user_agents).from({}).to({Digest::MD5.hexdigest('Chrome 10.0.648.204') => {'value' => 'Chrome 10.0.648.204', 'count' => 1}}) | 266 | }.should change(@problem, :user_agents).from({}).to({Digest::MD5.hexdigest('Chrome 10.0.648.204') => {'value' => 'Chrome 10.0.648.204', 'count' => 1}}) |
268 | end | 267 | end |
269 | 268 | ||
270 | it "removing a notice removes string from #user_agents" do | 269 | it "removing a notice removes string from #user_agents" do |
271 | - notice1 = Factory(:notice, :err => @err, :request => {'cgi-data' => {'HTTP_USER_AGENT' => 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_7; en-US) AppleWebKit/534.16 (KHTML, like Gecko) Chrome/10.0.648.204 Safari/534.16'}}) | 270 | + notice1 = Fabricate(:notice, :err => @err, :request => {'cgi-data' => {'HTTP_USER_AGENT' => 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_7; en-US) AppleWebKit/534.16 (KHTML, like Gecko) Chrome/10.0.648.204 Safari/534.16'}}) |
272 | lambda { | 271 | lambda { |
273 | @err.notices.first.destroy | 272 | @err.notices.first.destroy |
274 | @problem.reload | 273 | @problem.reload |
@@ -278,8 +277,8 @@ describe Problem do | @@ -278,8 +277,8 @@ describe Problem do | ||
278 | 277 | ||
279 | context "comment counter cache" do | 278 | context "comment counter cache" do |
280 | before do | 279 | before do |
281 | - @app = Factory(:app) | ||
282 | - @problem = Factory(:problem, :app => @app) | 280 | + @app = Fabricate(:app) |
281 | + @problem = Fabricate(:problem, :app => @app) | ||
283 | end | 282 | end |
284 | 283 | ||
285 | it "#comments_count returns 0 by default" do | 284 | it "#comments_count returns 0 by default" do |
@@ -288,12 +287,12 @@ describe Problem do | @@ -288,12 +287,12 @@ describe Problem do | ||
288 | 287 | ||
289 | it "adding a comment increases #comments_count by 1" do | 288 | it "adding a comment increases #comments_count by 1" do |
290 | lambda { | 289 | lambda { |
291 | - Factory(:comment, :err => @problem) | 290 | + Fabricate(:comment, :err => @problem) |
292 | }.should change(@problem, :comments_count).from(0).to(1) | 291 | }.should change(@problem, :comments_count).from(0).to(1) |
293 | end | 292 | end |
294 | 293 | ||
295 | it "removing a comment decreases #comments_count by 1" do | 294 | it "removing a comment decreases #comments_count by 1" do |
296 | - comment1 = Factory(:comment, :err => @problem) | 295 | + comment1 = Fabricate(:comment, :err => @problem) |
297 | lambda { | 296 | lambda { |
298 | @problem.reload.comments.first.destroy | 297 | @problem.reload.comments.first.destroy |
299 | @problem.reload | 298 | @problem.reload |