Files
nairobi/spec/shared/system/imageable.rb
Javi Martín 92ddcb7aef Use JavaScript in system tests by default
JavaScript is used by about 98% of web users, so by testing without it
enabled, we're only testing that the application works for a very
reduced number of users.

We proceeded this way in the past because CONSUL started using Rails 4.2
and truncating the database between JavaScript tests with database
cleaner, which made these tests terribly slow.

When we upgraded to Rails 5.1 and introduced system tests, we started
using database transactions in JavaScript tests, making these tests much
faster. So now we can use JavaScript tests everywhere without critically
slowing down our test suite.
2021-04-07 14:41:06 +02:00

44 lines
1.3 KiB
Ruby

shared_examples "imageable" do |imageable_factory_name, imageable_path, imageable_path_arguments|
let!(:administrator) { create(:user) }
let!(:user) { create(:user) }
let!(:imageable_arguments) { {} }
let!(:imageable) { create(imageable_factory_name, author: user) }
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" 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