Commit 5955193e79b8f9f09a2942f8ff7acd24c17fdec5

Authored by Weblate
2 parents 56bca894 0b9f2d0d

Merge remote-tracking branch 'origin/master'

plugins/custom_forms/lib/custom_forms_plugin/submission.rb
... ... @@ -5,7 +5,7 @@ class CustomFormsPlugin::Submission < Noosfero::Plugin::ActiveRecord
5 5 # validation is done manually, see below
6 6 has_many :answers, :class_name => 'CustomFormsPlugin::Answer', :dependent => :destroy, :validate => false
7 7  
8   - attr_accessible :form, :profile
  8 + attr_accessible :form, :profile, :author_name, :author_email
9 9  
10 10 validates_presence_of :form
11 11 validates_presence_of :author_name, :author_email, :if => lambda {|submission| submission.profile.nil?}
... ... @@ -13,13 +13,16 @@ class CustomFormsPlugin::Submission < Noosfero::Plugin::ActiveRecord
13 13 validates_format_of :author_email, :with => Noosfero::Constants::EMAIL_FORMAT, :if => (lambda {|submission| !submission.author_email.blank?})
14 14 validate :check_answers
15 15  
16   - def self.human_attribute_name(attrib)
17   - if /\d+/ =~ attrib and (f = CustomFormsPlugin::Field.find_by_id(attrib.to_i))
  16 + def self.human_attribute_name_with_customization(attrib, options={})
  17 + if /\d+/ =~ attrib and (f = CustomFormsPlugin::Field.find_by_id(attrib.to_s))
18 18 f.name
19 19 else
20   - attrib
  20 + _(self.human_attribute_name_without_customization(attrib))
21 21 end
22 22 end
  23 + class << self
  24 + alias_method_chain :human_attribute_name, :customization
  25 + end
23 26  
24 27 before_create do |submission|
25 28 if submission.profile
... ...
plugins/custom_forms/test/functional/custom_forms_plugin_profile_controller_test.rb
... ... @@ -40,6 +40,19 @@ class CustomFormsPluginProfileControllerTest &lt; ActionController::TestCase
40 40 assert_redirected_to :action => 'show'
41 41 end
42 42  
  43 + should 'display errors if user is not logged in and author_name is not uniq' do
  44 + logout
  45 + form = CustomFormsPlugin::Form.create(:profile => profile, :name => 'Free Software')
  46 + field = CustomFormsPlugin::TextField.create(:name => 'Name', :form => form)
  47 + submission = CustomFormsPlugin::Submission.create(:form => form, :author_name => "john", :author_email => 'john@example.com')
  48 +
  49 + assert_no_difference 'CustomFormsPlugin::Submission.count' do
  50 + post :show, :profile => profile.identifier, :id => form.id, :author_name => "john", :author_email => 'john@example.com', :submission => {field.id.to_s => 'Noosfero'}
  51 + end
  52 + assert_equal "Submission could not be saved", session[:notice]
  53 + assert_tag :tag => 'div', :attributes => { :class => 'errorExplanation', :id => 'errorExplanation' }
  54 + end
  55 +
43 56 should 'disable fields if form expired' do
44 57 form = CustomFormsPlugin::Form.create!(:profile => profile, :name => 'Free Software', :begining => Time.now + 1.day)
45 58 form.fields << CustomFormsPlugin::TextField.create(:name => 'Field Name', :form => form, :default_value => "First Field")
... ...