Commit 5ea3456100c96aabe225f89fee069f4d8545a96e

Authored by Jared Pace
1 parent a45142ac
Exists in master and in 1 other branch production

Update tests now that you must specify watcher_type to differentiate between user and email watchers

spec/controllers/apps_controller_spec.rb
@@ -22,8 +22,8 @@ describe AppsController do @@ -22,8 +22,8 @@ describe AppsController do
22 unwatched_app = Factory(:app) 22 unwatched_app = Factory(:app)
23 watched_app1 = Factory(:app) 23 watched_app1 = Factory(:app)
24 watched_app2 = Factory(:app) 24 watched_app2 = Factory(:app)
25 - Factory(:watcher, :user => user, :app => watched_app1)  
26 - Factory(:watcher, :user => user, :app => watched_app2) 25 + Factory(:user_watcher, :user => user, :app => watched_app1)
  26 + Factory(:user_watcher, :user => user, :app => watched_app2)
27 get :index 27 get :index
28 assigns(:apps).should include(watched_app1, watched_app2) 28 assigns(:apps).should include(watched_app1, watched_app2)
29 assigns(:apps).should_not include(unwatched_app) 29 assigns(:apps).should_not include(unwatched_app)
spec/controllers/errs_controller_spec.rb
@@ -28,8 +28,8 @@ describe ErrsController do @@ -28,8 +28,8 @@ describe ErrsController do
28 it 'gets a paginated list of unresolved errs for the users apps' do 28 it 'gets a paginated list of unresolved errs for the users apps' do
29 sign_in(user = Factory(:user)) 29 sign_in(user = Factory(:user))
30 unwatched_err = Factory(:err) 30 unwatched_err = Factory(:err)
31 - watched_unresolved_err = Factory(:err, :app => Factory(:watcher, :user => user).app, :resolved => false)  
32 - watched_resolved_err = Factory(:err, :app => Factory(:watcher, :user => user).app, :resolved => true) 31 + watched_unresolved_err = Factory(:err, :app => Factory(:user_watcher, :user => user).app, :resolved => false)
  32 + watched_resolved_err = Factory(:err, :app => Factory(:user_watcher, :user => user).app, :resolved => true)
33 get :index 33 get :index
34 assigns(:errs).should include(watched_unresolved_err) 34 assigns(:errs).should include(watched_unresolved_err)
35 assigns(:errs).should_not include(unwatched_err, watched_resolved_err) 35 assigns(:errs).should_not include(unwatched_err, watched_resolved_err)
@@ -56,8 +56,8 @@ describe ErrsController do @@ -56,8 +56,8 @@ describe ErrsController do
56 it 'gets a paginated list of all errs for the users apps' do 56 it 'gets a paginated list of all errs for the users apps' do
57 sign_in(user = Factory(:user)) 57 sign_in(user = Factory(:user))
58 unwatched_err = Factory(:err) 58 unwatched_err = Factory(:err)
59 - watched_unresolved_err = Factory(:err, :app => Factory(:watcher, :user => user).app, :resolved => false)  
60 - watched_resolved_err = Factory(:err, :app => Factory(:watcher, :user => user).app, :resolved => true) 59 + watched_unresolved_err = Factory(:err, :app => Factory(:user_watcher, :user => user).app, :resolved => false)
  60 + watched_resolved_err = Factory(:err, :app => Factory(:user_watcher, :user => user).app, :resolved => true)
61 get :all 61 get :all
62 assigns(:errs).should include(watched_resolved_err, watched_unresolved_err) 62 assigns(:errs).should include(watched_resolved_err, watched_unresolved_err)
63 assigns(:errs).should_not include(unwatched_err) 63 assigns(:errs).should_not include(unwatched_err)
@@ -100,7 +100,7 @@ describe ErrsController do @@ -100,7 +100,7 @@ describe ErrsController do
100 sign_in(@user = Factory(:user)) 100 sign_in(@user = Factory(:user))
101 @unwatched_err = Factory(:err) 101 @unwatched_err = Factory(:err)
102 @watched_app = Factory(:app) 102 @watched_app = Factory(:app)
103 - @watcher = Factory(:watcher, :user => @user, :app => @watched_app) 103 + @watcher = Factory(:user_watcher, :user => @user, :app => @watched_app)
104 @watched_err = Factory(:err, :app => @watched_app) 104 @watched_err = Factory(:err, :app => @watched_app)
105 end 105 end
106 106
spec/factories/app_factories.rb
@@ -12,10 +12,16 @@ Factory.define(:app_with_watcher, :parent => :app) do |p| @@ -12,10 +12,16 @@ Factory.define(:app_with_watcher, :parent => :app) do |p|
12 end 12 end
13 13
14 Factory.define(:watcher) do |w| 14 Factory.define(:watcher) do |w|
15 - w.app {|p| p.association :app} 15 + w.association :app
  16 + w.watcher_type 'email'
