aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLouise Crow <louise.crow@gmail.com>2014-03-17 17:26:49 +0000
committerLouise Crow <louise.crow@gmail.com>2014-03-24 13:07:50 +0000
commitaec70771b7029f8c312e779a6e7fa6d5537abbed (patch)
tree8606808579587dc5c416e17a7fcb380e36ee2655
parent4bde7f5d1dce36ffeb47826b146b5d53a155d123 (diff)
Add notices for subscribing something you're subscribed to.
These notices are full sentences, rather than being composed of phrases, which should make them easier to translate.
-rw-r--r--app/controllers/track_controller.rb2
-rw-r--r--app/helpers/track_helper.rb26
-rw-r--r--spec/factories.rb18
-rw-r--r--spec/helpers/track_helper_spec.rb86
4 files changed, 131 insertions, 1 deletions
diff --git a/app/controllers/track_controller.rb b/app/controllers/track_controller.rb
index 103121689..a3a1ec42c 100644
--- a/app/controllers/track_controller.rb
+++ b/app/controllers/track_controller.rb
@@ -118,7 +118,7 @@ class TrackController < ApplicationController
if @user
@existing_track = TrackThing.find_existing(@user, @track_thing)
if @existing_track
- flash[:notice] = _("You are already following updates about {{track_description}}", :track_description => @track_thing.params[:list_description])
+ flash[:notice] = view_context.already_subscribed_notice(@track_thing)
return true
end
end
diff --git a/app/helpers/track_helper.rb b/app/helpers/track_helper.rb
new file mode 100644
index 000000000..e2615a33f
--- /dev/null
+++ b/app/helpers/track_helper.rb
@@ -0,0 +1,26 @@
+module TrackHelper
+
+ def already_subscribed_notice(track_thing)
+ case track_thing.track_type
+ when 'request_updates'
+ _("You are already subscribed to '{{link_to_request}}', a request",
+ :link_to_request => request_link(track_thing.info_request))
+ when 'all_new_requests'
+ _('You are already subscribed to any <a href="{{new_requests_url}}">new requests</a>',
+ :new_requests_url => request_list_path)
+ when 'all_successful_requests'
+ _('You are already subscribed to any <a href="{{successful_requests_url}}">successful requests</a>',
+ :successful_requests_url => request_list_successful_path )
+ when 'public_body_updates'
+ _("You are already subscribed to '{{link_to_authority}}', a public authority",
+ :link_to_authority => public_body_link(track_thing.public_body))
+ when 'user_updates'
+ _("You are already subscribed to '{{link_to_user}}', a person",
+ :link_to_user => user_link(track_thing.tracked_user))
+ when 'search_query'
+ _('You are already subscribed to <a href="{{search_url}}">this search</a>',
+ :search_url => search_path([track_thing.track_query, 'newest', 'advanced']))
+ end
+ end
+
+end
diff --git a/spec/factories.rb b/spec/factories.rb
index 0996ff0c4..7e6f0da99 100644
--- a/spec/factories.rb
+++ b/spec/factories.rb
@@ -145,6 +145,24 @@ FactoryGirl.define do
track_type 'search_query'
track_query 'Example Query'
end
+ factory :user_track do
+ association :tracked_user, :factory => :user
+ track_type 'user_updates'
+ end
+ factory :public_body_track do
+ association :public_body, :factory => :public_body
+ track_type 'public_body_updates'
+ end
+ factory :request_update_track do
+ association :info_request, :factory => :info_request
+ track_type 'request_updates'
+ end
+ factory :successful_request_track do
+ track_type 'all_successful_requests'
+ end
+ factory :new_request_track do
+ track_type 'all_new_requests'
+ end
end
factory :public_body_change_request do
diff --git a/spec/helpers/track_helper_spec.rb b/spec/helpers/track_helper_spec.rb
new file mode 100644
index 000000000..a009f87ac
--- /dev/null
+++ b/spec/helpers/track_helper_spec.rb
@@ -0,0 +1,86 @@
+require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
+
+describe TrackHelper do
+
+ include TrackHelper
+ include LinkToHelper
+
+ describe 'when displaying notices for a search track' do
+
+ before do
+ @track_thing = FactoryGirl.build(:search_track)
+ end
+
+ it 'should create an already subscribed_notice' do
+ expected = %Q(You are already subscribed to <a href="/search/Example%20Query/newest/advanced">this search</a>)
+ already_subscribed_notice(@track_thing).should == expected
+ end
+
+ end
+
+ describe 'when displaying notices for a user track' do
+
+ before do
+ @track_thing = FactoryGirl.build(:user_track)
+ end
+
+ it 'should create an already subscribed_notice' do
+ expected = %Q(You are already subscribed to '#{user_link(@track_thing.tracked_user)}', a person)
+ already_subscribed_notice(@track_thing).should == expected
+ end
+
+ end
+
+ describe 'when displaying notices for a public body track' do
+
+ before do
+ @track_thing = FactoryGirl.build(:public_body_track)
+ end
+
+ it 'should create an already subscribed_notice' do
+ expected = %Q(You are already subscribed to '#{public_body_link(@track_thing.public_body)}', a public authority)
+ already_subscribed_notice(@track_thing).should == expected
+ end
+
+ end
+
+ describe 'when displaying notices for a successful request track' do
+
+ before do
+ @track_thing = FactoryGirl.build(:successful_request_track)
+ end
+
+ it 'should create an already subscribed_notice' do
+ expected = %Q(You are already subscribed to any <a href="/list/successful">successful requests</a>)
+ already_subscribed_notice(@track_thing).should == expected
+ end
+
+ end
+
+ describe 'when displaying notices for a new request track' do
+
+ before do
+ @track_thing = FactoryGirl.build(:new_request_track)
+ end
+
+ it 'should create an already subscribed_notice' do
+ expected = %Q(You are already subscribed to any <a href="/list">new requests</a>)
+ already_subscribed_notice(@track_thing).should == expected
+ end
+
+ end
+
+ describe 'when displaying notices for a request update track' do
+
+ before do
+ @track_thing = FactoryGirl.build(:request_update_track)
+ end
+
+ it 'should create an already subscribed_notice' do
+ expected = %Q(You are already subscribed to '#{request_link(@track_thing.info_request)}', a request)
+ already_subscribed_notice(@track_thing).should == expected
+ end
+
+ end
+
+end