Commit b1526ae1ae8e90e6b2af5e5b733d4a8c2b3fe88f
1 parent
bbd28eeb
Exists in
staging
and in
36 other branches
fix signup with custom_fields
Signed-off-by: Joenio Costa <joenio@colivre.coop.br> Signed-off-by: Marcos Ramos <ms.ramos@outlook.com> Signed-off-by: Marcos Ronaldo <marcos.rpj2@gmail.com>
Showing
5 changed files
with
25 additions
and
3 deletions
Show diff stats
app/controllers/my_profile/memberships_controller.rb
| ... | ... | @@ -18,12 +18,14 @@ class MembershipsController < MyProfileController |
| 18 | 18 | |
| 19 | 19 | def new_community |
| 20 | 20 | @community = Community.new(params[:community]) |
| 21 | + custom_values = params[:profile_data][:custom_values] if (params[:profile_data] && params[:profile_data][:custom_values]) | |
| 22 | + @community.custom_values = custom_values | |
| 21 | 23 | @community.environment = environment |
| 22 | 24 | @back_to = params[:back_to] || url_for(:action => 'index') |
| 23 | 25 | if request.post? && @community.valid? |
| 24 | 26 | begin |
| 25 | 27 | # Community was created |
| 26 | - @community = Community.create_after_moderation(user, params[:community].merge({:environment => environment})) | |
| 28 | + @community = Community.create_after_moderation(user, params[:community].merge({:environment => environment, :custom_values => custom_values})) | |
| 27 | 29 | @community.reload |
| 28 | 30 | redirect_to :action => 'welcome', :community_id => @community.id, :back_to => @back_to |
| 29 | 31 | rescue ActiveRecord::RecordNotFound | ... | ... |
app/models/community.rb
| ... | ... | @@ -33,7 +33,7 @@ class Community < Organization |
| 33 | 33 | community = Community.new(attributes) |
| 34 | 34 | community.environment = environment |
| 35 | 35 | if community.environment.enabled?('admin_must_approve_new_communities') |
| 36 | - CreateCommunity.create!(attributes.merge(:requestor => requestor, :environment => environment)) | |
| 36 | + CreateCommunity.create!(attributes.merge(:requestor => requestor, :environment => environment).except(:custom_values)) | |
| 37 | 37 | else |
| 38 | 38 | community.save! |
| 39 | 39 | community.add_admin(requestor) | ... | ... |
lib/acts_as_customizable.rb
| ... | ... | @@ -90,7 +90,7 @@ module Customizable |
| 90 | 90 | custom_values.each_pair do |key, value| |
| 91 | 91 | custom_field = environment.custom_fields.detect{|cf|cf.name==key} |
| 92 | 92 | next if custom_field.blank? |
| 93 | - custom_field_value = self.custom_field_values.detect{|cv| cv.custom_field.name==key} | |
| 93 | + custom_field_value = self.custom_field_values(true).detect{|cv| cv.custom_field.name==key} | |
| 94 | 94 | |
| 95 | 95 | if custom_field_value.nil? |
| 96 | 96 | custom_field_value = CustomFieldValue.new | ... | ... |
test/functional/account_controller_test.rb
| ... | ... | @@ -108,6 +108,15 @@ class AccountControllerTest < ActionController::TestCase |
| 108 | 108 | end |
| 109 | 109 | end |
| 110 | 110 | |
| 111 | + def test_shoud_save_with_custom_field_on_signup | |
| 112 | + assert_difference 'User.count' do | |
| 113 | + assert_difference 'CustomFieldValue.count' do | |
| 114 | + CustomField.create!(:name => "zombies", :format=>"String", :default_value => "awrrr", :customized_type=>"Profile", :active => true, :required => true, :signup => true, :environment => Environment.default) | |
| 115 | + new_user({},{"profile_data"=> {"custom_values"=>{"zombies"=>{"value"=>"BRAINSSS"}}}}) | |
| 116 | + end | |
| 117 | + end | |
| 118 | + end | |
| 119 | + | |
| 111 | 120 | def test_should_logout |
| 112 | 121 | login_as :johndoe |
| 113 | 122 | get :logout | ... | ... |
test/functional/memberships_controller_test.rb
| ... | ... | @@ -36,6 +36,17 @@ class MembershipsControllerTest < ActionController::TestCase |
| 36 | 36 | end |
| 37 | 37 | end |
| 38 | 38 | |
| 39 | + should 'be able to create a new community with custom field' do | |
| 40 | + assert_difference 'Community.count' do | |
| 41 | + assert_difference 'CustomFieldValue.count' do | |
| 42 | + CustomField.create!(:name => "zombies", :format=>"String", :default_value => "awrrr", :customized_type=>"Community", :active => true, :required => true, :signup => true, :environment => Environment.default) | |
| 43 | + 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"}}} | |
| 44 | + assert_response :redirect | |
| 45 | + assert Community.find_by_identifier('my-shiny-new-community').members.include?(profile), "Creator user should be added as member of the community just created" | |
| 46 | + end | |
| 47 | + end | |
| 48 | + end | |
| 49 | + | |
| 39 | 50 | should 'link to new community creation in index' do |
| 40 | 51 | get :index, :profile => profile.identifier |
| 41 | 52 | assert_tag :tag => 'a', :attributes => { :href => "/myprofile/#{profile.identifier}/memberships/new_community" } | ... | ... |