aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLouise Crow <louise.crow@gmail.com>2014-03-17 17:30:34 +0000
committerLouise Crow <louise.crow@gmail.com>2014-03-24 13:07:51 +0000
commita00067262fd7171a39e74a4ebcd75a5758e12ee6 (patch)
tree1f43df2e3e4c522f4feb1b1f689843785597dfe0
parentaec70771b7029f8c312e779a6e7fa6d5537abbed (diff)
Add notices for subscribing to something.
These notices are complete sentences, not composed on the fly, so should be easier to translate.
-rw-r--r--app/controllers/track_controller.rb6
-rw-r--r--app/helpers/track_helper.rb53
-rw-r--r--app/views/track/_track_set.erb6
-rw-r--r--spec/controllers/track_controller_spec.rb2
-rw-r--r--spec/helpers/track_helper_spec.rb60
5 files changed, 121 insertions, 6 deletions
diff --git a/app/controllers/track_controller.rb b/app/controllers/track_controller.rb
index a3a1ec42c..c861971bd 100644
--- a/app/controllers/track_controller.rb
+++ b/app/controllers/track_controller.rb
@@ -130,11 +130,7 @@ class TrackController < ApplicationController
@track_thing.track_medium = 'email_daily'
@track_thing.tracking_user_id = @user.id
@track_thing.save!
- if @user.receive_email_alerts
- flash[:notice] = _('You will now be emailed updates about {{track_description}}. <a href="{{change_email_alerts_url}}">Prefer not to receive emails?</a>', :track_description => @track_thing.params[:list_description], :change_email_alerts_url => url_for(:controller => "user", :action => "wall", :url_name => @user.url_name))
- else
- flash[:notice] = _('You are now <a href="{{wall_url_user}}">following</a> updates about {{track_description}}', :track_description => @track_thing.params[:list_description], :wall_url_user => url_for(:controller => "user", :action => "wall", :url_name => @user.url_name))
- end
+ flash[:notice] = render_to_string(:partial => 'track_set').html_safe
return true
end
diff --git a/app/helpers/track_helper.rb b/app/helpers/track_helper.rb
index e2615a33f..49209d6bc 100644
--- a/app/helpers/track_helper.rb
+++ b/app/helpers/track_helper.rb
@@ -23,4 +23,57 @@ module TrackHelper
end
end
+ def subscribe_email_notice(track_thing)
+ case track_thing.track_type
+ when 'request_updates'
+ _("You will now be emailed updates about '{{link_to_request}}', a request",
+ :link_to_request => request_link(track_thing.info_request))
+ when 'all_new_requests'
+ _('You will now be emailed updates about any <a href="{{new_requests_url}}">new requests</a>',
+ :new_requests_url => request_list_path)
+ when 'all_successful_requests'
+ _('You will now be emailed updates about <a href="{{successful_requests_url}}">successful requests</a>',
+ :successful_requests_url => request_list_successful_path )
+ when 'public_body_updates'
+ _("You will now be emailed updates about '{{link_to_authority}}', a public authority",
+ :link_to_authority => public_body_link(track_thing.public_body))
+ when 'user_updates'
+ _("You will now be emailed updates about '{{link_to_user}}', a person",
+ :link_to_user => user_link(track_thing.tracked_user))
+ when 'search_query'
+ _("You will now be emailed updates about <a href=\"{{search_url}}\">this search</a>",
+ :search_url => search_path([track_thing.track_query, 'newest', 'advanced']))
+ end
+ end
+
+ def subscribe_follow_notice(track_thing)
+ wall_url_user = show_user_wall_path(:url_name => track_thing.tracking_user.url_name)
+ case track_thing.track_type
+ when 'request_updates'
+ _('You are now <a href="{{wall_url_user}}">following</a> updates about \'{{link_to_request}}\', a request',
+ :link_to_request => request_link(track_thing.info_request),
+ :wall_url_user => wall_url_user)
+ when 'all_new_requests'
+ _('You are now <a href="{{wall_url_user}}">following</a> updates about <a href="{{new_requests_url}}">new requests</a>',
+ :new_requests_url => request_list_path,
+ :wall_url_user => wall_url_user)
+ when 'all_successful_requests'
+ _('You are now <a href="{{wall_url_user}}">following</a> updates about <a href="{{successful_requests_url}}">successful requests</a>',
+ :successful_requests_url => request_list_successful_path,
+ :wall_url_user => wall_url_user)
+ when 'public_body_updates'
+ _('You are now <a href="{{wall_url_user}}">following</a> updates about \'{{link_to_authority}}\', a public authority',
+ :wall_url_user => wall_url_user,
+ :link_to_authority => public_body_link(track_thing.public_body))
+ when 'user_updates'
+ _('You are now <a href="{{wall_url_user}}">following</a> updates about \'{{link_to_user}}\', a person',
+ :wall_url_user => wall_url_user,
+ :link_to_user => user_link(track_thing.tracked_user))
+ when 'search_query'
+ _('You are now <a href="{{wall_url_user}}">following</a> updates about <a href="{{search_url}}">this search</a>',
+ :wall_url_user => wall_url_user,
+ :search_url => search_path([track_thing.track_query, 'newest', 'advanced']))
+ end
+ end
+
end
diff --git a/app/views/track/_track_set.erb b/app/views/track/_track_set.erb
new file mode 100644
index 000000000..c7665312d
--- /dev/null
+++ b/app/views/track/_track_set.erb
@@ -0,0 +1,6 @@
+<% if @user.receive_email_alerts %>
+ <%= subscribe_email_notice(@track_thing) %>
+ <%= link_to(_('Prefer not to receive emails?'), show_user_wall_path(:url_name => @user.url_name)) %>
+<% else %>
+ <%= subscribe_follow_notice(@track_thing) %>
+<% end %>
diff --git a/spec/controllers/track_controller_spec.rb b/spec/controllers/track_controller_spec.rb
index 7c2e1b369..d2b45b6bf 100644
--- a/spec/controllers/track_controller_spec.rb
+++ b/spec/controllers/track_controller_spec.rb
@@ -5,7 +5,7 @@ describe TrackController, "when making a new track on a request" do
@ir = mock_model(InfoRequest, :url_title => 'myrequest',
:title => 'My request')
@track_thing = mock_model(TrackThing, :save! => true,
- :params => {:list_description => 'list description'},
+ :params => {},
:track_medium= => nil,
:tracking_user_id= => nil)
TrackThing.stub!(:create_track_for_request).and_return(@track_thing)
diff --git a/spec/helpers/track_helper_spec.rb b/spec/helpers/track_helper_spec.rb
index a009f87ac..d2c277993 100644
--- a/spec/helpers/track_helper_spec.rb
+++ b/spec/helpers/track_helper_spec.rb
@@ -16,6 +16,16 @@ describe TrackHelper do
already_subscribed_notice(@track_thing).should == expected
end
+ it 'should create an email subscription notice' do
+ expected = %Q(You will now be emailed updates about <a href="/search/Example%20Query/newest/advanced">this search</a>)
+ subscribe_email_notice(@track_thing).should == expected
+ end
+
+ it 'should create a following subscription notice' do
+ expected = %Q(You are now <a href="#{show_user_wall_path(:url_name => @track_thing.tracking_user.url_name)}">following</a> updates about <a href="/search/Example%20Query/newest/advanced">this search</a>)
+ subscribe_follow_notice(@track_thing).should == expected
+ end
+
end
describe 'when displaying notices for a user track' do
@@ -29,6 +39,16 @@ describe TrackHelper do
already_subscribed_notice(@track_thing).should == expected
end
+ it 'should create an email subscription notice' do
+ expected = %Q(You will now be emailed updates about '#{user_link(@track_thing.tracked_user)}', a person)
+ subscribe_email_notice(@track_thing).should == expected
+ end
+
+ it 'should create a following subscription notice' do
+ expected = %Q(You are now <a href="#{show_user_wall_path(:url_name => @track_thing.tracking_user.url_name)}">following</a> updates about '#{user_link(@track_thing.tracked_user)}', a person)
+ subscribe_follow_notice(@track_thing).should == expected
+ end
+
end
describe 'when displaying notices for a public body track' do
@@ -42,6 +62,16 @@ describe TrackHelper do
already_subscribed_notice(@track_thing).should == expected
end
+ it 'should create an email subscription notice' do
+ expected = %Q(You will now be emailed updates about '#{public_body_link(@track_thing.public_body)}', a public authority)
+ subscribe_email_notice(@track_thing).should == expected
+ end
+
+ it 'should create a following subscription notice' do
+ expected = %Q(You are now <a href="#{show_user_wall_path(:url_name => @track_thing.tracking_user.url_name)}">following</a> updates about '#{public_body_link(@track_thing.public_body)}', a public authority)
+ subscribe_follow_notice(@track_thing).should == expected
+ end
+
end
describe 'when displaying notices for a successful request track' do
@@ -55,6 +85,16 @@ describe TrackHelper do
already_subscribed_notice(@track_thing).should == expected
end
+ it 'should create an email subscription notice' do
+ expected = %Q(You will now be emailed updates about <a href="/list/successful">successful requests</a>)
+ subscribe_email_notice(@track_thing).should == expected
+ end
+
+ it 'should create a following subscription notice' do
+ expected = %Q(You are now <a href="#{show_user_wall_path(:url_name => @track_thing.tracking_user.url_name)}">following</a> updates about <a href="/list/successful">successful requests</a>)
+ subscribe_follow_notice(@track_thing).should == expected
+ end
+
end
describe 'when displaying notices for a new request track' do
@@ -68,6 +108,16 @@ describe TrackHelper do
already_subscribed_notice(@track_thing).should == expected
end
+ it 'should create an email subscription notice' do
+ expected = %Q(You will now be emailed updates about any <a href="/list">new requests</a>)
+ subscribe_email_notice(@track_thing).should == expected
+ end
+
+ it 'should create a following subscription notice' do
+ expected = %Q(You are now <a href="#{show_user_wall_path(:url_name => @track_thing.tracking_user.url_name)}">following</a> updates about <a href="/list">new requests</a>)
+ subscribe_follow_notice(@track_thing).should == expected
+ end
+
end
describe 'when displaying notices for a request update track' do
@@ -81,6 +131,16 @@ describe TrackHelper do
already_subscribed_notice(@track_thing).should == expected
end
+ it 'should create an email subscription notice' do
+ expected = %Q(You will now be emailed updates about '#{request_link(@track_thing.info_request)}', a request)
+ subscribe_email_notice(@track_thing).should == expected
+ end
+
+ it 'should create a following subscription notice' do
+ expected = %Q(You are now <a href="#{show_user_wall_path(:url_name => @track_thing.tracking_user.url_name)}">following</a> updates about '#{request_link(@track_thing.info_request)}', a request)
+ subscribe_follow_notice(@track_thing).should == expected
+ end
+
end
end