Commit a308ea359ba359a58a3d518e7156120ff20f90fc

Authored by Cyril Mougel
1 parent 0e00ac10
Exists in master and in 1 other branch production

fix spec/controller/apps with fabrication

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/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|
... ...