Commit 4b7804e48a10d3ea5547fbdb1d5d95b20b7be17e

Authored by Nathan B
2 parents e5875d94 de1cd644
Exists in master and in 1 other branch production

Merge pull request #134 from shingara/fabrication_gem

Migration from factory girls to Fabrication Gem
Showing 42 changed files with 397 additions and 378 deletions   Show diff stats
Gemfile
... ... @@ -31,8 +31,7 @@ gem 'ri_cal'
31 31 group :development, :test do
32 32 gem 'rspec-rails', '~> 2.6'
33 33 gem 'webmock', :require => false
34   - gem 'factory_girl', '~> 1.3.3'
35   - gem 'factory_girl_rails', '~> 1.0.1'
  34 + gem 'fabrication'
36 35 unless ENV['TRAVIS']
37 36 gem 'ruby-debug', :platform => :mri_18
38 37 gem 'ruby-debug19', :platform => :mri_19, :require => 'ruby-debug'
... ...
Gemfile.lock
... ... @@ -55,10 +55,7 @@ GEM
55 55 rspec (~> 2.0)
56 56 erubis (2.6.6)
57 57 abstract (>= 1.0.0)
58   - factory_girl (1.3.3)
59   - factory_girl_rails (1.0.1)
60   - factory_girl (~> 1.3)
61   - railties (>= 3.0.0)
  58 + fabrication (1.2.0)
62 59 faraday (0.7.4)
63 60 addressable (~> 2.2.6)
64 61 multipart-post (~> 1.1.0)
... ... @@ -219,8 +216,7 @@ DEPENDENCIES
219 216 database_cleaner (~> 0.6.0)
220 217 devise (~> 1.4.0)
221 218 email_spec
222   - factory_girl (~> 1.3.3)
223   - factory_girl_rails (~> 1.0.1)
  219 + fabrication
224 220 haml
225 221 hoptoad_notifier (~> 2.4)
226 222 htmlentities (~> 4.3.0)
... ...
app/models/problem.rb
... ... @@ -116,7 +116,9 @@ class Problem
116 116 self.last_deploy_at = if (last_deploy = app.deploys.where(:environment => self.environment).last)
117 117 last_deploy.created_at
118 118 end
119   - self.save if persisted?
  119 + collection.update({'_id' => self.id},
  120 + {'$set' => {'app_name' => self.app_name,
  121 + 'last_deploy_at' => self.last_deploy_at}})
120 122 end
121 123 end
122 124  
... ...
config/application.rb
... ... @@ -45,6 +45,7 @@ module Errbit
45 45 g.orm :mongoid
46 46 g.template_engine :haml
47 47 g.test_framework :rspec, :fixture => false
  48 + g.fixture_replacement :fabrication
48 49 end
49 50  
50 51 # IssueTracker subclasses use inheritance, so preloading models provides querying consistency in dev mode.
... ...
spec/controllers/apps_controller_spec.rb
... ... @@ -10,8 +10,8 @@ describe AppsController do
10 10 describe "GET /apps" do
11 11 context 'when logged in as an admin' do
12 12 it 'finds all apps' do
13   - sign_in Factory(:admin)
14   - 3.times { Factory(:app) }
  13 + sign_in Fabricate(:admin)
  14 + 3.times { Fabricate(:app) }
15 15 apps = App.all
16 16 get :index
17 17 assigns(:apps).should == apps
... ... @@ -20,12 +20,12 @@ describe AppsController do
20 20  
21 21 context 'when logged in as a regular user' do
22 22 it 'finds apps the user is watching' do
23   - sign_in(user = Factory(:user))
24   - unwatched_app = Factory(:app)
25   - watched_app1 = Factory(:app)
26   - watched_app2 = Factory(:app)
27   - Factory(:user_watcher, :user => user, :app => watched_app1)
28   - Factory(:user_watcher, :user => user, :app => watched_app2)
  23 + sign_in(user = Fabricate(:user))
  24 + unwatched_app = Fabricate(:app)
  25 + watched_app1 = Fabricate(:app)
  26 + watched_app2 = Fabricate(:app)
  27 + Fabricate(:user_watcher, :user => user, :app => watched_app1)
  28 + Fabricate(:user_watcher, :user => user, :app => watched_app2)
29 29 get :index
30 30 assigns(:apps).should include(watched_app1, watched_app2)
31 31 assigns(:apps).should_not include(unwatched_app)
... ... @@ -36,10 +36,10 @@ describe AppsController do
36 36 describe "GET /apps/:id" do
37 37 context 'logged in as an admin' do
38 38 before(:each) do
39   - @user = Factory(:admin)
  39 + @user = Fabricate(:admin)
40 40 sign_in @user
41   - @app = Factory(:app)
42   - @problem = Factory(:notice, :err => Factory(:err, :problem => Factory(:problem, :app => @app))).problem
  41 + @app = Fabricate(:app)
  42 + @problem = Fabricate(:notice, :err => Fabricate(:err, :problem => Fabricate(:problem, :app => @app))).problem
43 43 end
44 44  
45 45 it 'finds the app' do
... ... @@ -48,7 +48,7 @@ describe AppsController do
48 48 end
49 49  
50 50 it "should not raise errors for app with err without notices" do
51   - Factory(:err, :problem => Factory(:problem, :app => @app))
  51 + Fabricate(:err, :problem => Fabricate(:problem, :app => @app))
52 52 lambda { get :show, :id => @app.id }.should_not raise_error
53 53 end
54 54  
... ... @@ -60,7 +60,7 @@ describe AppsController do
60 60  
61 61 context "pagination" do
62 62 before(:each) do
63   - 35.times { Factory(:err, :problem => Factory(:problem, :app => @app)) }
  63 + 35.times { Fabricate(:err, :problem => Fabricate(:problem, :app => @app)) }
64 64 end
65 65  
66 66 it "should have default per_page value for user" do
... ... @@ -77,8 +77,8 @@ describe AppsController do
77 77  
78 78 context 'with resolved errors' do
79 79 before(:each) do
80   - resolved_problem = Factory(:problem, :app => @app)
81   - Factory(:notice, :err => Factory(:err, :problem => resolved_problem))
  80 + resolved_problem = Fabricate(:problem, :app => @app)
  81 + Fabricate(:notice, :err => Fabricate(:err, :problem => resolved_problem))
82 82 resolved_problem.resolve!
83 83 end
84 84  
... ... @@ -101,7 +101,7 @@ describe AppsController do
101 101 before(:each) do
102 102 environments = ['production', 'test', 'development', 'staging']
103 103 20.times do |i|
104   - Factory.create(:problem, :app => @app, :environment => environments[i % environments.length])
  104 + Fabricate(:problem, :app => @app, :environment => environments[i % environments.length])
105 105 end
106 106 end
107 107  
... ... @@ -144,17 +144,17 @@ describe AppsController do
144 144  
145 145 context 'logged in as a user' do
146 146 it 'finds the app if the user is watching it' do
147   - user = Factory(:user)
148   - app = Factory(:app)
149   - watcher = Factory(:user_watcher, :app => app, :user => user)
  147 + user = Fabricate(:user)
  148 + app = Fabricate(:app)
  149 + watcher = Fabricate(:user_watcher, :app => app, :user => user)
150 150 sign_in user
151 151 get :show, :id => app.id
152 152 assigns(:app).should == app
153 153 end
154 154  
155 155 it 'does not find the app if the user is not watching it' do
156   - sign_in Factory(:user)
157   - app = Factory(:app)
  156 + sign_in Fabricate(:user)
  157 + app = Fabricate(:app)
158 158 lambda {
159 159 get :show, :id => app.id
160 160 }.should raise_error(Mongoid::Errors::DocumentNotFound)
... ... @@ -164,7 +164,7 @@ describe AppsController do
164 164  
165 165 context 'logged in as an admin' do
166 166 before do
167   - sign_in Factory(:admin)
  167 + sign_in Fabricate(:admin)
168 168 end
169 169  
170 170 describe "GET /apps/new" do
... ... @@ -176,7 +176,7 @@ describe AppsController do
176 176 end
177 177  
178 178 it "should copy attributes from an existing app" do
179   - @app = Factory(:app, :name => "do not copy",
  179 + @app = Fabricate(:app, :name => "do not copy",
180 180 :github_url => "github.com/test/example")
181 181 get :new, :copy_attributes_from => @app.id
182 182 assigns(:app).should be_a(App)
... ... @@ -188,7 +188,7 @@ describe AppsController do
188 188  
189 189 describe "GET /apps/:id/edit" do
190 190 it 'finds the correct app' do
191   - app = Factory(:app)
  191 + app = Fabricate(:app)
192 192 get :edit, :id => app.id
193 193 assigns(:app).should == app
194 194 end
... ... @@ -196,7 +196,7 @@ describe AppsController do
196 196  
197 197 describe "POST /apps" do
198 198 before do
199   - @app = Factory(:app)
  199 + @app = Fabricate(:app)
200 200 App.stub(:new).and_return(@app)
201 201 end
202 202  
... ... @@ -219,7 +219,7 @@ describe AppsController do
219 219  
220 220 describe "PUT /apps/:id" do
221 221 before do
222   - @app = Factory(:app)
  222 + @app = Fabricate(:app)
223 223 end
224 224  
225 225 context "when the update is successful" do
... ... @@ -257,7 +257,7 @@ describe AppsController do
257 257 end
258 258 context "failed parsing of CSV" do
259 259 it "should set the default value" do
260   - @app = Factory(:app, :email_at_notices => [1, 2, 3, 4])
  260 + @app = Fabricate(:app, :email_at_notices => [1, 2, 3, 4])
261 261 put :update, :id => @app.id, :app => { :email_at_notices => 'asdf, -1,0,foobar,gd00,0,abc' }
262 262 @app.reload
263 263 @app.email_at_notices.should == Errbit::Config.email_at_notices
... ... @@ -320,7 +320,7 @@ describe AppsController do
320 320  
321 321 describe "DELETE /apps/:id" do
322 322 before do
323   - @app = Factory(:app)
  323 + @app = Fabricate(:app)
324 324 App.stub(:find).with(@app.id).and_return(@app)
325 325 end
326 326  
... ...
spec/controllers/deploys_controller_spec.rb
... ... @@ -12,7 +12,7 @@ describe DeploysController do
12 12 'scm_revision' => '19d77837eef37902cf5df7e4445c85f392a8d0d5',
13 13 'message' => 'johns first deploy'
14 14 }
15   - @app = Factory(:app_with_watcher, :notify_on_deploys => true, :api_key => 'APIKEY')
  15 + @app = Fabricate(:app_with_watcher, :notify_on_deploys => true, :api_key => 'APIKEY')
