Commit bba3d1e252263fe60fbb47232671153366e57394
1 parent
3e7e1a28
Exists in
master
and in
29 other branches
Allowing users to configure the page after login
Added field redirection_after_login on profiles and environments New db/schema Added a select to choose option to redirect on admin panel and on profile control panel (ActionItem2369)
Showing
13 changed files
with
321 additions
and
18 deletions
Show diff stats
app/controllers/public/account_controller.rb
| @@ -313,10 +313,27 @@ class AccountController < ApplicationController | @@ -313,10 +313,27 @@ class AccountController < ApplicationController | ||
| 313 | end | 313 | end |
| 314 | 314 | ||
| 315 | def go_to_initial_page | 315 | def go_to_initial_page |
| 316 | - if environment == current_user.environment | ||
| 317 | - redirect_back_or_default(user.admin_url) | 316 | + if environment.enabled?('allow_change_of_redirection_after_login') |
| 317 | + case user.preferred_login_redirection | ||
| 318 | + when 'keep_on_same_page' | ||
| 319 | + redirect_back_or_default(user.admin_url) | ||
| 320 | + when 'site_homepage' | ||
| 321 | + redirect_to :controller => :home | ||
| 322 | + when 'user_profile_page' | ||
| 323 | + redirect_to user.public_profile_url | ||
| 324 | + when 'user_homepage' | ||
| 325 | + redirect_to user.url | ||
| 326 | + when 'user_control_panel' | ||
| 327 | + redirect_to user.admin_url | ||
| 328 | + else | ||
| 329 | + redirect_back_or_default(user.admin_url) | ||
| 330 | + end | ||
| 318 | else | 331 | else |
| 319 | - redirect_back_or_default(:controller => 'home') | 332 | + if environment == current_user.environment |
| 333 | + redirect_back_or_default(user.admin_url) | ||
| 334 | + else | ||
| 335 | + redirect_back_or_default(:controller => 'home') | ||
| 336 | + end | ||
| 320 | end | 337 | end |
| 321 | end | 338 | end |
| 322 | 339 |
app/models/environment.rb
| @@ -123,10 +123,22 @@ class Environment < ActiveRecord::Base | @@ -123,10 +123,22 @@ class Environment < ActiveRecord::Base | ||
| 123 | 'xmpp_chat' => _('XMPP/Jabber based chat'), | 123 | 'xmpp_chat' => _('XMPP/Jabber based chat'), |
| 124 | 'show_zoom_button_on_article_images' => _('Show a zoom link on all article images'), | 124 | 'show_zoom_button_on_article_images' => _('Show a zoom link on all article images'), |
| 125 | 'captcha_for_logged_users' => _('Ask captcha when a logged user comments too'), | 125 | 'captcha_for_logged_users' => _('Ask captcha when a logged user comments too'), |
| 126 | - 'skip_new_user_email_confirmation' => _('Skip e-mail confirmation for new users') | 126 | + 'skip_new_user_email_confirmation' => _('Skip e-mail confirmation for new users'), |
| 127 | + 'allow_change_of_redirection_after_login' => _('Allow users to set the page to redirect after login') | ||
| 127 | } | 128 | } |
| 128 | end | 129 | end |
| 129 | 130 | ||
| 131 | + def self.login_redirection_options | ||
| 132 | + { | ||
| 133 | + 'keep_on_same_page' => _('Stays on the same page the user was before login.'), | ||
| 134 | + 'site_homepage' => _('Redirects the user to the environment homepage.'), | ||
| 135 | + 'user_profile_page' => _('Redirects the user to his profile page.'), | ||
| 136 | + 'user_homepage' => _('Redirects the user to his homepage.'), | ||
| 137 | + 'user_control_panel' => _('Redirects the user to his control panel.') | ||
| 138 | + } | ||
| 139 | + end | ||
| 140 | + validates_inclusion_of :redirection_after_login, :in => Environment.login_redirection_options.keys, :allow_nil => true | ||
| 141 | + | ||
| 130 | # ################################################# | 142 | # ################################################# |
| 131 | # Relationships and applied behaviour | 143 | # Relationships and applied behaviour |
| 132 | # ################################################# | 144 | # ################################################# |
app/models/profile.rb
| @@ -972,4 +972,8 @@ private :generate_url, :url_options | @@ -972,4 +972,8 @@ private :generate_url, :url_options | ||
| 972 | end | 972 | end |
| 973 | end | 973 | end |
| 974 | 974 | ||
| 975 | + validates_inclusion_of :redirection_after_login, :in => Environment.login_redirection_options.keys, :allow_nil => true | ||
| 976 | + def preferred_login_redirection | ||
| 977 | + redirection_after_login.blank? ? environment.redirection_after_login : redirection_after_login | ||
| 978 | + end | ||
| 975 | end | 979 | end |
app/views/features/index.rhtml
| @@ -26,17 +26,12 @@ Check all the features you want to enable for your environment, uncheck all the | @@ -26,17 +26,12 @@ Check all the features you want to enable for your environment, uncheck all the | ||
| 26 | 26 | ||
| 27 | <h2><%= _('Configure features') %></h2> | 27 | <h2><%= _('Configure features') %></h2> |
| 28 | 28 | ||
| 29 | -<table> | ||
| 30 | - <tr> | ||
| 31 | - <th><%= _('Option') %></th> | ||
| 32 | - <th><%= _('Choice') %></th> | ||
| 33 | - </tr> | ||
| 34 | - <tr> | ||
| 35 | - <td><%= _('Organization Approval Method') %></td> | ||
| 36 | - <td><%= select_organization_approval_method('environment', 'organization_approval_method') %></td> | ||
| 37 | - </tr> | ||
| 38 | -</table> | ||
| 39 | - | 29 | +<h3><%= _('Page to redirect after login') %></h3> |
| 30 | + <%= select 'environment', 'redirection_after_login', Environment.login_redirection_options.map{|key,value|[value,key]} %> | ||
| 31 | +<hr/> | ||
| 32 | +<h3><%= _('Organization Approval Method') %></h3> | ||
| 33 | + <%= select_organization_approval_method('environment', 'organization_approval_method') %> | ||
| 34 | +<hr/> | ||
| 40 | 35 | ||
| 41 | <div> | 36 | <div> |
| 42 | <% button_bar do %> | 37 | <% button_bar do %> |
app/views/profile_editor/edit.rhtml
| @@ -39,6 +39,11 @@ | @@ -39,6 +39,11 @@ | ||
| 39 | </div> | 39 | </div> |
| 40 | <% end %> | 40 | <% end %> |
| 41 | 41 | ||
| 42 | + <% if environment.enabled?('allow_change_of_redirection_after_login') %> | ||
| 43 | + <h2><%= _('Page to redirect after login') %></h2> | ||
| 44 | + <%= select 'profile_data', 'redirection_after_login', Environment.login_redirection_options.map{|key,value|[value,key]}, { :selected => @profile.preferred_login_redirection} %> | ||
| 45 | + <% end %> | ||
| 46 | + | ||
| 42 | <h2><%= _('Translations') %></h2> | 47 | <h2><%= _('Translations') %></h2> |
| 43 | <%= labelled_check_box( | 48 | <%= labelled_check_box( |
| 44 | _('Automaticaly redirect the visitor to the article translated to his/her language'), | 49 | _('Automaticaly redirect the visitor to the article translated to his/her language'), |
db/migrate/20120824183534_add_redirection_after_login_to_environment.rb
0 → 100644
| @@ -0,0 +1,9 @@ | @@ -0,0 +1,9 @@ | ||
| 1 | +class AddRedirectionAfterLoginToEnvironment < ActiveRecord::Migration | ||
| 2 | + def self.up | ||
| 3 | + add_column :environments, :redirection_after_login, :string, :default => 'keep_on_same_page' | ||
| 4 | + end | ||
| 5 | + | ||
| 6 | + def self.down | ||
| 7 | + remove_column :environments, :redirection_after_login | ||
| 8 | + end | ||
| 9 | +end |
db/migrate/20120824184046_add_redirection_after_login_to_profiles.rb
0 → 100644
db/schema.rb
| @@ -261,6 +261,7 @@ ActiveRecord::Schema.define(:version => 20120825185219) do | @@ -261,6 +261,7 @@ ActiveRecord::Schema.define(:version => 20120825185219) do | ||
| 261 | t.datetime "created_at" | 261 | t.datetime "created_at" |
| 262 | t.datetime "updated_at" | 262 | t.datetime "updated_at" |
| 263 | t.integer "reports_lower_bound", :default => 0, :null => false | 263 | t.integer "reports_lower_bound", :default => 0, :null => false |
| 264 | + t.string "redirection_after_login" :default => "keep_on_same_page" | ||
| 264 | end | 265 | end |
| 265 | 266 | ||
| 266 | create_table "external_feeds", :force => true do |t| | 267 | create_table "external_feeds", :force => true do |t| |
| @@ -438,6 +439,7 @@ ActiveRecord::Schema.define(:version => 20120825185219) do | @@ -438,6 +439,7 @@ ActiveRecord::Schema.define(:version => 20120825185219) do | ||
| 438 | t.string "national_region_code" | 439 | t.string "national_region_code" |
| 439 | t.boolean "is_template", :default => false | 440 | t.boolean "is_template", :default => false |
| 440 | t.integer "template_id" | 441 | t.integer "template_id" |
| 442 | + t.string "redirection_after_login" | ||
| 441 | end | 443 | end |
| 442 | 444 | ||
| 443 | add_index "profiles", ["environment_id"], :name => "index_profiles_on_environment_id" | 445 | add_index "profiles", ["environment_id"], :name => "index_profiles_on_environment_id" |
features/login.feature
| @@ -9,7 +9,8 @@ Feature: login | @@ -9,7 +9,8 @@ Feature: login | ||
| 9 | | joaosilva | Joao Silva | | 9 | | joaosilva | Joao Silva | |
| 10 | 10 | ||
| 11 | Scenario: login from portal homepage | 11 | Scenario: login from portal homepage |
| 12 | - Given I am not logged in | 12 | + Given feature "allow_change_of_redirection_after_login" is disabled on environment |
| 13 | + And I am not logged in | ||
| 13 | And I go to the homepage | 14 | And I go to the homepage |
| 14 | And I fill in the following: | 15 | And I fill in the following: |
| 15 | | Username | joaosilva | | 16 | | Username | joaosilva | |
| @@ -19,7 +20,8 @@ Feature: login | @@ -19,7 +20,8 @@ Feature: login | ||
| 19 | And I should be logged in as "joaosilva" | 20 | And I should be logged in as "joaosilva" |
| 20 | 21 | ||
| 21 | Scenario: login from some profile page | 22 | Scenario: login from some profile page |
| 22 | - Given I am not logged in | 23 | + Given feature "allow_change_of_redirection_after_login" is disabled on environment |
| 24 | + And I am not logged in | ||
| 23 | And the following users | 25 | And the following users |
| 24 | | login | name | | 26 | | login | name | |
| 25 | | mariasilva | Maria Silva | | 27 | | mariasilva | Maria Silva | |
| @@ -35,7 +37,8 @@ Feature: login | @@ -35,7 +37,8 @@ Feature: login | ||
| 35 | Then I should be on Maria Silva's homepage | 37 | Then I should be on Maria Silva's homepage |
| 36 | 38 | ||
| 37 | Scenario: view my control panel | 39 | Scenario: view my control panel |
| 38 | - Given I am not logged in | 40 | + Given feature "allow_change_of_redirection_after_login" is disabled on environment |
| 41 | + And I am not logged in | ||
| 39 | And I go to Joao Silva's control panel | 42 | And I go to Joao Silva's control panel |
| 40 | And I should be on login page | 43 | And I should be on login page |
| 41 | And I fill in the following: | 44 | And I fill in the following: |
| @@ -48,3 +51,146 @@ Feature: login | @@ -48,3 +51,146 @@ Feature: login | ||
| 48 | Given I am logged in as "joaosilva" | 51 | Given I am logged in as "joaosilva" |
| 49 | And I go to login page | 52 | And I go to login page |
| 50 | Then I should be on Joao Silva's control panel | 53 | Then I should be on Joao Silva's control panel |
| 54 | + | ||
| 55 | + Scenario: stay on the same page after login if this is the environment default | ||
| 56 | + Given feature "allow_change_of_redirection_after_login" is enabled on environment | ||
| 57 | + And I am not logged in | ||
| 58 | + And the environment is configured to stay on the same page after login | ||
| 59 | + And the following users | ||
| 60 | + | login | name | | ||
| 61 | + | mariasilva | Maria Silva | | ||
| 62 | + And the following articles | ||
| 63 | + | owner | name | homepage | | ||
| 64 | + | mariasilva | my home page | true | | ||
| 65 | + And I go to Maria Silva's homepage | ||
| 66 | + And I follow "Login" | ||
| 67 | + And I fill in the following: | ||
| 68 | + | Username | joaosilva | | ||
| 69 | + | Password | 123456 | | ||
| 70 | + When I press "Log in" | ||
| 71 | + Then I should be on Maria Silva's homepage | ||
| 72 | + | ||
| 73 | + Scenario: go to site homepage if this is the environment default | ||
| 74 | + Given feature "allow_change_of_redirection_after_login" is enabled on environment | ||
| 75 | + And I am not logged in | ||
| 76 | + And the environment is configured to redirect to site homepage after login | ||
| 77 | + And I go to Joao Silva's homepage | ||
| 78 | + And I follow "Login" | ||
| 79 | + And I fill in the following: | ||
| 80 | + | Username | joaosilva | | ||
| 81 | + | Password | 123456 | | ||
| 82 | + When I press "Log in" | ||
| 83 | + Then I should be on the homepage | ||
| 84 | + | ||
| 85 | + Scenario: go to user profile after login if this is the environment default | ||
| 86 | + Given feature "allow_change_of_redirection_after_login" is enabled on environment | ||
| 87 | + And I am not logged in | ||
| 88 | + And the environment is configured to redirect to user profile page after login | ||
| 89 | + And I go to the homepage | ||
| 90 | + And I follow "Login" | ||
| 91 | + And I fill in the following: | ||
| 92 | + | Username | joaosilva | | ||
| 93 | + | Password | 123456 | | ||
| 94 | + When I press "Log in" | ||
| 95 | + Then I should be on Joao Silva's profile | ||
| 96 | + | ||
| 97 | + Scenario: go to profile homepage after login if this is the environment default | ||
| 98 | + Given the following articles | ||
| 99 | + | owner | name | body | homepage | | ||
| 100 | + | joaosilva | Sample Article | This is an article | true | | ||
| 101 | + And feature "allow_change_of_redirection_after_login" is enabled on environment | ||
| 102 | + And I am not logged in | ||
| 103 | + And the environment is configured to redirect to profile homepage after login | ||
| 104 | + And I go to the homepage | ||
| 105 | + And I follow "Login" | ||
| 106 | + And I fill in the following: | ||
| 107 | + | Username | joaosilva | | ||
| 108 | + | Password | 123456 | | ||
| 109 | + When I press "Log in" | ||
| 110 | + Then I should be on Joao Silva's homepage | ||
| 111 | + | ||
| 112 | + Scenario: go to profile control panel after login if this is the environment default | ||
| 113 | + Given feature "allow_change_of_redirection_after_login" is enabled on environment | ||
| 114 | + And I am not logged in | ||
| 115 | + And the environment is configured to redirect to profile control panel after login | ||
| 116 | + And I go to the homepage | ||
| 117 | + And I follow "Login" | ||
| 118 | + And I fill in the following: | ||
| 119 | + | Username | joaosilva | | ||
| 120 | + | Password | 123456 | | ||
| 121 | + When I press "Log in" | ||
| 122 | + Then I should be on Joao Silva's control panel | ||
| 123 | + | ||
| 124 | + Scenario: stay on the same page after login if this is the profile default | ||
| 125 | + Given feature "allow_change_of_redirection_after_login" is enabled on environment | ||
| 126 | + And I am not logged in | ||
| 127 | + And the environment is configured to redirect to site homepage after login | ||
| 128 | + And the profile joaosilva is configured to stay on the same page after login | ||
| 129 | + And the following users | ||
| 130 | + | login | name | | ||
| 131 | + | mariasilva | Maria Silva | | ||
| 132 | + And the following articles | ||
| 133 | + | owner | name | homepage | | ||
| 134 | + | mariasilva | my home page | true | | ||
| 135 | + And I go to Maria Silva's homepage | ||
| 136 | + And I follow "Login" | ||
| 137 | + And I fill in the following: | ||
| 138 | + | Username | joaosilva | | ||
| 139 | + | Password | 123456 | | ||
| 140 | + When I press "Log in" | ||
| 141 | + Then I should be on Maria Silva's homepage | ||
| 142 | + | ||
| 143 | + Scenario: go to site homepage if this is the profile default | ||
| 144 | + Given feature "allow_change_of_redirection_after_login" is enabled on environment | ||
| 145 | + And I am not logged in | ||
| 146 | + And the environment is configured to stay on the same page after login | ||
| 147 | + And the profile joaosilva is configured to redirect to site homepage after login | ||
| 148 | + And I go to Joao Silva's homepage | ||
| 149 | + And I follow "Login" | ||
| 150 | + And I fill in the following: | ||
| 151 | + | Username | joaosilva | | ||
| 152 | + | Password | 123456 | | ||
| 153 | + When I press "Log in" | ||
| 154 | + Then I should be on the homepage | ||
| 155 | + | ||
| 156 | + Scenario: go to user profile after login if this is the profile default | ||
| 157 | + Given feature "allow_change_of_redirection_after_login" is enabled on environment | ||
| 158 | + And I am not logged in | ||
| 159 | + And the environment is configured to stay on the same page after login | ||
| 160 | + And the profile joaosilva is configured to redirect to user profile page after login | ||
| 161 | + And I go to the homepage | ||
| 162 | + And I follow "Login" | ||
| 163 | + And I fill in the following: | ||
| 164 | + | Username | joaosilva | | ||
| 165 | + | Password | 123456 | | ||
| 166 | + When I press "Log in" | ||
| 167 | + Then I should be on Joao Silva's profile | ||
| 168 | + | ||
| 169 | + Scenario: go to profile homepage after login if this is the profile default | ||
| 170 | + Given the following articles | ||
| 171 | + | owner | name | body | homepage | | ||
| 172 | + | joaosilva | Sample Article | This is an article | true | | ||
| 173 | + And feature "allow_change_of_redirection_after_login" is enabled on environment | ||
| 174 | + And I am not logged in | ||
| 175 | + And the environment is configured to stay on the same page after login | ||
| 176 | + And the profile joaosilva is configured to redirect to profile homepage after login | ||
| 177 | + And I go to the homepage | ||
| 178 | + And I follow "Login" | ||
| 179 | + And I fill in the following: | ||
| 180 | + | Username | joaosilva | | ||
| 181 | + | Password | 123456 | | ||
| 182 | + When I press "Log in" | ||
| 183 | + Then I should be on Joao Silva's homepage | ||
| 184 | + | ||
| 185 | + Scenario: go to profile control panel after login if this is the profile default | ||
| 186 | + Given feature "allow_change_of_redirection_after_login" is enabled on environment | ||
| 187 | + And I am not logged in | ||
| 188 | + And the environment is configured to stay on the same page after login | ||
| 189 | + And the profile joaosilva is configured to redirect to profile control panel after login | ||
| 190 | + And I go to the homepage | ||
| 191 | + And I follow "Login" | ||
| 192 | + And I fill in the following: | ||
| 193 | + | Username | joaosilva | | ||
| 194 | + | Password | 123456 | | ||
| 195 | + When I press "Log in" | ||
| 196 | + Then I should be on Joao Silva's control panel |
features/step_definitions/noosfero_steps.rb
| @@ -712,3 +712,39 @@ When /^I make a AJAX request to (.*)$/ do |page| | @@ -712,3 +712,39 @@ When /^I make a AJAX request to (.*)$/ do |page| | ||
| 712 | header 'X-Requested-With', 'XMLHttpRequest' | 712 | header 'X-Requested-With', 'XMLHttpRequest' |
| 713 | visit(path_to(page)) | 713 | visit(path_to(page)) |
| 714 | end | 714 | end |
| 715 | + | ||
| 716 | +Given /^the environment is configured to (.*) after login$/ do |option| | ||
| 717 | + redirection = case option | ||
| 718 | + when 'stay on the same page' | ||
| 719 | + 'keep_on_same_page' | ||
| 720 | + when 'redirect to site homepage' | ||
| 721 | + 'site_homepage' | ||
| 722 | + when 'redirect to user profile page' | ||
| 723 | + 'user_profile_page' | ||
| 724 | + when 'redirect to profile homepage' | ||
| 725 | + 'user_homepage' | ||
| 726 | + when 'redirect to profile control panel' | ||
| 727 | + 'user_control_panel' | ||
| 728 | + end | ||
| 729 | + environment = Environment.default | ||
| 730 | + environment.redirection_after_login = redirection | ||
| 731 | + environment.save | ||
| 732 | +end | ||
| 733 | + | ||
| 734 | +Given /^the profile (.*) is configured to (.*) after login$/ do |profile, option| | ||
| 735 | + redirection = case option | ||
| 736 | + when 'stay on the same page' | ||
| 737 | + 'keep_on_same_page' | ||
| 738 | + when 'redirect to site homepage' | ||
| 739 | + 'site_homepage' | ||
| 740 | + when 'redirect to user profile page' | ||
| 741 | + 'user_profile_page' | ||
| 742 | + when 'redirect to profile homepage' | ||
| 743 | + 'user_homepage' | ||
| 744 | + when 'redirect to profile control panel' | ||
| 745 | + 'user_control_panel' | ||
| 746 | + end | ||
| 747 | + profile = Profile.find_by_identifier(profile) | ||
| 748 | + profile.redirection_after_login = redirection | ||
| 749 | + profile.save | ||
| 750 | +end |
test/functional/profile_editor_controller_test.rb
| @@ -962,4 +962,21 @@ class ProfileEditorControllerTest < ActionController::TestCase | @@ -962,4 +962,21 @@ class ProfileEditorControllerTest < ActionController::TestCase | ||
| 962 | assert_no_tag :tag => 'input', :attributes => {:name => 'profile_data[is_template]'} | 962 | assert_no_tag :tag => 'input', :attributes => {:name => 'profile_data[is_template]'} |
| 963 | end | 963 | end |
| 964 | 964 | ||
| 965 | + should 'display select to change redirection after login if enabled' do | ||
| 966 | + e = Environment.default | ||
| 967 | + e.enable('allow_change_of_redirection_after_login') | ||
| 968 | + e.save | ||
| 969 | + | ||
| 970 | + get :edit, :profile => profile.identifier | ||
| 971 | + assert_tag :tag => 'select', :attributes => {:id => 'profile_data_redirection_after_login'} | ||
| 972 | + end | ||
| 973 | + | ||
| 974 | + should 'not display select to change redirection after login if not enabled' do | ||
| 975 | + e = Environment.default | ||
| 976 | + e.disable('allow_change_of_redirection_after_login') | ||
| 977 | + e.save | ||
| 978 | + | ||
| 979 | + get :edit, :profile => profile.identifier | ||
| 980 | + assert_no_tag :tag => 'select', :attributes => {:id => 'profile_data_redirection_after_login'} | ||
| 981 | + end | ||
| 965 | end | 982 | end |
test/unit/environment_test.rb
| @@ -1220,4 +1220,26 @@ class EnvironmentTest < ActiveSupport::TestCase | @@ -1220,4 +1220,26 @@ class EnvironmentTest < ActiveSupport::TestCase | ||
| 1220 | assert_includes environment.licenses, l2 | 1220 | assert_includes environment.licenses, l2 |
| 1221 | assert_not_includes environment.licenses, l3 | 1221 | assert_not_includes environment.licenses, l3 |
| 1222 | end | 1222 | end |
| 1223 | + | ||
| 1224 | + should 'return a Hash on login redirection options' do | ||
| 1225 | + assert_kind_of Hash, Environment.login_redirection_options | ||
| 1226 | + end | ||
| 1227 | + | ||
| 1228 | + should 'respond to redirection after login' do | ||
| 1229 | + assert_respond_to Environment.new, :redirection_after_login | ||
| 1230 | + end | ||
| 1231 | + | ||
| 1232 | + should 'allow only environment login redirection options' do | ||
| 1233 | + environment = fast_create(Environment) | ||
| 1234 | + environment.redirection_after_login = 'invalid_option' | ||
| 1235 | + environment.save | ||
| 1236 | + assert environment.errors.invalid?(:redirection_after_login) | ||
| 1237 | + | ||
| 1238 | + Environment.login_redirection_options.keys.each do |redirection| | ||
| 1239 | + environment.redirection_after_login = redirection | ||
| 1240 | + environment.save | ||
| 1241 | + assert !environment.errors.invalid?(:redirection_after_login) | ||
| 1242 | + end | ||
| 1243 | + end | ||
| 1244 | + | ||
| 1223 | end | 1245 | end |
test/unit/profile_test.rb
| @@ -1916,4 +1916,33 @@ class ProfileTest < ActiveSupport::TestCase | @@ -1916,4 +1916,33 @@ class ProfileTest < ActiveSupport::TestCase | ||
| 1916 | profile.save! | 1916 | profile.save! |
| 1917 | end | 1917 | end |
| 1918 | 1918 | ||
| 1919 | + should 'respond to redirection_after_login' do | ||
| 1920 | + assert_respond_to Profile.new, :redirection_after_login | ||
| 1921 | + end | ||
| 1922 | + | ||
| 1923 | + should 'return profile preference of redirection unless it is blank' do | ||
| 1924 | + environment = fast_create(Environment, :redirection_after_login => 'site_homepage') | ||
| 1925 | + profile = fast_create(Profile, :redirection_after_login => 'keep_on_same_page', :environment_id => environment.id) | ||
| 1926 | + assert_equal 'keep_on_same_page', profile.preferred_login_redirection | ||
| 1927 | + end | ||
| 1928 | + | ||
| 1929 | + should 'return environment preference of redirection when profile preference is blank' do | ||
| 1930 | + environment = fast_create(Environment, :redirection_after_login => 'site_homepage') | ||
| 1931 | + profile = fast_create(Profile, :environment_id => environment.id) | ||
| 1932 | + assert_equal 'site_homepage', profile.preferred_login_redirection | ||
| 1933 | + end | ||
| 1934 | + | ||
| 1935 | + should 'allow only environment login redirection options' do | ||
| 1936 | + profile = fast_create(Profile) | ||
| 1937 | + profile.redirection_after_login = 'invalid_option' | ||
| 1938 | + profile.save | ||
| 1939 | + assert profile.errors.invalid?(:redirection_after_login) | ||
| 1940 | + | ||
| 1941 | + Environment.login_redirection_options.keys.each do |redirection| | ||
| 1942 | + profile.redirection_after_login = redirection | ||
| 1943 | + profile.save | ||
| 1944 | + assert !profile.errors.invalid?(:redirection_after_login) | ||
| 1945 | + end | ||
| 1946 | + end | ||
| 1947 | + | ||
| 1919 | end | 1948 | end |