diff --git a/app/controllers/admin/poll/questions_controller.rb b/app/controllers/admin/poll/questions_controller.rb index e257d8821..a9a1d0c76 100644 --- a/app/controllers/admin/poll/questions_controller.rb +++ b/app/controllers/admin/poll/questions_controller.rb @@ -54,7 +54,7 @@ class Admin::Poll::QuestionsController < Admin::BaseController private def question_params - params.require(:poll_question).permit(:title, :question, :summary, :description, :proposal_id, :valid_answers) + params.require(:poll_question).permit(:poll_id, :title, :question, :summary, :description, :proposal_id, :valid_answers) end def search_params diff --git a/app/models/poll/question.rb b/app/models/poll/question.rb index 16786a9b6..7d3da1b00 100644 --- a/app/models/poll/question.rb +++ b/app/models/poll/question.rb @@ -13,6 +13,7 @@ class Poll::Question < ActiveRecord::Base has_many :partial_results belongs_to :proposal + validates :poll_id, presence: true validates :title, presence: true validates :summary, presence: true validates :author, presence: true diff --git a/spec/features/admin/poll/questions_spec.rb b/spec/features/admin/poll/questions_spec.rb index a5e155848..de26889d6 100644 --- a/spec/features/admin/poll/questions_spec.rb +++ b/spec/features/admin/poll/questions_spec.rb @@ -31,6 +31,7 @@ feature 'Admin poll questions' do end scenario 'Create' do + poll = create(:poll, name: 'Movies') title = "Star Wars: Episode IV - A New Hope" summary = "It is a period of civil war. Rebel spaceships, striking from a hidden base, have won their first victory against the evil Galactic Empire" description = %{ @@ -41,6 +42,7 @@ feature 'Admin poll questions' do visit admin_questions_path click_link "Create question" + select 'Movies', from: 'poll_question_poll_id' fill_in 'poll_question_title', with: title fill_in 'poll_question_summary', with: summary fill_in 'poll_question_description', with: description @@ -53,6 +55,7 @@ feature 'Admin poll questions' do end scenario 'Create from successful proposal index' do + poll = create(:poll, name: 'Proposals') proposal = create(:proposal, :successful) visit proposals_path @@ -64,6 +67,8 @@ feature 'Admin poll questions' do expect(page).to have_field('poll_question_description', with: proposal.description) expect(page).to have_field('poll_question_valid_answers', with: "Yes, No") + select 'Proposals', from: 'poll_question_poll_id' + click_button 'Save' expect(page).to have_content(proposal.title)