fixes bug: edit Debate was not validating captcha

This commit is contained in:
Juanjo Bazán
2015-08-15 23:49:05 +02:00
committed by Juanjo Bazán
parent b62729aac6
commit aeceaf9ea8
4 changed files with 46 additions and 2 deletions

View File

@@ -32,7 +32,8 @@ class DebatesController < ApplicationController
end
def update
if @debate.update(debate_params)
@debate.assign_attributes(debate_params)
if @debate.save_with_captcha
redirect_to @debate, notice: t('flash.actions.update.notice', resource_name: 'Debate')
else
load_featured_tags

View File

@@ -51,6 +51,26 @@ feature 'Debates' do
expect(page).to have_content I18n.l(Date.today)
end
scenario 'Captcha is required for debate creation' do
login_as(create(:user))
visit new_debate_path
fill_in 'debate_title', with: "Great title"
fill_in 'debate_description', with: 'Very important issue...'
fill_in 'debate_captcha', with: "wrongText!"
check 'debate_terms_of_service'
click_button "Create Debate"
expect(page).to_not have_content "Debate was successfully created."
expect(page).to have_content "1 error"
fill_in 'debate_captcha', with: correct_captcha_text
click_button "Create Debate"
expect(page).to have_content "Debate was successfully created."
end
scenario 'JS injection is prevented but safe html is respected' do
author = create(:user)
login_as(author)
@@ -152,6 +172,7 @@ feature 'Debates' do
fill_in 'debate_title', with: "End child poverty"
fill_in 'debate_description', with: "Let's..."
fill_in 'debate_captcha', with: correct_captcha_text
click_button "Update Debate"
@@ -160,6 +181,26 @@ feature 'Debates' do
expect(page).to have_content "Let's..."
end
scenario 'Captcha is required to update a debate' do
debate = create(:debate)
login_as(debate.author)
visit edit_debate_path(debate)
expect(current_path).to eq(edit_debate_path(debate))
fill_in 'debate_title', with: "New title"
fill_in 'debate_captcha', with: "wrong!"
click_button "Update Debate"
expect(page).to_not have_content "Debate was successfully updated."
expect(page).to have_content "1 error"
fill_in 'debate_captcha', with: correct_captcha_text
click_button "Update Debate"
expect(page).to have_content "Debate was successfully updated."
end
describe 'Limiting tags shown' do
let(:all_tags) {
["Hacienda", "Economía", "Medio Ambiente", "Corrupción", "Fiestas populares", "Prensa", "Huelgas"]

View File

@@ -85,6 +85,7 @@ feature 'Tags' do
expect(page).to have_selector("input[value='Economía']")
fill_in 'debate_tag_list', with: "Economía, Hacienda"
fill_in 'debate_captcha', with: correct_captcha_text
click_button 'Update Debate'
expect(page).to have_content 'Debate was successfully updated.'
@@ -101,6 +102,7 @@ feature 'Tags' do
visit edit_debate_path(debate)
fill_in 'debate_tag_list', with: ""
fill_in 'debate_captcha', with: correct_captcha_text
click_button 'Update Debate'
expect(page).to have_content 'Debate was successfully updated.'

View File

@@ -53,7 +53,7 @@ module CommonActions
end
def correct_captcha_text
SimpleCaptcha::SimpleCaptchaData.first.value
SimpleCaptcha::SimpleCaptchaData.last.value
end
def avatar(name)