Simplify creating images with title for milestones

This commit is contained in:
Javi Martín
2019-09-28 17:56:04 +02:00
parent 19edf0466b
commit c34ebc9a53
2 changed files with 10 additions and 9 deletions

View File

@@ -12,7 +12,11 @@ FactoryBot.define do
publication_date { Date.current }
trait :with_image do
after(:create) { |milestone| create(:image, imageable: milestone) }
transient { image_title { "Current status of the project" } }
after(:create) do |milestone, evaluator|
create(:image, imageable: milestone, title: evaluator.image_title)
end
end
factory :milestone_with_description do

View File

@@ -116,13 +116,10 @@ describe "Executions" do
end
scenario "renders last milestone's image if investment has multiple milestones with images associated" do
milestone1 = create(:milestone, milestoneable: investment1)
milestone2 = create(:milestone, milestoneable: investment1)
milestone3 = create(:milestone, milestoneable: investment1)
milestone4 = create(:milestone, milestoneable: investment1)
create(:image, imageable: milestone2, title: "Image for first milestone with image")
create(:image, imageable: milestone3, title: "Image for second milestone with image")
create(:milestone, milestoneable: investment1)
create(:milestone, :with_image, image_title: "First image", milestoneable: investment1)
create(:milestone, :with_image, image_title: "Second image", milestoneable: investment1)
create(:milestone, milestoneable: investment1)
visit budget_path(budget)
@@ -130,7 +127,7 @@ describe "Executions" do
click_link "Milestones"
expect(page).to have_content(investment1.title)
expect(page).to have_css("img[alt='#{milestone3.image.title}']")
expect(page).to have_css("img[alt='Second image']")
end
end