diff --git a/app/controllers/my_profile/memberships_controller.rb b/app/controllers/my_profile/memberships_controller.rb new file mode 100644 index 0000000..d47b1ed --- /dev/null +++ b/app/controllers/my_profile/memberships_controller.rb @@ -0,0 +1,15 @@ +class MembershipsController < MyProfileController + + def index + @memberships = profile.memberships + end + + def join + @to_join = Profile.find(params[:id]) + if request.post? && params[:confirmation] + @to_join.add_member(profile) + redirect_to @to_join.url + end + end + +end diff --git a/app/helpers/memberships_helper.rb b/app/helpers/memberships_helper.rb new file mode 100644 index 0000000..eaf43c7 --- /dev/null +++ b/app/helpers/memberships_helper.rb @@ -0,0 +1,2 @@ +module MembershipsHelper +end diff --git a/app/views/memberships/index.rhtml b/app/views/memberships/index.rhtml new file mode 100644 index 0000000..d941d00 --- /dev/null +++ b/app/views/memberships/index.rhtml @@ -0,0 +1,19 @@ +
+<%= _('%s is a member of the following groups:') % profile.name %> +
+ + +<%= _('Name') %> | +<%= _('Type') %> | +
---|---|
<%= link_to membership.name, membership.url %> | +<%= _(membership.class.name) %> | +
+<%= _('Are you sure you want to join %s?') % @to_join.name %> +
+ +<% form_tag do %> + <%= hidden_field_tag(:confirmation, 1) %> + <%= submit_button(:ok, _("Yes, I want to join.") % @to_join.name) %> + <%= button(:cancel, _("No, I don't want."), :action => 'index') %> +<% end %> diff --git a/test/functional/memberships_controller_test.rb b/test/functional/memberships_controller_test.rb new file mode 100644 index 0000000..e8e3667 --- /dev/null +++ b/test/functional/memberships_controller_test.rb @@ -0,0 +1,43 @@ +require File.dirname(__FILE__) + '/../test_helper' +require 'memberships_controller' + +# Re-raise errors caught by the controller. +class MembershipsController; def rescue_action(e) raise e end; end + +class MembershipsControllerTest < Test::Unit::TestCase + def setup + @controller = MembershipsController.new + @request = ActionController::TestRequest.new + @response = ActionController::TestResponse.new + + @profile = create_user('testuser').person + end + attr_reader :profile + + should 'list current memberships' do + get :index, :profile => profile.identifier + + assert_kind_of Array, assigns(:memberships) + end + + should 'present confirmation before joining a profile' do + community = Community.create!(:name => 'my test community') + get :join, :profile => profile.identifier, :id => community.id + + assert_response :success + assert_template 'join' + end + + should 'actually join profile' do + community = Community.create!(:name => 'my test community') + post :join, :profile => profile.identifier, :id => community.id, :confirmation => '1' + + assert_response :redirect + assert_redirected_to community.url + + profile.reload + assert profile.memberships.include?(community), 'profile should be actually added to the community' + end + + +end -- libgit2 0.21.2