diff --git a/app/controllers/public/account_controller.rb b/app/controllers/public/account_controller.rb index 6f3a5da..867c408 100644 --- a/app/controllers/public/account_controller.rb +++ b/app/controllers/public/account_controller.rb @@ -17,7 +17,7 @@ class AccountController < ApplicationController def login @user = User.new @person = @user.build_person - store_location(request.referer) + store_location(request.referer) unless session[:return_to] return unless request.post? self.current_user = User.authenticate(params[:user][:login], params[:user][:password]) if params[:user] if logged_in? @@ -290,4 +290,5 @@ class AccountController < ApplicationController redirect_back_or_default(:controller => 'home') end end + end diff --git a/app/controllers/public/profile_controller.rb b/app/controllers/public/profile_controller.rb index 44a0a25..88a35bd 100644 --- a/app/controllers/public/profile_controller.rb +++ b/app/controllers/public/profile_controller.rb @@ -55,6 +55,7 @@ class ProfileController < PublicController end def join + store_location(request.referer) @wizard = params[:wizard] if request.post? && params[:confirmation] profile.add_member(current_user.person) @@ -65,7 +66,6 @@ class ProfileController < PublicController redirect_to_before_join end else - store_location(request.referer) if request.xhr? render :layout => false end diff --git a/app/views/shared/join_community_popup.rhtml b/app/views/shared/join_community_popup.rhtml index 9fe2a22..bce60ae 100644 --- a/app/views/shared/join_community_popup.rhtml +++ b/app/views/shared/join_community_popup.rhtml @@ -1,14 +1,13 @@

<%= __('Do you want to join this community?') %>

- <% button_bar do %> - <% if logged_in? %> - <%= button(:ok, _('Yes'), profile.join_url.merge(:confirmation => '1'), :method => :post) %> - <% else %> - <%= button(:ok, _('Yes'), profile.join_url) %> + <% form_tag(profile.join_url) do %> + <%= hidden_field(:confirmation, 1) if logged_in? %> + <% button_bar do %> + <%= submit_button(:ok,"Yes") %> + <%= button_to_remote(:cancel, _('Not now'), :url => profile.join_url.merge({:controller => 'profile', :action => 'refuse_for_now', :profile => profile.identifier}), :loaded => '$("join-community-popup").hide()') %> + <%= button(:cancel, _('No and don\'t ask again'), :controller => 'profile', :action => 'refuse_join', :profile => profile.identifier) if logged_in? %> <% end %> - <%= button_to_remote(:cancel, _('Not now'), :url => profile.join_url.merge({:controller => 'profile', :action => 'refuse_for_now', :profile => profile.identifier}), :loaded => '$("join-community-popup").hide()') %> - <%= button(:cancel, _('No and don\'t ask again'), :controller => 'profile', :action => 'refuse_join', :profile => profile.identifier) if logged_in? %> <% end %>
<%= draggable_element('join-community-popup') %> diff --git a/features/join_community.feature b/features/join_community.feature new file mode 100644 index 0000000..9d66ab2 --- /dev/null +++ b/features/join_community.feature @@ -0,0 +1,61 @@ +Feature: join a community + As a user + I want to join a community + In order to interact with other people + + Background: + Given the following users + | login | name | + | joaosilva | Joao Silva | + Given the following communities + | identifier | name | + | sample-community | Sample Community | + + Scenario: a logged user asks to join a community with "join_community_popup" + Given feature "join_community_popup" is enabled on environment + And I am logged in as "joaosilva" + And I go to Sample Community's homepage + And I press "Yes" + Then I should be on Sample Community's homepage + And "Joao Silva" should be a member of "Sample Community" + + Scenario: a logged user asks to join a community without "join_community_popup" + Given feature "join_community_popup" is disabled on environment + And I am logged in as "joaosilva" + And I am on Sample Community's homepage + And I follow "Join" + And I should see "Are you sure you want to join Sample Community?" + When I press "Yes, I want to join." + Then "Joao Silva" should be a member of "Sample Community" + + Scenario: a not logged user asks join a community + Given feature "join_community_popup" is enabled on environment + And I am not logged in + And I go to Sample Community's homepage + And I press "Yes" + And I fill in the following: + | Username | joaosilva | + | Password | 123456 | + And I press "Log in" + And I should see "Are you sure you want to join Sample Community?" + When I press "Yes, I want to join" + Then I should be on Sample Community's homepage + And "Joao Silva" should be a member of "Sample Community" + + Scenario: a non-user ask to join a community + Given feature "join_community_popup" is enabled on environment + And I am not logged in + And I go to Sample Community's homepage + And I press "Yes" + And I follow "I want to participate" + And I fill in the following: + | e-mail | jose@domain.br | + | Username | joseoliveira | + | Password | 123456 | + | Password confirmation | 123456 | + | Full name | Jose Oliveira | + And I press "Sign up" + And I should see "Are you sure you want to join Sample 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" diff --git a/features/login.feature b/features/login.feature new file mode 100644 index 0000000..8c9db1e --- /dev/null +++ b/features/login.feature @@ -0,0 +1,41 @@ +Feature: login + As a user + I want to login + In order to view pages logged in + + Background: + Given the following users + | login | name | + | joaosilva | Joao Silva | + + Scenario: login from portal homepage + Given I am not logged in + And I go to the homepage + And I fill in the following: + | Username | joaosilva | + | Password | 123456 | + When I press "Log in" + Then I should be on the homepage + + Scenario: login from some profile page + Given I am not logged in + And the following users + | login | name | + | mariasilva | Maria Silva | + And I go to Maria Silva's homepage + And I follow "Login" + And I fill in the following: + | Username | joaosilva | + | Password | 123456 | + When I press "Log in" + Then I should be on Maria Silva's homepage + + Scenario: view my control panel + Given I am not logged in + And I go to Joao Silva's control panel + And I should be on login page + And I fill in the following: + | Username | joaosilva | + | Password | 123456 | + When I press "Log in" + Then I should be on Joao Silva's control panel diff --git a/test/functional/profile_controller_test.rb b/test/functional/profile_controller_test.rb index a7873c4..243ef34 100644 --- a/test/functional/profile_controller_test.rb +++ b/test/functional/profile_controller_test.rb @@ -616,7 +616,7 @@ class ProfileControllerTest < Test::Unit::TestCase login_as(profile.identifier) assert_nil @request.session[:return_to] - @request.expects(:referer).returns("/profile/redirect_to") + @request.expects(:referer).returns("/profile/redirect_to").at_least_once get :join, :profile => community.identifier @@ -626,7 +626,7 @@ class ProfileControllerTest < Test::Unit::TestCase should 'redirect to stored location after join community' do community = Community.create!(:name => 'my test community') - @request.session[:return_to] = "/profile/#{community.identifier}/to_go" + @request.expects(:referer).returns("/profile/#{community.identifier}/to_go") login_as(profile.identifier) post :join, :profile => community.identifier, :confirmation => '1' @@ -647,7 +647,7 @@ class ProfileControllerTest < Test::Unit::TestCase should 'redirect to location before login after join community' do community = Community.create!(:name => 'my test community') - @request.session[:before_join] = "/profile/#{community.identifier}/to_go" + @request.expects(:referer).returns("/profile/#{community.identifier}/to_go") login_as(profile.identifier) post :join, :profile => community.identifier, :confirmation => '1' -- libgit2 0.21.2