Permalink
Browse files

Update tests now that you must specify watcher_type to differentiate …

…between user and email watchers
  • Loading branch information...
1 parent a45142a commit 5ea3456100c96aabe225f89fee069f4d8545a96e @jdpace jdpace committed Aug 20, 2010
@@ -22,8 +22,8 @@
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)
@@ -28,8 +28,8 @@
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 @@
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 @@
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
@@ -12,10 +12,16 @@
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'
@@ -14,15 +14,15 @@
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
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 @@
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
@@ -15,19 +15,20 @@
watcher.should_not be_valid
watcher.user = Factory(:user)
+ watcher.watcher_type = 'user'
watcher.should be_valid
end
end
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

0 comments on commit 5ea3456

Please sign in to comment.