Merge pull request #2864 from consul/backport_1543-budget_execution_list
Budget execution list
This commit is contained in:
@@ -124,6 +124,15 @@ feature 'Budgets' do
|
||||
|
||||
expect(page).to have_content "There are no budgets"
|
||||
end
|
||||
|
||||
scenario "Accepting" do
|
||||
budget.update(phase: "accepting")
|
||||
login_as(create(:user, :level_two))
|
||||
|
||||
visit budgets_path
|
||||
|
||||
expect(page).to have_link "Create a budget investment"
|
||||
end
|
||||
end
|
||||
|
||||
scenario 'Index shows only published phases' do
|
||||
|
||||
252
spec/features/budgets/executions_spec.rb
Normal file
252
spec/features/budgets/executions_spec.rb
Normal file
@@ -0,0 +1,252 @@
|
||||
require 'rails_helper'
|
||||
|
||||
feature 'Executions' do
|
||||
|
||||
let(:budget) { create(:budget, phase: 'finished') }
|
||||
let(:group) { create(:budget_group, budget: budget) }
|
||||
let(:heading) { create(:budget_heading, group: group) }
|
||||
|
||||
let!(:investment1) { create(:budget_investment, :winner, heading: heading) }
|
||||
let!(:investment2) { create(:budget_investment, :winner, heading: heading) }
|
||||
let!(:investment4) { create(:budget_investment, :winner, heading: heading) }
|
||||
let!(:investment3) { create(:budget_investment, :incompatible, heading: heading) }
|
||||
|
||||
scenario 'only displays investments with milestones' do
|
||||
create(:budget_investment_milestone, investment: investment1)
|
||||
|
||||
visit budget_path(budget)
|
||||
click_link 'See results'
|
||||
|
||||
expect(page).to have_link('Milestones')
|
||||
|
||||
click_link 'Milestones'
|
||||
|
||||
expect(page).to have_content(investment1.title)
|
||||
expect(page).not_to have_content(investment2.title)
|
||||
expect(page).not_to have_content(investment3.title)
|
||||
expect(page).not_to have_content(investment4.title)
|
||||
end
|
||||
|
||||
scenario "Do not display headings with no winning investments for selected status" do
|
||||
create(:budget_investment_milestone, investment: investment1)
|
||||
|
||||
empty_group = create(:budget_group, budget: budget)
|
||||
empty_heading = create(:budget_heading, group: empty_group, price: 1000)
|
||||
|
||||
visit budget_path(budget)
|
||||
click_link 'See results'
|
||||
|
||||
expect(page).to have_content(heading.name)
|
||||
expect(page).to have_content(empty_heading.name)
|
||||
|
||||
click_link 'Milestones'
|
||||
|
||||
expect(page).to have_content(heading.name)
|
||||
expect(page).not_to have_content(empty_heading.name)
|
||||
end
|
||||
|
||||
scenario "Show message when there are no winning investments with the selected status", :js do
|
||||
create(:budget_investment_status, name: I18n.t('seeds.budgets.statuses.executed'))
|
||||
|
||||
visit budget_path(budget)
|
||||
|
||||
click_link 'See results'
|
||||
click_link 'Milestones'
|
||||
|
||||
expect(page).not_to have_content('No winner investments in this state')
|
||||
|
||||
select 'Executed (0)', from: 'status'
|
||||
|
||||
expect(page).to have_content('No winner investments in this state')
|
||||
end
|
||||
|
||||
context 'Images' do
|
||||
scenario 'renders milestone image if available' do
|
||||
milestone1 = create(:budget_investment_milestone, investment: investment1)
|
||||
create(:image, imageable: milestone1)
|
||||
|
||||
visit budget_path(budget)
|
||||
|
||||
click_link 'See results'
|
||||
click_link 'Milestones'
|
||||
|
||||
expect(page).to have_content(investment1.title)
|
||||
expect(page).to have_css("img[alt='#{milestone1.image.title}']")
|
||||
end
|
||||
|
||||
scenario 'renders investment image if no milestone image is available' do
|
||||
create(:budget_investment_milestone, investment: investment2)
|
||||
create(:image, imageable: investment2)
|
||||
|
||||
visit budget_path(budget)
|
||||
|
||||
click_link 'See results'
|
||||
click_link 'Milestones'
|
||||
|
||||
expect(page).to have_content(investment2.title)
|
||||
expect(page).to have_css("img[alt='#{investment2.image.title}']")
|
||||
end
|
||||
|
||||
scenario 'renders default image if no milestone nor investment images are available' do
|
||||
create(:budget_investment_milestone, investment: investment4)
|
||||
|
||||
visit budget_path(budget)
|
||||
|
||||
click_link 'See results'
|
||||
click_link 'Milestones'
|
||||
|
||||
expect(page).to have_content(investment4.title)
|
||||
expect(page).to have_css("img[alt='#{investment4.title}']")
|
||||
end
|
||||
|
||||
scenario "renders last milestone's image if investment has multiple milestones with images associated" do
|
||||
milestone1 = create(:budget_investment_milestone, investment: investment1,
|
||||
publication_date: 2.weeks.ago)
|
||||
|
||||
milestone2 = create(:budget_investment_milestone, investment: investment1,
|
||||
publication_date: Date.yesterday)
|
||||
|
||||
create(:image, imageable: milestone1, title: 'First milestone image')
|
||||
create(:image, imageable: milestone2, title: 'Second milestone image')
|
||||
|
||||
visit budget_path(budget)
|
||||
|
||||
click_link 'See results'
|
||||
click_link 'Milestones'
|
||||
|
||||
expect(page).to have_content(investment1.title)
|
||||
expect(page).to have_css("img[alt='#{milestone2.image.title}']")
|
||||
expect(page).not_to have_css("img[alt='#{milestone1.image.title}']")
|
||||
end
|
||||
end
|
||||
|
||||
context 'Filters' do
|
||||
|
||||
let!(:status1) { create(:budget_investment_status, name: I18n.t('seeds.budgets.statuses.studying_project')) }
|
||||
let!(:status2) { create(:budget_investment_status, name: I18n.t('seeds.budgets.statuses.bidding')) }
|
||||
|
||||
scenario 'Filters select with counter are shown' do
|
||||
create(:budget_investment_milestone, investment: investment1,
|
||||
publication_date: Date.yesterday,
|
||||
status: status1)
|
||||
|
||||
create(:budget_investment_milestone, investment: investment2,
|
||||
publication_date: Date.yesterday,
|
||||
status: status2)
|
||||
|
||||
visit budget_path(budget)
|
||||
|
||||
click_link 'See results'
|
||||
click_link 'Milestones'
|
||||
|
||||
expect(page).to have_content("All (2)")
|
||||
expect(page).to have_content("#{status1.name} (1)")
|
||||
expect(page).to have_content("#{status2.name} (1)")
|
||||
end
|
||||
|
||||
scenario 'by milestone status', :js do
|
||||
create(:budget_investment_milestone, investment: investment1, status: status1)
|
||||
create(:budget_investment_milestone, investment: investment2, status: status2)
|
||||
create(:budget_investment_status, name: I18n.t('seeds.budgets.statuses.executing_project'))
|
||||
|
||||
visit budget_path(budget)
|
||||
|
||||
click_link 'See results'
|
||||
click_link 'Milestones'
|
||||
|
||||
expect(page).to have_content(investment1.title)
|
||||
expect(page).to have_content(investment2.title)
|
||||
|
||||
select 'Studying the project (1)', from: 'status'
|
||||
|
||||
expect(page).to have_content(investment1.title)
|
||||
expect(page).not_to have_content(investment2.title)
|
||||
|
||||
select 'Bidding (1)', from: 'status'
|
||||
|
||||
expect(page).to have_content(investment2.title)
|
||||
expect(page).not_to have_content(investment1.title)
|
||||
|
||||
select 'Executing the project (0)', from: 'status'
|
||||
|
||||
expect(page).not_to have_content(investment1.title)
|
||||
expect(page).not_to have_content(investment2.title)
|
||||
end
|
||||
|
||||
scenario 'are based on latest milestone status', :js do
|
||||
create(:budget_investment_milestone, investment: investment1,
|
||||
publication_date: 1.month.ago,
|
||||
status: status1)
|
||||
|
||||
create(:budget_investment_milestone, investment: investment1,
|
||||
publication_date: Date.yesterday,
|
||||
status: status2)
|
||||
|
||||
visit budget_path(budget)
|
||||
click_link 'See results'
|
||||
click_link 'Milestones'
|
||||
|
||||
select 'Studying the project (0)', from: 'status'
|
||||
expect(page).not_to have_content(investment1.title)
|
||||
|
||||
select 'Bidding (1)', from: 'status'
|
||||
expect(page).to have_content(investment1.title)
|
||||
end
|
||||
|
||||
scenario 'milestones with future dates are not shown', :js do
|
||||
create(:budget_investment_milestone, investment: investment1,
|
||||
publication_date: Date.yesterday,
|
||||
status: status1)
|
||||
|
||||
create(:budget_investment_milestone, investment: investment1,
|
||||
publication_date: Date.tomorrow,
|
||||
status: status2)
|
||||
|
||||
visit budget_path(budget)
|
||||
click_link 'See results'
|
||||
click_link 'Milestones'
|
||||
|
||||
select 'Studying the project (1)', from: 'status'
|
||||
expect(page).to have_content(investment1.title)
|
||||
|
||||
select 'Bidding (0)', from: 'status'
|
||||
expect(page).not_to have_content(investment1.title)
|
||||
end
|
||||
end
|
||||
|
||||
context 'Heading Order' do
|
||||
|
||||
def create_heading_with_investment_with_milestone(group:, name:)
|
||||
heading = create(:budget_heading, group: group, name: name)
|
||||
investment = create(:budget_investment, :winner, heading: heading)
|
||||
milestone = create(:budget_investment_milestone, investment: investment)
|
||||
heading
|
||||
end
|
||||
|
||||
scenario 'City heading is displayed first' do
|
||||
heading.destroy!
|
||||
other_heading1 = create_heading_with_investment_with_milestone(group: group, name: 'Other 1')
|
||||
city_heading = create_heading_with_investment_with_milestone(group: group, name: 'Toda la ciudad')
|
||||
other_heading2 = create_heading_with_investment_with_milestone(group: group, name: 'Other 2')
|
||||
|
||||
visit budget_executions_path(budget)
|
||||
|
||||
expect(page).to have_css('.budget-execution', count: 3)
|
||||
expect(city_heading.name).to appear_before(other_heading1.name)
|
||||
expect(city_heading.name).to appear_before(other_heading2.name)
|
||||
end
|
||||
|
||||
scenario 'Non-city headings are displayed in alphabetical order' do
|
||||
heading.destroy!
|
||||
z_heading = create_heading_with_investment_with_milestone(group: group, name: 'Zzz')
|
||||
a_heading = create_heading_with_investment_with_milestone(group: group, name: 'Aaa')
|
||||
m_heading = create_heading_with_investment_with_milestone(group: group, name: 'Mmm')
|
||||
|
||||
visit budget_executions_path(budget)
|
||||
|
||||
expect(page).to have_css('.budget-execution', count: 3)
|
||||
expect(a_heading.name).to appear_before(m_heading.name)
|
||||
expect(m_heading.name).to appear_before(z_heading.name)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -69,4 +69,16 @@ describe Budget::Investment::Milestone do
|
||||
end
|
||||
end
|
||||
|
||||
describe ".published" do
|
||||
it "uses the application's time zone date", :with_different_time_zone do
|
||||
published_in_local_time_zone = create(:budget_investment_milestone,
|
||||
publication_date: Date.today)
|
||||
|
||||
published_in_application_time_zone = create(:budget_investment_milestone,
|
||||
publication_date: Date.current)
|
||||
|
||||
expect(Budget::Investment::Milestone.published).to include(published_in_application_time_zone)
|
||||
expect(Budget::Investment::Milestone.published).not_to include(published_in_local_time_zone)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -90,6 +90,17 @@ RSpec.configure do |config|
|
||||
travel_back
|
||||
end
|
||||
|
||||
config.before(:each, :with_different_time_zone) do
|
||||
system_zone = ActiveSupport::TimeZone.new("UTC")
|
||||
local_zone = ActiveSupport::TimeZone.new("Madrid")
|
||||
|
||||
# Make sure the date defined by `config.time_zone` and
|
||||
# the local date are different.
|
||||
allow(Time).to receive(:zone).and_return(system_zone)
|
||||
allow(Time).to receive(:now).and_return(Date.current.at_end_of_day.in_time_zone(local_zone))
|
||||
allow(Date).to receive(:today).and_return(Time.now.to_date)
|
||||
end
|
||||
|
||||
# Allows RSpec to persist some state between runs in order to support
|
||||
# the `--only-failures` and `--next-failure` CLI options.
|
||||
config.example_status_persistence_file_path = "spec/examples.txt"
|
||||
|
||||
Reference in New Issue
Block a user