Commit 5b7b8e5273a8ef165d8dba64e500832583da4835

Authored by Daniela Feitosa
1 parent 7eedf8a1

Fix: allowing submission of not logged users

Added the missing character to identify form
plugins/custom_forms/controllers/custom_forms_plugin_profile_controller.rb
@@ -9,7 +9,7 @@ class CustomFormsPluginProfileController < ProfileController @@ -9,7 +9,7 @@ class CustomFormsPluginProfileController < ProfileController
9 @submission = CustomFormsPlugin::Submission.find_by_form_id_and_profile_id(@form.id,user.id) 9 @submission = CustomFormsPlugin::Submission.find_by_form_id_and_profile_id(@form.id,user.id)
10 @submission ||= CustomFormsPlugin::Submission.new(:form => @form, :profile => user) 10 @submission ||= CustomFormsPlugin::Submission.new(:form => @form, :profile => user)
11 else 11 else
12 - @submission = CustomFormsPlugin::Submission.new(:form => @for) 12 + @submission = CustomFormsPlugin::Submission.new(:form => @form)
13 end 13 end
14 14
15 # build the answers 15 # build the answers
plugins/custom_forms/test/functional/custom_forms_plugin_profile_controller_test.rb
@@ -29,6 +29,17 @@ class CustomFormsPluginProfileControllerTest < ActionController::TestCase @@ -29,6 +29,17 @@ class CustomFormsPluginProfileControllerTest < ActionController::TestCase
29 assert_redirected_to :action => 'show' 29 assert_redirected_to :action => 'show'
30 end 30 end
31 31
  32 + should 'save submission if fields are ok and user is not logged in' do
  33 + logout
  34 + form = CustomFormsPlugin::Form.create!(:profile => profile, :name => 'Free Software')
  35 + field = CustomFormsPlugin::TextField.create(:name => 'Name', :form => form)
  36 +
  37 + assert_difference 'CustomFormsPlugin::Submission.count', 1 do
  38 + post :show, :profile => profile.identifier, :id => form.id, :author_name => "john", :author_email => 'john@example.com', :submission => {field.id.to_s => 'Noosfero'}
  39 + end
  40 + assert_redirected_to :action => 'show'
  41 + end
  42 +
32 should 'disable fields if form expired' do 43 should 'disable fields if form expired' do
33 form = CustomFormsPlugin::Form.create!(:profile => profile, :name => 'Free Software', :begining => Time.now + 1.day) 44 form = CustomFormsPlugin::Form.create!(:profile => profile, :name => 'Free Software', :begining => Time.now + 1.day)
34 form.fields << CustomFormsPlugin::TextField.create(:name => 'Field Name', :form => form, :default_value => "First Field") 45 form.fields << CustomFormsPlugin::TextField.create(:name => 'Field Name', :form => form, :default_value => "First Field")