16 16 end
17 17  
18 18 it 'finds the app via the api key' do
... ... @@ -30,7 +30,7 @@ describe DeploysController do
30 30 :revision => '19d77837eef37902cf5df7e4445c85f392a8d0d5',
31 31 :message => 'johns first deploy'
32 32  
33   - }).and_return(Factory(:deploy))
  33 + }).and_return(Fabricate(:deploy))
34 34 post :create, :deploy => @params, :api_key => 'APIKEY'
35 35 end
36 36  
... ... @@ -45,8 +45,8 @@ describe DeploysController do
45 45  
46 46 context "GET #index" do
47 47 before(:each) do
48   - @deploy = Factory :deploy
49   - sign_in Factory(:admin)
  48 + @deploy = Fabricate :deploy
  49 + sign_in Fabricate(:admin)
50 50 get :index, :app_id => @deploy.app.id
51 51 end
52 52  
... ...
spec/controllers/errs_controller_spec.rb
... ... @@ -7,17 +7,17 @@ describe ErrsController do
7 7 },
8 8 :params => {:app_id => 'dummyid', :id => 'dummyid'}
9 9  
10   - let(:app) { Factory(:app) }
11   - let(:err) { Factory(:err, :problem => Factory(:problem, :app => app, :environment => "production")) }
  10 + let(:app) { Fabricate(:app) }
  11 + let(:err) { Fabricate(:err, :problem => Fabricate(:problem, :app => app, :environment => "production")) }
12 12  
13 13  
14 14 describe "GET /errs" do
15 15 render_views
16 16 context 'when logged in as an admin' do
17 17 before(:each) do
18   - @user = Factory(:admin)
  18 + @user = Fabricate(:admin)
19 19 sign_in @user
20   - @problem = Factory(:notice, :err => Factory(:err, :problem => Factory(:problem, :app => app, :environment => "production"))).problem
  20 + @problem = Fabricate(:notice, :err => Fabricate(:err, :problem => Fabricate(:problem, :app => app, :environment => "production"))).problem
21 21 end
22 22  
23 23 it "should successfully list errs" do
... ... @@ -34,7 +34,7 @@ describe ErrsController do
34 34  
35 35 context "pagination" do
36 36 before(:each) do
37   - 35.times { Factory :err }
  37 + 35.times { Fabricate :err }
38 38 end
39 39  
40 40 it "should have default per_page value for user" do
... ... @@ -53,7 +53,7 @@ describe ErrsController do
53 53 before(:each) do
54 54 environments = ['production', 'test', 'development', 'staging']
55 55 20.times do |i|
56   - Factory(:problem, :environment => environments[i % environments.length])
  56 + Fabricate(:problem, :environment => environments[i % environments.length])
57 57 end
58 58 end
59 59  
... ... @@ -96,10 +96,10 @@ describe ErrsController do
96 96  
97 97 context 'when logged in as a user' do
98 98 it 'gets a paginated list of unresolved errs for the users apps' do
99   - sign_in(user = Factory(:user))
100   - unwatched_err = Factory(:err)
101   - watched_unresolved_err = Factory(:err, :problem => Factory(:problem, :app => Factory(:user_watcher, :user => user).app, :resolved => false))
102   - watched_resolved_err = Factory(:err, :problem => Factory(:problem, :app => Factory(:user_watcher, :user => user).app, :resolved => true))
  99 + sign_in(user = Fabricate(:user))
  100 + unwatched_err = Fabricate(:err)
  101 + watched_unresolved_err = Fabricate(:err, :problem => Fabricate(:problem, :app => Fabricate(:user_watcher, :user => user).app, :resolved => false))
  102 + watched_resolved_err = Fabricate(:err, :problem => Fabricate(:problem, :app => Fabricate(:user_watcher, :user => user).app, :resolved => true))
103 103 get :index
104 104 assigns(:problems).should include(watched_unresolved_err.problem)
105 105 assigns(:problems).should_not include(unwatched_err.problem, watched_resolved_err.problem)
... ... @@ -110,10 +110,10 @@ describe ErrsController do
110 110 describe "GET /errs/all" do
111 111 context 'when logged in as an admin' do
112 112 it "gets a paginated list of all errs" do
113   - sign_in Factory(:admin)
  113 + sign_in Fabricate(:admin)
114 114 errs = Kaminari.paginate_array((1..30).to_a)
115   - 3.times { errs << Factory(:err).problem }
116   - 3.times { errs << Factory(:err, :problem => Factory(:problem, :resolved => true)).problem }
  115 + 3.times { errs << Fabricate(:err).problem }
  116 + 3.times { errs << Fabricate(:err, :problem => Fabricate(:problem, :resolved => true)).problem }
117 117 Problem.should_receive(:ordered).and_return(
118 118 mock('proxy', :page => mock('other_proxy', :per => errs))
119 119 )
... ... @@ -124,10 +124,10 @@ describe ErrsController do
124 124  
125 125 context 'when logged in as a user' do
126 126 it 'gets a paginated list of all errs for the users apps' do
127   - sign_in(user = Factory(:user))
128   - unwatched_err = Factory(:problem)
129   - watched_unresolved_err = Factory(:problem, :app => Factory(:user_watcher, :user => user).app, :resolved => false)
130   - watched_resolved_err = Factory(:problem, :app => Factory(:user_watcher, :user => user).app, :resolved => true)
  127 + sign_in(user = Fabricate(:user))
  128 + unwatched_err = Fabricate(:problem)
  129 + watched_unresolved_err = Fabricate(:problem, :app => Fabricate(:user_watcher, :user => user).app, :resolved => false)
  130 + watched_resolved_err = Fabricate(:problem, :app => Fabricate(:user_watcher, :user => user).app, :resolved => true)
131 131 get :all
132 132 assigns(:problems).should include(watched_resolved_err, watched_unresolved_err)
133 133 assigns(:problems).should_not include(unwatched_err)
... ... @@ -139,12 +139,12 @@ describe ErrsController do
139 139 render_views
140 140  
141 141 before do
142   - 3.times { Factory(:notice, :err => err)}
  142 + 3.times { Fabricate(:notice, :err => err)}
143 143 end
144 144  
145 145 context 'when logged in as an admin' do
146 146 before do
147   - sign_in Factory(:admin)
  147 + sign_in Fabricate(:admin)
148 148 end
149 149  
150 150 it "finds the app" do
... ... @@ -166,23 +166,23 @@ describe ErrsController do
166 166 let(:button_matcher) { match(/create issue/) }
167 167  
168 168 it "should not exist for err's app without issue tracker" do
169   - err = Factory :err
  169 + err = Fabricate :err
170 170 get :show, :app_id => err.app.id, :id => err.problem.id
171 171  
172 172 response.body.should_not button_matcher
173 173 end
174 174  
175 175 it "should exist for err's app with issue tracker" do
176   - tracker = Factory(:lighthouse_tracker)
177   - err = Factory(:err, :problem => Factory(:problem, :app => tracker.app))
  176 + tracker = Fabricate(:lighthouse_tracker)
  177 + err = Fabricate(:err, :problem => Fabricate(:problem, :app => tracker.app))
178 178 get :show, :app_id => err.app.id, :id => err.problem.id
179 179  
180 180 response.body.should button_matcher
181 181 end
182 182  
183 183 it "should not exist for err with issue_link" do
184   - tracker = Factory(:lighthouse_tracker)
185   - err = Factory(:err, :problem => Factory(:problem, :app => tracker.app, :issue_link => "http://some.host"))
  184 + tracker = Fabricate(:lighthouse_tracker)
  185 + err = Fabricate(:err, :problem => Fabricate(:problem, :app => tracker.app, :issue_link => "http://some.host"))
186 186 get :show, :app_id => err.app.id, :id => err.problem.id
187 187  
188 188 response.body.should_not button_matcher
... ... @@ -192,11 +192,11 @@ describe ErrsController do
192 192  
193 193 context 'when logged in as a user' do
194 194 before do
195   - sign_in(@user = Factory(:user))
196   - @unwatched_err = Factory(:err)
197   - @watched_app = Factory(:app)
198   - @watcher = Factory(:user_watcher, :user => @user, :app => @watched_app)
199   - @watched_err = Factory(:err, :problem => Factory(:problem, :app => @watched_app))
  195 + sign_in(@user = Fabricate(:user))
  196 + @unwatched_err = Fabricate(:err)
  197 + @watched_app = Fabricate(:app)
  198 + @watcher = Fabricate(:user_watcher, :user => @user, :app => @watched_app)
  199 + @watched_err = Fabricate(:err, :problem => Fabricate(:problem, :app => @watched_app))
200 200 end
201 201  
202 202 it 'finds the err if the user is watching the app' do
... ... @@ -214,9 +214,9 @@ describe ErrsController do
214 214  
215 215 describe "PUT /apps/:app_id/errs/:id/resolve" do
216 216 before do
217   - sign_in Factory(:admin)
  217 + sign_in Fabricate(:admin)
218 218  
219   - @problem = Factory(:err)
  219 + @problem = Fabricate(:err)
220 220 App.stub(:find).with(@problem.app.id).and_return(@problem.app)
221 221 @problem.app.problems.stub(:find).and_return(@problem.problem)
222 222 @problem.problem.stub(:resolve!)
... ... @@ -256,13 +256,13 @@ describe ErrsController do
256 256 render_views
257 257  
258 258 before(:each) do
259   - sign_in Factory(:admin)
  259 + sign_in Fabricate(:admin)
260 260 end
261 261  
262 262 context "successful issue creation" do
263 263 context "lighthouseapp tracker" do
264   - let(:notice) { Factory :notice }
265   - let(:tracker) { Factory :lighthouse_tracker, :app => notice.app }
  264 + let(:notice) { Fabricate :notice }
  265 + let(:tracker) { Fabricate :lighthouse_tracker, :app => notice.app }
266 266 let(:problem) { notice.problem }
267 267  
268 268 before(:each) do
... ... @@ -283,7 +283,7 @@ describe ErrsController do
283 283 end
284 284  
285 285 context "absent issue tracker" do
286   - let(:problem) { Factory :problem }
  286 + let(:problem) { Fabricate :problem }
287 287  
288 288 before(:each) do
289 289 post :create_issue, :app_id => problem.app.id, :id => problem.id
... ... @@ -300,8 +300,8 @@ describe ErrsController do
300 300  
301 301 context "error during request to a tracker" do
302 302 context "lighthouseapp tracker" do
303   - let(:tracker) { Factory :lighthouse_tracker }
304   - let(:err) { Factory(:err, :problem => Factory(:problem, :app => tracker.app)) }
  303 + let(:tracker) { Fabricate :lighthouse_tracker }
  304 + let(:err) { Fabricate(:err, :problem => Fabricate(:problem, :app => tracker.app)) }
