diff --git a/app/controllers/public/content_viewer_controller.rb b/app/controllers/public/content_viewer_controller.rb index bc1021f..3e40684 100644 --- a/app/controllers/public/content_viewer_controller.rb +++ b/app/controllers/public/content_viewer_controller.rb @@ -52,6 +52,7 @@ class ContentViewerController < ApplicationController # At this point the page will be showed @page.hit + store_location unless @page.mime_type == 'text/html' || (@page.image? && params[:view]) headers['Content-Type'] = @page.mime_type diff --git a/app/controllers/public/profile_controller.rb b/app/controllers/public/profile_controller.rb index a1872be..af4b43a 100644 --- a/app/controllers/public/profile_controller.rb +++ b/app/controllers/public/profile_controller.rb @@ -55,7 +55,6 @@ class ProfileController < PublicController end def join - store_location(request.referer) @wizard = params[:wizard] if request.post? && params[:confirmation] profile.add_member(current_user.person) @@ -66,6 +65,12 @@ class ProfileController < PublicController redirect_to_before_join end else + store_location(request.referer) + if current_user.person.memberships.include?(profile) + flash[:notice] = _('You are already a member of "%s"') % profile.name + redirect_back_or_default profile.url + return + end if request.xhr? render :layout => false end diff --git a/features/join_community.feature b/features/join_community.feature index 9d66ab2..8c3e35d 100644 --- a/features/join_community.feature +++ b/features/join_community.feature @@ -59,3 +59,22 @@ Feature: join a community When I press "Yes, I want to join" Then I should be on Sample Community's homepage And "Jose Oliveira" should be a member of "Sample Community" + + Scenario: ask confirmation before join community + Given I am on the homepage + And the following communities + | name | + | Community to join | + And I am logged in as "joaosilva" + When I am on /profile/community-to-join/join + Then I should see "Are you sure you want to join Community to join" + + Scenario: dont ask confirmation before join community if already member + Given I am on the homepage + And the following communities + | name | + | Community to join | + And joaosilva is member of community-to-join + And I am logged in as "joaosilva" + When I am on /profile/community-to-join/join + Then I should not see "Are you sure you want to join Community to join" diff --git a/features/step_definitions/noosfero_steps.rb b/features/step_definitions/noosfero_steps.rb index f7d4f3b..8b2a226 100644 --- a/features/step_definitions/noosfero_steps.rb +++ b/features/step_definitions/noosfero_steps.rb @@ -131,3 +131,7 @@ Then /^"([^\"]*)" should have the following data$/ do |id, table| data = expected.keys.inject({}) { |hash, key| hash[key] = profile.send(key).to_s; hash } data.should == expected end + +Given /^(.+) is member of (.+)$/ do |person, group| + Organization[group].add_member(Person[person]) +end diff --git a/test/functional/profile_controller_test.rb b/test/functional/profile_controller_test.rb index e2874bd..0416a72 100644 --- a/test/functional/profile_controller_test.rb +++ b/test/functional/profile_controller_test.rb @@ -611,7 +611,7 @@ class ProfileControllerTest < Test::Unit::TestCase should 'redirect to stored location after join community' do community = Community.create!(:name => 'my test community') - @request.expects(:referer).returns("/profile/#{community.identifier}/to_go") + @request.session[:return_to] = "/profile/#{community.identifier}/to_go" login_as(profile.identifier) post :join, :profile => community.identifier, :confirmation => '1' @@ -632,7 +632,7 @@ class ProfileControllerTest < Test::Unit::TestCase should 'redirect to location before login after join community' do community = Community.create!(:name => 'my test community') - @request.expects(:referer).returns("/profile/#{community.identifier}/to_go") + @request.session[:return_to] = "/profile/#{community.identifier}/to_go" login_as(profile.identifier) post :join, :profile => community.identifier, :confirmation => '1' -- libgit2 0.21.2