infer locale for groups based on group context; fixes #7069

groups cheat and set @context to the group after get_context runs but before
set_locale runs, but we want to infer the locale based on the group context
(the actual context), if it has one.

test-plan:
- in a course with student groups
- set the course language to spanish
- go to the group page, it should also be in spanish

Change-Id: I2fcdd4c4b416eafbe1bddb5c91c77360448f75f2
Reviewed-on: https://gerrit.instructure.com/9845
Tested-by: Hudson <hudson@instructure.com>
Reviewed-by: Brian Palmer <brianp@instructure.com>
This commit is contained in:
Simon Williams 2012-04-04 16:28:09 -06:00
parent eee95883a7
commit 88769625ca
2 changed files with 20 additions and 0 deletions

View File

@ -5,6 +5,13 @@ module LocaleSelection
root_account = options[:root_account]
accept_language = options[:accept_language]
# groups cheat and set the context to be the group after get_context runs
# but before set_locale runs, but we want to do locale lookup based on the
# actual context.
if context && context.is_a?(Group) && context.context
context = context.context
end
if context && context.is_a?(Course) && context.locale
context.locale
elsif user && user.locale

View File

@ -149,5 +149,18 @@ describe LocaleSelection do
ls.infer_locale(:accept_language => "it", :root_account => @root_account, :user => @user, :context => @account).should eql('de')
ls.infer_locale(:accept_language => "it", :root_account => @root_account, :user => @user, :context => @course).should eql('pt')
end
it "should infer the locale of a group from the group's context" do
@course.update_attribute(:locale, 'es')
course_gc = @course.group_categories.create!(:name => "Discussion Groups")
course_gr = Group.create!(:name => "Group 1", :group_category => course_gc, :context => @course)
@account.update_attribute(:default_locale, 'fr')
account_gc = @account.group_categories.create!(:name => "Other Groups")
account_gr = Group.create!(:name => "Group 1", :group_category => account_gc, :context => @account)
ls.infer_locale(:accept_language => "it", :root_account => @root_account, :user => @user, :context => account_gr).should eql('fr')
ls.infer_locale(:accept_language => "it", :root_account => @root_account, :user => @user, :context => course_gr).should eql('es')
end
end
end