From a96e874cbd578722b3d799c571a9cb6abb008218 Mon Sep 17 00:00:00 2001 From: AntonioTerceiro Date: Fri, 15 Feb 2008 21:23:16 +0000 Subject: [PATCH] ActionItem154: refactoring: unifying manage_communities and memberships controlles into the later --- app/controllers/my_profile/manage_communities_controller.rb | 17 ----------------- app/controllers/my_profile/memberships_controller.rb | 10 ++++++++++ app/views/manage_communities/index.rhtml | 12 ------------ app/views/manage_communities/new.rhtml | 12 ------------ app/views/memberships/index.rhtml | 9 +++++++++ app/views/memberships/new_community.rhtml | 15 +++++++++++++++ test/functional/manage_communities_controller_test.rb | 46 ---------------------------------------------- test/functional/memberships_controller_test.rb | 20 ++++++++++++++++++++ 8 files changed, 54 insertions(+), 87 deletions(-) delete mode 100644 app/controllers/my_profile/manage_communities_controller.rb delete mode 100644 app/views/manage_communities/index.rhtml delete mode 100644 app/views/manage_communities/new.rhtml create mode 100644 app/views/memberships/new_community.rhtml delete mode 100644 test/functional/manage_communities_controller_test.rb diff --git a/app/controllers/my_profile/manage_communities_controller.rb b/app/controllers/my_profile/manage_communities_controller.rb deleted file mode 100644 index cc98f0d..0000000 --- a/app/controllers/my_profile/manage_communities_controller.rb +++ /dev/null @@ -1,17 +0,0 @@ -class ManageCommunitiesController < MyProfileController - - def index - @communities = profile.community_memberships - end - - def new - @community = Community.new(params[:community]) - if request.post? - if @community.save - @community.add_member(profile) - redirect_to :action => 'index' - end - end - end - -end diff --git a/app/controllers/my_profile/memberships_controller.rb b/app/controllers/my_profile/memberships_controller.rb index d47b1ed..7609bd0 100644 --- a/app/controllers/my_profile/memberships_controller.rb +++ b/app/controllers/my_profile/memberships_controller.rb @@ -12,4 +12,14 @@ class MembershipsController < MyProfileController end end + def new_community + @community = Community.new(params[:community]) + if request.post? + if @community.save + @community.add_member(profile) + redirect_to :action => 'index' + end + end + end + end diff --git a/app/views/manage_communities/index.rhtml b/app/views/manage_communities/index.rhtml deleted file mode 100644 index a8b3c0b..0000000 --- a/app/views/manage_communities/index.rhtml +++ /dev/null @@ -1,12 +0,0 @@ -

<%= _("%s's communities") % profile.name %>

- - - -<%= link_to _('Create a new community'), :action => 'new' %> diff --git a/app/views/manage_communities/new.rhtml b/app/views/manage_communities/new.rhtml deleted file mode 100644 index d737078..0000000 --- a/app/views/manage_communities/new.rhtml +++ /dev/null @@ -1,12 +0,0 @@ -<% labelled_form_for :community, @community do |f| %> - - <%= f.text_field :name %> - - <%= f.text_area :description %> - - <% button_bar do %> - <%= submit_button(:save, _('Create')) %> - <%= button(:cancel, _('Cancel'), :action => 'index') %> - <% end %> - -<% end %> diff --git a/app/views/memberships/index.rhtml b/app/views/memberships/index.rhtml index d941d00..38a2150 100644 --- a/app/views/memberships/index.rhtml +++ b/app/views/memberships/index.rhtml @@ -9,11 +9,20 @@ <%= _('Name') %> <%= _('Type') %> + <%= _('Actions') %> <% for membership in @memberships %> <%= link_to membership.name, membership.url %> <%= _(membership.class.name) %> + + <%= link_to _('Manage'), membership.admin_url %> + <% end %> + +<% button_bar do %> + <%= button(:add, _('Register a new Enterprise'), :controller => 'enterprise_registration') %> + <%= button(:add, _('Create a new community'), :action => 'new_community') %> +<% end %> diff --git a/app/views/memberships/new_community.rhtml b/app/views/memberships/new_community.rhtml new file mode 100644 index 0000000..9bb55d3 --- /dev/null +++ b/app/views/memberships/new_community.rhtml @@ -0,0 +1,15 @@ +<%= error_messages_for :community %> + + +<% labelled_form_for :community, @community do |f| %> + + <%= f.text_field :name %> + + <%= f.text_area :description %> + + <% button_bar do %> + <%= submit_button(:save, _('Create')) %> + <%= button(:cancel, _('Cancel'), :action => 'index') %> + <% end %> + +<% end %> diff --git a/test/functional/manage_communities_controller_test.rb b/test/functional/manage_communities_controller_test.rb deleted file mode 100644 index 5ebc0b8..0000000 --- a/test/functional/manage_communities_controller_test.rb +++ /dev/null @@ -1,46 +0,0 @@ -require File.dirname(__FILE__) + '/../test_helper' -require 'manage_communities_controller' - -# Re-raise errors caught by the controller. -class ManageCommunitiesController; def rescue_action(e) raise e end; end - -class ManageCommunitiesControllerTest < Test::Unit::TestCase - - def setup - @controller = ManageCommunitiesController.new - @request = ActionController::TestRequest.new - @response = ActionController::TestResponse.new - - @profile = create_user('mytestuser').person - end - attr_reader :profile - - should 'present new community form' do - get :new, :profile => profile.identifier - assert_response :success - assert_template 'new' - end - - should 'be able to create a new community' do - assert_difference Community, :count do - 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 '} - assert_response :redirect - assert_redirected_to :action => 'index' - - assert Community.find_by_identifier('my-shiny-new-community').members.include?(profile), "Creator user should be added as member of the community just created" - end - end - - should 'list current communities' do - get :index, :profile => profile.identifier - assert_kind_of Array, assigns(:communities) - assert_response :success - assert_template 'index' - end - - should 'link to new community creation' do - get :index, :profile => profile.identifier - assert_tag :tag => 'a', :attributes => { :href => '/myprofile/mytestuser/manage_communities/new' } - end - -end diff --git a/test/functional/memberships_controller_test.rb b/test/functional/memberships_controller_test.rb index e8e3667..ba8e3b6 100644 --- a/test/functional/memberships_controller_test.rb +++ b/test/functional/memberships_controller_test.rb @@ -39,5 +39,25 @@ class MembershipsControllerTest < Test::Unit::TestCase assert profile.memberships.include?(community), 'profile should be actually added to the community' end + should 'present new community form' do + get :new_community, :profile => profile.identifier + assert_response :success + assert_template 'new_community' + end + + should 'be able to create a new community' do + assert_difference Community, :count do + 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 '} + assert_response :redirect + assert_redirected_to :action => 'index' + + assert Community.find_by_identifier('my-shiny-new-community').members.include?(profile), "Creator user should be added as member of the community just created" + end + end + + should 'link to new community creation in index' do + get :index, :profile => profile.identifier + assert_tag :tag => 'a', :attributes => { :href => "/myprofile/#{profile.identifier}/memberships/new_community" } + end end -- libgit2 0.21.2