aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLouise Crow <louise.crow@gmail.com>2014-03-17 17:35:21 +0000
committerLouise Crow <louise.crow@gmail.com>2014-03-24 13:07:51 +0000
commit5ac63b9c812fc914fd52de7dae813e1bb5f0f36e (patch)
tree15feb8d085ba68d7a8b02dce7ff17502a3aa8112
parent5cb467c469d9a34336da483e47b931c9dd5b9078 (diff)
Move track descriptions to a helper.
We can access url generation methods more easily here.
-rw-r--r--app/helpers/track_helper.rb20
-rw-r--r--app/models/track_thing.rb9
-rw-r--r--app/views/user/show.html.erb2
-rw-r--r--spec/helpers/track_helper_spec.rb29
4 files changed, 51 insertions, 9 deletions
diff --git a/app/helpers/track_helper.rb b/app/helpers/track_helper.rb
index 5038cf5e8..7bd0fa55d 100644
--- a/app/helpers/track_helper.rb
+++ b/app/helpers/track_helper.rb
@@ -99,4 +99,24 @@ module TrackHelper
end
end
+ def track_description(track_thing)
+ case track_thing.track_type
+ when 'request_updates'
+ _("'{{link_to_request}}', a request",
+ :link_to_request => request_link(track_thing.info_request))
+ when 'all_new_requests'
+ link_to(_('new requests'), request_list_path)
+ when 'all_successful_requests'
+ link_to(_('successful requests'), request_list_successful_path)
+ when 'public_body_updates'
+ _("'{{link_to_authority}}', a public authority",
+ :link_to_authority => public_body_link(track_thing.public_body))
+ when 'user_updates'
+ _("'{{link_to_user}}', a person",
+ :link_to_user => user_link(track_thing.tracked_user))
+ when 'search_query'
+ link_to(track_thing.track_query_description,
+ search_path([track_thing.track_query, 'newest', 'advanced']))
+ end
+ end
end
diff --git a/app/models/track_thing.rb b/app/models/track_thing.rb
index 7c8c0003c..fffd3da83 100644
--- a/app/models/track_thing.rb
+++ b/app/models/track_thing.rb
@@ -158,14 +158,12 @@ class TrackThing < ActiveRecord::Base
end
# Return hash of text parameters describing the request etc.
- include LinkToHelper
def params
if @params.nil?
if self.track_type == 'request_updates'
@params = {
# Website
- :list_description => _("'{{link_to_request}}', a request",
- :link_to_request => ("<a href=\"/request/" + CGI.escapeHTML(self.info_request.url_title) + "\">" + CGI.escapeHTML(self.info_request.title) + "</a>").html_safe), # XXX yeuch, sometimes I just want to call view helpers from the model, sorry! can't work out how
+
:verb_on_page => _("Follow this request"),
:verb_on_page_already => _("You are already following this request"),
# Email
@@ -181,7 +179,6 @@ class TrackThing < ActiveRecord::Base
elsif self.track_type == 'all_new_requests'
@params = {
# Website
- :list_description => _("any <a href=\"/list\">new requests</a>"),
:verb_on_page => _("Follow all new requests"),
:verb_on_page_already => _("You are already following new requests"),
# Email
@@ -197,7 +194,6 @@ class TrackThing < ActiveRecord::Base
elsif self.track_type == 'all_successful_requests'
@params = {
# Website
- :list_description => _("any <a href=\"/list/successful\">successful requests</a>"),
:verb_on_page => _("Follow new successful responses"),
:verb_on_page_already => _("You are following all new successful responses"),
# Email
@@ -216,7 +212,6 @@ class TrackThing < ActiveRecord::Base
elsif self.track_type == 'public_body_updates'
@params = {
# Website
- :list_description => _("'{{link_to_authority}}', a public authority", :link_to_authority => ("<a href=\"/body/" + CGI.escapeHTML(self.public_body.url_name) + "\">" + CGI.escapeHTML(self.public_body.name) + "</a>").html_safe), # XXX yeuch, sometimes I just want to call view helpers from the model, sorry! can't work out how
:verb_on_page => _("Follow requests to {{public_body_name}}",:public_body_name=>CGI.escapeHTML(self.public_body.name)),
:verb_on_page_already => _("You are already following requests to {{public_body_name}}", :public_body_name=>CGI.escapeHTML(self.public_body.name)),
# Email
@@ -232,7 +227,6 @@ class TrackThing < ActiveRecord::Base
elsif self.track_type == 'user_updates'
@params = {
# Website
- :list_description => _("'{{link_to_user}}', a person", :link_to_user => ("<a href=\"/user/" + CGI.escapeHTML(self.tracked_user.url_name) + "\">" + CGI.escapeHTML(self.tracked_user.name) + "</a>").html_safe), # XXX yeuch, sometimes I just want to call view helpers from the model, sorry! can't work out how
:verb_on_page => _("Follow this person"),
:verb_on_page_already => _("You are already following this person"),
# Email
@@ -248,7 +242,6 @@ class TrackThing < ActiveRecord::Base
elsif self.track_type == 'search_query'
@params = {
# Website
- :list_description => ("<a href=\"/search/" + CGI.escapeHTML(self.track_query) + "/newest/advanced\">" + CGI.escapeHTML(self.track_query_description) + "</a>").html_safe, # XXX yeuch, sometimes I just want to call view helpers from the model, sorry! can't work out how
:verb_on_page => _("Follow things matching this search"),
:verb_on_page_already => _("You are already following things matching this search"),
# Email
diff --git a/app/views/user/show.html.erb b/app/views/user/show.html.erb
index 76ecdeda0..dafeebd63 100644
--- a/app/views/user/show.html.erb
+++ b/app/views/user/show.html.erb
@@ -224,7 +224,7 @@
<li>
<%= form_tag({:controller => 'track', :action => 'update', :track_id => track_thing.id}, :class => "feed_form") do %>
<div>
- <%= track_thing.params[:list_description] %>
+ <%= track_description(track_thing) %>
<%= hidden_field_tag 'track_medium', "delete", { :id => 'track_medium_' + track_thing.id.to_s } %>
<%= hidden_field_tag 'r', request.fullpath, { :id => 'r_' + track_thing.id.to_s } %>
<%= submit_tag _('unsubscribe') %>
diff --git a/spec/helpers/track_helper_spec.rb b/spec/helpers/track_helper_spec.rb
index bd4be5c3e..80857067b 100644
--- a/spec/helpers/track_helper_spec.rb
+++ b/spec/helpers/track_helper_spec.rb
@@ -31,6 +31,11 @@ describe TrackHelper do
unsubscribe_notice(@track_thing).should == expected
end
+ it 'should create a description of the track' do
+ expected = %Q(<a href="/search/Example%20Query/newest/advanced">anything matching text 'Example Query'</a>)
+ track_description(@track_thing).should == expected
+ end
+
end
describe 'when displaying notices for a user track' do
@@ -59,6 +64,11 @@ describe TrackHelper do
unsubscribe_notice(@track_thing).should == expected
end
+ it 'should create a description of the track' do
+ expected = %Q('#{user_link(@track_thing.tracked_user)}', a person)
+ track_description(@track_thing).should == expected
+ end
+
end
describe 'when displaying notices for a public body track' do
@@ -86,6 +96,11 @@ describe TrackHelper do
expected = %Q(You are no longer following '#{public_body_link(@track_thing.public_body)}', a public authority)
unsubscribe_notice(@track_thing).should == expected
end
+
+ it 'should create a description of the track' do
+ expected = %Q('#{public_body_link(@track_thing.public_body)}', a public authority)
+ track_description(@track_thing).should == expected
+ end
end
describe 'when displaying notices for a successful request track' do
@@ -114,6 +129,10 @@ describe TrackHelper do
unsubscribe_notice(@track_thing).should == expected
end
+ it 'should create a description of the track' do
+ expected = %Q(<a href="/list/successful">successful requests</a>)
+ track_description(@track_thing).should == expected
+ end
end
describe 'when displaying notices for a new request track' do
@@ -142,6 +161,11 @@ describe TrackHelper do
unsubscribe_notice(@track_thing).should == expected
end
+ it 'should create a description of the track' do
+ expected = %Q(<a href="/list">new requests</a>)
+ track_description(@track_thing).should == expected
+ end
+
end
describe 'when displaying notices for a request update track' do
@@ -170,6 +194,11 @@ describe TrackHelper do
unsubscribe_notice(@track_thing).should == expected
end
+ it 'should create a description of the track' do
+ expected = %Q('#{request_link(@track_thing.info_request)}', a request)
+ track_description(@track_thing).should == expected
+ end
+
end
end