docbrown/spec/helpers/social_image_helper_spec.rb
Mike Coutermarsh 4c9959f0ff Social Cards Part 2 (#2188)
* Social Cards Part 2

This is a follow up to part 1: https://github.com/thepracticaldev/dev.to/pull/2090.

This PR updates the og:image URLs to use the new social_preview.png urls
added in Part 1.

So that the already generated/cached images do not need to be recreated,
this sets a MIGRATION_DATETIME. Any object that has been updated after
that date will generate a new image

Objects from before that date will not. They will use the new url.

* Fix weird change made by rubocop autocorrect

* Handle organizations + users

* Run CI

* Use time with zone to be explicit about timezone

* Simplify branching in user_social_image_url method

* Fix param alignment + bump migration date
2019-05-01 11:07:25 -04:00

54 lines
1.6 KiB
Ruby

require "rails_helper"
describe SocialImageHelper do
let(:user) { create(:user) }
let(:article) { create(:article, main_image: nil) }
describe ".user_social_image_url" do
it "returns social preview path for newer users" do
url = helper.user_social_image_url(user)
expect(url).to eq user_social_preview_url(user, format: :png)
end
it "returns Organization social preview path for Orgs" do
organization = create(:organization)
url = helper.user_social_image_url(organization)
expect(url).to eq organization_social_preview_url(organization, format: :png)
end
it "returns older url2png image if already generated" do
user.updated_at = SocialImageHelper::SOCIAL_PREVIEW_MIGRATION_DATETIME - 1.week
url = helper.user_social_image_url(user)
expect(url).to eq GeneratedImage.new(user).social_image
end
end
describe ".article_social_image_url" do
it "returns social preview path for newer articles" do
url = helper.article_social_image_url(article)
expect(url).to eq article_social_preview_url(article, format: :png)
end
it "returns the main image if set" do
article.main_image = Faker::CryptoCoin.url_logo
url = helper.article_social_image_url(article)
expect(url).to match(/#{article.main_image}/)
end
it "returns older url2png image if already generated" do
article.updated_at = SocialImageHelper::SOCIAL_PREVIEW_MIGRATION_DATETIME - 1.week
url = helper.article_social_image_url(article)
expect(url).to eq GeneratedImage.new(article).social_image
end
end
end