diff --git a/lib/lti/variable_expander.rb b/lib/lti/variable_expander.rb index 194d9f02038..3ad7e998f99 100644 --- a/lib/lti/variable_expander.rb +++ b/lib/lti/variable_expander.rb @@ -106,8 +106,8 @@ module Lti -> { "#{@request.scheme}://#{HostUrl.context_host(@root_account, @request.host)}" } register_expansion 'Canvas.api.membershipServiceUrl', [], - -> { @controller.course_membership_service_url(@context) }, - COURSE_GUARD + -> { @controller.polymorphic_url([@context, :membership_service]) }, + -> { @context.is_a?(Course) || @context.is_a?(Group) } # returns the account id for the current context. # @example diff --git a/spec/lib/lti/variable_expander_spec.rb b/spec/lib/lti/variable_expander_spec.rb index d608f021298..eb0407bd736 100644 --- a/spec/lib/lti/variable_expander_spec.rb +++ b/spec/lib/lti/variable_expander_spec.rb @@ -22,6 +22,8 @@ module Lti let(:root_account) { Account.new } let(:account) { Account.new(root_account: root_account) } let(:course) { Course.new(account: account) } + let(:group_category) { course.group_categories.new(name: 'Category') } + let(:group) { course.groups.new(name: 'Group', group_category: group_category) } let(:user) { User.new } let(:assignment) { Assignment.new } let(:substitution_helper) { stub_everything } @@ -206,13 +208,25 @@ module Lti expect(exp_hash[:test]).to eq Shard.current.id end + context 'context is a group' do + subject { described_class.new(root_account, group, controller, current_user: user) } + + it 'has substitution for $Canvas.api.membershipServiceUrl when context is a group' do + exp_hash = { test: '$Canvas.api.membershipServiceUrl' } + group.stubs(:id).returns('1') + controller.stubs(:polymorphic_url).returns("/api/lti/groups/#{group.id}/membership_service") + subject.expand_variables!(exp_hash) + expect(exp_hash[:test]).to eq "/api/lti/groups/1/membership_service" + end + end + context 'context is a course' do subject { described_class.new(root_account, course, controller, current_user: user) } - it 'has substitution for $Canvas.api.membershipServiceUrl' do + it 'has substitution for $Canvas.api.membershipServiceUrl when context is a course' do exp_hash = { test: '$Canvas.api.membershipServiceUrl' } course.stubs(:id).returns('1') - controller.stubs(:course_membership_service_url).returns("/api/lti/courses/#{course.id}/membership_service") + controller.stubs(:polymorphic_url).returns("/api/lti/courses/#{course.id}/membership_service") subject.expand_variables!(exp_hash) expect(exp_hash[:test]).to eq "/api/lti/courses/1/membership_service" end