diff --git a/app/controllers/admin/budget_groups_controller.rb b/app/controllers/admin/budget_groups_controller.rb
index 512e2bfcd..d8048de48 100644
--- a/app/controllers/admin/budget_groups_controller.rb
+++ b/app/controllers/admin/budget_groups_controller.rb
@@ -17,7 +17,7 @@ class Admin::BudgetGroupsController < Admin::BaseController
private
def budget_group_params
- params.require(:budget_group).permit(:name)
+ params.require(:budget_group).permit(:name, :max_votable_headings)
end
end
diff --git a/app/views/admin/budgets/_group_form.html.erb b/app/views/admin/budgets/_group_form.html.erb
index c200973f0..0bb83b1b7 100644
--- a/app/views/admin/budgets/_group_form.html.erb
+++ b/app/views/admin/budgets/_group_form.html.erb
@@ -8,6 +8,19 @@
maxlength: 50,
placeholder: t("admin.budgets.form.group"),
class: "input-group-field" %>
+
+ <% if group.persisted? %>
+
+ <%= f.label :name, t("admin.budgets.form.max_votable_headings") %>
+
+ <%= f.select :max_votable_headings,
+ (1..group.headings.count),
+ label: false,
+ placeholder: t("admin.budgets.form.max_votable_headings"),
+ class: "input-group-field" %>
+
+ <% end %>
+
<%= f.submit button_title, class: "button success" %>
diff --git a/db/migrate/20180320104823_add_max_votable_headings_to_budget_groups.rb b/db/migrate/20180320104823_add_max_votable_headings_to_budget_groups.rb
new file mode 100644
index 000000000..e030b7b13
--- /dev/null
+++ b/db/migrate/20180320104823_add_max_votable_headings_to_budget_groups.rb
@@ -0,0 +1,5 @@
+class AddMaxVotableHeadingsToBudgetGroups < ActiveRecord::Migration
+ def change
+ add_column :budget_groups, :max_votable_headings, :integer, default: 1
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index a32417cc1..945f0d52e 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema.define(version: 20180220211105) do
+ActiveRecord::Schema.define(version: 20180320104823) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@@ -101,8 +101,9 @@ ActiveRecord::Schema.define(version: 20180220211105) do
create_table "budget_groups", force: :cascade do |t|
t.integer "budget_id"
- t.string "name", limit: 50
+ t.string "name", limit: 50
t.string "slug"
+ t.integer "max_votable_headings", default: 1
end
add_index "budget_groups", ["budget_id"], name: "index_budget_groups_on_budget_id", using: :btree
diff --git a/spec/features/admin/budget_groups_spec.rb b/spec/features/admin/budget_groups_spec.rb
index 90eaa90ac..d7c03d2e3 100644
--- a/spec/features/admin/budget_groups_spec.rb
+++ b/spec/features/admin/budget_groups_spec.rb
@@ -65,4 +65,49 @@ feature 'Admin can change the groups name' do
expect(page).to have_content('has already been taken')
end
+ context "Maximum votable headings" do
+
+ background do
+ 3.times { create(:budget_heading, group: group) }
+ end
+
+ scenario "Defaults to 1 heading per group", :js do
+ visit admin_budget_path(group.budget)
+
+ within("#budget_group_#{group.id}") do
+ click_link 'Edit group'
+
+ expect(page).to have_select('budget_group_max_votable_headings', selected: '1')
+ end
+ end
+
+ scenario "Update", :js do
+ visit admin_budget_path(group.budget)
+
+ within("#budget_group_#{group.id}") do
+ click_link 'Edit group'
+
+ select '2', from: 'budget_group_max_votable_headings'
+ click_button 'Save group'
+ end
+
+ visit admin_budget_path(group.budget)
+
+ within("#budget_group_#{group.id}") do
+ click_link 'Edit group'
+
+ expect(page).to have_select('budget_group_max_votable_headings', selected: '2')
+ end
+ end
+
+ scenario "Do not display maxium votable headings' select in new form", :js do
+ visit admin_budget_path(group.budget)
+
+ click_link 'Add new group'
+
+ expect(page).to have_field('budget_group_name')
+ expect(page).to_not have_field('budget_group_max_votable_headings')
+ end
+
+ end
end