305 305  
306 306 before(:each) do
307 307 stub_request(:post, "http://#{tracker.account}.lighthouseapp.com/projects/#{tracker.project_id}/tickets.xml").to_return(:status => 500)
... ... @@ -322,11 +322,11 @@ describe ErrsController do
322 322  
323 323 describe "DELETE /apps/:app_id/errs/:id/unlink_issue" do
324 324 before(:each) do
325   - sign_in Factory(:admin)
  325 + sign_in Fabricate(:admin)
326 326 end
327 327  
328 328 context "err with issue" do
329   - let(:err) { Factory(:err, :problem => Factory(:problem, :issue_link => "http://some.host")) }
  329 + let(:err) { Fabricate(:err, :problem => Fabricate(:problem, :issue_link => "http://some.host")) }
330 330  
331 331 before(:each) do
332 332 delete :unlink_issue, :app_id => err.app.id, :id => err.problem.id
... ... @@ -343,7 +343,7 @@ describe ErrsController do
343 343 end
344 344  
345 345 context "err without issue" do
346   - let(:err) { Factory :err }
  346 + let(:err) { Fabricate :err }
347 347  
348 348 before(:each) do
349 349 delete :unlink_issue, :app_id => err.app.id, :id => err.problem.id
... ... @@ -361,12 +361,12 @@ describe ErrsController do
361 361 render_views
362 362  
363 363 before(:each) do
364   - sign_in Factory(:admin)
  364 + sign_in Fabricate(:admin)
365 365 end
366 366  
367 367 context "successful comment creation" do
368   - let(:problem) { Factory(:problem) }
369   - let(:user) { Factory(:user) }
  368 + let(:problem) { Fabricate(:problem) }
  369 + let(:user) { Fabricate(:user) }
370 370  
371 371 before(:each) do
372 372 post :create_comment, :app_id => problem.app.id, :id => problem.id,
... ... @@ -388,15 +388,15 @@ describe ErrsController do
388 388 render_views
389 389  
390 390 before(:each) do
391   - sign_in Factory(:admin)
  391 + sign_in Fabricate(:admin)
392 392 end
393 393  
394 394 context "successful comment deletion" do
395   - let(:problem) { Factory(:problem_with_comments) }
396   - let(:comment) { problem.comments.first }
  395 + let(:problem) { Fabricate(:problem_with_comments) }
  396 + let(:comment) { problem.reload.comments.first }
397 397  
398 398 before(:each) do
399   - delete :destroy_comment, :app_id => problem.app.id, :id => problem.id, :comment_id => comment.id
  399 + delete :destroy_comment, :app_id => problem.app.id, :id => problem.id, :comment_id => comment.id.to_s
400 400 problem.reload
401 401 end
402 402  
... ... @@ -412,9 +412,9 @@ describe ErrsController do
412 412  
413 413 describe "Bulk Actions" do
414 414 before(:each) do
415   - sign_in Factory(:admin)
416   - @problem1 = Factory(:err, :problem => Factory(:problem, :resolved => true)).problem
417   - @problem2 = Factory(:err, :problem => Factory(:problem, :resolved => false)).problem
  415 + sign_in Fabricate(:admin)
  416 + @problem1 = Fabricate(:err, :problem => Fabricate(:problem, :resolved => true)).problem
  417 + @problem2 = Fabricate(:err, :problem => Fabricate(:problem, :resolved => false)).problem
418 418 end
419 419  
420 420 it "should apply to multiple problems" do
... ...
spec/controllers/notices_controller_spec.rb
... ... @@ -5,7 +5,7 @@ describe NoticesController do
5 5 context 'notices API' do
6 6 before do
7 7 @xml = Rails.root.join('spec','fixtures','hoptoad_test_notice.xml').read
8   - @app = Factory(:app_with_watcher)
  8 + @app = Fabricate(:app_with_watcher)
9 9 App.stub(:find_by_api_key!).and_return(@app)
10 10 @notice = App.report_error!(@xml)
11 11  
... ...
spec/controllers/users_controller_spec.rb
... ... @@ -14,16 +14,16 @@ describe UsersController do
14 14  
15 15 context 'Signed in as a regular user' do
16 16 before do
17   - sign_in @user = Factory(:user)
  17 + sign_in @user = Fabricate(:user)
18 18 end
19   -
  19 +
20 20 it "should set a time zone" do
21 21 Time.zone.should.to_s == @user.time_zone
22 22 end
23 23  
24 24 context "GET /users/:other_id/edit" do
25 25 it "redirects to the home page" do
26   - get :edit, :id => Factory(:user).id
  26 + get :edit, :id => Fabricate(:user).id
27 27 response.should redirect_to(root_path)
28 28 end
29 29 end
... ... @@ -47,7 +47,7 @@ describe UsersController do
47 47  
48 48 context "PUT /users/:other_id" do
49 49 it "redirects to the home page" do
50   - put :update, :id => Factory(:user).id
  50 + put :update, :id => Fabricate(:user).id
51 51 response.should redirect_to(root_path)
52 52 end
53 53 end
... ... @@ -73,7 +73,7 @@ describe UsersController do
73 73 put :update, :id => @user.to_param, :user => {:per_page => 555}
74 74 @user.reload.per_page.should == 555
75 75 end
76   -
  76 +
77 77 it "should be able to set time_zone option" do
78 78 put :update, :id => @user.to_param, :user => {:time_zone => "Warsaw"}
79 79 @user.reload.time_zone.should == "Warsaw"
... ... @@ -91,14 +91,14 @@ describe UsersController do
91 91  
92 92 context 'Signed in as an admin' do
93 93 before do
94   - @user = Factory(:admin)
  94 + @user = Fabricate(:admin)
95 95 sign_in @user
96 96 end
97 97  
98 98 context "GET /users" do
99 99 it 'paginates all users' do
100 100 @user.update_attribute :per_page, 2
101   - users = 3.times { Factory(:user) }
  101 + users = 3.times { Fabricate(:user) }
102 102 get :index
103 103 assigns(:users).to_a.size.should == 2
104 104 end
... ... @@ -106,7 +106,7 @@ describe UsersController do
106 106  
107 107 context "GET /users/:id" do
108 108 it 'finds the user' do
109   - user = Factory(:user)
  109 + user = Fabricate(:user)
110 110 get :show, :id => user.id
111 111 assigns(:user).should == user
112 112 end
... ... @@ -122,7 +122,7 @@ describe UsersController do
122 122  
123 123 context "GET /users/:id/edit" do
124 124 it 'finds the user' do
125   - user = Factory(:user)
  125 + user = Fabricate(:user)
126 126 get :edit, :id => user.id
127 127 assigns(:user).should == user
128 128 end
... ... @@ -131,7 +131,7 @@ describe UsersController do
131 131 context "POST /users" do
132 132 context "when the create is successful" do
133 133 before do
134   - @attrs = {:user => Factory.attributes_for(:user)}
  134 + @attrs = {:user => Fabricate.attributes_for(:user)}
135 135 end
136 136  
137 137 it "sets a message to display" do
... ... @@ -159,7 +159,7 @@ describe UsersController do
159 159  
160 160 context "when the create is unsuccessful" do
161 161 before do
162   - @user = Factory(:user)
  162 + @user = Fabricate(:user)
163 163 User.should_receive(:new).and_return(@user)
164 164 @user.should_receive(:save).and_return(false)
165 165 end
... ... @@ -174,7 +174,7 @@ describe UsersController do
174 174 context "PUT /users/:id" do
175 175 context "when the update is successful" do
176 176 before do
177   - @user = Factory(:user)
  177 + @user = Fabricate(:user)
178 178 end
179 179  
180 180 it "sets a message to display" do
... ... @@ -196,7 +196,7 @@ describe UsersController do
196 196  
197 197 context "when the update is unsuccessful" do
198 198 before do
199   - @user = Factory(:user)
  199 + @user = Fabricate(:user)
200 200 end
201 201  
202 202 it "renders the edit page" do
... ... @@ -208,7 +208,7 @@ describe UsersController do
208 208  
209 209 context "DELETE /users/:id" do
210 210 before do
211   - @user = Factory(:user)
  211 + @user = Fabricate(:user)
212 212 end
213 213  
214 214 it "destroys the user" do
... ...
spec/fabricators/app_fabricator.rb 0 → 100644
... ... @@ -0,0 +1,27 @@
  1 +Fabricator(:app) do
  2 + name { sequence(:app_name){|n| "App ##{n}"} }
  3 +end
  4 +
  5 +Fabricator(:app_with_watcher, :from => :app) do
  6 + watchers(:count => 1) { |parent, i| Fabricate.build(:watcher, :app => parent) }
  7 +end
  8 +
  9 +Fabricator(:watcher) do
  10 + app!
  11 + watcher_type 'email'
  12 + email { sequence(:email){|n| "email#{n}@example.com"} }
  13 +end
  14 +
  15 +Fabricator(:user_watcher, :from => :watcher) do
  16 + user!
  17 + watcher_type 'user'
  18 +end
  19 +
  20 +Fabricator(:deploy) do
  21 + app!
  22 + username 'clyde.frog'
  23 + repository 'git@github.com/errbit/errbit.git'
  24 + environment 'production'
  25 + revision { ActiveSupport::SecureRandom.hex(10) }
  26 +end
  27 +
... ...
spec/fabricators/comment_fabricator.rb 0 → 100644
... ... @@ -0,0 +1,6 @@
  1 +Fabricator :comment do
  2 + user!
  3 + body 'Test comment'
  4 + err!(:fabricator => :problem)
  5 +end
  6 +
... ...
spec/fabricators/err_fabricator.rb 0 → 100644
... ... @@ -0,0 +1,27 @@
  1 +Fabricator :err do
  2 + problem!
  3 + klass! { 'FooError' }
  4 + component 'foo'
  5 + action 'bar'
  6 + environment 'production'
  7 +end
  8 +
  9 +Fabricator :notice do
  10 + err!
  11 + message 'FooError: Too Much Bar'
  12 + backtrace { random_backtrace }
  13 + server_environment { {'environment-name' => 'production'} }
  14 + request {{ 'component' => 'foo', 'action' => 'bar' }}
  15 + notifier {{ 'name' => 'Notifier', 'version' => '1', 'url' => 'http://toad.com' }}
  16 +end
  17 +
  18 +def random_backtrace
  19 + backtrace = []
  20 + 99.times {|t| backtrace << {
  21 + 'number' => rand(999),
  22 + 'file' => "/path/to/file/#{ActiveSupport::SecureRandom.hex(4)}.rb",
  23 + 'method' => ActiveSupport.methods.shuffle.first
  24 + }}
  25 + backtrace
  26 +end
  27 +
