include sub-account assets in the right order

fixes #9674

with more than one level of sub-account branding, the branding
was being included in the wrong order for certain pages.

test plan:
- make sure global includes and sub-account includes are enabled
  on the root account
- make a sub account (S1) and enable sub-account includes
- make a sub account of that sub account (SS1)
- add custom branding on both sub accounts, where the branding on
  SS1 is meant to override the branding on S1
- the css should override in the right order

Change-Id: I7579a885e057ce06843bb0b73f2f297391466afa
Reviewed-on: https://gerrit.instructure.com/12567
Tested-by: Jenkins <jenkins@instructure.com>
Reviewed-by: Cody Cutrer <cody@instructure.com>
This commit is contained in:
Simon Williams 2012-07-27 16:52:42 -06:00
parent 31dabb9a18
commit afa435ef1f
2 changed files with 28 additions and 1 deletions

View File

@ -663,7 +663,7 @@ module ApplicationHelper
@include_accounts = [Account.site_admin, @domain_root_account]
if @domain_root_account.try(:sub_account_includes?)
# get the deepest account to start looking for branding
common_chain = account_context(@context).try(:account_chain)
common_chain = account_context(@context).try(:account_chain).try(:reverse)
common_chain ||= @current_user.common_account_chain(@domain_root_account) if @current_user.present?
@include_accounts.concat(common_chain) if common_chain.present?
end

View File

@ -170,6 +170,7 @@ describe ApplicationHelper do
@sub_account1 = account_model(:root_account => @domain_root_account)
@sub_account1.settings = @sub_account1.settings.merge({ :global_stylesheet => '/path/to/sub1/css' })
@sub_account1.settings = @sub_account1.settings.merge({ :sub_account_includes => true })
@sub_account1.save!
@sub_account2 = account_model(:root_account => @domain_root_account)
@ -230,6 +231,32 @@ describe ApplicationHelper do
output.should have_tag 'link'
output.scan(%r{/path/to/(sub1/|sub2/|root/|admin/)?css}).should eql [['admin/'], ['root/']]
end
it "should include multiple levesl of sub-account css in the right order for course page" do
@sub_sub_account1 = account_model(:parent_account => @sub_account1, :root_account => @domain_root_account)
@sub_sub_account1.settings = @sub_sub_account1.settings.merge({ :global_stylesheet => '/path/to/subsub1/css' })
@sub_sub_account1.save!
@context = @sub_sub_account1.courses.create!
output = include_account_css
output.should have_tag 'link'
output.scan(%r{/path/to/(subsub1/|sub1/|sub2/|root/|admin/)?css}).should eql [['admin/'], ['root/'], ['sub1/'], ['subsub1/']]
end
it "should include multiple levesl of sub-account css in the right order" do
@sub_sub_account1 = account_model(:parent_account => @sub_account1, :root_account => @domain_root_account)
@sub_sub_account1.settings = @sub_sub_account1.settings.merge({ :global_stylesheet => '/path/to/subsub1/css' })
@sub_sub_account1.save!
@course = @sub_sub_account1.courses.create!
@course.offer!
student_in_course(:active_all => true)
@context = @user
@current_user = @user
output = include_account_css
output.should have_tag 'link'
output.scan(%r{/path/to/(subsub1/|sub1/|sub2/|root/|admin/)?css}).should eql [['admin/'], ['root/'], ['sub1/'], ['subsub1/']]
end
end
end