diff options
author | Robin Houston <robin.houston@gmail.com> | 2012-05-03 18:56:21 +0100 |
---|---|---|
committer | Robin Houston <robin.houston@gmail.com> | 2012-05-04 15:13:37 +0100 |
commit | 88d5103ec40120b64a7579994ad2f11334dee71a (patch) | |
tree | 5dc543bec817d68a382d37d7dbe3b0eea43b3c1e | |
parent | 5344f5dad381698cf4de9361c7a39aefb3eb2e8d (diff) |
Filter public body tracks by event type
Add the facility to filter the public body feed by event type
using a query string parameter, e.g. event_type=sent.
-rw-r--r-- | app/controllers/track_controller.rb | 8 | ||||
-rw-r--r-- | app/models/info_request_event.rb | 42 | ||||
-rw-r--r-- | app/models/track_thing.rb | 12 | ||||
-rw-r--r-- | spec/controllers/track_controller_spec.rb | 29 |
4 files changed, 66 insertions, 25 deletions
diff --git a/app/controllers/track_controller.rb b/app/controllers/track_controller.rb index d858ab233..95b573cdc 100644 --- a/app/controllers/track_controller.rb +++ b/app/controllers/track_controller.rb @@ -50,11 +50,15 @@ class TrackController < ApplicationController raise ActiveRecord::RecordNotFound.new("None found") if @public_body.nil? # If found by historic name, or alternate locale name, redirect to new name if @public_body.url_name != params[:url_name] - redirect_to track_public_body_url(:url_name => @public_body.url_name, :feed => params[:feed]) + redirect_to track_public_body_url(:url_name => @public_body.url_name, :feed => params[:feed], :event_type => params[:event_type]) return end - @track_thing = TrackThing.create_track_for_public_body(@public_body) + if params[:event_type] + @track_thing = TrackThing.create_track_for_public_body(@public_body, params[:event_type]) + else + @track_thing = TrackThing.create_track_for_public_body(@public_body) + end return atom_feed_internal if params[:feed] == 'feed' diff --git a/app/models/info_request_event.rb b/app/models/info_request_event.rb index 99f34cf9e..cb49596cb 100644 --- a/app/models/info_request_event.rb +++ b/app/models/info_request_event.rb @@ -36,25 +36,29 @@ class InfoRequestEvent < ActiveRecord::Base has_many :track_things_sent_emails validates_presence_of :event_type - validates_inclusion_of :event_type, :in => [ - 'sent', - 'resent', - 'followup_sent', - 'followup_resent', - - 'edit', # title etc. edited (in admin interface) - 'edit_outgoing', # outgoing message edited (in admin interface) - 'edit_comment', # comment edited (in admin interface) - 'destroy_incoming', # deleted an incoming message (in admin interface) - 'destroy_outgoing', # deleted an outgoing message (in admin interface) - 'redeliver_incoming', # redelivered an incoming message elsewhere (in admin interface) - 'move_request', # changed user or public body (in admin interface) - 'manual', # you did something in the db by hand - - 'response', - 'comment', - 'status_update' - ] + + def self.enumerate_event_types + [ + 'sent', + 'resent', + 'followup_sent', + 'followup_resent', + + 'edit', # title etc. edited (in admin interface) + 'edit_outgoing', # outgoing message edited (in admin interface) + 'edit_comment', # comment edited (in admin interface) + 'destroy_incoming', # deleted an incoming message (in admin interface) + 'destroy_outgoing', # deleted an outgoing message (in admin interface) + 'redeliver_incoming', # redelivered an incoming message elsewhere (in admin interface) + 'move_request', # changed user or public body (in admin interface) + 'manual', # you did something in the db by hand + + 'response', + 'comment', + 'status_update', + ] + end + validates_inclusion_of :event_type, :in => enumerate_event_types # user described state (also update in info_request) validate :must_be_valid_state diff --git a/app/models/track_thing.rb b/app/models/track_thing.rb index 58d70ed86..b277e72b0 100644 --- a/app/models/track_thing.rb +++ b/app/models/track_thing.rb @@ -146,11 +146,15 @@ class TrackThing < ActiveRecord::Base return track_thing end - def TrackThing.create_track_for_public_body(public_body) + def TrackThing.create_track_for_public_body(public_body, event_type = nil) track_thing = TrackThing.new track_thing.track_type = 'public_body_updates' track_thing.public_body = public_body - track_thing.track_query = "requested_from:" + public_body.url_name + query = "requested_from:" + public_body.url_name + if InfoRequestEvent.enumerate_event_types.include?(event_type) + query += " variety:" + event_type + end + track_thing.track_query = query return track_thing end @@ -172,9 +176,9 @@ class TrackThing < ActiveRecord::Base when "users" query += " variety:user" when "authorities" - query += " variety:authority" + query += " variety:authority" end - end + end track_thing.track_query = query # XXX should extract requested_by:, request:, requested_from: # and stick their values into the respective relations. diff --git a/spec/controllers/track_controller_spec.rb b/spec/controllers/track_controller_spec.rb index 0dc5db607..5d299caa5 100644 --- a/spec/controllers/track_controller_spec.rb +++ b/spec/controllers/track_controller_spec.rb @@ -183,6 +183,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 |