... ...
spec/fabricators/issue_tracker_fabricator.rb 0 → 100644
... ... @@ -0,0 +1,27 @@
  1 +Fabricator :issue_tracker do
  2 + app!
  3 + api_token { sequence :word }
  4 + project_id { sequence :word }
  5 + account { sequence :word }
  6 + username { sequence :word }
  7 + password { sequence :word }
  8 +end
  9 +
  10 +%w(lighthouse pivotal_labs fogbugz).each do |t|
  11 + Fabricator "#{t}_tracker".to_sym, :from => :issue_tracker, :class_name => "#{t}_tracker".to_sym
  12 +end
  13 +
  14 +Fabricator :redmine_tracker, :from => :issue_tracker, :class_name => :redmine_tracker do
  15 + account 'http://redmine.example.com'
  16 +end
  17 +
  18 +Fabricator :mingle_tracker, :from => :issue_tracker, :class_name => :mingle_tracker do
  19 + account 'https://mingle.example.com'
  20 + ticket_properties 'card_type = Defect, defect_status = open, priority = essential'
  21 +end
  22 +
  23 +Fabricator :github_issues_tracker, :from => :issue_tracker, :class_name => :github_issues_tracker do
  24 + project_id 'test_account/test_project'
  25 + username 'test_username'
  26 +end
  27 +
... ...
spec/fabricators/problem_fabricator.rb 0 → 100644
... ... @@ -0,0 +1,12 @@
  1 +Fabricator(:problem) do
  2 + app! { Fabricate(:app) }
  3 + comments { [] }
  4 +end
  5 +
  6 +Fabricator(:problem_with_comments, :from => :problem) do
  7 + after_create { |parent|
  8 + 3.times do
  9 + Fabricate(:comment, :err => parent)
  10 + end
  11 + }
  12 +end
... ...
spec/fabricators/sequences_fabricator.rb 0 → 100644
... ... @@ -0,0 +1,3 @@
  1 +Fabricate.sequence(:name) {|n| "John #{n} Doe"}
  2 +Fabricate.sequence(:word) {|n| "word#{n}"}
  3 +
... ...
spec/fabricators/user_fabricator.rb 0 → 100644
... ... @@ -0,0 +1,10 @@
  1 +Fabricator :user do
  2 + name 'Clyde Frog'
  3 + email { sequence(:user_email) {|n| "user.#{n}@example.com"} }
  4 + password 'password'
  5 + password_confirmation 'password'
  6 +end
  7 +
  8 +Fabricator :admin, :from => :user do
  9 + admin true
  10 +end
... ...
spec/factories.rb
... ... @@ -1,6 +0,0 @@
1   -Factory.sequence(:name) {|n| "John #{n} Doe"}
2   -Factory.sequence(:word) {|n| "word#{n}"}
3   -Factory.sequence(:app_name) {|n| "App ##{n}"}
4   -Factory.sequence(:email) {|n| "email#{n}@example.com"}
5   -Factory.sequence(:user_email) {|n| "user.#{n}@example.com"}
6   -
spec/factories/app_factories.rb
... ... @@ -1,29 +0,0 @@
1   -Factory.define(:app) do |p|
2   - p.name { Factory.next :app_name }
3   -end
4   -
5   -Factory.define(:app_with_watcher, :parent => :app) do |p|
6   - p.after_create {|app|
7   - Factory(:watcher, :app => app)
8   - }
9   -end
10   -
11   -Factory.define(:watcher) do |w|
12   - w.association :app
13   - w.watcher_type 'email'
14   - w.email { Factory.next :email }
15   -end
16   -
17   -Factory.define(:user_watcher, :parent => :watcher) do |w|
18   - w.watcher_type 'user'
19   - w.association :user
20   -end
21   -
22   -Factory.define(:deploy) do |d|
23   - d.app {|p| p.association :app}
24   - d.username 'clyde.frog'
25   - d.repository 'git@github.com/errbit/errbit.git'
26   - d.environment 'production'
27   - d.revision ActiveSupport::SecureRandom.hex(10)
28   -end
29   -
spec/factories/comment_factories.rb
... ... @@ -1,6 +0,0 @@
1   -Factory.define :comment do |c|
2   - c.user {|u| u.association :user}
3   - c.body 'Test comment'
4   - c.err {|e| e.association :problem}
5   -end
6   -
spec/factories/err_factories.rb
... ... @@ -1,40 +0,0 @@
1   -Factory.define :problem do |p|
2   - p.app {|a| a.association :app}
3   - p.comments []
4   -end
5   -
6   -Factory.define(:problem_with_comments, :parent => :problem) do |ec|
7   - ec.comments { (1..3).map { Factory(:comment) } }
8   -end
9   -
10   -
11   -
12   -Factory.define :err do |e|
13   - e.problem {|p| p.association :problem}
14   - e.klass 'FooError'
15   - e.component 'foo'
16   - e.action 'bar'
17   - e.environment 'production'
18   -end
19   -
20   -
21   -
22   -Factory.define :notice do |n|
23   - n.err {|e| e.association :err}
24   - n.message 'FooError: Too Much Bar'
25   - n.backtrace { random_backtrace }
26   - n.server_environment 'environment-name' => 'production'
27   - n.request {{ 'component' => 'foo', 'action' => 'bar' }}
28   - n.notifier 'name' => 'Notifier', 'version' => '1', 'url' => 'http://toad.com'
29   -end
30   -
31   -def random_backtrace
32   - backtrace = []
33   - 99.times {|t| backtrace << {
34   - 'number' => rand(999),
35   - 'file' => "/path/to/file/#{ActiveSupport::SecureRandom.hex(4)}.rb",
36   - 'method' => ActiveSupport.methods.shuffle.first
37   - }}
38   - backtrace
39   -end
40   -
spec/factories/issue_tracker_factories.rb
... ... @@ -1,27 +0,0 @@
1   -Factory.define :issue_tracker do |e|
2   - e.api_token { Factory.next :word }
3   - e.project_id { Factory.next :word }
4   - e.association :app, :factory => :app
5   - e.account { Factory.next :word }
6   - e.username { Factory.next :word }
7   - e.password { Factory.next :word }
8   -end
9   -
10   -%w(lighthouse pivotal_labs fogbugz).each do |t|
11   - Factory.define "#{t}_tracker".to_sym, :parent => :issue_tracker, :class => "#{t}_tracker".to_sym do |e|; end
12   -end
13   -
14   -Factory.define :redmine_tracker, :parent => :issue_tracker, :class => :redmine_tracker do |e|
15   - e.account 'http://redmine.example.com'
16   -end
17   -
18   -Factory.define :mingle_tracker, :parent => :issue_tracker, :class => :mingle_tracker do |e|
19   - e.account 'https://mingle.example.com'
20   - e.ticket_properties 'card_type = Defect, defect_status = open, priority = essential'
21   -end
22   -
23   -Factory.define :github_issues_tracker, :parent => :issue_tracker, :class => :github_issues_tracker do |e|
24   - e.project_id 'test_account/test_project'
25   - e.username 'test_username'
26   -end
27   -
spec/factories/user_factories.rb
... ... @@ -1,10 +0,0 @@
1   -Factory.define :user do |u|
2   - u.name 'Clyde Frog'
3   - u.email { Factory.next :user_email }
4   - u.password 'password'
5   - u.password_confirmation 'password'
6   -end
7   -
8   -Factory.define :admin, :parent => :user do |a|
9   - a.admin true
10   -end
spec/mailers/mailer_spec.rb
... ... @@ -6,7 +6,7 @@ describe Mailer do
6 6 include EmailSpec::Matchers
7 7  
8 8 before do
9   - @notice = Factory(:notice, :message => "class < ActionController::Base")
  9 + @notice = Fabricate(:notice, :message => "class < ActionController::Base")
10 10 @email = Mailer.err_notification(@notice).deliver
11 11 end
12 12  
... ...
spec/models/app_spec.rb
... ... @@ -3,21 +3,21 @@ require &#39;spec_helper&#39;
3 3 describe App do
4 4 context 'validations' do
5 5 it 'requires a name' do
6   - app = Factory.build(:app, :name => nil)
  6 + app = Fabricate.build(:app, :name => nil)
7 7 app.should_not be_valid
8 8 app.errors[:name].should include("can't be blank")
9 9 end
10 10  
11 11 it 'requires unique names' do
12   - Factory(:app, :name => 'Errbit')
13   - app = Factory.build(:app, :name => 'Errbit')
  12 + Fabricate(:app, :name => 'Errbit')
  13 + app = Fabricate.build(:app, :name => 'Errbit')
14 14 app.should_not be_valid
15 15 app.errors[:name].should include('is already taken')
16 16 end
17 17  
18 18 it 'requires unique api_keys' do
19   - Factory(:app, :api_key => 'APIKEY')
20   - app = Factory.build(:app, :api_key => 'APIKEY')
  19 + Fabricate(:app, :api_key => 'APIKEY')
  20 + app = Fabricate.build(:app, :api_key => 'APIKEY')
21 21 app.should_not be_valid
22 22 app.errors[:api_key].should include('is already taken')
23 23 end
... ... @@ -26,43 +26,43 @@ describe App do
26 26  
27 27 context 'being created' do
28 28 it 'generates a new api-key' do
29   - app = Factory.build(:app)
  29 + app = Fabricate.build(:app)
30 30 app.api_key.should be_nil
31 31 app.save
32 32 app.api_key.should_not be_nil
33 33 end
34 34  
35 35 it 'generates a correct api-key' do
36   - app = Factory(:app)
  36 + app = Fabricate(:app)
37 37 app.api_key.should match(/^[a-f0-9]{32}$/)
38 38 end
39 39  
40 40 it 'is fine with blank github urls' do
41   - app = Factory.build(:app, :github_url => "")
  41 + app = Fabricate.build(:app, :github_url => "")
42 42 app.save
43 43 app.github_url.should == ""
44 44 end
45 45  
46 46 it 'does not touch https github urls' do
47   - app = Factory.build(:app, :github_url => "https://github.com/errbit/errbit")
  47 + app = Fabricate.build(:app, :github_url => "https://github.com/errbit/errbit")
