diff --git a/spec/controllers/application_controller_spec.rb b/spec/controllers/application_controller_spec.rb index 4dbbcde18..00ba7824b 100644 --- a/spec/controllers/application_controller_spec.rb +++ b/spec/controllers/application_controller_spec.rb @@ -1,5 +1,51 @@ require 'spec_helper' +describe TopicsController do + before do + TopicUser.stubs(:track_visit!) + end + + let :topic do + Fabricate(:post).topic + end + + def set_referer(ref) + request.env['HTTP_REFERER'] = ref + end + + it "doesn't store an incoming link when there's no referer" do + lambda { + get :show, id: topic.id + }.should_not change(IncomingLink, :count) + end + + it "doesn't raise an error on a very long link" do + set_referer("http://#{'a' * 2000}.com") + lambda { get :show, {id: topic.id} }.should_not raise_error + end + + it "stores an incoming link when there is an off-site referer" do + lambda { + set_referer("http://google.com/search") + get :show, {id: topic.id} + }.should change(IncomingLink, :count).by(1) + end + + describe 'after inserting an incoming link' do + + it 'sets last link correctly' do + set_referer("http://google.com/search") + get :show, {topic_id: topic.id} + + last_link = IncomingLink.last + last_link.topic_id.should == topic.id + last_link.post_number.should == 1 + end + + end + +end + describe 'api' do describe PostsController do let(:user) do diff --git a/spec/requests/store_incoming_spec.rb b/spec/requests/store_incoming_spec.rb deleted file mode 100644 index d5d8e3864..000000000 --- a/spec/requests/store_incoming_spec.rb +++ /dev/null @@ -1,39 +0,0 @@ -require "spec_helper" - -describe "Stores incoming links" do - before do - TopicUser.stubs(:track_visit!) - end - - let :topic do - Fabricate(:post).topic - end - - it "doesn't store an incoming link when there's no referer" do - lambda { - get topic.relative_url - }.should_not change(IncomingLink, :count) - end - - it "doesn't raise an error on a very long link" do - lambda { get topic.relative_url, nil, {'HTTP_REFERER' => "http://#{'a' * 2000}.com"} }.should_not raise_error - end - - it "stores an incoming link when there is an off-site referer" do - lambda { - get topic.relative_url, nil, {'HTTP_REFERER' => "http://google.com/search"} - }.should change(IncomingLink, :count).by(1) - end - - describe 'after inserting an incoming link' do - - before do - get topic.relative_url + "/1", nil, {'HTTP_REFERER' => "http://google.com/search"} - @last_link = IncomingLink.last - @last_link.topic_id.should == topic.id - @last_link.post_number.should == 1 - end - - end - -end