diff --git a/plugins/custom_forms/lib/custom_forms_plugin/submission.rb b/plugins/custom_forms/lib/custom_forms_plugin/submission.rb index b0d91c8..b02cd82 100644 --- a/plugins/custom_forms/lib/custom_forms_plugin/submission.rb +++ b/plugins/custom_forms/lib/custom_forms_plugin/submission.rb @@ -5,7 +5,7 @@ class CustomFormsPlugin::Submission < Noosfero::Plugin::ActiveRecord # validation is done manually, see below has_many :answers, :class_name => 'CustomFormsPlugin::Answer', :dependent => :destroy, :validate => false - attr_accessible :form, :profile + attr_accessible :form, :profile, :author_name, :author_email validates_presence_of :form validates_presence_of :author_name, :author_email, :if => lambda {|submission| submission.profile.nil?} @@ -13,13 +13,16 @@ class CustomFormsPlugin::Submission < Noosfero::Plugin::ActiveRecord validates_format_of :author_email, :with => Noosfero::Constants::EMAIL_FORMAT, :if => (lambda {|submission| !submission.author_email.blank?}) validate :check_answers - def self.human_attribute_name(attrib) - if /\d+/ =~ attrib and (f = CustomFormsPlugin::Field.find_by_id(attrib.to_i)) + def self.human_attribute_name_with_customization(attrib, options={}) + if /\d+/ =~ attrib and (f = CustomFormsPlugin::Field.find_by_id(attrib.to_s)) f.name else - attrib + _(self.human_attribute_name_without_customization(attrib)) end end + class << self + alias_method_chain :human_attribute_name, :customization + end before_create do |submission| if submission.profile diff --git a/plugins/custom_forms/test/functional/custom_forms_plugin_profile_controller_test.rb b/plugins/custom_forms/test/functional/custom_forms_plugin_profile_controller_test.rb index 5965650..d6976b0 100644 --- a/plugins/custom_forms/test/functional/custom_forms_plugin_profile_controller_test.rb +++ b/plugins/custom_forms/test/functional/custom_forms_plugin_profile_controller_test.rb @@ -40,6 +40,19 @@ class CustomFormsPluginProfileControllerTest < ActionController::TestCase assert_redirected_to :action => 'show' end + should 'display errors if user is not logged in and author_name is not uniq' do + logout + form = CustomFormsPlugin::Form.create(:profile => profile, :name => 'Free Software') + field = CustomFormsPlugin::TextField.create(:name => 'Name', :form => form) + submission = CustomFormsPlugin::Submission.create(:form => form, :author_name => "john", :author_email => 'john@example.com') + + assert_no_difference 'CustomFormsPlugin::Submission.count' do + post :show, :profile => profile.identifier, :id => form.id, :author_name => "john", :author_email => 'john@example.com', :submission => {field.id.to_s => 'Noosfero'} + end + assert_equal "Submission could not be saved", session[:notice] + assert_tag :tag => 'div', :attributes => { :class => 'errorExplanation', :id => 'errorExplanation' } + end + should 'disable fields if form expired' do form = CustomFormsPlugin::Form.create!(:profile => profile, :name => 'Free Software', :begining => Time.now + 1.day) form.fields << CustomFormsPlugin::TextField.create(:name => 'Field Name', :form => form, :default_value => "First Field") -- libgit2 0.21.2