diff options
-rw-r--r-- | app/models/track_thing.rb | 15 | ||||
-rw-r--r-- | spec/models/track_thing_spec.rb | 7 |
2 files changed, 14 insertions, 8 deletions
diff --git a/app/models/track_thing.rb b/app/models/track_thing.rb index 6938fade9..58d70ed86 100644 --- a/app/models/track_thing.rb +++ b/app/models/track_thing.rb @@ -71,14 +71,13 @@ class TrackThing < ActiveRecord::Base def track_query_description # XXX this is very brittle... we should probably ask users # simply to name their tracks when they make them? - self.track_query = self.track_query.gsub(/([()]|OR)/, "") - filters = self.track_query.scan /\b\S+:\S+\b/ - text = self.track_query + original_text = parsed_text = self.track_query.gsub(/([()]|OR)/, "") + filters = parsed_text.scan /\b\S+:\S+\b/ varieties = Set.new date = "" statuses = Set.new for filter in filters - text = text.sub(filter, "") + parsed_text = parsed_text.sub(filter, "") if filter =~ /variety:user/ varieties << _("users") end @@ -105,7 +104,7 @@ class TrackThing < ActiveRecord::Base end end if filters.empty? - text = self.track_query + parsed_text = original_text end descriptions = [] if varieties.include? _("requests") @@ -116,10 +115,10 @@ class TrackThing < ActiveRecord::Base varieties << _("anything") end descriptions += Array(varieties) - text = text.strip + parsed_text = parsed_text.strip descriptions = descriptions.join(_(" or ")) - if !text.empty? - descriptions += _("{{list_of_things}} matching text '{{search_query}}'", :list_of_things => "", :search_query => text) + if !parsed_text.empty? + descriptions += _("{{list_of_things}} matching text '{{search_query}}'", :list_of_things => "", :search_query => parsed_text) end return descriptions end diff --git a/spec/models/track_thing_spec.rb b/spec/models/track_thing_spec.rb index 4922a96c7..7891bd229 100644 --- a/spec/models/track_thing_spec.rb +++ b/spec/models/track_thing_spec.rb @@ -28,6 +28,13 @@ describe TrackThing, "when tracking changes" do found_track.should == @track_thing end + it "can display the description of a deleted track_thing" do + track_thing = TrackThing.create_track_for_search_query('fancy dog') + description = track_thing.track_query_description + track_thing.destroy + track_thing.track_query_description.should == description + end + it "will make some sane descriptions of search-based tracks" do tests = [['bob variety:user', "users matching text 'bob'"], ['bob (variety:sent OR variety:followup_sent OR variety:response OR variety:comment) (latest_status:successful OR latest_status:partially_successful OR latest_status:rejected OR latest_status:not_held)', "requests which are successful or unsuccessful or comments matching text 'bob'"], |