2021-12-26 13:07:58 -08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2023-10-18 14:26:10 -07:00
|
|
|
require "rails_helper"
|
2021-12-26 13:07:58 -08:00
|
|
|
|
2023-10-18 14:26:10 -07:00
|
|
|
describe SocialHelper::TumblrMethods, type: :helper do
|
2021-12-26 13:07:58 -08:00
|
|
|
let(:user) { FactoryBot.create(:user) }
|
2023-10-18 14:26:10 -07:00
|
|
|
let(:answer) do
|
|
|
|
FactoryBot.create(:answer, user:,
|
|
|
|
content: "aaaa",
|
|
|
|
question_content: "q",)
|
|
|
|
end
|
2021-12-26 13:07:58 -08:00
|
|
|
|
2021-12-27 05:15:19 -08:00
|
|
|
before do
|
|
|
|
stub_const("APP_CONFIG", {
|
2023-10-18 14:26:10 -07:00
|
|
|
"hostname" => "example.com",
|
|
|
|
"anonymous_name" => "Anonymous",
|
|
|
|
"https" => true,
|
|
|
|
"items_per_page" => 5,
|
|
|
|
"sharing" => {},
|
|
|
|
},)
|
2021-12-27 05:15:19 -08:00
|
|
|
end
|
|
|
|
|
2023-10-18 14:26:10 -07:00
|
|
|
describe "#tumblr_title" do
|
|
|
|
context "Asker is anonymous" do
|
2021-12-26 13:07:58 -08:00
|
|
|
subject { tumblr_title(answer) }
|
|
|
|
|
2023-10-18 14:26:10 -07:00
|
|
|
it "should return a proper title" do
|
|
|
|
expect(subject).to eq("Anonymous asked: q")
|
2021-12-26 13:07:58 -08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-10-18 14:26:10 -07:00
|
|
|
context "Asker is known" do
|
2021-12-26 13:07:58 -08:00
|
|
|
before do
|
|
|
|
@user = FactoryBot.create(:user)
|
|
|
|
answer.question.user = @user
|
|
|
|
answer.question.author_is_anonymous = false
|
|
|
|
end
|
|
|
|
|
|
|
|
subject { tumblr_title(answer) }
|
|
|
|
|
2023-10-18 14:26:10 -07:00
|
|
|
it "should return a proper title" do
|
2021-12-26 13:07:58 -08:00
|
|
|
expect(subject).to eq("#{answer.question.user.profile.display_name} asked: q")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-10-18 14:26:10 -07:00
|
|
|
describe "#tumblr_body" do
|
2021-12-26 13:07:58 -08:00
|
|
|
subject { tumblr_body(answer) }
|
|
|
|
|
2023-10-18 14:26:10 -07:00
|
|
|
it "should return a proper body" do
|
2022-07-22 14:20:21 -07:00
|
|
|
expect(subject).to eq("aaaa\n\n[Smile or comment on the answer here](https://example.com/@#{answer.user.screen_name}/a/#{answer.id})")
|
2021-12-26 13:07:58 -08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-10-18 14:26:10 -07:00
|
|
|
describe "#tumblr_share_url" do
|
2021-12-26 13:07:58 -08:00
|
|
|
subject { tumblr_share_url(answer) }
|
|
|
|
|
2023-10-18 14:26:10 -07:00
|
|
|
it "should return a proper share link" do
|
2022-07-22 14:47:08 -07:00
|
|
|
expect(subject).to eq("https://www.tumblr.com/widgets/share/tool?shareSource=legacy&posttype=text&title=#{CGI.escape(tumblr_title(answer))}&url=#{CGI.escape("https://example.com/@#{answer.user.screen_name}/a/#{answer.id}")}&caption=&content=#{CGI.escape(tumblr_body(answer))}")
|
2021-12-26 13:07:58 -08:00
|
|
|
end
|
|
|
|
end
|
2022-01-05 09:32:30 -08:00
|
|
|
end
|