Merge pull request #3095 from consul/backport-share_milestoneable_code

Make milestones code reusable
This commit is contained in:
Javier Martín
2018-12-11 20:08:07 +01:00
committed by GitHub
125 changed files with 532 additions and 365 deletions

View File

@@ -2,120 +2,8 @@ require 'rails_helper'
feature 'Admin budget investment milestones' do
background do
admin = create(:administrator)
login_as(admin.user)
end
let!(:investment) { create(:budget_investment) }
it_behaves_like "translatable",
"milestone",
"edit_admin_budget_budget_investment_milestone_path",
%w[description]
context "Index" do
scenario 'Displaying milestones' do
milestone = create(:milestone, milestoneable: investment)
create(:image, imageable: milestone)
document = create(:document, documentable: milestone)
visit admin_budget_budget_investment_path(investment.budget, investment)
expect(page).to have_content("Milestone")
expect(page).to have_content(milestone.title)
expect(page).to have_content(milestone.id)
expect(page).to have_content(milestone.publication_date.to_date)
expect(page).to have_content(milestone.status.name)
expect(page).to have_link 'Show image'
expect(page).to have_link document.title
end
scenario 'Displaying no_milestones text' do
visit admin_budget_budget_investment_path(investment.budget, investment)
expect(page).to have_content("Milestone")
expect(page).to have_content("Don't have defined milestones")
end
end
context "New" do
scenario "Add milestone" do
status = create(:milestone_status)
visit admin_budget_budget_investment_path(investment.budget, investment)
click_link 'Create new milestone'
select status.name, from: 'milestone_status_id'
fill_in 'Description', with: 'New description milestone'
fill_in 'milestone_publication_date', with: Date.current
click_button 'Create milestone'
expect(page).to have_content 'New description milestone'
expect(page).to have_content Date.current
expect(page).to have_content status.name
end
scenario "Status select is disabled if there are no statuses available" do
visit admin_budget_budget_investment_path(investment.budget, investment)
click_link 'Create new milestone'
expect(find("#milestone_status_id").disabled?).to be true
end
scenario "Show validation errors on milestone form" do
visit admin_budget_budget_investment_path(investment.budget, investment)
click_link 'Create new milestone'
fill_in 'Description', with: 'New description milestone'
click_button 'Create milestone'
within "#new_milestone" do
expect(page).to have_content "can't be blank", count: 1
expect(page).to have_content 'New description milestone'
end
end
end
context "Edit" do
scenario "Change title, description and document names" do
milestone = create(:milestone, milestoneable: investment)
create(:image, imageable: milestone)
document = create(:document, documentable: milestone)
visit admin_budget_budget_investment_path(investment.budget, investment)
expect(page).to have_link document.title
click_link milestone.title
expect(page).to have_css("img[alt='#{milestone.image.title}']")
fill_in 'Description', with: 'Changed description'
fill_in 'milestone_publication_date', with: Date.current
fill_in 'milestone_documents_attributes_0_title', with: 'New document title'
click_button 'Update milestone'
expect(page).to have_content 'Changed description'
expect(page).to have_content Date.current
expect(page).to have_link 'Show image'
expect(page).to have_link 'New document title'
end
end
context "Delete" do
scenario "Remove milestone" do
milestone = create(:milestone, milestoneable: investment, title: "Title will it remove")
visit admin_budget_budget_investment_path(investment.budget, investment)
click_link "Delete milestone"
expect(page).not_to have_content 'Title will it remove'
end
end
end

View File

@@ -7,6 +7,10 @@ feature 'Admin budget investments' do
create(:administrator, user: create(:user, username: 'Ana', email: 'ana@admins.org'))
end
it_behaves_like "admin_milestoneable",
:budget_investment,
"admin_budget_budget_investment_path"
background do
@admin = create(:administrator)
login_as(@admin.user)

View File

@@ -10,6 +10,10 @@ feature 'Budget Investments' do
let(:group) { create(:budget_group, name: "Health", budget: budget) }
let!(:heading) { create(:budget_heading, name: "More hospitals", price: 666666, group: group) }
it_behaves_like "milestoneable",
:budget_investment,
"budget_investment_path"
before do
Setting['feature.allow_images'] = true
end
@@ -1118,59 +1122,6 @@ feature 'Budget Investments' do
expect(page).not_to have_content("Local government is not competent in this matter")
end
scenario "Show milestones", :js do
user = create(:user)
investment = create(:budget_investment)
create(:milestone, milestoneable: investment,
description_en: "Last milestone with a link to https://consul.dev",
description_es: "Último hito con el link https://consul.dev",
publication_date: Date.tomorrow)
first_milestone = create(:milestone, milestoneable: investment,
description: "First milestone",
publication_date: Date.yesterday)
image = create(:image, imageable: first_milestone)
document = create(:document, documentable: first_milestone)
login_as(user)
visit budget_investment_path(budget_id: investment.budget.id, id: investment.id)
find("#tab-milestones-label").click
within("#tab-milestones") do
expect(first_milestone.description).to appear_before('Last milestone with a link to https://consul.dev')
expect(page).to have_content(Date.tomorrow)
expect(page).to have_content(Date.yesterday)
expect(page).not_to have_content(Date.current)
expect(page.find("#image_#{first_milestone.id}")['alt']).to have_content(image.title)
expect(page).to have_link(document.title)
expect(page).to have_link("https://consul.dev")
expect(page).to have_content(first_milestone.status.name)
end
select('Español', from: 'locale-switcher')
find("#tab-milestones-label").click
within("#tab-milestones") do
expect(page).to have_content('Último hito con el link https://consul.dev')
expect(page).to have_link("https://consul.dev")
end
end
scenario "Show no_milestones text", :js do
user = create(:user)
investment = create(:budget_investment)
login_as(user)
visit budget_investment_path(budget_id: investment.budget.id, id: investment.id)
find("#tab-milestones-label").click
within("#tab-milestones") do
expect(page).to have_content("Don't have defined milestones")
end
end
scenario "Only winner investments are show when budget is finished" do
3.times { create(:budget_investment, heading: heading) }