[Git][noosfero/noosfero][master] 2 commits: fix signup with custom_fields
Antonio Terceiro
gitlab at mg.gitlab.com
Thu Feb 11 11:23:53 BRST 2016
Antonio Terceiro pushed to branch master at Noosfero / noosfero
Commits:
b1526ae1 by Marcos Ronaldo at 2016-02-05T10:51:52-02:00
fix signup with custom_fields
Signed-off-by: Joenio Costa <joenio at colivre.coop.br>
Signed-off-by: Marcos Ramos <ms.ramos at outlook.com>
Signed-off-by: Marcos Ronaldo <marcos.rpj2 at gmail.com>
- - - - -
6a203a5b by Antonio Terceiro at 2016-02-11T13:23:29+00:00
Merge branch 'fix_custom_fields' into 'master'
fix signup with custom_fields
Fixes bugs with signup with required custom fields, as well as required custom values not being saved for new communities.
See merge request !783
- - - - -
5 changed files:
- app/controllers/my_profile/memberships_controller.rb
- app/models/community.rb
- lib/acts_as_customizable.rb
- test/functional/account_controller_test.rb
- test/functional/memberships_controller_test.rb
Changes:
=====================================
app/controllers/my_profile/memberships_controller.rb
=====================================
--- a/app/controllers/my_profile/memberships_controller.rb
+++ b/app/controllers/my_profile/memberships_controller.rb
@@ -18,12 +18,14 @@ class MembershipsController < MyProfileController
def new_community
@community = Community.new(params[:community])
+ custom_values = params[:profile_data][:custom_values] if (params[:profile_data] && params[:profile_data][:custom_values])
+ @community.custom_values = custom_values
@community.environment = environment
@back_to = params[:back_to] || url_for(:action => 'index')
if request.post? && @community.valid?
begin
# Community was created
- @community = Community.create_after_moderation(user, params[:community].merge({:environment => environment}))
+ @community = Community.create_after_moderation(user, params[:community].merge({:environment => environment, :custom_values => custom_values}))
@community.reload
redirect_to :action => 'welcome', :community_id => @community.id, :back_to => @back_to
rescue ActiveRecord::RecordNotFound
=====================================
app/models/community.rb
=====================================
--- a/app/models/community.rb
+++ b/app/models/community.rb
@@ -33,7 +33,7 @@ class Community < Organization
community = Community.new(attributes)
community.environment = environment
if community.environment.enabled?('admin_must_approve_new_communities')
- CreateCommunity.create!(attributes.merge(:requestor => requestor, :environment => environment))
+ CreateCommunity.create!(attributes.merge(:requestor => requestor, :environment => environment).except(:custom_values))
else
community.save!
community.add_admin(requestor)
=====================================
lib/acts_as_customizable.rb
=====================================
--- a/lib/acts_as_customizable.rb
+++ b/lib/acts_as_customizable.rb
@@ -90,7 +90,7 @@ module Customizable
custom_values.each_pair do |key, value|
custom_field = environment.custom_fields.detect{|cf|cf.name==key}
next if custom_field.blank?
- custom_field_value = self.custom_field_values.detect{|cv| cv.custom_field.name==key}
+ custom_field_value = self.custom_field_values(true).detect{|cv| cv.custom_field.name==key}
if custom_field_value.nil?
custom_field_value = CustomFieldValue.new
=====================================
test/functional/account_controller_test.rb
=====================================
--- a/test/functional/account_controller_test.rb
+++ b/test/functional/account_controller_test.rb
@@ -108,6 +108,15 @@ class AccountControllerTest < ActionController::TestCase
end
end
+ def test_shoud_save_with_custom_field_on_signup
+ assert_difference 'User.count' do
+ assert_difference 'CustomFieldValue.count' do
+ CustomField.create!(:name => "zombies", :format=>"String", :default_value => "awrrr", :customized_type=>"Profile", :active => true, :required => true, :signup => true, :environment => Environment.default)
+ new_user({},{"profile_data"=> {"custom_values"=>{"zombies"=>{"value"=>"BRAINSSS"}}}})
+ end
+ end
+ end
+
def test_should_logout
login_as :johndoe
get :logout
=====================================
test/functional/memberships_controller_test.rb
=====================================
--- a/test/functional/memberships_controller_test.rb
+++ b/test/functional/memberships_controller_test.rb
@@ -36,6 +36,17 @@ class MembershipsControllerTest < ActionController::TestCase
end
end
+ should 'be able to create a new community with custom field' do
+ assert_difference 'Community.count' do
+ assert_difference 'CustomFieldValue.count' do
+ CustomField.create!(:name => "zombies", :format=>"String", :default_value => "awrrr", :customized_type=>"Community", :active => true, :required => true, :signup => true, :environment => Environment.default)
+ post :new_community, :profile => profile.identifier, :community => { :name => 'My shiny new community', :description => 'This is a community devoted to anything interesting we find in the internet '}, "profile_data"=>{"custom_values"=>{"zombies"=>{"value"=>"BRAINSSS"}}}
+ assert_response :redirect
+ assert Community.find_by_identifier('my-shiny-new-community').members.include?(profile), "Creator user should be added as member of the community just created"
+ end
+ end
+ end
+
should 'link to new community creation in index' do
get :index, :profile => profile.identifier
assert_tag :tag => 'a', :attributes => { :href => "/myprofile/#{profile.identifier}/memberships/new_community" }
View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/833e001202e00dccf0709b670c0df231b0bac97f...6a203a5b8efc263db1961593280c8f775f20bbeb
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20160211/c476f566/attachment-0001.html>
More information about the Noosfero-dev
mailing list