aboutsummaryrefslogtreecommitdiffstats
path: root/spec/controllers/track_controller_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/controllers/track_controller_spec.rb')
-rw-r--r--spec/controllers/track_controller_spec.rb43
1 files changed, 39 insertions, 4 deletions
diff --git a/spec/controllers/track_controller_spec.rb b/spec/controllers/track_controller_spec.rb
index 0dc5db607..bc7cfce64 100644
--- a/spec/controllers/track_controller_spec.rb
+++ b/spec/controllers/track_controller_spec.rb
@@ -1,9 +1,7 @@
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
-require 'json'
-
describe TrackController, "when making a new track on a request" do
- before do
+ before(:each) do
@ir = mock_model(InfoRequest, :url_title => 'myrequest',
:title => 'My request')
@track_thing = mock_model(TrackThing, :save! => true,
@@ -11,6 +9,7 @@ describe TrackController, "when making a new track on a request" do
:track_medium= => nil,
:tracking_user_id= => nil)
TrackThing.stub!(:create_track_for_request).and_return(@track_thing)
+ TrackThing.stub!(:create_track_for_search_query).and_return(@track_thing)
TrackThing.stub!(:find_by_existing_track).and_return(nil)
InfoRequest.stub!(:find_by_url_title).and_return(@ir)
@@ -25,13 +24,20 @@ describe TrackController, "when making a new track on a request" do
response.should redirect_to(:controller => 'user', :action => 'signin', :token => post_redirect.token)
end
- it "should save the track and redirect if you are logged in" do
+ it "should save a request track and redirect if you are logged in" do
session[:user_id] = @user.id
@track_thing.should_receive(:save!)
get :track_request, :url_title => @ir.url_title, :feed => 'track'
response.should redirect_to(:controller => 'request', :action => 'show', :url_title => @ir.url_title)
end
+ it "should save a search track and redirect to the right place" do
+ session[:user_id] = @user.id
+ @track_thing.should_receive(:save!)
+ get :track_search_query, :query_array => ["bob variety:sent"], :feed => 'track'
+ response.should redirect_to(:controller => 'general', :action => 'search', :combined => ["bob", "requests"])
+ end
+
end
describe TrackController, "when sending alerts for a track" do
@@ -183,6 +189,35 @@ describe TrackController, "when viewing JSON version of a track feed" do
end
+describe TrackController, "when tracking a public body" do
+
+ integrate_views
+ before(:each) do
+ load_raw_emails_data
+ rebuild_xapian_index
+ end
+
+ it "should work" do
+ geraldine = public_bodies(:geraldine_public_body)
+ get :track_public_body, :feed => 'feed', :url_name => geraldine.url_name
+ response.should be_success
+ response.should render_template('track/atom_feed')
+ tt = assigns[:track_thing]
+ tt.public_body.should == geraldine
+ tt.track_type.should == 'public_body_updates'
+ tt.track_query.should == "requested_from:" + geraldine.url_name
+ end
+ it "should filter by event type" do
+ geraldine = public_bodies(:geraldine_public_body)
+ get :track_public_body, :feed => 'feed', :url_name => geraldine.url_name, :event_type => 'sent'
+ response.should be_success
+ response.should render_template('track/atom_feed')
+ tt = assigns[:track_thing]
+ tt.public_body.should == geraldine
+ tt.track_type.should == 'public_body_updates'
+ tt.track_query.should == "requested_from:" + geraldine.url_name + " variety:sent"
+ end
+end