Commit Graph

3 Commits

Author SHA1 Message Date
Strand McCutchen 05f4b9190e Extract Soft Deletion
fixes CNVS-20361

This is the first step in extracting soft deletion and
only touches grading period models. I audited other models
to see if this extraction would work for them, but no other
models met my criteria which are as follows

- [ ] defines workflow state of _only_ active and deleted
- [ ] active scope where state is active
      (not `workflow_state<>'deleted'`)
In `def destroy`:
  - [ ] state set to deleted
  - [ ] then save
  - [ ] runs callbacks

Many variants of soft deletion exist, including scoping
active to `workflow_state<>'deleted'`, not running
callbacks after save, and wrapping the state change in a
transaction block.

This is the first step in making soft deletion behave
consistently. There are approximately 30 models that have
an implementation of soft deletion.

Change-Id: I6cb48571377a4bb403285f95c058020b46ca3a30
Reviewed-on: https://gerrit.instructure.com/53821
Reviewed-by: Derek Bender <dbender@instructure.com>
Product-Review: Strand McCutchen <smccutchen@instructure.com>
QA-Review: Strand McCutchen <smccutchen@instructure.com>
Tested-by: Jenkins
2015-05-18 18:45:01 +00:00
Spencer Olson 0f53b9f7a7 add workflow state to grading period groups and grading period grades
add workflow state to grading period groups and grading period grades.
also add a default value of 'active' and a not-null constraint for
workflow state on grading periods, grading period groups, and grading
period grades. also add a validate method for grading period group
that ensures the group belongs to either a course or account. add a
not-null constraint for grading period group id on grading periods. add
an index for workflow_state on grading period groups, grading periods,
and grading period grades.

closes CNVS-18995

test plan:

run migrations. in rails console:
  $ bundle exec rake db:migrate
  $ bundle exec rake db:migrate RAILS_ENV=test

Grading Period Groups:
  - you should not be able to create a Grading Period Group without
    assigning it either a course or account. If you don't supply a
    workflow state when you create a grading period group, it should
    default to 'active'.

    $ g = GradingPeriodGroup.create
    $ g.valid? #should return false

    $ g = Account.default.grading_period_groups.create
    $ g.valid? #should return true
    $ g.workflow_state #should return 'active'

    $ new_course = Course.create
    $ g = new_course.grading_period_groups.create
    $ g.valid? #should return true
    $ g.workflow_state #should return 'active'

  - when you delete a grading period group, it should do a 'soft delete',
    which means it should set its workflow_state to 'deleted' instead of
    actually deleting it from the database

    $ g = Account.default.grading_period_groups.create
    $ g.destroy
    $ g.workflow_state #should return 'deleted'

  - when you delete a grading period group, it should also soft delete
    any grading periods that belong to it.

    $ gp_group = Account.default.grading_period_groups.create
    $ gp = gp_group.grading_periods.create(
        start_date: Time.now,
        end_date: 1.month.from_now)
    $ gp_group.destroy
    $ gp_group.workflow_state #should return 'deleted'
    $ gp.workflow_state #should return 'deleted'

Grading Periods:
  - you should no longer be able to create a grading period without
    giving it a grading_period_group id. also, if you don't give it
    a workflow_state, it should default to 'active'. when you
    delete a grading period it should do a 'soft delete'.

    $ g = GradingPeriod.create(start_date: Time.now, end_date: 1.month.from_now)
    $ g.valid? #should return false

    $ gp_group = Account.default.grading_period_groups.create
    $ gp = gp_group.grading_periods.create(
        start_date: Time.now,
        end_date: 1.month.from_now)
    $ gp.valid? #should return true
    $ gp.workflow_state #should return 'active'
    $ gp.destroy
    $ gp.workflow_state #should return 'deleted'

  -  when you delete a grading period, it should also do a 'soft delete'
    on any owned grading period grades. Enrollments are tricky to make
    via the rails console, so i'm just grabbing one here that was already
    made -- you should be able to do the same. if you don't have any
    enrollments created, create one via Canvas and then come back to
    the rails console.

    $ gp_group = Account.default.grading_period_groups.create
    $ gp = gp_group.grading_periods.create(
        start_date: Time.now,
        end_date: 1.month.from_now)
    $ enrollment = Enrollment.first
    $ gp_grade = gp.grading_period_grades.create(
        enrollment_id: enrollment)
    $ gp_grade.workflow_state #should return 'active'
    $ gp.destroy
    $ gp.workflow_state #should return 'deleted'
    $ gp_grade.workflow_state #should return 'deleted'

Grading Period Grades:
  - these should now 'soft delete' as well. they require a grading period
    and an enrollment to be created (no change here, this has always been
    the case).

    $ enrollment = Enrollment.first
    $ gp_group = Account.default.grading_period_groups.create
    $ gp = gp_group.grading_periods.create(
        start_date: Time.now,
        end_date: 1.month.from_now)
    $ gp_grade = gp.grading_period_grades.create(
        enrollment_id: enrollment)
    $ gp_grade.workflow_state #should return 'active'
    $ gp_grade.destroy
    $ gp_grade.workflow_state #should return 'deleted'

Change-Id: Ic397a03beca4782c0c80e486673c7cfef59d38e5
Reviewed-on: https://gerrit.instructure.com/49754
Reviewed-by: Josh Simpson <jsimpson@instructure.com>
Reviewed-by: Jacob Fugal <jacob@instructure.com>
QA-Review: Robert Lamb <rlamb@instructure.com>
Tested-by: Jenkins
Product-Review: Spencer Olson <solson@instructure.com>
2015-04-01 00:07:44 +00:00
Cameron Sutter f2e2e76d5b Grading Period Grade join table - MGP
fixes CNVS-16454

test plan:
 * test in the console
 - `GradingPeriodGrade.all` should return `[]` (no error)
 - `Enrollment.find(1).grading_period_grades` should return `[]` (no error)
 - make a GradingPeriod:
   `g = GradingPeriod.create(weight: 100, start_date: Time.now, end_date: 1.month.from_now)`
   `g.save!`
 - `g.grading_period_grades` should return `[]` (no error)

Change-Id: I7183d715dbfac3fcd89ab7e453237ad4ce6c650d
Reviewed-on: https://gerrit.instructure.com/45312
Product-Review: Cameron Sutter <csutter@instructure.com>
Reviewed-by: Nick Cloward <ncloward@instructure.com>
Tested-by: Jenkins <jenkins@instructure.com>
QA-Review: Amber Taniuchi <amber@instructure.com>
2014-12-11 17:28:33 +00:00