[Git][noosfero/noosfero][master] 3 commits: Admin automatic follow after create an Organization

Leandro Nunes gitlab at mg.gitlab.com
Thu Feb 23 18:40:08 BRT 2017


Leandro Nunes pushed to branch master at Noosfero / noosfero


Commits:
813b01c5 by Karine Valença at 2016-11-24T17:27:37-02:00
Admin automatic follow after create an Organization

Signed-off-by: Iago Rodrigues <iago006 at hotmail.com>
Signed-off-by: Karine Valença <valenca.karine at gmail.com>
Signed-off-by: Murilo Duarte <muriloduartegoncalves at hotmail.com>

- - - - -
f1896cc3 by Leandro Nunes dos Santos at 2017-02-23T18:19:19-03:00
fix translation and identation

- - - - -
5b838667 by Leandro Nunes dos Santos at 2017-02-23T18:39:24-03:00
fix merge conflit

- - - - -


5 changed files:

- app/models/circle.rb
- app/models/profile.rb
- + db/migrate/20161004194609_change_circle_name_index.rb
- test/functional/profile_controller_test.rb
- + test/unit/circle_test.rb


Changes:

=====================================
app/models/circle.rb
=====================================
--- a/app/models/circle.rb
+++ b/app/models/circle.rb
@@ -13,7 +13,7 @@ class Circle < ApplicationRecord
   validates :name, presence: true
   validates :person_id, presence: true
   validates :profile_type, presence: true
-  validates :person_id, :uniqueness => {:scope => :name, :message => "can't add two circles with the same name"}
+  validates_uniqueness_of :person_id, scope: [:name, :profile_type], :message => N_("can't add two circles with the same name")
 
   validate :profile_type_must_be_in_list
 


=====================================
app/models/profile.rb
=====================================
--- a/app/models/profile.rb
+++ b/app/models/profile.rb
@@ -844,6 +844,8 @@ private :generate_url, :url_options
   # adds a person as administrator os this profile
   def add_admin(person)
     self.affiliate(person, Profile::Roles.admin(environment.id))
+    circle = Circle.find_or_create_by(name: _('memberships'), person: person, profile_type: self.class.name)
+    person.follow(self, circle)
   end
 
   def remove_admin(person)


=====================================
db/migrate/20161004194609_change_circle_name_index.rb
=====================================
--- /dev/null
+++ b/db/migrate/20161004194609_change_circle_name_index.rb
@@ -0,0 +1,11 @@
+class ChangeCircleNameIndex < ActiveRecord::Migration
+  def up
+    remove_index :circles, :name => "circles_composite_key_index"
+    add_index :circles, [:person_id, :name, :profile_type], :name => "circles_composite_key_index", :unique => true
+  end
+
+  def down
+    remove_index :circles, :name => "circles_composite_key_index"
+    add_index :circles, [:person_id, :name], :name => "circles_composite_key_index", :unique => true
+  end
+end


=====================================
test/functional/profile_controller_test.rb
=====================================
--- a/test/functional/profile_controller_test.rb
+++ b/test/functional/profile_controller_test.rb
@@ -2172,4 +2172,20 @@ class ProfileControllerTest < ActionController::TestCase
     assert assigns(:activities)
   end
 
+  should 'follow a community after creating it' do
+    user = create_user('sample-user').person
+    community = Community.create!(:name => 'my test community')
+    community.add_admin(user)
+
+    assert community.followed_by?user
+  end
+
+  should 'follow an enterprise after creating it' do
+    user = create_user('sample-user').person
+    enterprise = Enterprise.create!(:name => 'my test enterprise', :identifier =>'my-test-enterprise')
+    enterprise.add_admin(user)
+
+    assert enterprise.followed_by?user
+  end
+
 end


=====================================
test/unit/circle_test.rb
=====================================
--- /dev/null
+++ b/test/unit/circle_test.rb
@@ -0,0 +1,43 @@
+require_relative "../test_helper"
+
+class CircleTest < ActiveSupport::TestCase
+
+  should 'two circles with same name and different profile types' do
+    person = create_user('testinguser').person
+
+    circle1 = create(Circle, :name => 'test', :profile_type => 'Enterprise', :person => person)
+    circle2 = create(Circle, :name => 'test', :profile_type => 'Community', :person => person)
+
+    circles = Circle.all
+    assert_includes circles, circle2
+  end
+
+  should 'two circles with same name and same profile types' do
+    person = create_user('testinguser').person
+  
+    circle1 = create(Circle, :name => 'test', :profile_type => 'Enterprise', :person => person)
+    circle2 = Circle.new(:name => 'test', :profile_type => 'Enterprise', :person => person)
+    refute circle2.valid?
+  end
+  
+  should 'two circles with different names and same profile types' do
+    person = create_user('testinguser').person
+  
+    circle1 = create(Circle, :name => 'test', :profile_type => 'Enterprise', :person => person)
+    circle2 = create(Circle, :name => 'different-test', :profile_type => 'Enterprise', :person => person)
+  
+    circles = Circle.all
+    assert_includes circles, circle2
+  end
+  
+  should 'two circles with different names and different profile types' do
+    person = create_user('testinguser').person
+  
+    circle1 = create(Circle, :name => 'test', :profile_type => 'Enterprise', :person => person)
+    circle2 = create(Circle, :name => 'different-test', :profile_type => 'Community', :person => person)
+
+    circles = Circle.all
+    assert_includes circles, circle2
+  end
+  
+end



View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/87b3f8961895966b0f00d34ae2fefdb976041cb4...5b838667e4f6834216b346be2495b8b11f741606
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20170223/d4501514/attachment-0001.html>


More information about the Noosfero-dev mailing list