16 w.email { Factory.next :email } 17 w.email { Factory.next :email }
17 end 18 end
18 19
  20 +Factory.define(:user_watcher, :parent => :watcher) do |w|
  21 + w.watcher_type 'user'
  22 + w.association :user
  23 +end
  24 +
19 Factory.define(:deploy) do |d| 25 Factory.define(:deploy) do |d|
20 d.app {|p| p.association :app} 26 d.app {|p| p.association :app}
21 d.username 'clyde.frog' 27 d.username 'clyde.frog'
spec/models/user_spec.rb
@@ -14,7 +14,7 @@ describe User do @@ -14,7 +14,7 @@ describe User do
14 14
15 it 'has many watchers' do 15 it 'has many watchers' do
16 user = Factory(:user) 16 user = Factory(:user)
17 - watcher = Factory(:watcher, :user => user, :email => nil) 17 + watcher = Factory(:user_watcher, :user => user)
18 user.watchers.should_not be_empty 18 user.watchers.should_not be_empty
19 user.watchers.should include(watcher) 19 user.watchers.should include(watcher)
20 end 20 end
@@ -22,7 +22,7 @@ describe User do @@ -22,7 +22,7 @@ describe User do
22 it "destroys any related watchers when it is destroyed" do 22 it "destroys any related watchers when it is destroyed" do
23 user = Factory(:user) 23 user = Factory(:user)
24 app = Factory(:app) 24 app = Factory(:app)
25 - watcher = Factory(:watcher, :app => app, :user => user, :email => nil) 25 + watcher = Factory(:user_watcher, :app => app, :user => user)
26 user.watchers.should_not be_empty 26 user.watchers.should_not be_empty
27 user.destroy 27 user.destroy
28 app.reload.watchers.should_not include(watcher) 28 app.reload.watchers.should_not include(watcher)
@@ -32,7 +32,7 @@ describe User do @@ -32,7 +32,7 @@ describe User do
32 user = Factory(:user) 32 user = Factory(:user)
33 watched_app = Factory(:app) 33 watched_app = Factory(:app)
34 unwatched_app = Factory(:app) 34 unwatched_app = Factory(:app)
35 - watcher = Factory(:watcher, :app => watched_app, :user => user, :email => nil) 35 + watcher = Factory(:user_watcher, :app => watched_app, :user => user)
36 user.apps.all.should include(watched_app) 36 user.apps.all.should include(watched_app)
37 user.apps.all.should_not include(unwatched_app) 37 user.apps.all.should_not include(unwatched_app)
38 end 38 end
spec/models/watcher_spec.rb
@@ -15,6 +15,7 @@ describe Watcher do @@ -15,6 +15,7 @@ describe Watcher do
15 watcher.should_not be_valid 15 watcher.should_not be_valid
16 16
17 watcher.user = Factory(:user) 17 watcher.user = Factory(:user)
  18 + watcher.watcher_type = 'user'
18 watcher.should be_valid 19 watcher.should be_valid
19 end 20 end
20 end 21 end
@@ -22,12 +23,12 @@ describe Watcher do @@ -22,12 +23,12 @@ describe Watcher do
22 context 'address' do 23 context 'address' do
23 it "returns the user's email address if there is a user" do 24 it "returns the user's email address if there is a user" do
24 user = Factory(:user, :email => 'foo@bar.com') 25 user = Factory(:user, :email => 'foo@bar.com')
25 - watcher = Factory(:watcher, :user => user) 26 + watcher = Factory(:user_watcher, :user => user)
26 watcher.address.should == 'foo@bar.com' 27 watcher.address.should == 'foo@bar.com'
27 end 28 end
28 29
29 it "returns the email if there is no user" do 30 it "returns the email if there is no user" do
30 - watcher = Factory(:watcher, :email => 'widgets@acme.com', :user => nil) 31 + watcher = Factory(:watcher, :email => 'widgets@acme.com')
31 watcher.address.should == 'widgets@acme.com' 32 watcher.address.should == 'widgets@acme.com'
32 end 33 end
33 end 34 end