Merge pull request #3150 from consul/backport-1769-crud_budget_and_usa

[Backport] new CRUD budgets, content blocks and heading map
This commit is contained in:
Julian Nicolas Herrero
2019-01-09 17:35:46 +01:00
committed by GitHub
21 changed files with 98 additions and 58 deletions

View File

@@ -20,7 +20,9 @@ feature "Admin budget groups" do
end
scenario "Disabled with a feature flag" do
expect { visit admin_budget_groups_path(budget) }.to raise_exception(FeatureFlags::FeatureDisabled)
expect do
visit admin_budget_groups_path(budget)
end.to raise_exception(FeatureFlags::FeatureDisabled)
end
end
@@ -30,7 +32,8 @@ feature "Admin budget groups" do
scenario "Displaying no groups for budget" do
visit admin_budget_groups_path(budget)
expect(page).to have_content "No groups created yet. Each user will be able to vote in only one heading per group."
expect(page).to have_content "No groups created yet. "
expect(page).to have_content "Each user will be able to vote in only one heading per group."
end
scenario "Displaying groups" do
@@ -49,21 +52,21 @@ feature "Admin budget groups" do
expect(page).to have_content(group1.name)
expect(page).to have_content(group1.max_votable_headings)
expect(page).to have_content(group1.headings.count)
expect(page).to have_link "Manage headings", href: admin_budget_group_headings_path(budget, group1)
expect(page).to have_link "Manage headings"
end
within "#budget_group_#{group2.id}" do
expect(page).to have_content(group2.name)
expect(page).to have_content(group2.max_votable_headings)
expect(page).to have_content(group2.headings.count)
expect(page).to have_link "Manage headings", href: admin_budget_group_headings_path(budget, group2)
expect(page).to have_link "Manage headings"
end
within "#budget_group_#{group3.id}" do
expect(page).to have_content(group3.name)
expect(page).to have_content(group3.max_votable_headings)
expect(page).to have_content(group3.headings.count)
expect(page).to have_link "Manage headings", href: admin_budget_group_headings_path(budget, group3)
expect(page).to have_link "Manage headings"
end
end
@@ -151,7 +154,7 @@ feature "Admin budget groups" do
fill_in "Group name", with: "Districts"
select "2", from: "Maximum number of headings in which a user can vote"
click_button "Edit group"
click_button "Save group"
expect(page).to have_content "Group updated successfully"
@@ -167,7 +170,7 @@ feature "Admin budget groups" do
expect(page).to have_field "Group name", with: "All City"
fill_in "Group name", with: "Districts"
click_button "Edit group"
click_button "Save group"
expect(page).not_to have_content "Group updated successfully"
expect(page).to have_css("label.error", text: "Group name")

View File

@@ -21,7 +21,9 @@ feature "Admin budget headings" do
end
scenario "Disabled with a feature flag" do
expect { visit admin_budget_group_headings_path(budget, group) }.to raise_exception(FeatureFlags::FeatureDisabled)
expect do
visit admin_budget_group_headings_path(budget, group)
end.to raise_exception(FeatureFlags::FeatureDisabled)
end
end
@@ -31,7 +33,8 @@ feature "Admin budget headings" do
scenario "Displaying no headings for group" do
visit admin_budget_group_headings_path(budget, group)
expect(page).to have_content "No headings created yet. Each user will be able to vote in only one heading per group."
expect(page).to have_content "No headings created yet. "
expect(page).to have_content "Each user will be able to vote in only one heading per group."
end
scenario "Displaying headings" do
@@ -47,8 +50,8 @@ feature "Admin budget headings" do
expect(page).to have_content "€1,000"
expect(page).not_to have_content "10000"
expect(page).to have_content "Yes"
expect(page).to have_link "Edit", href: edit_admin_budget_group_heading_path(budget, group, heading1)
expect(page).to have_link "Delete", href: admin_budget_group_heading_path(budget, group, heading1)
expect(page).to have_link "Edit"
expect(page).to have_link "Delete"
end
within "#budget_heading_#{heading2.id}" do
@@ -56,8 +59,8 @@ feature "Admin budget headings" do
expect(page).to have_content "€2,000"
expect(page).to have_content "10000"
expect(page).to have_content "No"
expect(page).to have_link "Edit", href: edit_admin_budget_group_heading_path(budget, group, heading2)
expect(page).to have_link "Delete", href: admin_budget_group_heading_path(budget, group, heading2)
expect(page).to have_link "Edit"
expect(page).to have_link "Delete"
end
within "#budget_heading_#{heading3.id}" do
@@ -65,8 +68,8 @@ feature "Admin budget headings" do
expect(page).to have_content "€3,000"
expect(page).to have_content "10000"
expect(page).to have_content "No"
expect(page).to have_link "Edit", href: edit_admin_budget_group_heading_path(budget, group, heading3)
expect(page).to have_link "Delete", href: admin_budget_group_heading_path(budget, group, heading3)
expect(page).to have_link "Edit"
expect(page).to have_link "Delete"
end
end
@@ -144,8 +147,8 @@ feature "Admin budget headings" do
expect(page).to have_field "Heading name", with: heading.name
expect(page).to have_field "Amount", with: heading.price
expect(page).to have_field "Population (optional)", with: heading.population
expect(page).to have_field "Longitude", with: heading.longitude
expect(page).to have_field "Latitude", with: heading.latitude
expect(page).to have_field "Longitude (optional)", with: heading.longitude
expect(page).to have_field "Latitude (optional)", with: heading.latitude
expect(find_field("Allow content block")).not_to be_checked
end
@@ -167,17 +170,17 @@ feature "Admin budget headings" do
expect(page).to have_field "Heading name", with: "All City"
expect(page).to have_field "Amount", with: 1000
expect(page).to have_field "Population (optional)", with: 10000
expect(page).to have_field "Longitude", with: 20.50
expect(page).to have_field "Latitude", with: -10.50
expect(page).to have_field "Longitude (optional)", with: 20.50
expect(page).to have_field "Latitude (optional)", with: -10.50
expect(find_field("Allow content block")).to be_checked
fill_in "Heading name", with: "Districts"
fill_in "Amount", with: "2000"
fill_in "Population (optional)", with: "20000"
fill_in "Longitude", with: "-40.47"
fill_in "Latitude", with: "25.25"
fill_in "Longitude (optional)", with: "-40.47"
fill_in "Latitude (optional)", with: "25.25"
uncheck "Allow content block"
click_button "Edit heading"
click_button "Save heading"
expect(page).to have_content "Heading updated successfully"
@@ -185,8 +188,8 @@ feature "Admin budget headings" do
expect(page).to have_field "Heading name", with: "Districts"
expect(page).to have_field "Amount", with: 2000
expect(page).to have_field "Population (optional)", with: 20000
expect(page).to have_field "Longitude", with: -40.47
expect(page).to have_field "Latitude", with: 25.25
expect(page).to have_field "Longitude (optional)", with: -40.47
expect(page).to have_field "Latitude (optional)", with: 25.25
expect(find_field("Allow content block")).not_to be_checked
end
@@ -197,7 +200,7 @@ feature "Admin budget headings" do
expect(page).to have_field "Heading name", with: "All City"
fill_in "Heading name", with: "Districts"
click_button "Edit heading"
click_button "Save heading"
expect(page).not_to have_content "Heading updated successfully"
expect(page).to have_css("label.error", text: "Heading name")

