docbrown/spec/labor/generated_image_spec.rb
rhymes e588fa7ece Code cleanups (#659)
* Initial automatic cleanup with rubocop

* Fix syntax error introduced by rubocop

* Cleanup seeds file

* Cleanup lib folder

* Exclude bin folder because it contains auto generated files

* Make Rubocop a little bit more chatty

* Block length should not include comments in the count

* Cleanup config folder

* Cleanup specs

* Updated Rubocop version and generated a todo file

* Fix broken ArticlesApi spec

* Fix tests

* Restored rubocop pre-commit hook
2018-08-07 11:00:13 -04:00

31 lines
1.1 KiB
Ruby

require "rails_helper"
RSpec.describe GeneratedImage do
let(:user) { create(:user) }
let(:article) { create(:article, user_id: user.id) }
it "returns the social image url if there is a social image" do
article.social_image = Faker::Avatar.image
expect(described_class.new(article).social_image).to eq(article.social_image)
end
it "returns the main image if there is a main image" do
article.main_image = Faker::Avatar.image
article.social_image = nil
expect(described_class.new(article).social_image).to eq(article.main_image)
end
it "returns article social image" do
article.main_image = nil
article.social_image = nil
article.cached_tag_list = "discuss, hello, goodbye"
expect(described_class.new(article).social_image.include?("article/#{article.id}")).to eq(true)
end
it "creates various generated images of different title lengths" do
[25, 49, 79, 99, 105].each do |n|
article.assign_attributes(title: "0" * n, main_image: nil, cached_tag_list: "discuss, hello")
expect(described_class.new(article).social_image.include?(article.title)).to eq(true)
end
end
end