drop conditional release template models
despite all initial appearances it turns out these are functionally unused and probably won't change any time soon test plan: * specs closes #LA-1108 Change-Id: Ia5411d355659471465971e3f154292230841a709 Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/239380 Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com> Reviewed-by: Jeremy Stanley <jeremy@instructure.com> QA-Review: Jeremy Stanley <jeremy@instructure.com> Product-Review: Jeremy Stanley <jeremy@instructure.com>
This commit is contained in:
parent
4560b41a9b
commit
99c5a44fec
|
@ -1,38 +0,0 @@
|
|||
#
|
||||
# Copyright (C) 2020 - 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 ConditionalRelease
|
||||
class RuleTemplate < ActiveRecord::Base
|
||||
include Deletion
|
||||
|
||||
validates :name, presence: true
|
||||
validates :context_id, presence: true
|
||||
validates :context_type, inclusion: { in: %w(Account Course) }
|
||||
|
||||
belongs_to :context, polymorphic: [:course, :account]
|
||||
has_many :scoring_range_templates, -> { active }, inverse_of: :rule_template, dependent: :destroy
|
||||
accepts_nested_attributes_for :scoring_range_templates, allow_destroy: true
|
||||
|
||||
def build_rule
|
||||
rule = Rule.new root_account_id: root_account_id
|
||||
scoring_range_templates.each do |t|
|
||||
rule.scoring_ranges << t.build_scoring_range
|
||||
end
|
||||
rule
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,31 +0,0 @@
|
|||
#
|
||||
# Copyright (C) 2020 - 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 ConditionalRelease
|
||||
class ScoringRangeTemplate < ActiveRecord::Base
|
||||
include BoundsValidations
|
||||
include Deletion
|
||||
|
||||
belongs_to :rule_template, required: true
|
||||
|
||||
delegate :context_id, :context_type, to: :rule_template
|
||||
|
||||
def build_scoring_range
|
||||
ScoringRange.new upper_bound: upper_bound, lower_bound: lower_bound
|
||||
end
|
||||
end
|
||||
end
|
|
@ -86,30 +86,5 @@ class CreateConditionalReleaseTables < ActiveRecord::Migration[5.2]
|
|||
index: { name: 'index_cr_assignment_set_actions_on_root_account_id' }
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
create_table :conditional_release_rule_templates do |t|
|
||||
t.string :name
|
||||
t.integer :context_id, limit: 8
|
||||
t.string :context_type
|
||||
t.datetime :deleted_at
|
||||
|
||||
t.references :root_account, foreign_key: { to_table: 'accounts'}, limit: 8, null: false,
|
||||
index: { name: 'index_cr_rule_templates_on_root_account_id' }
|
||||
t.index [:root_account_id, :context_id, :context_type], where: 'deleted_at IS NULL',
|
||||
name: 'index_cr_rule_templates_on_account_and_context'
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
create_table :conditional_release_scoring_range_templates do |t|
|
||||
t.references :rule_template, foreign_key: { to_table: 'conditional_release_rule_templates' }, limit: 8, index: false
|
||||
t.decimal :upper_bound
|
||||
t.decimal :lower_bound
|
||||
t.datetime :deleted_at
|
||||
t.index :rule_template_id, where: 'deleted_at IS NULL', name: 'index_cr_scoring_range_templates_on_rule_template_id'
|
||||
|
||||
t.references :root_account, foreign_key: { to_table: 'accounts'}, limit: 8, null: false,
|
||||
index: { name: 'index_cr_scoring_range_templates_on_root_account_id' }
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
class DropConditionalReleaseTemplates < ActiveRecord::Migration[5.2]
|
||||
tag :predeploy
|
||||
|
||||
def up
|
||||
if table_exists?(:conditional_release_scoring_range_templates)
|
||||
drop_table :conditional_release_scoring_range_templates
|
||||
end
|
||||
if table_exists?(:conditional_release_rule_templates)
|
||||
drop_table :conditional_release_rule_templates
|
||||
end
|
||||
end
|
||||
|
||||
def down
|
||||
raise ActiveRecord::IrreversibleMigration
|
||||
end
|
||||
end
|
|
@ -1,44 +0,0 @@
|
|||
#
|
||||
# Copyright (C) 2020 - 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/>.
|
||||
#
|
||||
FactoryBot.define do
|
||||
factory :rule_template, class: ConditionalRelease::RuleTemplate do
|
||||
sequence(:name) { |n| "rule template #{n}" }
|
||||
context :factory => :course
|
||||
root_account_id { Account.default.id }
|
||||
|
||||
factory :rule_template_with_scoring_ranges do
|
||||
transient do
|
||||
scoring_range_template_count { 2 }
|
||||
end
|
||||
|
||||
after(:create) do |template, evaluator|
|
||||
values = (0..evaluator.scoring_range_template_count).collect { |i| i * 11 }
|
||||
create_list(
|
||||
:scoring_range_template,
|
||||
evaluator.scoring_range_template_count,
|
||||
rule_template: template
|
||||
) do |range_template|
|
||||
# give ascending bounds
|
||||
range_template.lower_bound = values.shift
|
||||
range_template.upper_bound = values[0]
|
||||
range_template.save!
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,25 +0,0 @@
|
|||
#
|
||||
# Copyright (C) 2020 - 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/>.
|
||||
#
|
||||
FactoryBot.define do
|
||||
factory :scoring_range_template, class: ConditionalRelease::ScoringRangeTemplate do
|
||||
rule_template
|
||||
lower_bound { 65 }
|
||||
upper_bound { 95 }
|
||||
root_account_id { Account.default.id }
|
||||
end
|
||||
end
|
|
@ -1,94 +0,0 @@
|
|||
#
|
||||
# Copyright (C) 2020 - 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_relative '../../conditional_release_spec_helper'
|
||||
require_dependency "conditional_release/rule_template"
|
||||
|
||||
module ConditionalRelease
|
||||
describe RuleTemplate, :type => :model do
|
||||
it_behaves_like 'a soft-deletable model'
|
||||
|
||||
describe 'rule template definition' do
|
||||
before do
|
||||
@rule_template = build :rule_template
|
||||
end
|
||||
|
||||
it 'cannot have null context_type' do
|
||||
@rule_template.context_type = nil
|
||||
expect(@rule_template.valid?).to be false
|
||||
end
|
||||
|
||||
it 'must have a context' do
|
||||
[Account, Course].each do |valid_klass|
|
||||
@rule_template.context = valid_klass.create!
|
||||
expect(@rule_template.valid?).to be true
|
||||
end
|
||||
expect {
|
||||
@rule_template.context = User.create!
|
||||
}.to raise_error(ActiveRecord::AssociationTypeMismatch)
|
||||
end
|
||||
|
||||
it 'cannot have a null context id' do
|
||||
@rule_template.context_id = nil
|
||||
expect(@rule_template.valid?).to be false
|
||||
end
|
||||
|
||||
it 'cannot have a null name' do
|
||||
@rule_template.name = nil
|
||||
expect(@rule_template.valid?).to be false
|
||||
end
|
||||
|
||||
it 'cannot have a null root account id' do
|
||||
@rule_template.root_account_id = nil
|
||||
expect(@rule_template.valid?).to be false
|
||||
end
|
||||
end
|
||||
|
||||
describe 'build_rule' do
|
||||
it 'has the same account id' do
|
||||
root_account = Account.create!
|
||||
template = create :rule_template, :root_account_id => root_account.id
|
||||
rule = template.build_rule
|
||||
expect(rule.root_account_id).to eq root_account.id
|
||||
end
|
||||
|
||||
it 'has the same number of ranges' do
|
||||
template = create :rule_template_with_scoring_ranges, scoring_range_template_count: 5
|
||||
rule = template.build_rule
|
||||
expect(rule.scoring_ranges.length).to eq 5
|
||||
end
|
||||
|
||||
it 'has the same values for ranges' do
|
||||
template = create :rule_template_with_scoring_ranges, scoring_range_template_count: 9
|
||||
rule = template.build_rule
|
||||
template.scoring_range_templates.each_with_index do |sr_template, i|
|
||||
range = rule.scoring_ranges[i]
|
||||
expect(range.upper_bound).to eq sr_template.upper_bound
|
||||
expect(range.lower_bound).to eq sr_template.lower_bound
|
||||
end
|
||||
end
|
||||
|
||||
it 'does not save rules or ranges' do
|
||||
template = create :rule_template_with_scoring_ranges, scoring_range_template_count: 1
|
||||
rule = template.build_rule
|
||||
expect(rule.new_record?).to be true
|
||||
expect(rule.scoring_ranges.first.new_record?).to be true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,78 +0,0 @@
|
|||
#
|
||||
# Copyright (C) 2020 - 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_relative '../../conditional_release_spec_helper'
|
||||
require_dependency "conditional_release/scoring_range_template"
|
||||
|
||||
module ConditionalRelease
|
||||
describe ScoringRangeTemplate, :type => :model do
|
||||
it_behaves_like 'a soft-deletable model'
|
||||
|
||||
describe 'scoring range definition' do
|
||||
before do
|
||||
@scoring_range_template = build :scoring_range_template
|
||||
end
|
||||
|
||||
it 'uses bounds validations' do
|
||||
@scoring_range_template.upper_bound = nil
|
||||
@scoring_range_template.lower_bound = nil
|
||||
expect(@scoring_range_template.valid?).to be false
|
||||
|
||||
@scoring_range_template.upper_bound = 10
|
||||
@scoring_range_template.lower_bound = 30
|
||||
expect(@scoring_range_template.valid?).to be false
|
||||
end
|
||||
|
||||
it 'must have an associated rule template' do
|
||||
@scoring_range_template.rule_template = nil
|
||||
expect(@scoring_range_template.valid?).to be false
|
||||
end
|
||||
end
|
||||
|
||||
describe 'build_scoring_range' do
|
||||
it 'has the same bounds' do
|
||||
template = create :scoring_range_template
|
||||
range = template.build_scoring_range
|
||||
expect(range.upper_bound).to eq template.upper_bound
|
||||
expect(range.lower_bound).to eq template.lower_bound
|
||||
end
|
||||
|
||||
it 'works with null bounds' do
|
||||
template = create :scoring_range_template, upper_bound: nil
|
||||
range = template.build_scoring_range
|
||||
expect(range.upper_bound).to be nil
|
||||
|
||||
template = create :scoring_range_template, lower_bound: nil
|
||||
range = template.build_scoring_range
|
||||
expect(range.lower_bound).to be nil
|
||||
end
|
||||
|
||||
it 'does not assign assignments' do
|
||||
template = create :scoring_range_template
|
||||
range = template.build_scoring_range
|
||||
expect(range.assignment_set_associations.count).to be 0
|
||||
end
|
||||
|
||||
it 'does not save to database' do
|
||||
template = create :scoring_range_template
|
||||
range = template.build_scoring_range
|
||||
expect(range.new_record?).to be true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue