Commit 2f70f8a493a1257249f2d9ea6ec20785f7d1bae4
1 parent
f15fb2d2
Exists in
master
and in
28 other branches
ActionItem41: initial implementation of community creation
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1326 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
8 changed files
with
87 additions
and
5 deletions
Show diff stats
app/controllers/my_profile/manage_communities_controller.rb
1 | -class ManageCommunitiesController < ApplicationController | |
1 | +class ManageCommunitiesController < MyProfileController | |
2 | + | |
3 | + def index | |
4 | + @communities = profile.community_memberships | |
5 | + end | |
6 | + | |
7 | + def new | |
8 | + @community = Community.new(params[:community]) | |
9 | + if request.post? | |
10 | + if @community.save | |
11 | + @community.add_member(profile) | |
12 | + redirect_to :action => 'index' | |
13 | + end | |
14 | + end | |
15 | + end | |
16 | + | |
2 | 17 | end | ... | ... |
app/models/community.rb
... | ... | @@ -7,4 +7,11 @@ class Community < Organization |
7 | 7 | self.identifier = value.to_slug |
8 | 8 | end |
9 | 9 | |
10 | + # FIXME should't this method be in Profile class? | |
11 | + # | |
12 | + # Adds a person as member of this Community (FIXME). | |
13 | + def add_member(person) | |
14 | + self.affiliate(person, Profile::Roles.member) | |
15 | + end | |
16 | + | |
10 | 17 | end | ... | ... |
app/models/person.rb
... | ... | @@ -24,7 +24,11 @@ class Person < Profile |
24 | 24 | end |
25 | 25 | |
26 | 26 | def enterprise_memberships |
27 | - memberships.select{|p|p.class == Enterprise} | |
27 | + memberships(:type => Enterprise.name) | |
28 | + end | |
29 | + | |
30 | + def community_memberships | |
31 | + memberships(:type => Community.name) | |
28 | 32 | end |
29 | 33 | |
30 | 34 | ... | ... |
test/fixtures/roles.yml
... | ... | @@ -27,3 +27,13 @@ four: |
27 | 27 | - manage_environment_categories |
28 | 28 | - manage_environment_roles |
29 | 29 | - manage_environment_validators |
30 | +profile_admin: | |
31 | + id: 5 | |
32 | + key: 'profile_admin' | |
33 | + name: 'Profile Administrator' | |
34 | + system: true | |
35 | +profile_member: | |
36 | + id: 6 | |
37 | + key: 'profile_member' | |
38 | + name: 'Profile Member' | |
39 | + system: true | ... | ... |
test/functional/manage_communities_controller_test.rb
... | ... | @@ -5,14 +5,42 @@ require 'manage_communities_controller' |
5 | 5 | class ManageCommunitiesController; def rescue_action(e) raise e end; end |
6 | 6 | |
7 | 7 | class ManageCommunitiesControllerTest < Test::Unit::TestCase |
8 | + | |
8 | 9 | def setup |
9 | 10 | @controller = ManageCommunitiesController.new |
10 | 11 | @request = ActionController::TestRequest.new |
11 | 12 | @response = ActionController::TestResponse.new |
13 | + | |
14 | + @profile = create_user('mytestuser').person | |
15 | + end | |
16 | + attr_reader :profile | |
17 | + | |
18 | + should 'present new community form' do | |
19 | + get :new, :profile => profile.identifier | |
20 | + assert_response :success | |
21 | + assert_template 'new' | |
22 | + end | |
23 | + | |
24 | + should 'be able to create a new community' do | |
25 | + assert_difference Community, :count do | |
26 | + post :new, :profile => profile.identifier, :community => { :name => 'My shiny new community', :description => 'This is a community devoted to anything interesting we find in the internet '} | |
27 | + assert_response :redirect | |
28 | + assert_redirected_to :action => 'index' | |
29 | + | |
30 | + assert Community.find_by_identifier('my-shiny-new-community').members.include?(profile), "Creator user should be added as member of the community just created" | |
31 | + end | |
32 | + end | |
33 | + | |
34 | + should 'list current communities' do | |
35 | + get :index, :profile => profile.identifier | |
36 | + assert_kind_of Array, assigns(:communities) | |
37 | + assert_response :success | |
38 | + assert_template 'index' | |
12 | 39 | end |
13 | 40 | |
14 | - should 'have tests' do | |
15 | - flunk 'pending' | |
41 | + should 'link to new community creation' do | |
42 | + get :index, :profile => profile.identifier | |
43 | + assert_tag :tag => 'a', :attributes => { :href => '/myprofile/mytestuser/manage_communities/new' } | |
16 | 44 | end |
17 | 45 | |
18 | 46 | end | ... | ... |
test/test_helper.rb
test/unit/community_test.rb
... | ... | @@ -18,4 +18,13 @@ class CommunityTest < Test::Unit::TestCase |
18 | 18 | assert_equal 'the description of the community', c.description |
19 | 19 | end |
20 | 20 | |
21 | + should 'allow to add new members' do | |
22 | + c = Community.create!(:name => 'my test community') | |
23 | + p = create_user('mytestuser').person | |
24 | + | |
25 | + c.add_member(p) | |
26 | + | |
27 | + assert c.members.include?(p), "Community should add the new member" | |
28 | + end | |
29 | + | |
21 | 30 | end | ... | ... |
test/unit/person_test.rb
... | ... | @@ -34,6 +34,15 @@ class PersonTest < Test::Unit::TestCase |
34 | 34 | assert p.memberships.include?(e) |
35 | 35 | assert p.enterprise_memberships.include?(e) |
36 | 36 | end |
37 | + | |
38 | + should 'belong to communities' do | |
39 | + c = Community.create!(:name => 'my test community') | |
40 | + p = create_user('mytestuser').person | |
41 | + | |
42 | + c.add_member(p) | |
43 | + | |
44 | + assert p.community_memberships.include?(c), "Community should add a new member" | |
45 | + end | |
37 | 46 | |
38 | 47 | def test_can_have_user |
39 | 48 | u = User.new(:login => 'john', :email => 'john@doe.org', :password => 'dhoe', :password_confirmation => 'dhoe') | ... | ... |