diff --git a/spec/controllers/apps_controller_spec.rb b/spec/controllers/apps_controller_spec.rb index bccaa5c..2d2d45d 100644 --- a/spec/controllers/apps_controller_spec.rb +++ b/spec/controllers/apps_controller_spec.rb @@ -22,8 +22,8 @@ describe AppsController do unwatched_app = Factory(:app) watched_app1 = Factory(:app) watched_app2 = Factory(:app) - Factory(:watcher, :user => user, :app => watched_app1) - Factory(:watcher, :user => user, :app => watched_app2) + Factory(:user_watcher, :user => user, :app => watched_app1) + Factory(:user_watcher, :user => user, :app => watched_app2) get :index assigns(:apps).should include(watched_app1, watched_app2) assigns(:apps).should_not include(unwatched_app) diff --git a/spec/controllers/errs_controller_spec.rb b/spec/controllers/errs_controller_spec.rb index 5b9f4b0..f0dc622 100644 --- a/spec/controllers/errs_controller_spec.rb +++ b/spec/controllers/errs_controller_spec.rb @@ -28,8 +28,8 @@ describe ErrsController do it 'gets a paginated list of unresolved errs for the users apps' do sign_in(user = Factory(:user)) unwatched_err = Factory(:err) - watched_unresolved_err = Factory(:err, :app => Factory(:watcher, :user => user).app, :resolved => false) - watched_resolved_err = Factory(:err, :app => Factory(:watcher, :user => user).app, :resolved => true) + watched_unresolved_err = Factory(:err, :app => Factory(:user_watcher, :user => user).app, :resolved => false) + watched_resolved_err = Factory(:err, :app => Factory(:user_watcher, :user => user).app, :resolved => true) get :index assigns(:errs).should include(watched_unresolved_err) assigns(:errs).should_not include(unwatched_err, watched_resolved_err) @@ -56,8 +56,8 @@ describe ErrsController do it 'gets a paginated list of all errs for the users apps' do sign_in(user = Factory(:user)) unwatched_err = Factory(:err) - watched_unresolved_err = Factory(:err, :app => Factory(:watcher, :user => user).app, :resolved => false) - watched_resolved_err = Factory(:err, :app => Factory(:watcher, :user => user).app, :resolved => true) + watched_unresolved_err = Factory(:err, :app => Factory(:user_watcher, :user => user).app, :resolved => false) + watched_resolved_err = Factory(:err, :app => Factory(:user_watcher, :user => user).app, :resolved => true) get :all assigns(:errs).should include(watched_resolved_err, watched_unresolved_err) assigns(:errs).should_not include(unwatched_err) @@ -100,7 +100,7 @@ describe ErrsController do sign_in(@user = Factory(:user)) @unwatched_err = Factory(:err) @watched_app = Factory(:app) - @watcher = Factory(:watcher, :user => @user, :app => @watched_app) + @watcher = Factory(:user_watcher, :user => @user, :app => @watched_app) @watched_err = Factory(:err, :app => @watched_app) end diff --git a/spec/factories/app_factories.rb b/spec/factories/app_factories.rb index 1339730..ea72f41 100644 --- a/spec/factories/app_factories.rb +++ b/spec/factories/app_factories.rb @@ -12,10 +12,16 @@ Factory.define(:app_with_watcher, :parent => :app) do |p| end Factory.define(:watcher) do |w| - w.app {|p| p.association :app} + w.association :app + w.watcher_type 'email' w.email { Factory.next :email } end +Factory.define(:user_watcher, :parent => :watcher) do |w| + w.watcher_type 'user' + w.association :user +end + Factory.define(:deploy) do |d| d.app {|p| p.association :app} d.username 'clyde.frog' diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 3722456..c031589 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -14,7 +14,7 @@ describe User do it 'has many watchers' do user = Factory(:user) - watcher = Factory(:watcher, :user => user, :email => nil) + watcher = Factory(:user_watcher, :user => user) user.watchers.should_not be_empty user.watchers.should include(watcher) end @@ -22,7 +22,7 @@ describe User do it "destroys any related watchers when it is destroyed" do user = Factory(:user) app = Factory(:app) - watcher = Factory(:watcher, :app => app, :user => user, :email => nil) + watcher = Factory(:user_watcher, :app => app, :user => user) user.watchers.should_not be_empty user.destroy app.reload.watchers.should_not include(watcher) @@ -32,7 +32,7 @@ describe User do user = Factory(:user) watched_app = Factory(:app) unwatched_app = Factory(:app) - watcher = Factory(:watcher, :app => watched_app, :user => user, :email => nil) + watcher = Factory(:user_watcher, :app => watched_app, :user => user) user.apps.all.should include(watched_app) user.apps.all.should_not include(unwatched_app) end diff --git a/spec/models/watcher_spec.rb b/spec/models/watcher_spec.rb index 96460eb..91df9e7 100644 --- a/spec/models/watcher_spec.rb +++ b/spec/models/watcher_spec.rb @@ -15,6 +15,7 @@ describe Watcher do watcher.should_not be_valid watcher.user = Factory(:user) + watcher.watcher_type = 'user' watcher.should be_valid end end @@ -22,12 +23,12 @@ describe Watcher do context 'address' do it "returns the user's email address if there is a user" do user = Factory(:user, :email => 'foo@bar.com') - watcher = Factory(:watcher, :user => user) + watcher = Factory(:user_watcher, :user => user) watcher.address.should == 'foo@bar.com' end it "returns the email if there is no user" do - watcher = Factory(:watcher, :email => 'widgets@acme.com', :user => nil) + watcher = Factory(:watcher, :email => 'widgets@acme.com') watcher.address.should == 'widgets@acme.com' end end -- libgit2 0.21.2