48 48 app.save
49 49 app.github_url.should == "https://github.com/errbit/errbit"
50 50 end
51 51  
52 52 it 'normalizes http github urls' do
53   - app = Factory.build(:app, :github_url => "http://github.com/errbit/errbit")
  53 + app = Fabricate.build(:app, :github_url => "http://github.com/errbit/errbit")
54 54 app.save
55 55 app.github_url.should == "https://github.com/errbit/errbit"
56 56 end
57 57  
58 58 it 'normalizes public git repo as a github url' do
59   - app = Factory.build(:app, :github_url => "https://github.com/errbit/errbit.git")
  59 + app = Fabricate.build(:app, :github_url => "https://github.com/errbit/errbit.git")
60 60 app.save
61 61 app.github_url.should == "https://github.com/errbit/errbit"
62 62 end
63 63  
64 64 it 'normalizes private git repo as a github url' do
65   - app = Factory.build(:app, :github_url => "git@github.com:errbit/errbit.git")
  65 + app = Fabricate.build(:app, :github_url => "git@github.com:errbit/errbit.git")
66 66 app.save
67 67 app.github_url.should == "https://github.com/errbit/errbit"
68 68 end
... ... @@ -70,28 +70,28 @@ describe App do
70 70  
71 71 context '#github_url_to_file' do
72 72 it 'resolves to full path to file' do
73   - app = Factory(:app, :github_url => "https://github.com/errbit/errbit")
  73 + app = Fabricate(:app, :github_url => "https://github.com/errbit/errbit")
74 74 app.github_url_to_file('/path/to/file').should == "https://github.com/errbit/errbit/blob/master/path/to/file"
75 75 end
76 76 end
77 77  
78 78 context '#github_url?' do
79 79 it 'is true when there is a github_url' do
80   - app = Factory(:app, :github_url => "https://github.com/errbit/errbit")
  80 + app = Fabricate(:app, :github_url => "https://github.com/errbit/errbit")
81 81 app.github_url?.should be_true
82 82 end
83 83  
84 84 it 'is false when no github_url' do
85   - app = Factory(:app)
  85 + app = Fabricate(:app)
86 86 app.github_url?.should be_false
87 87 end
88 88 end
89 89  
90 90 context "notification recipients" do
91 91 it "should send notices to either all users, or the configured watchers" do
92   - @app = Factory(:app)
93   - 3.times { Factory(:user) }
94   - 5.times { Factory(:watcher, :app => @app) }
  92 + @app = Fabricate(:app)
  93 + 3.times { Fabricate(:user) }
  94 + 5.times { Fabricate(:watcher, :app => @app) }
95 95 @app.notify_all_users = true
96 96 @app.notification_recipients.size.should == 3
97 97 @app.notify_all_users = false
... ... @@ -102,9 +102,9 @@ describe App do
102 102  
103 103 context "copying attributes from existing app" do
104 104 it "should only copy the necessary fields" do
105   - @app, @copy_app = Factory(:app, :name => "app", :github_url => "url"),
106   - Factory(:app, :name => "copy_app", :github_url => "copy url")
107   - @copy_watcher = Factory(:watcher, :email => "copywatcher@example.com", :app => @copy_app)
  105 + @app, @copy_app = Fabricate(:app, :name => "app", :github_url => "url"),
  106 + Fabricate(:app, :name => "copy_app", :github_url => "copy url")
  107 + @copy_watcher = Fabricate(:watcher, :email => "copywatcher@example.com", :app => @copy_app)
108 108 @app.copy_attributes_from(@copy_app.id)
109 109 @app.name.should == "app"
110 110 @app.github_url.should == "copy url"
... ... @@ -115,7 +115,7 @@ describe App do
115 115  
116 116 context '#find_or_create_err!' do
117 117 before do
118   - @app = Factory(:app)
  118 + @app = Fabricate(:app)
119 119 @conditions = {
120 120 :klass => 'Whoops',
121 121 :component => 'Foo',
... ... @@ -125,7 +125,7 @@ describe App do
125 125 end
126 126  
127 127 it 'returns the correct err if one already exists' do
128   - existing = Factory(:err, @conditions.merge(:problem => Factory(:problem, :app => @app)))
  128 + existing = Fabricate(:err, @conditions.merge(:problem => Fabricate(:problem, :app => @app)))
129 129 Err.where(@conditions).first.should == existing
130 130 @app.find_or_create_err!(@conditions).should == existing
131 131 end
... ... @@ -146,7 +146,7 @@ describe App do
146 146 context '#report_error!' do
147 147 before do
148 148 @xml = Rails.root.join('spec','fixtures','hoptoad_test_notice.xml').read
149   - @app = Factory(:app, :api_key => 'APIKEY')
  149 + @app = Fabricate(:app, :api_key => 'APIKEY')
150 150 ErrorReport.any_instance.stub(:fingerprint).and_return('fingerprintdigest')
151 151 end
152 152  
... ... @@ -163,7 +163,7 @@ describe App do
163 163 :action => 'verify',
164 164 :environment => 'development',
165 165 :fingerprint => 'fingerprintdigest'
166   - }).and_return(err = Factory(:err))
  166 + }).and_return(err = Fabricate(:err))
167 167 err.notices.stub(:create!)
168 168 @notice = App.report_error!(@xml)
169 169 end
... ... @@ -176,7 +176,7 @@ describe App do
176 176 :action => 'verify',
177 177 :environment => 'development',
178 178 :fingerprint => 'fingerprintdigest'
179   - }).and_return(err = Factory(:err, :problem => Factory(:problem, :resolved => true)))
  179 + }).and_return(err = Fabricate(:err, :problem => Fabricate(:problem, :resolved => true)))
180 180 err.should be_resolved
181 181 @notice = App.report_error!(@xml)
182 182 @notice.err.should == err
... ...
spec/models/comment_spec.rb
... ... @@ -3,7 +3,7 @@ require &#39;spec_helper&#39;
3 3 describe Comment do
4 4 context 'validations' do
5 5 it 'should require a body' do
6   - comment = Factory.build(:comment, :body => nil)
  6 + comment = Fabricate.build(:comment, :body => nil)
7 7 comment.should_not be_valid
8 8 comment.errors[:body].should include("can't be blank")
9 9 end
... ...
spec/models/deploy_spec.rb
... ... @@ -4,13 +4,13 @@ describe Deploy do
4 4  
5 5 context 'validations' do
6 6 it 'requires a username' do
7   - deploy = Factory.build(:deploy, :username => nil)
  7 + deploy = Fabricate.build(:deploy, :username => nil)
8 8 deploy.should_not be_valid
9 9 deploy.errors[:username].should include("can't be blank")
10 10 end
11 11  
12 12 it 'requires an environment' do
13   - deploy = Factory.build(:deploy, :environment => nil)
  13 + deploy = Fabricate.build(:deploy, :environment => nil)
14 14 deploy.should_not be_valid
15 15 deploy.errors[:environment].should include("can't be blank")
16 16 end
... ... @@ -20,24 +20,24 @@ describe Deploy do
20 20 it 'should send an email notification' do
21 21 Mailer.should_receive(:deploy_notification).
22 22 and_return(mock('email', :deliver => true))
23   - Factory(:deploy, :app => Factory(:app_with_watcher, :notify_on_deploys => true))
  23 + Fabricate(:deploy, :app => Fabricate(:app_with_watcher, :notify_on_deploys => true))
24 24 end
25 25  
26 26 context 'when the app has resolve_errs_on_deploy set to false' do
27 27 it 'should not resolve the apps errs' do
28   - app = Factory(:app, :resolve_errs_on_deploy => false)
29   - @problems = 3.times.map{Factory(:err, :problem => Factory(:problem, :resolved => false, :app => app))}
30   - Factory(:deploy, :app => app)
  28 + app = Fabricate(:app, :resolve_errs_on_deploy => false)
  29 + @problems = 3.times.map{Fabricate(:err, :problem => Fabricate(:problem, :resolved => false, :app => app))}
  30 + Fabricate(:deploy, :app => app)
31 31 app.reload.problems.none?{|problem| problem.resolved?}.should == true
32 32 end
33 33 end
34 34  
35 35 context 'when the app has resolve_errs_on_deploy set to true' do
36 36 it 'should resolve the apps errs that were in the same environment' do
37   - app = Factory(:app, :resolve_errs_on_deploy => true)
38   - @prod_errs = 3.times.map{Factory(:problem, :resolved => false, :app => app, :environment => 'production')}
39   - @staging_errs = 3.times.map{Factory(:problem, :resolved => false, :app => app, :environment => 'staging')}
40   - Factory(:deploy, :app => app, :environment => 'production')
  37 + app = Fabricate(:app, :resolve_errs_on_deploy => true)
  38 + @prod_errs = 3.times.map{Fabricate(:problem, :resolved => false, :app => app, :environment => 'production')}
  39 + @staging_errs = 3.times.map{Fabricate(:problem, :resolved => false, :app => app, :environment => 'staging')}
  40 + Fabricate(:deploy, :app => app, :environment => 'production')
41 41 @prod_errs.all?{|problem| problem.reload.resolved?}.should == true
42 42 @staging_errs.all?{|problem| problem.reload.resolved?}.should == false
43 43 end
... ... @@ -46,7 +46,7 @@ describe Deploy do
46 46 context 'when the app has deploy notifications set to false' do
47 47 it 'should not send an email notification' do
48 48 Mailer.should_not_receive(:deploy_notification)
49   - Factory(:deploy, :app => Factory(:app_with_watcher, :notify_on_deploys => false))
  49 + Fabricate(:deploy, :app => Fabricate(:app_with_watcher, :notify_on_deploys => false))
50 50 end
51 51 end
52 52 end
... ...
spec/models/err_spec.rb
... ... @@ -4,13 +4,13 @@ describe Err do
4 4  
5 5 context 'validations' do
6 6 it 'requires a klass' do
7   - err = Factory.build(:err, :klass => nil)
  7 + err = Fabricate.build(:err, :klass => nil)
8 8 err.should_not be_valid
9 9 err.errors[:klass].should include("can't be blank")
10 10 end
11 11  
12 12 it 'requires an environment' do
13   - err = Factory.build(:err, :environment => nil)
  13 + err = Fabricate.build(:err, :environment => nil)
14 14 err.should_not be_valid
15 15 err.errors[:environment].should include("can't be blank")
16 16 end
... ...
spec/models/issue_trackers/fogbugz_tracker_spec.rb
... ... @@ -2,8 +2,8 @@ require &#39;spec_helper&#39;
2 2  
3 3 describe FogbugzTracker do
4 4 it "should create an issue on Fogbugz with problem params, and set issue link for problem" do
5   - notice = Factory :notice
6   - tracker = Factory :fogbugz_tracker, :app => notice.app
  5 + notice = Fabricate :notice
  6 + tracker = Fabricate :fogbugz_tracker, :app => notice.app
