Commit e83b4b8c194574ca004350802b873c63a8fd3cc0
Exists in
staging
and in
2 other branches
Merge branch 'master' into staging
Showing
8 changed files
with
47 additions
and
4 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) | ... | ... |
app/models/suggest_article.rb
| ... | ... | @@ -23,6 +23,10 @@ class SuggestArticle < Task |
| 23 | 23 | requestor ? "#{requestor.name}" : "#{name} (#{email})" |
| 24 | 24 | end |
| 25 | 25 | |
| 26 | + def author_name | |
| 27 | + sender | |
| 28 | + end | |
| 29 | + | |
| 26 | 30 | def article_object |
| 27 | 31 | if @article_object.nil? |
| 28 | 32 | @article_object = article_type.new(article.merge(target.present? ? {:profile => target} : {}).except(:type)) |
| ... | ... | @@ -41,7 +45,6 @@ class SuggestArticle < Task |
| 41 | 45 | return type if type < Article |
| 42 | 46 | end |
| 43 | 47 | TinyMceArticle |
| 44 | - (article[:type] || 'TinyMceArticle').constantize | |
| 45 | 48 | end |
| 46 | 49 | |
| 47 | 50 | def perform | ... | ... |
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" } | ... | ... |
test/functional/tasks_controller_test.rb
| ... | ... | @@ -360,6 +360,19 @@ class TasksControllerTest < ActionController::TestCase |
| 360 | 360 | assert_select "#tasks_#{t.id}_task_name" |
| 361 | 361 | end |
| 362 | 362 | |
| 363 | + should "not crash when article suggestion task fails" do | |
| 364 | + TinyMceArticle.destroy_all | |
| 365 | + c = fast_create(Community) | |
| 366 | + c.affiliate(profile, Profile::Roles.all_roles(profile.environment.id)) | |
| 367 | + @controller.stubs(:profile).returns(c) | |
| 368 | + t = SuggestArticle.create!(:article => {:name => 'test name', :abstract => 'test abstract', :body => 'test body'}, :name => 'some name', :email => 'test@localhost.com', :target => c) | |
| 369 | + | |
| 370 | + SuggestArticle.any_instance.stubs(:perform).raises('erro') | |
| 371 | + assert_nothing_raised do | |
| 372 | + post :close, :tasks => {t.id => { :task => {}, :decision => "finish"}} | |
| 373 | + end | |
| 374 | + end | |
| 375 | + | |
| 363 | 376 | should "append hidden tag with type value from article suggestion" do |
| 364 | 377 | Task.destroy_all |
| 365 | 378 | c = fast_create(Community) | ... | ... |
test/unit/suggest_article_test.rb
| ... | ... | @@ -242,4 +242,9 @@ class SuggestArticleTest < ActiveSupport::TestCase |
| 242 | 242 | t.article_type == TinyMceArticle |
| 243 | 243 | end |
| 244 | 244 | |
| 245 | + should 'fallback to tinymce when type parameter is blank' do | |
| 246 | + t = SuggestArticle.new | |
| 247 | + t.article = {:name => 'name', :body => 'body', :type => ''} | |
| 248 | + t.article_type == TinyMceArticle | |
| 249 | + end | |
| 245 | 250 | end | ... | ... |