Commit a308ea359ba359a58a3d518e7156120ff20f90fc
1 parent
0e00ac10
Exists in
master
and in
1 other branch
fix spec/controller/apps with fabrication
Showing
2 changed files
with
29 additions
and
29 deletions
Show diff stats
spec/controllers/apps_controller_spec.rb
| @@ -10,8 +10,8 @@ describe AppsController do | @@ -10,8 +10,8 @@ describe AppsController do | ||
| 10 | describe "GET /apps" do | 10 | describe "GET /apps" do |
| 11 | context 'when logged in as an admin' do | 11 | context 'when logged in as an admin' do |
| 12 | it 'finds all apps' do | 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 | apps = App.all | 15 | apps = App.all |
| 16 | get :index | 16 | get :index |
| 17 | assigns(:apps).should == apps | 17 | assigns(:apps).should == apps |
| @@ -20,12 +20,12 @@ describe AppsController do | @@ -20,12 +20,12 @@ describe AppsController do | ||
| 20 | 20 | ||
| 21 | context 'when logged in as a regular user' do | 21 | context 'when logged in as a regular user' do |
| 22 | it 'finds apps the user is watching' do | 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 | get :index | 29 | get :index |
| 30 | assigns(:apps).should include(watched_app1, watched_app2) | 30 | assigns(:apps).should include(watched_app1, watched_app2) |
| 31 | assigns(:apps).should_not include(unwatched_app) | 31 | assigns(:apps).should_not include(unwatched_app) |
| @@ -36,10 +36,10 @@ describe AppsController do | @@ -36,10 +36,10 @@ describe AppsController do | ||
| 36 | describe "GET /apps/:id" do | 36 | describe "GET /apps/:id" do |
| 37 | context 'logged in as an admin' do | 37 | context 'logged in as an admin' do |
| 38 | before(:each) do | 38 | before(:each) do |
| 39 | - @user = Factory(:admin) | 39 | + @user = Fabricate(:admin) |
| 40 | sign_in @user | 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 | end | 43 | end |
| 44 | 44 | ||
| 45 | it 'finds the app' do | 45 | it 'finds the app' do |
| @@ -48,7 +48,7 @@ describe AppsController do | @@ -48,7 +48,7 @@ describe AppsController do | ||
| 48 | end | 48 | end |
| 49 | 49 | ||
| 50 | it "should not raise errors for app with err without notices" do | 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 | lambda { get :show, :id => @app.id }.should_not raise_error | 52 | lambda { get :show, :id => @app.id }.should_not raise_error |
| 53 | end | 53 | end |
| 54 | 54 | ||
| @@ -60,7 +60,7 @@ describe AppsController do | @@ -60,7 +60,7 @@ describe AppsController do | ||
| 60 | 60 | ||
| 61 | context "pagination" do | 61 | context "pagination" do |
| 62 | before(:each) do | 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 | end | 64 | end |
| 65 | 65 | ||
| 66 | it "should have default per_page value for user" do | 66 | it "should have default per_page value for user" do |
| @@ -77,8 +77,8 @@ describe AppsController do | @@ -77,8 +77,8 @@ describe AppsController do | ||
| 77 | 77 | ||
| 78 | context 'with resolved errors' do | 78 | context 'with resolved errors' do |
| 79 | before(:each) do | 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 | resolved_problem.resolve! | 82 | resolved_problem.resolve! |
| 83 | end | 83 | end |
| 84 | 84 | ||
| @@ -101,7 +101,7 @@ describe AppsController do | @@ -101,7 +101,7 @@ describe AppsController do | ||
| 101 | before(:each) do | 101 | before(:each) do |
| 102 | environments = ['production', 'test', 'development', 'staging'] | 102 | environments = ['production', 'test', 'development', 'staging'] |
| 103 | 20.times do |i| | 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 | end | 105 | end |
| 106 | end | 106 | end |
| 107 | 107 | ||
| @@ -144,17 +144,17 @@ describe AppsController do | @@ -144,17 +144,17 @@ describe AppsController do | ||
| 144 | 144 | ||
| 145 | context 'logged in as a user' do | 145 | context 'logged in as a user' do |
| 146 | it 'finds the app if the user is watching it' do | 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 | sign_in user | 150 | sign_in user |
| 151 | get :show, :id => app.id | 151 | get :show, :id => app.id |
| 152 | assigns(:app).should == app | 152 | assigns(:app).should == app |
| 153 | end | 153 | end |
| 154 | 154 | ||
| 155 | it 'does not find the app if the user is not watching it' do | 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 | lambda { | 158 | lambda { |
| 159 | get :show, :id => app.id | 159 | get :show, :id => app.id |
| 160 | }.should raise_error(Mongoid::Errors::DocumentNotFound) | 160 | }.should raise_error(Mongoid::Errors::DocumentNotFound) |
| @@ -164,7 +164,7 @@ describe AppsController do | @@ -164,7 +164,7 @@ describe AppsController do | ||
| 164 | 164 | ||
| 165 | context 'logged in as an admin' do | 165 | context 'logged in as an admin' do |
| 166 | before do | 166 | before do |
| 167 | - sign_in Factory(:admin) | 167 | + sign_in Fabricate(:admin) |
| 168 | end | 168 | end |
| 169 | 169 | ||
| 170 | describe "GET /apps/new" do | 170 | describe "GET /apps/new" do |
| @@ -176,7 +176,7 @@ describe AppsController do | @@ -176,7 +176,7 @@ describe AppsController do | ||
| 176 | end | 176 | end |
| 177 | 177 | ||
| 178 | it "should copy attributes from an existing app" do | 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 | :github_url => "github.com/test/example") | 180 | :github_url => "github.com/test/example") |
| 181 | get :new, :copy_attributes_from => @app.id | 181 | get :new, :copy_attributes_from => @app.id |
| 182 | assigns(:app).should be_a(App) | 182 | assigns(:app).should be_a(App) |
| @@ -188,7 +188,7 @@ describe AppsController do | @@ -188,7 +188,7 @@ describe AppsController do | ||
| 188 | 188 | ||
| 189 | describe "GET /apps/:id/edit" do | 189 | describe "GET /apps/:id/edit" do |
| 190 | it 'finds the correct app' do | 190 | it 'finds the correct app' do |
| 191 | - app = Factory(:app) | 191 | + app = Fabricate(:app) |
| 192 | get :edit, :id => app.id | 192 | get :edit, :id => app.id |
| 193 | assigns(:app).should == app | 193 | assigns(:app).should == app |
| 194 | end | 194 | end |
| @@ -196,7 +196,7 @@ describe AppsController do | @@ -196,7 +196,7 @@ describe AppsController do | ||
| 196 | 196 | ||
| 197 | describe "POST /apps" do | 197 | describe "POST /apps" do |
| 198 | before do | 198 | before do |
| 199 | - @app = Factory(:app) | 199 | + @app = Fabricate(:app) |
| 200 | App.stub(:new).and_return(@app) | 200 | App.stub(:new).and_return(@app) |
| 201 | end | 201 | end |
| 202 | 202 | ||
| @@ -219,7 +219,7 @@ describe AppsController do | @@ -219,7 +219,7 @@ describe AppsController do | ||
| 219 | 219 | ||
| 220 | describe "PUT /apps/:id" do | 220 | describe "PUT /apps/:id" do |
| 221 | before do | 221 | before do |
| 222 | - @app = Factory(:app) | 222 | + @app = Fabricate(:app) |
| 223 | end | 223 | end |
| 224 | 224 | ||
| 225 | context "when the update is successful" do | 225 | context "when the update is successful" do |
| @@ -257,7 +257,7 @@ describe AppsController do | @@ -257,7 +257,7 @@ describe AppsController do | ||
| 257 | end | 257 | end |
| 258 | context "failed parsing of CSV" do | 258 | context "failed parsing of CSV" do |
| 259 | it "should set the default value" do | 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 | put :update, :id => @app.id, :app => { :email_at_notices => 'asdf, -1,0,foobar,gd00,0,abc' } | 261 | put :update, :id => @app.id, :app => { :email_at_notices => 'asdf, -1,0,foobar,gd00,0,abc' } |
| 262 | @app.reload | 262 | @app.reload |
| 263 | @app.email_at_notices.should == Errbit::Config.email_at_notices | 263 | @app.email_at_notices.should == Errbit::Config.email_at_notices |
| @@ -320,7 +320,7 @@ describe AppsController do | @@ -320,7 +320,7 @@ describe AppsController do | ||
| 320 | 320 | ||
| 321 | describe "DELETE /apps/:id" do | 321 | describe "DELETE /apps/:id" do |
| 322 | before do | 322 | before do |
| 323 | - @app = Factory(:app) | 323 | + @app = Fabricate(:app) |
| 324 | App.stub(:find).with(@app.id).and_return(@app) | 324 | App.stub(:find).with(@app.id).and_return(@app) |
| 325 | end | 325 | end |
| 326 | 326 |
spec/support/macros.rb
| @@ -45,7 +45,7 @@ def it_requires_admin_privileges(options = {}) | @@ -45,7 +45,7 @@ def it_requires_admin_privileges(options = {}) | ||
| 45 | context 'when signed in as a regular user' do | 45 | context 'when signed in as a regular user' do |
| 46 | before do | 46 | before do |
| 47 | sign_out :user | 47 | sign_out :user |
| 48 | - sign_in Factory(:user) | 48 | + sign_in Fabricate(:user) |
| 49 | end | 49 | end |
| 50 | 50 | ||
| 51 | options[:for].each do |action, method| | 51 | options[:for].each do |action, method| |