mirror of
https://github.com/discourse/discourse.git
synced 2025-05-30 15:28:37 +08:00
track incoming links, amend share link to include user
fix pm styling
This commit is contained in:
@ -8,68 +8,75 @@ describe IncomingLink do
|
||||
it { should ensure_length_of(:referer).is_at_least(3).is_at_most(1000) }
|
||||
it { should ensure_length_of(:domain).is_at_least(1).is_at_most(100) }
|
||||
|
||||
let :post do
|
||||
Fabricate(:post)
|
||||
end
|
||||
|
||||
let :topic do
|
||||
post.topic
|
||||
end
|
||||
|
||||
let :incoming_link do
|
||||
IncomingLink.create(url: "/t/slug/#{topic.id}/#{post.post_number}",
|
||||
referer: "http://twitter.com")
|
||||
end
|
||||
|
||||
describe 'local topic link' do
|
||||
|
||||
it 'should validate properly' do
|
||||
Fabricate.build(:incoming_link).should be_valid
|
||||
end
|
||||
|
||||
describe 'tracking link counts' do
|
||||
it "increases the incoming link counts" do
|
||||
incoming_link
|
||||
lambda { post.reload }.should change(post, :incoming_link_count).by(1)
|
||||
lambda { topic.reload }.should change(topic, :incoming_link_count).by(1)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'saving local link' do
|
||||
|
||||
before do
|
||||
@post = Fabricate(:post)
|
||||
@topic = @post.topic
|
||||
@incoming_link = IncomingLink.create(url: "/t/slug/#{@topic.id}/#{@post.post_number}",
|
||||
referer: "http://twitter.com")
|
||||
it 'has correct info set' do
|
||||
incoming_link.domain.should == "twitter.com"
|
||||
incoming_link.topic_id.should == topic.id
|
||||
incoming_link.post_number.should == post.post_number
|
||||
end
|
||||
|
||||
describe 'incoming link counts' do
|
||||
it "increases the post's incoming link count" do
|
||||
lambda { @incoming_link.save; @post.reload }.should change(@post, :incoming_link_count).by(1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
it "increases the topic's incoming link count" do
|
||||
lambda { @incoming_link.save; @topic.reload }.should change(@topic, :incoming_link_count).by(1)
|
||||
end
|
||||
describe 'add' do
|
||||
it "does nothing if referer is empty" do
|
||||
env = Rack::MockRequest.env_for("http://somesite.com")
|
||||
request = Rack::Request.new(env)
|
||||
IncomingLink.expects(:create).never
|
||||
IncomingLink.add(request)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe 'after save' do
|
||||
before do
|
||||
@incoming_link.save
|
||||
end
|
||||
|
||||
it 'has a domain' do
|
||||
@incoming_link.domain.should == "twitter.com"
|
||||
end
|
||||
|
||||
it 'has the topic_id' do
|
||||
@incoming_link.topic_id.should == @topic.id
|
||||
end
|
||||
|
||||
it 'has the post_number' do
|
||||
@incoming_link.post_number.should == @post.post_number
|
||||
end
|
||||
end
|
||||
it "does nothing if referer is same as host" do
|
||||
env = Rack::MockRequest.env_for("http://somesite.com")
|
||||
env['HTTP_REFERER'] = 'http://somesite.com'
|
||||
request = Rack::Request.new(env)
|
||||
IncomingLink.expects(:create).never
|
||||
IncomingLink.add(request)
|
||||
end
|
||||
|
||||
it "expects to be called with referer and user id" do
|
||||
env = Rack::MockRequest.env_for("http://somesite.com")
|
||||
env['HTTP_REFERER'] = 'http://some.other.site.com'
|
||||
request = Rack::Request.new(env)
|
||||
IncomingLink.expects(:create).once.returns(true)
|
||||
IncomingLink.add(request, 100)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'non-topic url' do
|
||||
|
||||
before do
|
||||
@link = Fabricate(:incoming_link_not_topic)
|
||||
end
|
||||
|
||||
it 'has no topic_id' do
|
||||
@link.topic_id.should be_blank
|
||||
end
|
||||
|
||||
it 'has no post_number' do
|
||||
@link.topic_id.should be_blank
|
||||
it 'has nothing set' do
|
||||
link = Fabricate(:incoming_link_not_topic)
|
||||
link.topic_id.should be_blank
|
||||
link.user_id.should be_blank
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
Reference in New Issue
Block a user