7 7 problem = notice.problem
8 8  
9 9 number = 123
... ...
spec/models/issue_trackers/github_issues_tracker_spec.rb
... ... @@ -2,8 +2,8 @@ require &#39;spec_helper&#39;
2 2  
3 3 describe GithubIssuesTracker do
4 4 it "should create an issue on Github Issues with problem params, and set issue link for problem" do
5   - notice = Factory :notice
6   - tracker = Factory :github_issues_tracker, :app => notice.app
  5 + notice = Fabricate :notice
  6 + tracker = Fabricate :github_issues_tracker, :app => notice.app
7 7 problem = notice.problem
8 8  
9 9 number = 5
... ...
spec/models/issue_trackers/lighthouse_tracker_spec.rb
... ... @@ -2,8 +2,8 @@ require &#39;spec_helper&#39;
2 2  
3 3 describe LighthouseTracker do
4 4 it "should create an issue on Lighthouse with problem params, and set issue link for problem" do
5   - notice = Factory :notice
6   - tracker = Factory :lighthouse_tracker, :app => notice.app
  5 + notice = Fabricate :notice
  6 + tracker = Fabricate :lighthouse_tracker, :app => notice.app
7 7 problem = notice.problem
8 8  
9 9 number = 5
... ...
spec/models/issue_trackers/mingle_tracker_spec.rb
... ... @@ -2,8 +2,8 @@ require &#39;spec_helper&#39;
2 2  
3 3 describe MingleTracker do
4 4 it "should create an issue on Mingle with problem params, and set issue link for problem" do
5   - notice = Factory :notice
6   - tracker = Factory :mingle_tracker, :app => notice.app
  5 + notice = Fabricate :notice
  6 + tracker = Fabricate :mingle_tracker, :app => notice.app
7 7 problem = notice.problem
8 8  
9 9 number = 5
... ...
spec/models/issue_trackers/pivotal_labs_tracker_spec.rb
... ... @@ -2,8 +2,8 @@ require &#39;spec_helper&#39;
2 2  
3 3 describe PivotalLabsTracker do
4 4 it "should create an issue on Pivotal Tracker with problem params, and set issue link for problem" do
5   - notice = Factory :notice
6   - tracker = Factory :pivotal_labs_tracker, :app => notice.app, :project_id => 10
  5 + notice = Fabricate :notice
  6 + tracker = Fabricate :pivotal_labs_tracker, :app => notice.app, :project_id => 10
7 7 problem = notice.problem
8 8  
9 9 story_id = 5
... ...
spec/models/issue_trackers/redmine_tracker_spec.rb
... ... @@ -2,8 +2,8 @@ require &#39;spec_helper&#39;
2 2  
3 3 describe RedmineTracker do
4 4 it "should create an issue on Redmine with problem params, and set issue link for problem" do
5   - notice = Factory(:notice)
6   - tracker = Factory(:redmine_tracker, :app => notice.app, :project_id => 10)
  5 + notice = Fabricate(:notice)
  6 + tracker = Fabricate(:redmine_tracker, :app => notice.app, :project_id => 10)
7 7 problem = notice.problem
8 8 number = 5
9 9 @issue_link = "#{tracker.account}/issues/#{number}.xml?project_id=#{tracker.project_id}"
... ... @@ -24,7 +24,7 @@ describe RedmineTracker do
24 24 end
25 25  
26 26 it "should generate a url where a file with line number can be viewed" do
27   - t = Factory(:redmine_tracker, :account => 'http://redmine.example.com', :project_id => "errbit")
  27 + t = Fabricate(:redmine_tracker, :account => 'http://redmine.example.com', :project_id => "errbit")
