aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/track_controller_spec.rb6
-rw-r--r--spec/factories.rb6
-rw-r--r--spec/factories/track_things.rb26
-rw-r--r--spec/helpers/track_helper_spec.rb204
-rw-r--r--spec/models/track_thing_spec.rb9
5 files changed, 235 insertions, 16 deletions
diff --git a/spec/controllers/track_controller_spec.rb b/spec/controllers/track_controller_spec.rb
index 40865d2b9..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)
@@ -58,7 +58,7 @@ end
describe TrackController, "when unsubscribing from a track" do
before do
- @track_thing = FactoryGirl.create(:track_thing)
+ @track_thing = FactoryGirl.create(:search_track)
end
it 'should destroy the track thing' do
@@ -78,7 +78,7 @@ describe TrackController, "when unsubscribing from a track" do
end
it 'should not redirect to a url on another site' do
- track_thing = FactoryGirl.create(:track_thing)
+ track_thing = FactoryGirl.create(:search_track)
get :update, {:track_id => @track_thing.id,
:track_medium => 'delete',
:r => 'http://example.com/'},
diff --git a/spec/factories.rb b/spec/factories.rb
deleted file mode 100644
index 7dec41aaf..000000000
--- a/spec/factories.rb
+++ /dev/null
@@ -1,6 +0,0 @@
-# Factories are defined in spec/factories/*.rb
-#
-# You can use this file to define shared sequences
-FactoryGirl.define do
-
-end
diff --git a/spec/factories/track_things.rb b/spec/factories/track_things.rb
index d1a937c02..cf76b00b3 100644
--- a/spec/factories/track_things.rb
+++ b/spec/factories/track_things.rb
@@ -2,9 +2,29 @@ FactoryGirl.define do
factory :track_thing do
association :tracking_user, :factory => :user
- track_medium 'email_daily'
- track_type 'search_query'
- track_query 'Example Query'
+ factory :search_track do
+ track_medium 'email_daily'
+ 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
end
diff --git a/spec/helpers/track_helper_spec.rb b/spec/helpers/track_helper_spec.rb
new file mode 100644
index 000000000..80857067b
--- /dev/null
+++ b/spec/helpers/track_helper_spec.rb
@@ -0,0 +1,204 @@
+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
+
+ 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
+
+ it 'should create an unsubscribe notice' do
+ expected = %Q(You are no longer following <a href="/search/Example%20Query/newest/advanced">this search</a>)
+ 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
+
+ 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
+
+ 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
+
+ it 'should create an unsubscribe notice' do
+ expected = %Q(You are no longer following '#{user_link(@track_thing.tracked_user)}', a person)
+ 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
+
+ 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
+
+ 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
+
+ it 'should create an unsubscribe notice' 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
+
+ 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
+
+ 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
+
+ it 'should create an unsubscribe notice' do
+ expected = %Q(You are no longer following <a href="/list/successful">successful requests</a>)
+ 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
+
+ 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
+
+ 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
+
+ it 'should create an unsubscribe notice' do
+ expected = %Q(You are no longer following <a href="/list">new requests</a>)
+ 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
+
+ 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
+
+ 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
+
+ it 'should create an unsubscribe notice' do
+ expected = %Q(You are no longer following '#{request_link(@track_thing.info_request)}', a request)
+ 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
diff --git a/spec/models/track_thing_spec.rb b/spec/models/track_thing_spec.rb
index 1c582564b..3edf2d1ad 100644
--- a/spec/models/track_thing_spec.rb
+++ b/spec/models/track_thing_spec.rb
@@ -51,10 +51,11 @@ describe TrackThing, "when tracking changes" do
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)' => "comments or requests which are successful or unsuccessful matching text 'bob'",
- '(latest_status:waiting_response OR latest_status:waiting_clarification OR waiting_classification:true)' => 'requests which are awaiting a response',
- ' (variety:sent OR variety:followup_sent OR variety:response OR variety:comment)' => 'all requests or comments' }
+ tests = { ' (variety:sent OR variety:followup_sent OR variety:response OR variety:comment)' => 'all requests or comments',
+ 'bob (variety:sent OR variety:followup_sent OR variety:response OR variety:comment)' => "all requests or comments matching text 'bob'",
+ 'bob (latest_status:successful OR latest_status:partially_successful)' => "requests which are successful matching text 'bob'",
+ '(latest_status:successful OR latest_status:partially_successful)' => 'requests which are successful',
+ 'bob' => "anything matching text 'bob'" }
tests.each do |query, description|
track_thing = TrackThing.create_track_for_search_query(query)
track_thing.track_query_description.should == description