From 9b46a7fe8f15c192e108db7b367e6b37093f0e1b Mon Sep 17 00:00:00 2001 From: rgarcia Date: Thu, 17 Nov 2016 11:52:51 +0100 Subject: [PATCH] tmp commit adds specs for admin poll questions --- spec/features/admin/poll/questions_spec.rb | 108 +++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 spec/features/admin/poll/questions_spec.rb diff --git a/spec/features/admin/poll/questions_spec.rb b/spec/features/admin/poll/questions_spec.rb new file mode 100644 index 000000000..bab4e1a0e --- /dev/null +++ b/spec/features/admin/poll/questions_spec.rb @@ -0,0 +1,108 @@ +require 'rails_helper' + +feature 'Admin enquiries' do + background { login_as(create(:administrator).user) } + + scenario 'Index' do + e1 = create(:enquiry) + e2 = create(:enquiry) + + visit admin_enquiries_path + + expect(page).to have_content(e1.title) + expect(page).to have_content(e2.title) + end + + scenario 'Destroy' do + e1 = create(:enquiry) + e2 = create(:enquiry) + + visit admin_enquiries_path + + 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) + end + + scenario 'Create' do + 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 = %{ + 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" + + fill_in 'enquiry_title', with: title + fill_in 'enquiry_summary', with: summary + fill_in 'enquiry_description', with: description + fill_in 'enquiry_question', with: question + + 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 + geozones = create_list(:geozone, 3) + p = create(:proposal, :successful) + + visit proposals_path + click_link "Create enquiry" + + 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 + + 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 + end + +end \ No newline at end of file