add scope to allow selection of placements
fixes PLAT-656 test *specs pass Change-Id: I824bb17df3d20c89224d453c858237969a869a24 Reviewed-on: https://gerrit.instructure.com/41785 Tested-by: Jenkins <jenkins@instructure.com> Reviewed-by: Brad Humphrey <brad@instructure.com> Product-Review: Nathan Mills <nathanm@instructure.com> QA-Review: Nathan Mills <nathanm@instructure.com>
This commit is contained in:
parent
ce3d9a1634
commit
791eaad7cb
|
@ -508,6 +508,24 @@ class ContextExternalTool < ActiveRecord::Base
|
|||
scope :having_setting, lambda { |setting| setting ? joins(:context_external_tool_placements).
|
||||
where("context_external_tool_placements.placement_type = ?", setting) : scoped }
|
||||
|
||||
scope :placements, lambda { |*placements|
|
||||
if placements
|
||||
module_item_sql = if placements.include? 'module_item'
|
||||
"(context_external_tools.not_selectable IS NOT TRUE AND
|
||||
((COALESCE(context_external_tools.url, '') <> '' ) OR
|
||||
(COALESCE(context_external_tools.domain, '') <> ''))) OR "
|
||||
else
|
||||
''
|
||||
end
|
||||
where(module_item_sql + 'EXISTS (
|
||||
SELECT * FROM context_external_tool_placements
|
||||
WHERE context_external_tools.id = context_external_tool_placements.context_external_tool_id
|
||||
AND context_external_tool_placements.placement_type IN (?) )', placements || [])
|
||||
else
|
||||
scoped
|
||||
end
|
||||
}
|
||||
|
||||
def self.find_for(id, context, type, raise_error=true)
|
||||
id = id[Api::ID_REGEX] if id.is_a?(String)
|
||||
unless id.present?
|
||||
|
|
|
@ -386,6 +386,44 @@ describe ContextExternalTool do
|
|||
end
|
||||
end
|
||||
|
||||
describe "placements" do
|
||||
|
||||
it 'returns multiple requested placements' do
|
||||
tool1 = @course.context_external_tools.create!(:name => "First Tool", :url => "http://www.example.com", :consumer_key => "key", :shared_secret => "secret")
|
||||
tool2 = @course.context_external_tools.new(:name => "Another Tool", :consumer_key => "key", :shared_secret => "secret")
|
||||
tool2.settings[:editor_button] = {:url => "http://www.example.com", :icon_url => "http://www.example.com", :selection_width => 100, :selection_height => 100}.with_indifferent_access
|
||||
tool2.save!
|
||||
tool3 = @course.context_external_tools.new(:name => "Third Tool", :consumer_key => "key", :shared_secret => "secret")
|
||||
tool3.settings[:resource_selection] = {:url => "http://www.example.com", :icon_url => "http://www.example.com", :selection_width => 100, :selection_height => 100}.with_indifferent_access
|
||||
tool3.save!
|
||||
ContextExternalTool.all_tools_for(@course).placements('module_item', 'resource_selection').to_a.should eql([tool1, tool3].sort_by(&:name))
|
||||
end
|
||||
|
||||
it 'it only returns a single requested placements' do
|
||||
tool1 = @course.context_external_tools.create!(:name => "First Tool", :url => "http://www.example.com", :consumer_key => "key", :shared_secret => "secret")
|
||||
tool2 = @course.context_external_tools.new(:name => "Another Tool", :consumer_key => "key", :shared_secret => "secret")
|
||||
tool2.settings[:editor_button] = {:url => "http://www.example.com", :icon_url => "http://www.example.com", :selection_width => 100, :selection_height => 100}.with_indifferent_access
|
||||
tool2.save!
|
||||
tool3 = @course.context_external_tools.new(:name => "Third Tool", :consumer_key => "key", :shared_secret => "secret")
|
||||
tool3.settings[:resource_selection] = {:url => "http://www.example.com", :icon_url => "http://www.example.com", :selection_width => 100, :selection_height => 100}.with_indifferent_access
|
||||
tool3.save!
|
||||
ContextExternalTool.all_tools_for(@course).placements('resource_selection').to_a.should eql([tool3])
|
||||
end
|
||||
|
||||
it "doesn't return not selectable tools placements for moudle_item" do
|
||||
tool1 = @course.context_external_tools.create!(:name => "First Tool", :url => "http://www.example.com", :consumer_key => "key", :shared_secret => "secret")
|
||||
tool2 = @course.context_external_tools.new(:name => "Another Tool", :consumer_key => "key", :shared_secret => "secret")
|
||||
tool2.settings[:editor_button] = {:url => "http://www.example.com", :icon_url => "http://www.example.com", :selection_width => 100, :selection_height => 100}.with_indifferent_access
|
||||
tool2.save!
|
||||
tool3 = @course.context_external_tools.new(:name => "Third Tool", :consumer_key => "key", :shared_secret => "secret")
|
||||
tool3.settings[:resource_selection] = {:url => "http://www.example.com", :icon_url => "http://www.example.com", :selection_width => 100, :selection_height => 100}.with_indifferent_access
|
||||
tool3.not_selectable = true
|
||||
tool3.save!
|
||||
ContextExternalTool.all_tools_for(@course).placements('module_item').to_a.should eql([tool1])
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "find_integration_for" do
|
||||
it "should return nil if there are no matching integrations" do
|
||||
at = @account.context_external_tools.create!(name: 'at', url: 'http://example.com', consumer_key: '12345', shared_secret: 'secret')
|
||||
|
|
Loading…
Reference in New Issue