diff --git a/plugins/custom_forms/controllers/custom_forms_plugin_myprofile_controller.rb b/plugins/custom_forms/controllers/custom_forms_plugin_myprofile_controller.rb index 4aedeb3..caafcb6 100644 --- a/plugins/custom_forms/controllers/custom_forms_plugin_myprofile_controller.rb +++ b/plugins/custom_forms/controllers/custom_forms_plugin_myprofile_controller.rb @@ -75,13 +75,14 @@ class CustomFormsPluginMyprofileController < MyProfileController format.csv do # CSV contains form fields, timestamp, user name and user email columns = @form.fields.count + 3 - csv_content = CSV.generate_line(['Timestamp', 'Name', 'Email'] + @form.fields.map(&:name)) + "\n" + csv_content = CSV.generate_line(['Timestamp', 'Name', 'Email'] + @form.fields.map(&:name)) @submissions.each do |s| fields = [s.updated_at.strftime('%Y/%m/%d %T %Z'), s.profile.present? ? s.profile.name : s.author_name, s.profile.present? ? s.profile.email : s.author_email] @form.fields.each do |f| fields << s.answers.select{|a| a.field == f}.map{|answer| answer.to_s} end - CSV.generate_row(fields, columns, csv_content) + fields = fields.flatten + csv_content << CSV.generate_line(fields + (columns - fields.size).times.map{""}) end send_data csv_content, :type => 'text/csv', :filename => "#{@form.name}.csv" end diff --git a/plugins/custom_forms/controllers/custom_forms_plugin_profile_controller.rb b/plugins/custom_forms/controllers/custom_forms_plugin_profile_controller.rb index e1138e7..c770b0f 100644 --- a/plugins/custom_forms/controllers/custom_forms_plugin_profile_controller.rb +++ b/plugins/custom_forms/controllers/custom_forms_plugin_profile_controller.rb @@ -7,9 +7,9 @@ class CustomFormsPluginProfileController < ProfileController @form = CustomFormsPlugin::Form.find(params[:id]) if user @submission ||= CustomFormsPlugin::Submission.find_by_form_id_and_profile_id(@form.id,user.id) - @submission ||= CustomFormsPlugin::Submission.new(:form_id => @form.id, :profile_id => user.id) + @submission ||= CustomFormsPlugin::Submission.new(:form => @form, :profile => user) else - @submission ||= CustomFormsPlugin::Submission.new(:form_id => @form.id) + @submission ||= CustomFormsPlugin::Submission.new(:form => @form) end # build the answers diff --git a/plugins/custom_forms/lib/custom_forms_plugin/alternative.rb b/plugins/custom_forms/lib/custom_forms_plugin/alternative.rb index 81aee63..20077e9 100644 --- a/plugins/custom_forms/lib/custom_forms_plugin/alternative.rb +++ b/plugins/custom_forms/lib/custom_forms_plugin/alternative.rb @@ -4,5 +4,7 @@ class CustomFormsPlugin::Alternative < ActiveRecord::Base validates_presence_of :label belongs_to :field, :class_name => 'CustomFormsPlugin::Field' + + attr_accessible :label, :field, :position end diff --git a/plugins/custom_forms/lib/custom_forms_plugin/answer.rb b/plugins/custom_forms/lib/custom_forms_plugin/answer.rb index d29766f..c7730a9 100644 --- a/plugins/custom_forms/lib/custom_forms_plugin/answer.rb +++ b/plugins/custom_forms/lib/custom_forms_plugin/answer.rb @@ -1,10 +1,13 @@ -class CustomFormsPlugin::Answer < Noosfero::Plugin::ActiveRecord +class CustomFormsPlugin::Answer < ActiveRecord::Base + set_table_name :custom_forms_plugin_answers belongs_to :field, :class_name => 'CustomFormsPlugin::Field' belongs_to :submission, :class_name => 'CustomFormsPlugin::Submission' validates_presence_of :field validate :value_mandatory, :if => 'field.present?' + attr_accessible :field, :value, :submission + def value_mandatory if field.mandatory && value.blank? errors.add(:value, _("is mandatory.").fix_i18n) diff --git a/plugins/custom_forms/lib/custom_forms_plugin/field.rb b/plugins/custom_forms/lib/custom_forms_plugin/field.rb index 5b1d45c..7d53b75 100644 --- a/plugins/custom_forms/lib/custom_forms_plugin/field.rb +++ b/plugins/custom_forms/lib/custom_forms_plugin/field.rb @@ -3,6 +3,8 @@ class CustomFormsPlugin::Field < ActiveRecord::Base validates_presence_of :name + attr_accessible :name, :form, :mandatory, :type, :position, :default_value, :select_field_type, :alternatives_attributes + belongs_to :form, :class_name => 'CustomFormsPlugin::Form' has_many :answers, :class_name => 'CustomFormsPlugin::Answer' diff --git a/plugins/custom_forms/lib/custom_forms_plugin/form.rb b/plugins/custom_forms/lib/custom_forms_plugin/form.rb index 0eed935..3d58c0e 100644 --- a/plugins/custom_forms/lib/custom_forms_plugin/form.rb +++ b/plugins/custom_forms/lib/custom_forms_plugin/form.rb @@ -13,6 +13,8 @@ class CustomFormsPlugin::Form < Noosfero::Plugin::ActiveRecord validate :period_range, :if => Proc.new { |f| f.begining.present? && f.ending.present? } validate :access_format + attr_accessible :name, :profile, :for_admission, :access, :begining, :ending, :description, :fields_attributes, :profile_id, :on_membership + before_validation do |form| form.slug = form.name.to_slug if form.name.present? form.access = nil if form.access.blank? @@ -23,11 +25,11 @@ class CustomFormsPlugin::Form < Noosfero::Plugin::ActiveRecord tasks.each {|task| task.cancel} end - named_scope :from, lambda {|profile| {:conditions => {:profile_id => profile.id}}} - named_scope :on_memberships, {:conditions => {:on_membership => true, :for_admission => false}} - named_scope :for_admissions, {:conditions => {:for_admission => true}} + scope :from, lambda {|profile| {:conditions => {:profile_id => profile.id}}} + scope :on_memberships, {:conditions => {:on_membership => true, :for_admission => false}} + scope :for_admissions, {:conditions => {:for_admission => true}} =begin - named_scope :accessible_to lambda do |profile| + scope :accessible_to lambda do |profile| #TODO should verify is profile is associated with the form owner profile_associated = ??? {:conditions => [" diff --git a/plugins/custom_forms/lib/custom_forms_plugin/membership_survey.rb b/plugins/custom_forms/lib/custom_forms_plugin/membership_survey.rb index fa13893..4e1e22e 100644 --- a/plugins/custom_forms/lib/custom_forms_plugin/membership_survey.rb +++ b/plugins/custom_forms/lib/custom_forms_plugin/membership_survey.rb @@ -5,7 +5,7 @@ class CustomFormsPlugin::MembershipSurvey < Task include CustomFormsPlugin::Helper - named_scope :from, lambda {|profile| {:conditions => {:requestor_id => profile.id}}} + scope :from, lambda {|profile| {:conditions => {:requestor_id => profile.id}}} def perform form = CustomFormsPlugin::Form.find(form_id) diff --git a/plugins/custom_forms/lib/custom_forms_plugin/submission.rb b/plugins/custom_forms/lib/custom_forms_plugin/submission.rb index 752872b..463dd36 100644 --- a/plugins/custom_forms/lib/custom_forms_plugin/submission.rb +++ b/plugins/custom_forms/lib/custom_forms_plugin/submission.rb @@ -4,6 +4,8 @@ class CustomFormsPlugin::Submission < Noosfero::Plugin::ActiveRecord has_many :answers, :class_name => 'CustomFormsPlugin::Answer', :dependent => :destroy + attr_accessible :form, :profile + validates_presence_of :form validates_presence_of :author_name, :author_email, :if => lambda {|submission| submission.profile.nil?} validates_uniqueness_of :author_email, :scope => :form_id, :allow_nil => true diff --git a/plugins/custom_forms/lib/custom_forms_plugin/text_field.rb b/plugins/custom_forms/lib/custom_forms_plugin/text_field.rb index 9524a81..e923030 100644 --- a/plugins/custom_forms/lib/custom_forms_plugin/text_field.rb +++ b/plugins/custom_forms/lib/custom_forms_plugin/text_field.rb @@ -1,3 +1,5 @@ class CustomFormsPlugin::TextField < CustomFormsPlugin::Field set_table_name :custom_forms_plugin_fields + + attr_accessible :name end diff --git a/plugins/custom_forms/lib/ext/role_assignment_trigger.rb b/plugins/custom_forms/lib/ext/role_assignment_trigger.rb index d3145f7..3348819 100644 --- a/plugins/custom_forms/lib/ext/role_assignment_trigger.rb +++ b/plugins/custom_forms/lib/ext/role_assignment_trigger.rb @@ -14,7 +14,7 @@ module RoleAssignmentTrigger end end - before_validation_on_create do |ra| + before_validation :on => :create do |ra| proceed_creation = true if ra.resource.kind_of?(Profile) profile = ra.resource diff --git a/plugins/custom_forms/test/functional/custom_forms_plugin_myprofile_controller_test.rb b/plugins/custom_forms/test/functional/custom_forms_plugin_myprofile_controller_test.rb index b02896d..7a4fa45 100644 --- a/plugins/custom_forms/test/functional/custom_forms_plugin_myprofile_controller_test.rb +++ b/plugins/custom_forms/test/functional/custom_forms_plugin_myprofile_controller_test.rb @@ -41,7 +41,7 @@ class CustomFormsPluginMyprofileControllerTest < ActionController::TestCase format = '%Y-%m-%d %H:%M' begining = Time.now.strftime(format) ending = (Time.now + 1.day).strftime(format) - assert_difference CustomFormsPlugin::Form, :count, 1 do + assert_difference 'CustomFormsPlugin::Form.count', 1 do post :create, :profile => profile.identifier, :form => { :name => 'My Form', @@ -102,7 +102,7 @@ class CustomFormsPluginMyprofileControllerTest < ActionController::TestCase :type => 'CustomFormsPlugin::TextField' } end - assert_difference CustomFormsPlugin::Form, :count, 1 do + assert_difference 'CustomFormsPlugin::Form.count', 1 do post :create, :profile => profile.identifier, :form => { :name => 'My Form', @@ -139,7 +139,7 @@ class CustomFormsPluginMyprofileControllerTest < ActionController::TestCase :type => 'CustomFormsPlugin::TextField', :position => '1' } - assert_difference CustomFormsPlugin::Form, :count, 1 do + assert_difference 'CustomFormsPlugin::Form.count', 1 do post :create, :profile => profile.identifier, :form => { :name => 'My Form', @@ -195,26 +195,26 @@ class CustomFormsPluginMyprofileControllerTest < ActionController::TestCase answer = CustomFormsPlugin::Answer.create!(:value => 'example', :field => field) - sub1 = CustomFormsPlugin::Submission.create!(:author_name => "john", :author_email => 'john@example.com', :form => form) + sub1 = create(CustomFormsPlugin::Submission, :author_name => "john", :author_email => 'john@example.com', :form => form) sub1.answers << answer bob = create_user('bob').person sub2 = CustomFormsPlugin::Submission.create!(:profile => bob, :form => form) get :submissions, :profile => profile.identifier, :id => form.id, :format => 'csv' - assert_equal @response.content_type, 'text/csv' - assert_equal @response.body.split("\n")[0], 'Timestamp,Name,Email,Title' - assert_equal @response.body.split("\n")[1], "#{sub1.updated_at.strftime('%Y/%m/%d %T %Z')},john,john@example.com,example" - assert_equal @response.body.split("\n")[2], "#{sub2.updated_at.strftime('%Y/%m/%d %T %Z')},bob,#{bob.email},\"\"" + assert_equal 'text/csv', @response.content_type + assert_equal 'Timestamp,Name,Email,Title', @response.body.split("\n")[0] + assert_equal "#{sub1.updated_at.strftime('%Y/%m/%d %T %Z')},john,john@example.com,example", @response.body.split("\n")[1] + assert_equal "#{sub2.updated_at.strftime('%Y/%m/%d %T %Z')},bob,#{bob.email},\"\"", @response.body.split("\n")[2] end should 'order submissions by name or time' do form = CustomFormsPlugin::Form.create!(:profile => profile, :name => 'Free Software') field = CustomFormsPlugin::TextField.create!(:name => "Title") form.fields << field - sub1 = CustomFormsPlugin::Submission.create!(:author_name => "john", :author_email => 'john@example.com', :form => form) + sub1 = create(CustomFormsPlugin::Submission, :author_name => "john", :author_email => 'john@example.com', :form => form) bob = create_user('bob').person - sub2 = CustomFormsPlugin::Submission.create!(:profile => bob, :form => form) + sub2 = create(CustomFormsPlugin::Submission, :profile => bob, :form => form) get :submissions, :profile => profile.identifier, :id => form.id, :sort_by => 'time' assert_not_nil assigns(:sort_by) 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 237ca95..a350096 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 @@ -22,7 +22,7 @@ class CustomFormsPluginProfileControllerTest < ActionController::TestCase field1 = CustomFormsPlugin::TextField.create(:name => 'Name', :form => form, :mandatory => true) field2 = CustomFormsPlugin::TextField.create(:name => 'License', :form => form) - assert_difference CustomFormsPlugin::Submission, :count, 1 do + assert_difference 'CustomFormsPlugin::Submission.count', 1 do post :show, :profile => profile.identifier, :id => form.id, :submission => {field1.id.to_s => 'Noosfero', field2.id.to_s => 'GPL'} end assert !session[:notice].include?('not saved') diff --git a/plugins/custom_forms/test/unit/custom_forms_plugin/answer_test.rb b/plugins/custom_forms/test/unit/custom_forms_plugin/answer_test.rb index f566b66..273f132 100644 --- a/plugins/custom_forms/test/unit/custom_forms_plugin/answer_test.rb +++ b/plugins/custom_forms/test/unit/custom_forms_plugin/answer_test.rb @@ -4,13 +4,13 @@ class CustomFormsPlugin::AnswerTest < ActiveSupport::TestCase should 'validates presence of field' do answer = CustomFormsPlugin::Answer.new answer.valid? - assert answer.errors.invalid?(:field) + assert answer.errors.include?(:field) form = CustomFormsPlugin::Form.create!(:name => 'Free Software', :profile => fast_create(Profile)) field = CustomFormsPlugin::Field.create!(:name => 'License', :form => form) answer.field = field answer.valid? - assert !answer.errors.invalid?(:field) + assert !answer.errors.include?(:field) end should 'belong to a submission' do @@ -27,11 +27,11 @@ class CustomFormsPlugin::AnswerTest < ActiveSupport::TestCase field = CustomFormsPlugin::Field.create!(:name => 'License', :form => form, :mandatory => true) answer = CustomFormsPlugin::Answer.new(:field => field) answer.valid? - assert answer.errors.invalid?(:value) + assert answer.errors.include?(:value) answer.value = "GPL" answer.valid? - assert !answer.errors.invalid?(:value) + assert !answer.errors.include?(:value) end should 'make string representation show answers' do diff --git a/plugins/custom_forms/test/unit/custom_forms_plugin/field_test.rb b/plugins/custom_forms/test/unit/custom_forms_plugin/field_test.rb index 82e9225..a1468fa 100644 --- a/plugins/custom_forms/test/unit/custom_forms_plugin/field_test.rb +++ b/plugins/custom_forms/test/unit/custom_forms_plugin/field_test.rb @@ -27,7 +27,7 @@ class CustomFormsPlugin::FieldTest < ActiveSupport::TestCase license_field = CustomFormsPlugin::Field.create!(:name => 'License', :form => form) url_field = CustomFormsPlugin::Field.create!(:name => 'URL', :form => form) - assert_no_difference CustomFormsPlugin::Form, :count do + assert_no_difference 'CustomFormsPlugin::Form.count' do url_field.destroy end assert_equal form.fields, [license_field] diff --git a/plugins/custom_forms/test/unit/custom_forms_plugin/form_test.rb b/plugins/custom_forms/test/unit/custom_forms_plugin/form_test.rb index f44f1ca..66eaba0 100644 --- a/plugins/custom_forms/test/unit/custom_forms_plugin/form_test.rb +++ b/plugins/custom_forms/test/unit/custom_forms_plugin/form_test.rb @@ -4,14 +4,14 @@ class CustomFormsPlugin::FormTest < ActiveSupport::TestCase should 'validates presence of a profile and a name' do form = CustomFormsPlugin::Form.new form.valid? - assert form.errors.invalid?(:profile) - assert form.errors.invalid?(:name) + assert form.errors.include?(:profile) + assert form.errors.include?(:name) form.profile = fast_create(Profile) form.name = 'Free Software' form.valid? - assert !form.errors.invalid?(:profile) - assert !form.errors.invalid?(:name) + assert !form.errors.include?(:profile) + assert !form.errors.include?(:name) end should 'have many fields including fields subclasses' do @@ -46,11 +46,11 @@ class CustomFormsPlugin::FormTest < ActiveSupport::TestCase CustomFormsPlugin::Form.create!(:profile => profile, :name => 'Free Software') form = CustomFormsPlugin::Form.new(:profile => profile, :name => 'Free Software') form.valid? - assert form.errors.invalid?(:slug) + assert form.errors.include?(:slug) form.profile = another_profile form.valid? - assert !form.errors.invalid?(:slug) + assert !form.errors.include?(:slug) end should 'validate the difference between ending and beginning is positive' do @@ -60,11 +60,11 @@ class CustomFormsPlugin::FormTest < ActiveSupport::TestCase form.begining = Time.now form.ending = Time.now + 1.day assert form.valid? - assert !form.errors.invalid?(:base) + assert !form.errors.include?(:base) form.ending = Time.now - 2.day assert !form.valid? - assert form.errors.invalid?(:base) + assert form.errors.include?(:base) end should 'define form expiration' do @@ -108,38 +108,38 @@ class CustomFormsPlugin::FormTest < ActiveSupport::TestCase should 'validates format of access' do form = CustomFormsPlugin::Form.new form.valid? - assert !form.errors.invalid?(:access) + assert !form.errors.include?(:access) form.access = 'bli' form.valid? - assert form.errors.invalid?(:access) + assert form.errors.include?(:access) form.access = 'logged' form.valid? - assert !form.errors.invalid?(:access) + assert !form.errors.include?(:access) form.access = 'associated' form.valid? - assert !form.errors.invalid?(:access) + assert !form.errors.include?(:access) form.access = {:bli => 1} form.valid? - assert form.errors.invalid?(:access) + assert form.errors.include?(:access) form.access = 999 form.valid? - assert form.errors.invalid?(:access) + assert form.errors.include?(:access) p1 = fast_create(Profile) form.access = p1.id form.valid? - assert !form.errors.invalid?(:access) + assert !form.errors.include?(:access) p2 = fast_create(Profile) p3 = fast_create(Profile) form.access = [p1,p2,p3].map(&:id) form.valid? - assert !form.errors.invalid?(:access) + assert !form.errors.include?(:access) end should 'defines who is able to access the form' do @@ -173,7 +173,7 @@ class CustomFormsPlugin::FormTest < ActiveSupport::TestCase assert form.accessible_to(owner) end - should 'have a named_scope that retrieve forms from a profile' do + should 'have a scope that retrieve forms from a profile' do profile = fast_create(Profile) another_profile = fast_create(Profile) f1 = CustomFormsPlugin::Form.create!(:name => 'Free Software', :profile => profile) @@ -181,20 +181,20 @@ class CustomFormsPlugin::FormTest < ActiveSupport::TestCase f3 = CustomFormsPlugin::Form.create!(:name => 'Free Software', :profile => another_profile) scope = CustomFormsPlugin::Form.from(profile) - assert_equal ActiveRecord::NamedScope::Scope, scope.class + assert_equal ActiveRecord::Relation, scope.class assert_includes scope, f1 assert_includes scope, f2 assert_not_includes scope, f3 end - should 'have a named_scope that retrieves all forms that are triggered on membership' do + should 'have a scope that retrieves all forms that are triggered on membership' do profile = fast_create(Profile) f1 = CustomFormsPlugin::Form.create!(:name => 'On membership 1', :profile => profile, :on_membership => true) f2 = CustomFormsPlugin::Form.create!(:name => 'On membership 2', :profile => profile, :on_membership => true) f3 = CustomFormsPlugin::Form.create!(:name => 'Not on memberhsip', :profile => profile, :on_membership => false) scope = CustomFormsPlugin::Form.from(profile).on_memberships - assert_equal ActiveRecord::NamedScope::Scope, scope.class + assert_equal ActiveRecord::Relation, scope.class assert_includes scope, f1 assert_includes scope, f2 assert_not_includes scope, f3 @@ -205,7 +205,7 @@ class CustomFormsPlugin::FormTest < ActiveSupport::TestCase license_field = CustomFormsPlugin::Field.create!(:name => 'License', :form => form) url_field = CustomFormsPlugin::Field.create!(:name => 'URL', :form => form) - assert_difference CustomFormsPlugin::Field, :count, -2 do + assert_difference 'CustomFormsPlugin::Field.count', -2 do form.destroy end end @@ -218,14 +218,14 @@ class CustomFormsPlugin::FormTest < ActiveSupport::TestCase assert_equal form.fields, [url_field, license_field] end - should 'have a named_scope that retrieves all forms required for membership' do + should 'have a scope that retrieves all forms required for membership' do profile = fast_create(Profile) f1 = CustomFormsPlugin::Form.create!(:name => 'For admission 1', :profile => profile, :for_admission => true) f2 = CustomFormsPlugin::Form.create!(:name => 'For admission 2', :profile => profile, :for_admission => true) f3 = CustomFormsPlugin::Form.create!(:name => 'Not for admission', :profile => profile, :for_admission => false) scope = CustomFormsPlugin::Form.from(profile).for_admissions - assert_equal ActiveRecord::NamedScope::Scope, scope.class + assert_equal ActiveRecord::Relation, scope.class assert_includes scope, f1 assert_includes scope, f2 assert_not_includes scope, f3 @@ -237,7 +237,7 @@ class CustomFormsPlugin::FormTest < ActiveSupport::TestCase f2 = CustomFormsPlugin::Form.create!(:name => 'For admission', :profile => profile, :on_membership => true, :for_admission => true) scope = CustomFormsPlugin::Form.from(profile).on_memberships - assert_equal ActiveRecord::NamedScope::Scope, scope.class + assert_equal ActiveRecord::Relation, scope.class assert_includes scope, f1 assert_not_includes scope, f2 end diff --git a/plugins/custom_forms/test/unit/custom_forms_plugin/membership_survey_test.rb b/plugins/custom_forms/test/unit/custom_forms_plugin/membership_survey_test.rb index e693204..78f667d 100644 --- a/plugins/custom_forms/test/unit/custom_forms_plugin/membership_survey_test.rb +++ b/plugins/custom_forms/test/unit/custom_forms_plugin/membership_survey_test.rb @@ -4,11 +4,11 @@ class CustomFormsPlugin::MembershipSurveyTest < ActiveSupport::TestCase should 'validates presence of form_id' do task = CustomFormsPlugin::MembershipSurvey.new task.valid? - assert task.errors.invalid?(:form_id) + assert task.errors.include?(:form_id) task.form_id = 1 task.valid? - assert !task.errors.invalid?(:form_id) + assert !task.errors.include?(:form_id) end should 'create submission with answers on perform' do @@ -18,7 +18,7 @@ class CustomFormsPlugin::MembershipSurveyTest < ActiveSupport::TestCase field = CustomFormsPlugin::Field.create!(:name => 'Name', :form => form) task = CustomFormsPlugin::MembershipSurvey.create!(:form_id => form.id, :submission => {field.id.to_s => 'Jack'}, :target => person, :requestor => profile) - assert_difference CustomFormsPlugin::Submission, :count, 1 do + assert_difference 'CustomFormsPlugin::Submission.count', 1 do task.finish end @@ -29,7 +29,7 @@ class CustomFormsPlugin::MembershipSurveyTest < ActiveSupport::TestCase assert_equal answer.value, 'Jack' end - should 'have a named_scope that retrieves all tasks requested by profile' do + should 'have a scope that retrieves all tasks requested by profile' do profile = fast_create(Profile) person = fast_create(Person) form = CustomFormsPlugin::Form.create!(:name => 'Simple Form', :profile => profile) @@ -37,7 +37,7 @@ class CustomFormsPlugin::MembershipSurveyTest < ActiveSupport::TestCase task2 = CustomFormsPlugin::MembershipSurvey.create!(:form_id => form.id, :target => person, :requestor => fast_create(Profile)) scope = CustomFormsPlugin::MembershipSurvey.from(profile) - assert_equal ActiveRecord::NamedScope::Scope, scope.class + assert_equal ActiveRecord::Relation, scope.class assert_includes scope, task1 assert_not_includes scope, task2 end diff --git a/plugins/custom_forms/test/unit/custom_forms_plugin/submission_test.rb b/plugins/custom_forms/test/unit/custom_forms_plugin/submission_test.rb index 947404c..94653ec 100644 --- a/plugins/custom_forms/test/unit/custom_forms_plugin/submission_test.rb +++ b/plugins/custom_forms/test/unit/custom_forms_plugin/submission_test.rb @@ -4,12 +4,12 @@ class CustomFormsPlugin::SubmissionTest < ActiveSupport::TestCase should 'validates presence of form' do submission = CustomFormsPlugin::Submission.new submission.valid? - assert submission.errors.invalid?(:form) + assert submission.errors.include?(:form) form = CustomFormsPlugin::Form.create!(:name => 'Free Software', :profile => fast_create(Profile)) submission.form = form submission.valid? - assert !submission.errors.invalid?(:form) + assert !submission.errors.include?(:form) end should 'belong to a profile' do @@ -22,14 +22,14 @@ class CustomFormsPlugin::SubmissionTest < ActiveSupport::TestCase should 'require presence of author name and email if profile is nil' do submission = CustomFormsPlugin::Submission.new submission.valid? - assert submission.errors.invalid?(:author_name) - assert submission.errors.invalid?(:author_email) + assert submission.errors.include?(:author_name) + assert submission.errors.include?(:author_email) submission.author_name = 'Jack Sparrow' submission.author_email = 'jack@black-pearl.com' submission.valid? - assert !submission.errors.invalid?(:author_name) - assert !submission.errors.invalid?(:author_email) + assert !submission.errors.include?(:author_name) + assert !submission.errors.include?(:author_email) end should 'have answers' do diff --git a/plugins/custom_forms/test/unit/ext/role_assingment_test.rb b/plugins/custom_forms/test/unit/ext/role_assingment_test.rb index 2c6bc5d..150dd65 100644 --- a/plugins/custom_forms/test/unit/ext/role_assingment_test.rb +++ b/plugins/custom_forms/test/unit/ext/role_assingment_test.rb @@ -10,7 +10,7 @@ class RoleAssignmentsTest < ActiveSupport::TestCase f2 = CustomFormsPlugin::Form.create!(:profile => organization, :name => 'Form 2', :on_membership => true) f3 = CustomFormsPlugin::Form.create!(:profile => organization, :name => 'Form 3', :on_membership => false) - assert_difference CustomFormsPlugin::MembershipSurvey, :count, 2 do + assert_difference 'CustomFormsPlugin::MembershipSurvey.count', 2 do organization.add_member(person) end end @@ -22,7 +22,7 @@ class RoleAssignmentsTest < ActiveSupport::TestCase person = fast_create(Person) form = CustomFormsPlugin::Form.create!(:profile => organization, :name => 'Form', :on_membership => true, :access => 'associated') - assert_difference CustomFormsPlugin::MembershipSurvey, :count, 1 do + assert_difference 'CustomFormsPlugin::MembershipSurvey.count', 1 do organization.add_member(person) end end @@ -35,14 +35,14 @@ class RoleAssignmentsTest < ActiveSupport::TestCase form1 = CustomFormsPlugin::Form.create!(:profile => organization, :name => 'Form 1', :on_membership => true) organization.add_member(person) - assert_difference CustomFormsPlugin::MembershipSurvey.pending, :count, -1 do + assert_difference 'CustomFormsPlugin::MembershipSurvey.pending.count', -1 do organization.remove_member(person) end form2 = CustomFormsPlugin::Form.create!(:profile => organization, :name => 'Form 2', :for_admission => true) organization.add_member(person) - assert_difference CustomFormsPlugin::AdmissionSurvey.pending, :count, -1 do + assert_difference 'CustomFormsPlugin::AdmissionSurvey.pending.count', -1 do organization.remove_member(person) end @@ -50,7 +50,7 @@ class RoleAssignmentsTest < ActiveSupport::TestCase tasks = CustomFormsPlugin::MembershipSurvey.all.last(2) tasks.each {|t| t.status = Task::Status::FINISHED } tasks.each {|t| t.save! } - assert_no_difference CustomFormsPlugin::MembershipSurvey.finished, :count do + assert_no_difference 'CustomFormsPlugin::MembershipSurvey.finished.count' do organization.remove_member(person) end end @@ -64,7 +64,7 @@ class RoleAssignmentsTest < ActiveSupport::TestCase f2 = CustomFormsPlugin::Form.create!(:profile => organization, :name => 'Form 2', :for_admission => true) f3 = CustomFormsPlugin::Form.create!(:profile => organization, :name => 'Form 3', :for_admission => false) - assert_difference CustomFormsPlugin::AdmissionSurvey, :count, 2 do + assert_difference 'CustomFormsPlugin::AdmissionSurvey.count', 2 do organization.add_member(person) end assert !organization.members.include?(person) diff --git a/plugins/custom_forms/views/custom_forms_plugin_myprofile/_field.html.erb b/plugins/custom_forms/views/custom_forms_plugin_myprofile/_field.html.erb index e27e2be..b14fd3b 100644 --- a/plugins/custom_forms/views/custom_forms_plugin_myprofile/_field.html.erb +++ b/plugins/custom_forms/views/custom_forms_plugin_myprofile/_field.html.erb @@ -12,7 +12,7 @@ <%= f.hidden_field(:position) %> <%= f.hidden_field :_destroy, :class => 'destroy-field' %> - <%= button_to_function :delete, _('Remove field'), "customFormsPlugin.removeFieldBox(this, #{_('Are you sure you want to remove this field?').to_json})" %> + <%= button_to_function :delete, _('Remove field'), "customFormsPlugin.removeFieldBox(this, #{j _('Are you sure you want to remove this field?').to_json})" %> <%= yield %> diff --git a/plugins/custom_forms/views/custom_forms_plugin_myprofile/_form.html.erb b/plugins/custom_forms/views/custom_forms_plugin_myprofile/_form.html.erb index b082c2c..ba5f158 100644 --- a/plugins/custom_forms/views/custom_forms_plugin_myprofile/_form.html.erb +++ b/plugins/custom_forms/views/custom_forms_plugin_myprofile/_form.html.erb @@ -1,7 +1,7 @@ <% self.extend(CustomFormsPlugin::Helper) %> <%= render :file => 'shared/tiny_mce', :locals => {:mode => 'simple'} %> -<%= f.error_messages %> +<%= error_messages_for :form %> <%= required labelled_form_field _('Name'), f.text_field(:name) %> <%= labelled_form_field(_('What is the time limit for this form to be filled?'), ( date_range_field('form[begining]', 'form[ending]', @form.begining, @form.ending, @@ -31,8 +31,8 @@
- <%= button(:add, _('Add a new text field'), '#', :onclick => "customFormsPlugin.addFields(this, 'fields', #{html_for_field(f, :fields, CustomFormsPlugin::TextField).to_json}); return false")%> - <%= button(:add, _('Add a new select field'), '#', :onclick => "customFormsPlugin.addFields(this, 'fields', #{html_for_field(f, :fields, CustomFormsPlugin::SelectField).to_json}); return false")%> + <%= button(:add, _('Add a new text field'), '#', :onclick => "customFormsPlugin.addFields(this, 'fields', #{j html_for_field(f, :fields, CustomFormsPlugin::TextField).to_json}); return false")%> + <%= button(:add, _('Add a new select field'), '#', :onclick => "customFormsPlugin.addFields(this, 'fields', #{j html_for_field(f, :fields, CustomFormsPlugin::SelectField).to_json}); return false")%>
<% button_bar do %> diff --git a/plugins/custom_forms/views/custom_forms_plugin_myprofile/custom_forms_plugin/_alternative.html.erb b/plugins/custom_forms/views/custom_forms_plugin_myprofile/custom_forms_plugin/_alternative.html.erb index cd31867..5a6f488 100644 --- a/plugins/custom_forms/views/custom_forms_plugin_myprofile/custom_forms_plugin/_alternative.html.erb +++ b/plugins/custom_forms/views/custom_forms_plugin_myprofile/custom_forms_plugin/_alternative.html.erb @@ -7,6 +7,6 @@ <%= f.hidden_field :_destroy, :class => 'destroy-field' %> - <%= button_to_function_without_text :remove, _('Remove alternative'), "customFormsPlugin.removeAlternative(this, #{_('Are you sure you want to remove this alternative?').to_json})", :class => 'remove-field', :title => _('Remove alternative') %> + <%= button_to_function_without_text :remove, _('Remove alternative'), "customFormsPlugin.removeAlternative(this, #{j _('Are you sure you want to remove this alternative?').to_json})", :class => 'remove-field', :title => _('Remove alternative') %> diff --git a/plugins/custom_forms/views/custom_forms_plugin_myprofile/custom_forms_plugin/_select_field.html.erb b/plugins/custom_forms/views/custom_forms_plugin_myprofile/custom_forms_plugin/_select_field.html.erb index 5f74210..3026311 100644 --- a/plugins/custom_forms/views/custom_forms_plugin_myprofile/custom_forms_plugin/_select_field.html.erb +++ b/plugins/custom_forms/views/custom_forms_plugin_myprofile/custom_forms_plugin/_select_field.html.erb @@ -1,4 +1,4 @@ -<% render :layout => 'field', :locals => { :f => f } do %> +<%= render :layout => 'field', :locals => { :f => f } do %>
<%= _('Type:') %> <%= f.radio_button(:select_field_type, 'radio') %> @@ -22,7 +22,7 @@ - <%= button(:add, _('Add a new alternative'), '#', :onclick => "customFormsPlugin.addFields(this, 'alternatives', #{html_for_field(f, :alternatives, CustomFormsPlugin::Alternative).to_json}); return false") %> + <%= button(:add, _('Add a new alternative'), '#', :onclick => "customFormsPlugin.addFields(this, 'alternatives', #{j html_for_field(f, :alternatives, CustomFormsPlugin::Alternative).to_json}); return false") %> diff --git a/plugins/custom_forms/views/custom_forms_plugin_myprofile/custom_forms_plugin/_text_field.html.erb b/plugins/custom_forms/views/custom_forms_plugin_myprofile/custom_forms_plugin/_text_field.html.erb index 7e43a94..f1d0e11 100644 --- a/plugins/custom_forms/views/custom_forms_plugin_myprofile/custom_forms_plugin/_text_field.html.erb +++ b/plugins/custom_forms/views/custom_forms_plugin_myprofile/custom_forms_plugin/_text_field.html.erb @@ -1,4 +1,4 @@ -<% render :layout => 'field', :locals => { :f => f } do %> +<%= render :layout => 'field', :locals => { :f => f } do %>
<%= f.label(:default_value, _('Default text:')) %> <%= f.text_field(:default_value) %> diff --git a/plugins/custom_forms/views/custom_forms_plugin_myprofile/edit.html.erb b/plugins/custom_forms/views/custom_forms_plugin_myprofile/edit.html.erb index 657b0c1..d3344dc 100644 --- a/plugins/custom_forms/views/custom_forms_plugin_myprofile/edit.html.erb +++ b/plugins/custom_forms/views/custom_forms_plugin_myprofile/edit.html.erb @@ -1,5 +1,5 @@

<%= _('Edit form') %>

-<%= form_for :form, @form, :url => { :action => 'update', :id => params[:id] } do |f| %> +<%= form_for @form, :as => :form, :url => { :action => 'update', :id => params[:id] } do |f| %> <%= render :partial => 'form', :locals => {:f => f} %> <% end %> diff --git a/plugins/custom_forms/views/custom_forms_plugin_myprofile/new.html.erb b/plugins/custom_forms/views/custom_forms_plugin_myprofile/new.html.erb index c8cb86c..bb6da73 100644 --- a/plugins/custom_forms/views/custom_forms_plugin_myprofile/new.html.erb +++ b/plugins/custom_forms/views/custom_forms_plugin_myprofile/new.html.erb @@ -1,5 +1,5 @@

<%= _('New form') %>

-<%= form_for :form, @form, :url => { :action => 'create', :id => params[:id] } do |f| %> +<%= form_for @form, :as => :form, :url => { :action => 'create', :id => params[:id] } do |f| %> <%= render :partial => 'form', :locals => {:f => f} %> <% end %> diff --git a/plugins/custom_forms/views/custom_forms_plugin_profile/show.html.erb b/plugins/custom_forms/views/custom_forms_plugin_profile/show.html.erb index cb6057d..99e0086 100644 --- a/plugins/custom_forms/views/custom_forms_plugin_profile/show.html.erb +++ b/plugins/custom_forms/views/custom_forms_plugin_profile/show.html.erb @@ -12,7 +12,7 @@ <%= error_messages_for :submission %> - <%= form_for :submission, @submission do |f| %> + <%= form_for :submission do |f| %> <% if !user %> <%= required labelled_form_field _('Author name'), text_field_tag(:author_name, @submission.author_name) %> <%= required labelled_form_field _('Author email'), text_field_tag(:author_email, @submission.author_email) %> -- libgit2 0.21.2