aboutsummaryrefslogtreecommitdiffstats
path: root/spec/controllers/track_controller_spec.rb
diff options
context:
space:
mode:
authorfrancis <francis>2008-04-03 15:29:50 +0000
committerfrancis <francis>2008-04-03 15:29:50 +0000
commit2e57753854146b7e7e26d7e490ad2cdd49b06aa3 (patch)
tree5ea09ff9e1dfe4ef389fda890dae4969b5ca2011 /spec/controllers/track_controller_spec.rb
parent7e0677c9c7fd5ba42fd5689057d9a9da3a0a68b0 (diff)
Email alerts for tracking a particular request.
Diffstat (limited to 'spec/controllers/track_controller_spec.rb')
-rw-r--r--spec/controllers/track_controller_spec.rb72
1 files changed, 72 insertions, 0 deletions
diff --git a/spec/controllers/track_controller_spec.rb b/spec/controllers/track_controller_spec.rb
new file mode 100644
index 000000000..295f9353a
--- /dev/null
+++ b/spec/controllers/track_controller_spec.rb
@@ -0,0 +1,72 @@
+require File.dirname(__FILE__) + '/../spec_helper'
+
+describe TrackController, "when making a new track on a request" do
+ integrate_views
+ fixtures :info_requests, :outgoing_messages, :incoming_messages, :info_request_events, :users
+
+ it "should render with 'track_set' template" do
+ get :track_request, :url_title => info_requests(:fancy_dog_request).url_title
+ response.should render_template('track_set')
+ end
+
+ it "should assign the title" do
+ get :track_request, :url_title => info_requests(:fancy_dog_request).url_title
+
+ assigns[:title].should include("Track the request")
+ end
+
+ it "should require login when making new track" do
+ post :track_request, :url_title => info_requests(:fancy_dog_request).url_title,
+ :track_thing => { :track_medium => "email_daily" },
+ :submitted_track => 1
+ post_redirect = PostRedirect.get_last_post_redirect
+ response.should redirect_to(:controller => 'user', :action => 'signin', :token => post_redirect.token)
+ end
+
+ it "should make track and redirect if you are logged in " do
+ TrackThing.count.should == 1
+ session[:user_id] = users(:bob_smith_user).id
+ post :track_request, :url_title => info_requests(:fancy_dog_request).url_title,
+ :track_thing => { :track_medium => "email_daily" },
+ :submitted_track => 1
+ TrackThing.count.should == 2
+ response.should redirect_to(:controller => 'request', :action => 'show', :url_title => info_requests(:fancy_dog_request).url_title)
+ end
+
+end
+
+describe TrackController, "when sending alerts for a track" do
+ integrate_views
+ fixtures :info_requests, :outgoing_messages, :incoming_messages, :info_request_events, :users, :track_things
+
+ it "should send alerts" do
+ TrackMailer.alert_tracks
+
+ deliveries = ActionMailer::Base.deliveries
+ deliveries.size.should == 1
+ mail = deliveries[0]
+ mail.body.should =~ /Alter your subscription/
+ mail.to_addrs.to_s.should include(users(:silly_name_user).email)
+ mail.body =~ /(http:\/\/.*\/c\/(.*))/
+ mail_url = $1
+ mail_token = $2
+
+ # Check subscription managing link
+# XXX reenable this if we ever have a page manager in the track controller
+# session[:user_id].should be_nil
+# controller.test_code_redirect_by_email_token(mail_token, self) # XXX hack to avoid having to call User controller for email link
+# session[:user_id].should == users(:silly_name_user).id
+#
+# response.should render_template('users/show')
+# assigns[:display_user].should == users(:silly_name_user)
+
+ # Check nothing more is delivered if we try again
+ deliveries.clear
+ TrackMailer.alert_tracks
+ deliveries = ActionMailer::Base.deliveries
+ deliveries.size.should == 0
+ end
+
+end
+
+