[Git][noosfero/noosfero][master] 2 commits: should create a task for create communities if the environment is properlly configured

Leandro Nunes gitlab at mg.gitlab.com
Sun May 6 07:52:57 BRT 2018


Leandro Nunes pushed to branch master at Noosfero / noosfero


Commits:
491f97fb by Leandro Nunes dos Santos at 2018-05-05T19:38:13Z
should create a task for create communities if the environment is properlly configured

- - - - -
ac1830a5 by Leandro Nunes at 2018-05-06T10:52:32Z
Merge branch 'create-moderated-community' into 'master'

should create a task for create communities if the environment is properlly configured

See merge request noosfero/noosfero!1465
- - - - -


2 changed files:

- app/api/v1/communities.rb
- test/api/communities_test.rb


Changes:

=====================================
app/api/v1/communities.rb
=====================================
--- a/app/api/v1/communities.rb
+++ b/app/api/v1/communities.rb
@@ -38,11 +38,11 @@ module Api
             community = Community.create_after_moderation(current_person, params[:community].merge({:environment => environment}))
           rescue
             community = Community.new(params[:community])
+            if !community.save
+              render_model_errors!(community.errors)
+            end
           end
 
-          if !community.save
-            render_model_errors!(community.errors)
-          end
 
           present_partial community, :with => Entities::Community, :current_person => current_person
         end


=====================================
test/api/communities_test.rb
=====================================
--- a/test/api/communities_test.rb
+++ b/test/api/communities_test.rb
@@ -67,6 +67,26 @@ class CommunitiesTest < ActiveSupport::TestCase
     assert_equal 'some', json['name']
   end
 
+  should 'make a create community request if the environment was configured to admin_must_approve_new_communities' do
+    login_api
+    env = Environment.default
+    env.enable('admin_must_approve_new_communities')
+    person.stubs(:notification_emails).returns(['sample at example.org'])
+    params[:community] = {:name => 'some'}
+    post "/api/v1/communities?#{params.to_query}"
+    json = JSON.parse(last_response.body)
+    assert_nil json['id']
+  end
+
+  should 'not create community with the same identifier' do
+    login_api
+    community = fast_create(Community)
+    params[:community] = {:name => community.name}
+    post "/api/v1/communities?#{params.to_query}"
+    json = JSON.parse(last_response.body)
+    assert_equal 'not_available', json['errors']['identifier'].first['error']
+  end
+
   should 'return 400 status for invalid community creation to logged user ' do
     login_api
     post "/api/v1/communities?#{params.to_query}"



View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/37eec379245356604c9059f1b36b40c0be4e42bd...ac1830a56ae8064faf5e94e9c0b960cd59211f20

---
View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/37eec379245356604c9059f1b36b40c0be4e42bd...ac1830a56ae8064faf5e94e9c0b960cd59211f20
You're receiving this email because of your account on gitlab.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20180506/3432e2c0/attachment-0001.html>


More information about the Noosfero-dev mailing list