2013-02-05 14:16:51 -05:00
|
|
|
require "spec_helper"
|
|
|
|
|
|
|
|
describe "Stores incoming links" do
|
2013-02-25 11:42:20 -05:00
|
|
|
before do
|
2013-02-05 14:16:51 -05:00
|
|
|
TopicUser.stubs(:track_visit!)
|
|
|
|
end
|
|
|
|
|
2013-02-25 11:42:20 -05:00
|
|
|
let :topic do
|
2013-02-05 14:16:51 -05:00
|
|
|
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
|