Add ToolConfiguration model

Closes PLAT-3694

Test Plan:
- Run migrations
- Verify the new ToolConfiguration model
  requires settings to be present
- Verify the new ToolConfiguration model
  requires developer_key_id to be present.

Change-Id: Ic3977a3d01a5e133e8e775441844b78a40478339
Reviewed-on: https://gerrit.instructure.com/163799
Reviewed-by: Marc Alan Phillips <mphillips@instructure.com>
QA-Review: August Thornton <august@instructure.com>
Tested-by: Jenkins
Reviewed-by: Rob Orton <rob@instructure.com>
Product-Review: Weston Dransfield <wdransfield@instructure.com>
This commit is contained in:
wdransfield 2018-09-10 10:56:04 -06:00 committed by Weston Dransfield
parent 3a7d2e2713
commit fee04b7abe
4 changed files with 98 additions and 0 deletions

View File

@ -31,6 +31,7 @@ class DeveloperKey < ActiveRecord::Base
has_many :context_external_tools
has_one :tool_consumer_profile, :class_name => 'Lti::ToolConsumerProfile'
has_one :tool_configuration, class_name: 'Lti::ToolConfiguration'
serialize :scopes, Array
before_validation :validate_scopes!

View File

@ -0,0 +1,24 @@
#
# Copyright (C) 2018 - present Instructure, Inc.
#
# This file is part of Canvas.
#
# Canvas is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
# Software Foundation, version 3 of the License.
#
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
# details.
#
# You should have received a copy of the GNU Affero General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
module Lti
class ToolConfiguration < ActiveRecord::Base
belongs_to :developer_key
validates :developer_key_id, :settings, presence: true
end
end

View File

@ -0,0 +1,30 @@
#
# Copyright (C) 2018 - present Instructure, Inc.
#
# This file is part of Canvas.
#
# Canvas is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
# Software Foundation, version 3 of the License.
#
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
# details.
#
# You should have received a copy of the GNU Affero General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
class CreateToolConfigurations < ActiveRecord::Migration[5.1]
tag :predeploy
def change
create_table :lti_tool_configurations do |t|
t.references :developer_key, limit: 8, null: false, foreign_key: true, index: false
t.jsonb :settings, null: false
t.timestamps null: false
end
add_index :lti_tool_configurations, :developer_key_id, unique: true
end
end

View File

@ -0,0 +1,43 @@
#
# Copyright (C) 2018 - present Instructure, Inc.
#
# This file is part of Canvas.
#
# Canvas is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
# Software Foundation, version 3 of the License.
#
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
# details.
#
# You should have received a copy of the GNU Affero General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
#
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb')
require_dependency 'lti/tool_configuration'
module Lti
describe ToolConfiguration do
let(:tool_configuration) { Lti::ToolConfiguration.new }
let_once(:developer_key) { DeveloperKey.create }
describe 'validations' do
subject { tool_configuration.valid? }
context 'when "settings" is blank' do
before { tool_configuration.developer_key = developer_key }
it { is_expected.to eq false }
end
context 'when "developer_key_id" is blank' do
before { tool_configuration.settings = {foo: 'bar'} }
it { is_expected.to eq false }
end
end
end
end