2019-04-30 08:27:42 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-07-28 10:27:38 +08:00
|
|
|
RSpec.describe ClicksController do
|
2019-04-23 17:41:36 +08:00
|
|
|
let(:url) { "https://discourse.org/" }
|
|
|
|
let(:headers) { { REMOTE_ADDR: "192.168.0.1" } }
|
2019-05-07 16:19:13 +08:00
|
|
|
let(:post_with_url) { create_post(raw: "this is a post with a link #{url}") }
|
2018-06-07 12:57:29 +08:00
|
|
|
|
2022-07-27 18:21:10 +08:00
|
|
|
describe "#track" do
|
2019-04-23 17:41:36 +08:00
|
|
|
it "creates a TopicLinkClick" do
|
|
|
|
sign_in(Fabricate(:user))
|
2018-06-07 12:57:29 +08:00
|
|
|
|
2019-04-23 17:41:36 +08:00
|
|
|
expect {
|
2019-05-07 16:19:13 +08:00
|
|
|
post "/clicks/track",
|
|
|
|
params: {
|
|
|
|
url: url,
|
|
|
|
post_id: post_with_url.id,
|
|
|
|
topic_id: post_with_url.topic_id,
|
|
|
|
},
|
|
|
|
headers: headers
|
2019-04-23 17:41:36 +08:00
|
|
|
}.to change { TopicLinkClick.count }.by(1)
|
2018-06-07 12:57:29 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|