28 28 t.url_to_file("/example/file").should ==
29 29 'http://redmine.example.com/projects/errbit/repository/annotate/example/file'
30 30 t.url_to_file("/example/file", 25).should ==
... ... @@ -32,7 +32,7 @@ describe RedmineTracker do
32 32 end
33 33  
34 34 it "should use the alt_project_id to generate a file/linenumber url, if given" do
35   - t = Factory(:redmine_tracker, :account => 'http://redmine.example.com',
  35 + t = Fabricate(:redmine_tracker, :account => 'http://redmine.example.com',
36 36 :project_id => "errbit",
37 37 :alt_project_id => "actual_project")
38 38 t.url_to_file("/example/file", 25).should ==
... ...
spec/models/notice_spec.rb
... ... @@ -5,19 +5,19 @@ describe Notice do
5 5  
6 6 context 'validations' do
7 7 it 'requires a backtrace' do
8   - notice = Factory.build(:notice, :backtrace => nil)
  8 + notice = Fabricate.build(:notice, :backtrace => nil)
9 9 notice.should_not be_valid
10 10 notice.errors[:backtrace].should include("can't be blank")
11 11 end
12 12  
13 13 it 'requires the server_environment' do
14   - notice = Factory.build(:notice, :server_environment => nil)
  14 + notice = Fabricate.build(:notice, :server_environment => nil)
15 15 notice.should_not be_valid
16 16 notice.errors[:server_environment].should include("can't be blank")
17 17 end
18 18  
19 19 it 'requires the notifier' do
20   - notice = Factory.build(:notice, :notifier => nil)
  20 + notice = Fabricate.build(:notice, :notifier => nil)
21 21 notice.should_not be_valid
22 22 notice.errors[:notifier].should include("can't be blank")
23 23 end
... ... @@ -61,8 +61,8 @@ describe Notice do
61 61 end
62 62 [:server_environment, :request, :notifier].each do |key|
63 63 it "replaces . with &#46; and $ with &#36; in keys used in #{key}" do
64   - err = Factory(:err)
65   - notice = Factory(:notice, :err => err, key => @hash)
  64 + err = Fabricate(:err)
  65 + notice = Fabricate(:notice, :err => err, key => @hash)
66 66 notice.send(key).should == @hash_sanitized
67 67 end
68 68 end
... ... @@ -71,42 +71,42 @@ describe Notice do
71 71  
72 72 describe "user agent" do
73 73 it "should be parsed and human-readable" do
74   - notice = Factory.build(:notice, :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'}})
  74 + notice = Fabricate.build(:notice, :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'}})
75 75 notice.user_agent.browser.should == 'Chrome'
76 76 notice.user_agent.version.to_s.should =~ /^10\.0/
77 77 end
78 78  
79 79 it "should be nil if HTTP_USER_AGENT is blank" do
80   - notice = Factory.build(:notice)
  80 + notice = Fabricate.build(:notice)
81 81 notice.user_agent.should == nil
82 82 end
83 83 end
84 84  
85 85 describe "user agent string" do
86 86 it "should be parsed and human-readable" do
87   - notice = Factory.build(:notice, :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'}})
  87 + notice = Fabricate.build(:notice, :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'}})
88 88 notice.user_agent_string.should == 'Chrome 10.0.648.204'
89 89 end
90 90  
91 91 it "should be nil if HTTP_USER_AGENT is blank" do
92   - notice = Factory.build(:notice)
  92 + notice = Fabricate.build(:notice)
93 93 notice.user_agent_string.should == "N/A"
94 94 end
95 95 end
96 96  
97 97 describe "host" do
98 98 it "returns host if url is valid" do
99   - notice = Factory.build(:notice, :request => {'url' => "http://example.com/resource/12"})
  99 + notice = Fabricate.build(:notice, :request => {'url' => "http://example.com/resource/12"})
100 100 notice.host.should == 'example.com'
101 101 end
102   -
  102 +
103 103 it "returns 'N/A' when url is not valid" do
104   - notice = Factory.build(:notice, :request => {'url' => "some string"})
  104 + notice = Fabricate.build(:notice, :request => {'url' => "some string"})
105 105 notice.host.should == 'N/A'
106 106 end
107 107  
108 108 it "returns 'N/A' when url is empty" do
109   - notice = Factory.build(:notice, :request => {})
  109 + notice = Fabricate.build(:notice, :request => {})
110 110 notice.host.should == 'N/A'
111 111 end
112 112  
... ... @@ -118,8 +118,8 @@ describe Notice do
118 118  
119 119 before do
120 120 Errbit::Config.per_app_email_at_notices = true
121   - @app = Factory(:app_with_watcher, :email_at_notices => custom_thresholds)
122   - @err = Factory(:err, :problem => Factory(:problem, :app => @app))
  121 + @app = Fabricate(:app_with_watcher, :email_at_notices => custom_thresholds)
  122 + @err = Fabricate(:err, :problem => Fabricate(:problem, :app => @app))
123 123 end
124 124  
125 125 after do
... ... @@ -131,7 +131,7 @@ describe Notice do
131 131 @err.problem.stub(:notices_count).and_return(threshold)
132 132 Mailer.should_receive(:err_notification).
133 133 and_return(mock('email', :deliver => true))
134   - Factory(:notice, :err => @err)
  134 + Fabricate(:notice, :err => @err)
135 135 end
136 136 end
137 137 end
... ... @@ -140,8 +140,8 @@ describe Notice do
140 140  
141 141 before do
142 142 Errbit::Config.per_app_email_at_notices = true
143   - @app = Factory(:app_with_watcher, :email_at_notices => [1])
144   - @err = Factory(:err, :problem => Factory(:problem, :app => @app, :notices_count => 100))
  143 + @app = Fabricate(:app_with_watcher, :email_at_notices => [1])
  144 + @err = Fabricate(:err, :problem => Fabricate(:problem, :app => @app, :notices_count => 100))
145 145 end
146 146  
147 147 after do
... ... @@ -152,7 +152,7 @@ describe Notice do
152 152 @err.problem.resolve!
153 153 Mailer.should_receive(:err_notification).
154 154 and_return(mock('email', :deliver => true))
155   - Factory(:notice, :err => @err)
  155 + Fabricate(:notice, :err => @err)
156 156 end
157 157 end
158 158 end
... ...
spec/models/problem_spec.rb
1 1 require 'spec_helper'
2 2  
3 3 describe Problem do
  4 + describe "Fabrication" do
  5 + context "Fabricate(:problem)" do
  6 + it 'should be valid' do
  7 + Fabricate.build(:problem).should be_valid
  8 + end
  9 + it 'should have no comment' do
  10 + lambda do
  11 + Fabricate(:problem)
  12 + end.should_not change(Comment, :count)
  13 + end
  14 + end
  15 +
  16 + context "Fabricate(:problem_with_comments)" do
  17 + it 'should be valid' do
  18 + Fabricate.build(:problem_with_comments).should be_valid
  19 + end
  20 + it 'should have 3 comments' do
  21 + lambda do
  22 + Fabricate(:problem_with_comments)
  23 + end.should change(Comment, :count).by(3)
  24 + end
  25 + end
  26 + end
4 27 context '#last_notice_at' do
5 28 it "returns the created_at timestamp of the latest notice" do
6   - err = Factory(:err)
  29 + err = Fabricate(:err)
7 30 problem = err.problem
8 31 problem.should_not be_nil
9 32  
10 33 problem.last_notice_at.should be_nil
11 34  
12   - notice1 = Factory(:notice, :err => err)
  35 + notice1 = Fabricate(:notice, :err => err)
13 36 problem.last_notice_at.should == notice1.created_at
14 37  
15   - notice2 = Factory(:notice, :err => err)
  38 + notice2 = Fabricate(:notice, :err => err)
16 39 problem.last_notice_at.should == notice2.created_at
17 40 end
18 41 end
... ... @@ -20,10 +43,10 @@ describe Problem do
20 43  
21 44 context '#message' do
22 45 it "adding a notice caches its message" do
23   - err = Factory(:err)
  46 + err = Fabricate(:err)
24 47 problem = err.problem
25 48 lambda {
26   - Factory(:notice, :err => err, :message => 'ERR 1')
  49 + Fabricate(:notice, :err => err, :message => 'ERR 1')
27 50 }.should change(problem, :message).from(nil).to('ERR 1')
28 51 end
29 52 end
... ... @@ -32,9 +55,9 @@ describe Problem do
32 55 context 'being created' do
33 56 context 'when the app has err notifications set to false' do
34 57 it 'should not send an email notification' do
35   - app = Factory(:app_with_watcher, :notify_on_errs => false)
  58 + app = Fabricate(:app_with_watcher, :notify_on_errs => false)
36 59 Mailer.should_not_receive(:err_notification)
37   - Factory(:problem, :app => app)
  60 + Fabricate(:problem, :app => app)
38 61 end
39 62 end
40 63 end
... ... @@ -48,7 +71,7 @@ describe Problem do
48 71 end
49 72  
50 73 it "should be able to be resolved" do
51   - problem = Factory(:problem)
  74 + problem = Fabricate(:problem)
52 75 problem.should_not be_resolved
53 76 problem.resolve!
54 77 problem.reload.should be_resolved
... ... @@ -58,14 +81,14 @@ describe Problem do
58 81  
59 82 context "resolve!" do
60 83 it "marks the problem as resolved" do
61   - problem = Factory(:problem)
  84 + problem = Fabricate(:problem)
62 85 problem.should_not be_resolved
63 86 problem.resolve!
64 87 problem.should be_resolved
65 88 end
66 89  
67 90 it "should throw an err if it's not successful" do
68   - problem = Factory(:problem)
  91 + problem = Fabricate(:problem)
69 92 problem.should_not be_resolved
70 93 problem.stub!(:valid?).and_return(false)
71 94 problem.should_not be_valid
... ... @@ -78,8 +101,8 @@ describe Problem do
78 101  
79 102 context ".merge!" do
80 103 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
  104 + problem1 = Fabricate(:err).problem
  105 + problem2 = Fabricate(:err).problem
83 106 problem1.errs.length.should == 1
84 107 problem2.errs.length.should == 1
85 108  
... ... @@ -93,8 +116,8 @@ describe Problem do
93 116  
94 117 context "#unmerge!" do
95 118 it "creates a separate problem for each err" do
96   - problem1 = Factory(:notice).problem
97   - problem2 = Factory(:notice).problem
  119 + problem1 = Fabricate(:notice).problem
  120 + problem2 = Fabricate(:notice).problem
98 121 merged_problem = Problem.merge!(problem1, problem2)
99 122 merged_problem.errs.length.should == 2
100 123  
... ... @@ -103,7 +126,7 @@ describe Problem do
103 126 end
104 127  
105 128 it "runs smoothly for problem without errs" do
106   - expect { Factory(:problem).unmerge! }.not_to raise_error
  129 + expect { Fabricate(:problem).unmerge! }.not_to raise_error
107 130 end
108 131 end
109 132  
... ... @@ -111,8 +134,8 @@ describe Problem do
111 134 context "Scopes" do
112 135 context "resolved" do
113 136 it 'only finds resolved Problems' do
114   - resolved = Factory(:problem, :resolved => true)
115   - unresolved = Factory(:problem, :resolved => false)
  137 + resolved = Fabricate(:problem, :resolved => true)
  138 + unresolved = Fabricate(:problem, :resolved => false)
116 139 Problem.resolved.all.should include(resolved)
117 140 Problem.resolved.all.should_not include(unresolved)
118 141 end
... ... @@ -120,8 +143,8 @@ describe Problem do
120 143  
121 144 context "unresolved" do
122 145 it 'only finds unresolved Problems' do
123   - resolved = Factory(:problem, :resolved => true)
124   - unresolved = Factory(:problem, :resolved => false)
  146 + resolved = Fabricate(:problem, :resolved => true)
  147 + unresolved = Fabricate(:problem, :resolved => false)
125 148 Problem.unresolved.all.should_not include(resolved)
126 149 Problem.unresolved.all.should include(unresolved)
127 150 end
... ... @@ -131,9 +154,9 @@ describe Problem do
131 154  
132 155 context "notice counter cache" do
133 156 before do
134   - @app = Factory(:app)
135   - @problem = Factory(:problem, :app => @app)
136   - @err = Factory(:err, :problem => @problem)
  157 + @app = Fabricate(:app)
  158 + @problem = Fabricate(:problem, :app => @app)
  159 + @err = Fabricate(:err, :problem => @problem)
137 160 end
138 161  
139 162 it "#notices_count returns 0 by default" do
... ... @@ -142,12 +165,12 @@ describe Problem do
142 165  
143 166 it "adding a notice increases #notices_count by 1" do
144 167 lambda {
145   - Factory(:notice, :err => @err, :message => 'ERR 1')
  168 + Fabricate(:notice, :err => @err, :message => 'ERR 1')
146 169 }.should change(@problem, :notices_count).from(0).to(1)
147 170 end
148 171  
149 172 it "removing a notice decreases #notices_count by 1" do
150   - notice1 = Factory(:notice, :err => @err, :message => 'ERR 1')
  173 + notice1 = Fabricate(:notice, :err => @err, :message => 'ERR 1')
151 174 lambda {
152 175 @err.notices.first.destroy
153 176 @problem.reload
... ... @@ -157,19 +180,18 @@ describe Problem do
157 180  
158 181  
159 182 context "#app_name" do
160   - before do
161   - @app = Factory(:app)
162   - end
  183 + let!(:app) { Fabricate(:app) }
  184 + let!(:problem) { Fabricate(:problem, :app => app) }
  185 +
  186 + before { app.reload }
163 187  
164 188 it "is set when a problem is created" do
165   - problem = Factory(:problem, :app => @app)
166   - assert_equal @app.name, problem.app_name
  189 + assert_equal app.name, problem.app_name
167 190 end
168 191  
169 192 it "is updated when an app is updated" do
170   - problem = Factory(:problem, :app => @app)
171 193 lambda {
172   - @app.update_attributes!(:name => "Bar App")
  194 + app.update_attributes!(:name => "Bar App")
173 195 problem.reload
174 196 }.should change(problem, :app_name).to("Bar App")
175 197 end
... ... @@ -178,21 +200,21 @@ describe Problem do
178 200  
179 201 context "#last_deploy_at" do
180 202 before do
181   - @app = Factory(:app)
  203 + @app = Fabricate(:app)
182 204 @last_deploy = 10.days.ago.localtime.round(0)
183   - deploy = Factory(:deploy, :app => @app, :created_at => @last_deploy, :environment => "production")
  205 + deploy = Fabricate(:deploy, :app => @app, :created_at => @last_deploy, :environment => "production")
184 206 end
185 207  
186 208 it "is set when a problem is created" do
187   - problem = Factory(:problem, :app => @app, :environment => "production")
  209 + problem = Fabricate(:problem, :app => @app, :environment => "production")
188 210 assert_equal @last_deploy, problem.last_deploy_at
189 211 end
190 212  
191 213 it "is updated when a deploy is created" do
192   - problem = Factory(:problem, :app => @app, :environment => "production")
  214 + problem = Fabricate(:problem, :app => @app, :environment => "production")
193 215 next_deploy = 5.minutes.ago.localtime.round(0)
194 216 lambda {
195   - @deploy = Factory(:deploy, :app => @app, :created_at => next_deploy)
  217 + @deploy = Fabricate(:deploy, :app => @app, :created_at => next_deploy)
196 218 problem.reload
197 219 }.should change(problem, :last_deploy_at).from(@last_deploy).to(next_deploy)
198 220 end
... ... @@ -200,9 +222,9 @@ describe Problem do
200 222  
201 223 context "notice messages cache" do
202 224 before do
203   - @app = Factory(:app)
204   - @problem = Factory(:problem, :app => @app)
205   - @err = Factory(:err, :problem => @problem)
  225 + @app = Fabricate(:app)
  226 + @problem = Fabricate(:problem, :app => @app)
  227 + @err = Fabricate(:err, :problem => @problem)
206 228 end
207 229  
208 230 it "#messages should be empty by default" do
... ... @@ -211,12 +233,12 @@ describe Problem do
211 233  
212 234 it "adding a notice adds a string to #messages" do
213 235 lambda {
214   - Factory(:notice, :err => @err, :message => 'ERR 1')
  236 + Fabricate(:notice, :err => @err, :message => 'ERR 1')
215 237 }.should change(@problem, :messages).from({}).to({Digest::MD5.hexdigest('ERR 1') => {'value' => 'ERR 1', 'count' => 1}})
216 238 end
217 239  
218 240 it "removing a notice removes string from #messages" do
219   - notice1 = Factory(:notice, :err => @err, :message => 'ERR 1')
  241 + notice1 = Fabricate(:notice, :err => @err, :message => 'ERR 1')
220 242 lambda {
221 243 @err.notices.first.destroy
222 244 @problem.reload
... ... @@ -226,9 +248,9 @@ describe Problem do
226 248  
227 249 context "notice hosts cache" do
228 250 before do
229   - @app = Factory(:app)
230   - @problem = Factory(:problem, :app => @app)
231   - @err = Factory(:err, :problem => @problem)
  251 + @app = Fabricate(:app)
  252 + @problem = Fabricate(:problem, :app => @app)
  253 + @err = Fabricate(:err, :problem => @problem)
232 254 end
233 255  
234 256 it "#hosts should be empty by default" do
... ... @@ -237,12 +259,12 @@ describe Problem do
237 259  
238 260 it "adding a notice adds a string to #hosts" do
239 261 lambda {
240   - Factory(:notice, :err => @err, :request => {'url' => "http://example.com/resource/12"})
  262 + Fabricate(:notice, :err => @err, :request => {'url' => "http://example.com/resource/12"})
241 263 }.should change(@problem, :hosts).from({}).to({Digest::MD5.hexdigest('example.com') => {'value' => 'example.com', 'count' => 1}})
242 264 end
243 265  
244 266 it "removing a notice removes string from #hosts" do
245   - notice1 = Factory(:notice, :err => @err, :request => {'url' => "http://example.com/resource/12"})
  267 + notice1 = Fabricate(:notice, :err => @err, :request => {'url' => "http://example.com/resource/12"})
246 268 lambda {
247 269 @err.notices.first.destroy
248 270 @problem.reload
... ... @@ -252,9 +274,9 @@ describe Problem do
252 274  
253 275 context "notice user_agents cache" do
254 276 before do
255   - @app = Factory(:app)
256   - @problem = Factory(:problem, :app => @app)
257   - @err = Factory(:err, :problem => @problem)
  277 + @app = Fabricate(:app)
  278 + @problem = Fabricate(:problem, :app => @app)
  279 + @err = Fabricate(:err, :problem => @problem)
258 280 end
259 281  
260 282 it "#user_agents should be empty by default" do
... ... @@ -263,12 +285,12 @@ describe Problem do
263 285  
264 286 it "adding a notice adds a string to #user_agents" do
265 287 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'}})
  288 + 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 289 }.should change(@problem, :user_agents).from({}).to({Digest::MD5.hexdigest('Chrome 10.0.648.204') => {'value' => 'Chrome 10.0.648.204', 'count' => 1}})
268 290 end
269 291  
270 292 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'}})
  293 + 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 294 lambda {
273 295 @err.notices.first.destroy
274 296 @problem.reload
... ... @@ -278,8 +300,8 @@ describe Problem do
278 300  
279 301 context "comment counter cache" do
280 302 before do
281   - @app = Factory(:app)
282   - @problem = Factory(:problem, :app => @app)
  303 + @app = Fabricate(:app)
  304 + @problem = Fabricate(:problem, :app => @app)
283 305 end
284 306  
285 307 it "#comments_count returns 0 by default" do
... ... @@ -288,12 +310,12 @@ describe Problem do
288 310  
289 311 it "adding a comment increases #comments_count by 1" do
290 312 lambda {
291   - Factory(:comment, :err => @problem)
  313 + Fabricate(:comment, :err => @problem)
292 314 }.should change(@problem, :comments_count).from(0).to(1)
293 315 end
294 316  
295 317 it "removing a comment decreases #comments_count by 1" do
296   - comment1 = Factory(:comment, :err => @problem)
  318 + comment1 = Fabricate(:comment, :err => @problem)
297 319 lambda {
298 320 @problem.reload.comments.first.destroy
299 321 @problem.reload
... ...
spec/models/user_spec.rb
... ... @@ -4,7 +4,7 @@ describe User do
4 4  
5 5 context 'validations' do
6 6 it 'require that a name is present' do
7   - user = Factory.build(:user, :name => nil)
  7 + user = Fabricate.build(:user, :name => nil)
8 8 user.should_not be_valid
9 9 user.errors[:name].should include("can't be blank")
10 10 end
... ... @@ -13,26 +13,26 @@ describe User do
13 13 context 'Watchers' do
14 14  
15 15 it 'has many watchers' do
16   - user = Factory(:user)
17   - watcher = Factory(:user_watcher, :user => user)
  16 + user = Fabricate(:user)
  17 + watcher = Fabricate(:user_watcher, :user => user)
18 18 user.watchers.should_not be_empty
19 19 user.watchers.should include(watcher)
20 20 end
21 21  
22 22 it "destroys any related watchers when it is destroyed" do
23   - user = Factory(:user)
24   - app = Factory(:app)
25   - watcher = Factory(:user_watcher, :app => app, :user => user)
  23 + user = Fabricate(:user)
  24 + app = Fabricate(:app)
  25 + watcher = Fabricate(:user_watcher, :app => app, :user => user)
26 26 user.watchers.should_not be_empty
27 27 user.destroy
28 28 app.reload.watchers.should_not include(watcher)
29 29 end
30 30  
31 31 it "has many apps through watchers" do
32   - user = Factory(:user)
33   - watched_app = Factory(:app)
34   - unwatched_app = Factory(:app)
35   - watcher = Factory(:user_watcher, :app => watched_app, :user => user)
  32 + user = Fabricate(:user)
  33 + watched_app = Fabricate(:app)
  34 + unwatched_app = Fabricate(:app)
  35 + watcher = Fabricate(:user_watcher, :app => watched_app, :user => user)
36 36 user.apps.all.should include(watched_app)
37 37 user.apps.all.should_not include(unwatched_app)
38 38 end
... ...
spec/models/watcher_spec.rb
... ... @@ -4,7 +4,7 @@ describe Watcher do
4 4  
5 5 context 'validations' do
6 6 it 'requires an email address or an associated user' do
7   - watcher = Factory.build(:watcher, :email => nil, :user => nil)
  7 + watcher = Fabricate.build(:watcher, :email => nil, :user => nil)
8 8 watcher.should_not be_valid
9 9 watcher.errors[:base].should include("You must specify either a user or an email address")
10 10  
... ... @@ -14,7 +14,7 @@ describe Watcher do
14 14 watcher.email = nil
15 15 watcher.should_not be_valid
16 16  
17   - watcher.user = Factory(:user)
  17 + watcher.user = Fabricate(:user)
18 18 watcher.watcher_type = 'user'
19 19 watcher.should be_valid
20 20 end
... ... @@ -22,13 +22,13 @@ describe Watcher do
22 22  
23 23 context 'address' do
24 24 it "returns the user's email address if there is a user" do
25   - user = Factory(:user, :email => 'foo@bar.com')
26   - watcher = Factory(:user_watcher, :user => user)
  25 + user = Fabricate(:user, :email => 'foo@bar.com')
  26 + watcher = Fabricate(:user_watcher, :user => user)
27 27 watcher.address.should == 'foo@bar.com'
28 28 end
29 29  
30 30 it "returns the email if there is no user" do
31   - watcher = Factory(:watcher, :email => 'widgets@acme.com')
  31 + watcher = Fabricate(:watcher, :email => 'widgets@acme.com')
32 32 watcher.address.should == 'widgets@acme.com'
33 33 end
34 34 end
... ...
spec/spec_helper.rb
... ... @@ -10,6 +10,10 @@ require &#39;webmock/rspec&#39;
10 10 # in ./support/ and its subdirectories.
11 11 Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
12 12  
  13 +Fabrication.configure do |config|
  14 + fabricator_dir = "spec/fabricators"
  15 +end
  16 +
13 17 RSpec.configure do |config|
14 18 config.mock_with :rspec
15 19 config.include Devise::TestHelpers, :type => :controller
... ...
spec/support/macros.rb
... ... @@ -45,7 +45,7 @@ def it_requires_admin_privileges(options = {})
45 45 context 'when signed in as a regular user' do
46 46 before do
47 47 sign_out :user
48   - sign_in Factory(:user)
  48 + sign_in Fabricate(:user)
49 49 end
50 50  
51 51 options[:for].each do |action, method|
... ...
spec/views/apps/index.html.haml_spec.rb
... ... @@ -2,9 +2,9 @@ require &#39;spec_helper&#39;
2 2  
3 3 describe "apps/index.html.haml" do
4 4 before do
5   - app = Factory(:app, :deploys => [Factory(:deploy, :revision => "123456789abcdef")])
  5 + app = Fabricate(:app, :deploys => [Fabricate(:deploy, :revision => "123456789abcdef")])
6 6 assign :apps, [app]
7   - controller.stub(:current_user) { Factory(:user) }
  7 + controller.stub(:current_user) { Fabricate(:user) }
8 8 end
9 9  
10 10 describe "deploy column" do
... ...
spec/views/errs/show.html.haml_spec.rb
... ... @@ -2,15 +2,15 @@ require &#39;spec_helper&#39;
2 2  
3 3 describe "errs/show.html.haml" do
4 4 before do
5   - err = Factory(:err)
  5 + err = Fabricate(:err)
6 6 problem = err.problem
7   - comment = Factory(:comment)
  7 + comment = Fabricate(:comment)
8 8 assign :problem, problem
9 9 assign :comment, comment
10 10 assign :app, problem.app
11 11 assign :notices, err.notices.page(1).per(1)
12 12 assign :notice, err.notices.first
13   - controller.stub(:current_user) { Factory(:user) }
  13 + controller.stub(:current_user) { Fabricate(:user) }
14 14 end
15 15  
16 16 describe "content_for :action_bar" do
... ... @@ -46,7 +46,7 @@ describe &quot;errs/show.html.haml&quot; do
46 46 end
47 47  
48 48 it 'should display comments and new comment form when no issue tracker' do
49   - problem = Factory(:problem_with_comments)
  49 + problem = Fabricate(:problem_with_comments)
50 50 assign :problem, problem
51 51 assign :app, problem.app
52 52 render
... ... @@ -63,14 +63,15 @@ describe &quot;errs/show.html.haml&quot; do
63 63 end
64 64  
65 65 it 'should not display the comments section' do
66   - problem = Factory(:problem)
  66 + problem = Fabricate(:problem)
67 67 with_issue_tracker(problem)
68 68 render
69 69 view.instance_variable_get(:@_content_for)[:comments].should be_blank
70 70 end
71 71  
72 72 it 'should display existing comments' do
73   - problem = Factory(:problem_with_comments)
  73 + problem = Fabricate(:problem_with_comments)
  74 + problem.reload
74 75 with_issue_tracker(problem)
75 76 render
76 77 comments_section = String.new(view.instance_variable_get(:@_content_for)[:comments])
... ...
spec/views/notices/_backtrace.html.haml_spec.rb
... ... @@ -3,7 +3,7 @@ require &#39;spec_helper&#39;
3 3 describe "notices/_backtrace.html.haml" do
4 4 describe 'missing file in backtrace' do
5 5 before do
6   - @notice = Factory(:notice, :backtrace => [{
  6 + @notice = Fabricate(:notice, :backtrace => [{
7 7 'number' => rand(999),
8 8 'file' => nil,
9 9 'method' => ActiveSupport.methods.shuffle.first
... ...