View File

@@ -1425,10 +1425,12 @@ feature 'Budget Investments' do
user = create(:user, :level_two)
global_group = create(:budget_group, budget: budget, name: 'Global Group')
global_heading = create(:budget_heading, group: global_group, name: 'Global Heading', latitude: -43.145412, longitude: 12.009423)
global_heading = create(:budget_heading, group: global_group, name: 'Global Heading',
latitude: -43.145412, longitude: 12.009423)
carabanchel_heading = create(:budget_heading, group: group, name: "Carabanchel")
new_york_heading = create(:budget_heading, group: group, name: "New York", latitude: -43.223412, longitude: 12.009423)
new_york_heading = create(:budget_heading, group: group, name: "New York",
latitude: -43.223412, longitude: 12.009423)
sp1 = create(:budget_investment, :selected, price: 1, heading: global_heading)
sp2 = create(:budget_investment, :selected, price: 10, heading: global_heading)

View File

@@ -5,7 +5,8 @@ feature 'Tags' do
let(:author) { create(:user, :level_two, username: 'Isabel') }
let(:budget) { create(:budget, name: "Big Budget") }
let(:group) { create(:budget_group, name: "Health", budget: budget) }
let!(:heading) { create(:budget_heading, name: "More hospitals", group: group, latitude: '40.416775', longitude: '-3.703790') }
let!(:heading) { create(:budget_heading, name: "More hospitals",
group: group, latitude: '40.416775', longitude: '-3.703790') }
let!(:tag_medio_ambiente) { create(:tag, :category, name: 'Medio Ambiente') }
let!(:tag_economia) { create(:tag, :category, name: 'Economía') }
let(:admin) { create(:administrator).user }

View File

@@ -1,6 +1,6 @@
require 'rails_helper'
RSpec.describe Budget::ContentBlock do
describe Budget::ContentBlock do
let(:block) { build(:heading_content_block) }
it "is valid" do
@@ -9,12 +9,14 @@ RSpec.describe Budget::ContentBlock do
it "Heading is unique per locale" do
heading_content_block_en = create(:heading_content_block, locale: "en")
invalid_block = build(:heading_content_block, heading: heading_content_block_en.heading, locale: "en")
invalid_block = build(:heading_content_block,
heading: heading_content_block_en.heading, locale: "en")
expect(invalid_block).to be_invalid
expect(invalid_block.errors.full_messages).to include("Heading has already been taken")
valid_block = build(:heading_content_block, heading: heading_content_block_en.heading, locale: "es")
valid_block = build(:heading_content_block,
heading: heading_content_block_en.heading, locale: "es")
expect(valid_block).to be_valid
end
end

View File

@@ -7,8 +7,8 @@ describe Budget::Heading do
it_behaves_like "sluggable", updatable_slug_trait: :drafting_budget
describe "::OSM_DISTRICT_LEVEL_ZOOM" do
it "should be defined" do
describe "OSM_DISTRICT_LEVEL_ZOOM constant" do
it "is defined" do
expect(Budget::Heading::OSM_DISTRICT_LEVEL_ZOOM).to be 12
end
end
@@ -205,7 +205,8 @@ describe Budget::Heading do
end
it "Allows longitude inside [-180,180] interval" do
heading = create(:budget_heading, group: group, name: 'Longitude is inside [-180,180] interval')
heading = create(:budget_heading, group: group,
name: 'Longitude is inside [-180,180] interval')
heading.longitude = '180'
expect(heading).to be_valid