-
Notifications
You must be signed in to change notification settings - Fork 481
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update add_script and Curriculum Model Relationships #35884
Conversation
This reverts commit 0d79ad9.
@@ -359,6 +359,8 @@ class Api::V1::AssessmentsControllerTest < ActionController::TestCase | |||
# Sign in as teacher and create a new script. | |||
sign_in @teacher | |||
script = create :script | |||
lesson_group = create :lesson_group, script: script | |||
lesson = create :lesson, script: script, lesson_group: lesson_group |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missed one test that needed lesson group added to it.
@@ -147,7 +147,7 @@ class Api::V1::TeacherScoresControllerTest < ActionDispatch::IntegrationTest | |||
|
|||
post '/dashboardapi/v1/teacher_scores', params: {section_id: section.id, stage_scores: [{stage_id: lesson.id, score: score}]} | |||
|
|||
assert_queries 13 do | |||
assert_queries 14 do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would love for someone to help me confirm that this update is ok but I think its because of the changes to the associations to the through relationships.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this seems fine -- I wouldn't want to block a large refactor like this on an added query to a non-critical codepath.
@@ -2071,7 +2073,7 @@ class SummarizeVisibleAfterScriptTests < ActiveSupport::TestCase | |||
ScriptDSL.parse(dsl, 'a filename')[0][:lesson_groups] | |||
) | |||
end | |||
assert_equal 'Expect if one lesson has a lesson group all lessons have lesson groups. Lesson Lesson1 does not have a lesson group.', raise.message | |||
assert_equal 'Expect if one lesson has a lesson group all lessons have lesson groups.', raise.message |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved where the check for this is so we don't have the lesson information as easily.
@@ -2096,7 +2098,7 @@ class SummarizeVisibleAfterScriptTests < ActiveSupport::TestCase | |||
ScriptDSL.parse(dsl, 'a filename')[0][:lesson_groups] | |||
) | |||
end | |||
assert_equal 'Only consecutive lessons can have the same lesson group. Lesson Group content is on two non-consecutive lessons.', raise.message | |||
assert_equal 'Duplicate Lesson Group. Lesson Group: content is used twice in Script: lesson-group-test-script.', raise.message |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated the wording on this error to make it more clear.
@@ -1467,10 +1467,12 @@ class SummarizeVisibleAfterScriptTests < ActiveSupport::TestCase | |||
end | |||
|
|||
script.curriculum_path = '//example.com/foo/{LESSON}' | |||
script.save! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needed to save here in order for the curriculum_path to take effect.
Hey Dani, this looks like great progress. One top-level comment I want to share is that I think this gets you suuuuuper close to being able to just use the new associations to do the ordering properly, so if you want to just finish this off and finish the "fix positioning" task, I think that option should definitely be on the table. maybe we can check in about what's left to do there once this PR is over the hump. |
The UI tests were failing because I was incorrectly setting chapter values for script levels. Since this was not caught by a unit test I added a new unit test in script_test.rb to check that chapter and position values of script levels are correctly set by add_script. I tested it before and after the change to fix the chapter values and it failed before and passed after :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks really good overall!
My main concern is making sure there's no unexpected behavior changes from this refactor, especially since we had a bug that was only caught by UI tests just now. I have the impression @islemaster has some process to verify big seeding changes like this. I thought he had a way to verify the results of seeding everything, before and after a change. Can you check with him on that before merging?
lesson_group.lessons = new_lessons | ||
lesson_group.save! | ||
|
||
lesson_position += lesson_group.lessons.length |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This pattern of passing in all the position counters (lockable_count, non_lockable_count, lesson_position, position, chapter) into the lower-level methods, and then afterwards figuring out how to update them in the higher-level methods, seems a bit redundant and fragile to me. The lower-level methods already incremented the values locally so ideally we shouldn't repeat that work somewhere else.
One option I can think of is to create a single "Counters" Struct to hold these values, and to pass that object into each of the lower-level methods instead of passing them all separately. Then, when the lower-level methods increment the counters, those changes will automatically be reflected in the higher-level methods already, since everything is sharing that one "Counters" object.
This would also have the side benefit of shortening the parameter lists for some of these methods and making them more readable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will follow up with another PR to do this but I want to get these changes in first.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you thinking of this process? The general approach was to dump the contents of relevant seeded tables before and after the code change, using a difftool to prove that the outcome of the process was the same. If I understand this change correctly, we expect the outcome (at least in terms of database rows) to be different. You could probably do something similar to verify that only the expected change occurs, but it'll take some thinking. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a few more miscellaneous comments. this is shaping up really well!
has_many :lesson_groups, -> {order(:position)}, dependent: :destroy | ||
has_many :lessons, through: :lesson_groups | ||
has_many :script_levels, through: :lessons |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these associations look great!
end.to_h | ||
end | ||
temp_lgs = LessonGroup.add_lesson_groups(raw_lesson_groups, script, new_suffix, editor_experiment) | ||
script.reload |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
now that you've got tests passing, is it possible to remove this reload without breaking anything?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no unfortunately the tests don't pass if I remove it
Good point Brad. Since we are touching "seed" but not "serialize", perhaps this could be tested manually by going into a few script edit pages |
I thought this was just a refactor of the seeding logic which preserved the same behavior? What are some of the changes we expect? |
I don't expect any changes. It should be the same output. |
Great. @islemaster, do you have a sense of how much work it'd take to adapt what you did for custom levels to this change? From my understanding of it, it seems like the main differences would be:
|
@uponthesun the differences you list sound exactly right. The db setup may require a few extra seed steps to support script seeding, and you might want to dump different tables to verify this change, omitting columns like |
Tested allthethings and csd2-2019 scripts and I get the same changes on staging that I get in staging. I checked coursef-2020 and csp9-2020 and both had no changes to the script files. |
Great! I did misunderstand when I suggested this, thinking that there might be some expected DB content differences. but this is still good evidence that the PR isn't breaking anything in those scripts. |
Verifying correctness
Result:
Fixed a couple files see commit d4108ae. After those changes there were no diffs. I'm also going to add in a check to prevent empty lessons getting added as the script overview page does not like empty lessons. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉 Thanks for doing the additional verification!
Background
As we added lesson groups between scripts and lessons we created the possibility of two sources of truth for the position of a lesson. In looking to improve the positions values in lessons in order to get rid of the possibility of two sources of truth we realized that we would need to update the
add_script
method which was adding lessons byscript.lessons =
. Instead we needed to add lessons to their lesson groups and have script access lessons through lesson groups.Overview
This breaks up the old
add_script
method which is used when you create a new script or when you seed scripts into multiple methods, one for each object type.In addition is updates the associations between objects in the curriculum data model. Script has many lessons through lesson_groups and Script has many script_levels through lessons.
When I ran
bundle exec rake build
it came up with an error for ui-test-course.course because it has no scripts in it (I created this when I was testing something on levelbuilder). When I deleted the file it passed so I have deleted the file here. Is that alright? Will I need to go into each environment to clean this up? The same issue seems to be happening on my staging branch.Future work
In the future we will use this to update position values for lesson and script_level.
Links
Testing story
bundle exec rake build
locally to make sure that it worked and no changes resulted from itShould I create tests for each
add_blah
method that I created or is the testing onadd_script
enough?Reviewer Checklist: