updates specs for admin poll questions
This commit is contained in:
@@ -181,6 +181,10 @@ FactoryGirl.define do
|
||||
4.times { create(:vote, votable: debate) }
|
||||
end
|
||||
end
|
||||
|
||||
trait :successful do
|
||||
cached_votes_up { Proposal.votes_needed_for_success + 100 }
|
||||
end
|
||||
end
|
||||
|
||||
factory :spending_proposal do
|
||||
@@ -280,6 +284,15 @@ FactoryGirl.define do
|
||||
end
|
||||
end
|
||||
|
||||
factory :poll_question, class: 'Poll::Question' do
|
||||
poll
|
||||
association :author, factory: :user
|
||||
sequence(:title) { |n| "Question title #{n}" }
|
||||
sequence(:summary) { |n| "Question summary #{n}" }
|
||||
sequence(:description) { |n| "Question description #{n}" }
|
||||
valid_answers { Faker::Lorem.words(3).join(', ') }
|
||||
end
|
||||
|
||||
factory :poll_officer, class: 'Poll::Officer' do
|
||||
user
|
||||
end
|
||||
@@ -309,16 +322,6 @@ FactoryGirl.define do
|
||||
end
|
||||
end
|
||||
|
||||
factory :poll_question, class: 'Poll::Question' do
|
||||
poll
|
||||
association :author, factory: :user
|
||||
sequence(:title) { |n| "Question title #{n}" }
|
||||
sequence(:summary) { |n| "Question summary #{n}" }
|
||||
sequence(:description) { |n| "Question description #{n}" }
|
||||
sequence(:question) { |n| "Question question #{n}" }
|
||||
valid_answers { Faker::Lorem.words(3).join(', ') }
|
||||
end
|
||||
|
||||
factory :poll_partial_result, class: 'Poll::PartialResult' do
|
||||
association :question, factory: :poll_question
|
||||
association :author, factory: :user
|
||||
|
||||
@@ -1,52 +1,33 @@
|
||||
require 'rails_helper'
|
||||
|
||||
feature 'Admin enquiries' do
|
||||
background { login_as(create(:administrator).user) }
|
||||
|
||||
background do
|
||||
login_as(create(:administrator).user)
|
||||
end
|
||||
|
||||
scenario 'Index' do
|
||||
e1 = create(:enquiry)
|
||||
e2 = create(:enquiry)
|
||||
question1 = create(:poll_question)
|
||||
question2 = create(:poll_question)
|
||||
|
||||
visit admin_enquiries_path
|
||||
visit admin_questions_path
|
||||
|
||||
expect(page).to have_content(e1.title)
|
||||
expect(page).to have_content(e2.title)
|
||||
expect(page).to have_content(question1.title)
|
||||
expect(page).to have_content(question2.title)
|
||||
end
|
||||
|
||||
scenario 'Destroy' do
|
||||
e1 = create(:enquiry)
|
||||
e2 = create(:enquiry)
|
||||
scenario 'Show' do
|
||||
geozone = create(:geozone)
|
||||
question = create(:poll_question, geozone_ids: geozone.id)
|
||||
|
||||
visit admin_enquiries_path
|
||||
visit admin_question_path(question)
|
||||
|
||||
within("#enquiry_#{e1.id}") do
|
||||
click_link "Delete"
|
||||
end
|
||||
|
||||
expect(page).to_not have_content(e1.title)
|
||||
expect(page).to have_content(e2.title)
|
||||
end
|
||||
|
||||
scenario 'Update' do
|
||||
e1 = create(:enquiry)
|
||||
visit admin_enquiries_path
|
||||
within("#enquiry_#{e1.id}") do
|
||||
click_link "Edit"
|
||||
end
|
||||
|
||||
old_title = e1.title
|
||||
new_title = "Potatoes are great and everyone should have one"
|
||||
fill_in 'enquiry_title', with: new_title
|
||||
|
||||
click_button 'Save'
|
||||
|
||||
expect(page).to have_content "Changes saved"
|
||||
expect(page).to have_content new_title
|
||||
|
||||
visit admin_enquiries_path
|
||||
|
||||
expect(page).to have_content(new_title)
|
||||
expect(page).to_not have_content(old_title)
|
||||
expect(page).to have_content(question.title)
|
||||
expect(page).to have_content(question.description)
|
||||
expect(page).to have_content(question.summary)
|
||||
expect(page).to have_content(question.author.name)
|
||||
expect(page).to have_content(question.valid_answers.join(", "))
|
||||
expect(page).to have_content(geozone.name)
|
||||
end
|
||||
|
||||
scenario 'Create' do
|
||||
@@ -56,53 +37,80 @@ feature 'Admin enquiries' do
|
||||
During the battle, Rebel spies managed to steal secret plans to the Empire's ultimate weapon, the DEATH STAR, an armored space station with enough power to destroy an entire planet.
|
||||
Pursued by the Empire's sinister agents, Princess Leia races home aboard her starship, custodian of the stolen plans that can save her people and restore freedom to the galaxy....
|
||||
}
|
||||
question = "Aren't you a little short for a stormtrooper?"
|
||||
|
||||
visit admin_enquiries_path
|
||||
click_link "Create enquiry"
|
||||
visit admin_questions_path
|
||||
click_link "Create question"
|
||||
|
||||
fill_in 'enquiry_title', with: title
|
||||
fill_in 'enquiry_summary', with: summary
|
||||
fill_in 'enquiry_description', with: description
|
||||
fill_in 'enquiry_question', with: question
|
||||
fill_in 'poll_question_title', with: title
|
||||
fill_in 'poll_question_summary', with: summary
|
||||
fill_in 'poll_question_description', with: description
|
||||
|
||||
click_button 'Save'
|
||||
|
||||
expect(page).to have_content(title)
|
||||
expect(page).to have_content(description)
|
||||
expect(page).to have_content(summary)
|
||||
expect(page).to have_content(question)
|
||||
end
|
||||
|
||||
scenario 'Create from successful proposal' do
|
||||
scenario 'Create from successful proposal', :focus do
|
||||
geozones = create_list(:geozone, 3)
|
||||
p = create(:proposal, :successful)
|
||||
proposal = create(:proposal, :successful)
|
||||
|
||||
visit proposals_path
|
||||
click_link "Create enquiry"
|
||||
click_link "Create question"
|
||||
|
||||
expect(current_path).to eq(new_admin_enquiry_path)
|
||||
expect(page).to have_field('enquiry_title', with: p.title)
|
||||
expect(page).to have_field('enquiry_summary', with: p.summary)
|
||||
expect(page).to have_field('enquiry_description', with: p.description)
|
||||
expect(page).to have_field('enquiry_question', with: p.question)
|
||||
expect(page).to have_field('enquiry_valid_answers', with: "Yes, No")
|
||||
|
||||
geozones.each do |g|
|
||||
expect(page).to have_checked_field("enquiry_geozone_ids_#{g.id}")
|
||||
end
|
||||
expect(current_path).to eq(new_admin_question_path)
|
||||
expect(page).to have_field('poll_question_title', with: proposal.title)
|
||||
expect(page).to have_field('poll_question_summary', with: proposal.summary)
|
||||
expect(page).to have_field('poll_question_description', with: proposal.description)
|
||||
expect(page).to have_field('poll_question_valid_answers', with: "Yes, No")
|
||||
|
||||
click_button 'Save'
|
||||
|
||||
expect(page).to have_content(p.title)
|
||||
expect(page).to have_content(p.summary)
|
||||
expect(page).to have_content(p.description)
|
||||
expect(page).to have_content(p.question)
|
||||
expect(page).to have_link('Original proposal', href: proposal_path(p))
|
||||
expect(page).to have_link(p.author.name, href: user_path(p.author))
|
||||
geozones.each do |g|
|
||||
expect(page).to have_content(g.name)
|
||||
end
|
||||
expect(page).to have_content(proposal.title)
|
||||
expect(page).to have_content(proposal.summary)
|
||||
expect(page).to have_content(proposal.description)
|
||||
expect(page).to have_link(proposal.title, href: proposal_path(proposal))
|
||||
expect(page).to have_link(proposal.author.name, href: user_path(proposal.author))
|
||||
end
|
||||
|
||||
scenario 'Update' do
|
||||
question1 = create(:poll_question)
|
||||
|
||||
visit admin_questions_path
|
||||
within("#poll_question_#{question1.id}") do
|
||||
click_link "Edit"
|
||||
end
|
||||
|
||||
old_title = question1.title
|
||||
new_title = "Potatoes are great and everyone should have one"
|
||||
fill_in 'poll_question_title', with: new_title
|
||||
|
||||
click_button 'Save'
|
||||
|
||||
expect(page).to have_content "Changes saved"
|
||||
expect(page).to have_content new_title
|
||||
|
||||
visit admin_questions_path
|
||||
|
||||
expect(page).to have_content(new_title)
|
||||
expect(page).to_not have_content(old_title)
|
||||
end
|
||||
|
||||
scenario 'Destroy' do
|
||||
question1 = create(:poll_question)
|
||||
question2 = create(:poll_question)
|
||||
|
||||
visit admin_questions_path
|
||||
|
||||
within("#poll_question_#{question1.id}") do
|
||||
click_link "Delete"
|
||||
end
|
||||
|
||||
expect(page).to_not have_content(question1.title)
|
||||
expect(page).to have_content(question2.title)
|
||||
end
|
||||
|
||||
pending "Mark all city by default when creating a poll question from a successful proposal"
|
||||
|
||||
end
|
||||
Reference in New Issue
Block a user