From 74d508b1fb5e37f27ff1cb5e165f54e2d6302c96 Mon Sep 17 00:00:00 2001 From: Cody Cutrer Date: Fri, 31 Jan 2014 09:47:47 -0700 Subject: [PATCH] add foreign keys part 14 refs CNVS-6202 Change-Id: I4a86dff6cba47e33ac5aeef789bc0fe0db69dde4 Reviewed-on: https://gerrit.instructure.com/29494 Tested-by: Jenkins Reviewed-by: Brian Palmer Product-Review: Cody Cutrer QA-Review: Cody Cutrer --- .../20140128205246_add_foreign_keys14.rb | 30 +++++++++++++++++++ spec/apis/v1/courses_api_spec.rb | 2 ++ ...fix_out_of_sync_outcome_alignments_spec.rb | 3 +- spec/selenium/accounts_spec.rb | 7 ++++- 4 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20140128205246_add_foreign_keys14.rb diff --git a/db/migrate/20140128205246_add_foreign_keys14.rb b/db/migrate/20140128205246_add_foreign_keys14.rb new file mode 100644 index 00000000000..4d6f394d133 --- /dev/null +++ b/db/migrate/20140128205246_add_foreign_keys14.rb @@ -0,0 +1,30 @@ +class AddForeignKeys14 < ActiveRecord::Migration + tag :postdeploy + disable_ddl_transaction! + + def self.up + add_foreign_key_if_not_exists :assignment_override_students, :quizzes, delay_validation: true + add_foreign_key_if_not_exists :assignment_overrides, :quizzes, delay_validation: true + add_foreign_key_if_not_exists :collaborators, :groups, delay_validation: true + add_foreign_key_if_not_exists :content_participations, :users, delay_validation: true + add_foreign_key_if_not_exists :content_tags, :learning_outcomes, delay_validation: true + add_foreign_key_if_not_exists :context_module_progressions, :context_modules, delay_validation: true + add_foreign_key_if_not_exists :course_sections, :courses, delay_validation: true + add_foreign_key_if_not_exists :delayed_messages, :communication_channels, delay_validation: true + add_foreign_key_if_not_exists :discussion_topic_materialized_views, :discussion_topics, delay_validation: true + add_foreign_key_if_not_exists :migration_issues, :content_migrations, delay_validation: true + end + + def self.down + remove_foreign_key_if_exists :assignment_override_students, :quizzes + remove_foreign_key_if_exists :assignment_overrides, :quizzes + remove_foreign_key_if_exists :collaborators, :groups + remove_foreign_key_if_exists :content_participations, :users + remove_foreign_key_if_exists :content_tags, :learning_outcomes + remove_foreign_key_if_exists :context_module_progressions, :context_modules + remove_foreign_key_if_exists :course_sections, :courses + remove_foreign_key_if_exists :delayed_messages, :communication_channels + remove_foreign_key_if_exists :discussion_topic_materialized_views, :discussion_topics + remove_foreign_key_if_exists :migration_issues, :content_migrations + end +end diff --git a/spec/apis/v1/courses_api_spec.rb b/spec/apis/v1/courses_api_spec.rb index 38a5ea57e5f..5ee5afc6d59 100644 --- a/spec/apis/v1/courses_api_spec.rb +++ b/spec/apis/v1/courses_api_spec.rb @@ -670,6 +670,7 @@ describe CoursesController, type: :request do it "should deal gracefully with an invalid course id" do @course2.enrollments.scoped.delete_all @course2.course_account_associations.scoped.delete_all + @course2.course_sections.scoped.delete_all @course2.destroy! json = api_call(:put, @path + "?event=offer&course_ids[]=#{@course1.id}&course_ids[]=#{@course2.id}", @params.merge(:event => 'offer', :course_ids => [@course1.id.to_s, @course2.id.to_s])) @@ -728,6 +729,7 @@ describe CoursesController, type: :request do it "should report a failure if no updates succeeded" do @course2.enrollments.scoped.delete_all @course2.course_account_associations.scoped.delete_all + @course2.course_sections.scoped.delete_all @course2.destroy! json = api_call(:put, @path + "?event=offer&course_ids[]=#{@course2.id}", @params.merge(:event => 'offer', :course_ids => [@course2.id.to_s])) diff --git a/spec/migrations/fix_out_of_sync_outcome_alignments_spec.rb b/spec/migrations/fix_out_of_sync_outcome_alignments_spec.rb index aa2f7813659..f3c06195e35 100644 --- a/spec/migrations/fix_out_of_sync_outcome_alignments_spec.rb +++ b/spec/migrations/fix_out_of_sync_outcome_alignments_spec.rb @@ -74,7 +74,8 @@ describe DataFixup::FixOutOfSyncOutcomeAlignments do it "should delete alignments to assignments with rubrics without matching alignments" do align = @rubric_association_object.learning_outcome_alignments.first - @rubric.learning_outcome_alignments.update_all(:learning_outcome_id => 0) + lo = LearningOutcome.create!(short_description: 's') + @rubric.learning_outcome_alignments.update_all(:learning_outcome_id => lo) align.reload.should_not be_deleted DataFixup::FixOutOfSyncOutcomeAlignments.run diff --git a/spec/selenium/accounts_spec.rb b/spec/selenium/accounts_spec.rb index 2aa90322fb6..28509304ea6 100644 --- a/spec/selenium/accounts_spec.rb +++ b/spec/selenium/accounts_spec.rb @@ -133,7 +133,12 @@ describe "account" do end it "should be able to create a new course when no other courses exist" do - Account.default.courses.each { |c| c.enrollments.scoped.delete_all; c.course_account_associations.scoped.delete_all; c.destroy! } + Account.default.courses.each do |c| + c.course_account_associations.scoped.delete_all + c.enrollments.scoped.delete_all + c.course_sections.scoped.delete_all + c.destroy! + end get "/accounts/#{Account.default.to_param}" f('.add_course_link').click