We were very inconsistent regarding these rules. Personally I prefer no empty lines around blocks, clases, etc... as recommended by the Ruby style guide [1], and they're the default values in rubocop, so those are the settings I'm applying. The exception is the `private` access modifier, since we were leaving empty lines around it most of the time. That's the default rubocop rule as well. Personally I don't have a strong preference about this one. [1] https://rubystyle.guide/#empty-lines-around-bodies
50 lines
1.5 KiB
Ruby
50 lines
1.5 KiB
Ruby
shared_examples "imageable" do |imageable_factory_name, imageable_path, imageable_path_arguments|
|
|
include ActionView::Helpers
|
|
include ImagesHelper
|
|
include ImageablesHelper
|
|
|
|
let!(:administrator) { create(:user) }
|
|
let!(:user) { create(:user) }
|
|
let!(:imageable_arguments) { {} }
|
|
let!(:imageables_arguments) { {} }
|
|
let!(:imageable) { create(imageable_factory_name, author: user) }
|
|
let!(:imageable_dom_name) { imageable_factory_name.parameterize }
|
|
|
|
before do
|
|
create(:administrator, user: administrator)
|
|
|
|
imageable_path_arguments.each do |argument_name, path_to_value|
|
|
imageable_arguments.merge!("#{argument_name}": imageable.send(path_to_value))
|
|
end
|
|
end
|
|
|
|
context "Show" do
|
|
scenario "Show descriptive image when exists", :js do
|
|
image = create(:image, imageable: imageable)
|
|
|
|
visit send(imageable_path, imageable_arguments)
|
|
|
|
expect(page).to have_css("img[alt='#{image.title}'][title='#{image.title}']")
|
|
end
|
|
|
|
scenario "Show image title when image exists" do
|
|
image = create(:image, imageable: imageable)
|
|
|
|
visit send(imageable_path, imageable_arguments)
|
|
|
|
expect(page).to have_content image.title
|
|
end
|
|
end
|
|
end
|
|
|
|
def attach_image(path, success = true)
|
|
image = find(".image")
|
|
image_input = image.find("input[type=file]", visible: false)
|
|
attach_file image_input[:id], path, make_visible: true
|
|
if success
|
|
expect(page).to have_css ".loading-bar.complete"
|
|
else
|
|
expect(page).to have_css ".loading-bar.errors"
|
|
end
|
|
end
|