forked from doubtfire-lms/doubtfire-api
-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: remove stages/criterion and introduce feedback groups/templates
- Modified `feedback_comment_template.rb`, `feedback_group.rb`, and `task_definition.rb` models to align with the new feedback structure. - Removed outdated migrations related to stages and criterion options and introduced new migrations for Feedback Groups and Feedback Comment Templates. - Updated schema to reflect the new feedback group/template structure. - Refactored factories for `FeedbackCommentTemplate` and `FeedbackGroup` to align with the new model relationships. - Deleted obsolete tests and introduced new tests for `FeedbackCommentTemplate` and `FeedbackGroup` to ensure correct functionality.
- Loading branch information
1 parent
f8cd0d8
commit a24bdc7
Showing
14 changed files
with
255 additions
and
187 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,12 @@ | ||
class FeedbackCommentTemplate < ApplicationRecord | ||
# Associations | ||
has_and_belongs_to_many :criterion_options | ||
belongs_to :feedback_group | ||
# belongs_to :task_status, optional: true | ||
|
||
# Constraints | ||
validates :comment_text_situation, presence: true | ||
validates :comment_text_next_action, presence: true | ||
# Validations | ||
validates :abbreviation, presence: true | ||
validates :order, numericality: { only_integer: true, greater_than_or_equal_to: 0 } | ||
validates :chip_text, length: { maximum: 20 } | ||
validates :description, :comment_text, :summary_text, presence: true | ||
# validates :task_status, presence: true | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 0 additions & 8 deletions
8
db/migrate/20240806051447_create_feedback_comment_templates.rb
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
class RemoveOldFeedbackTables < ActiveRecord::Migration[7.0] | ||
def change | ||
drop_table :stages if ActiveRecord::Base.connection.table_exists?(:stages) | ||
drop_table :criteria if ActiveRecord::Base.connection.table_exists?(:criteria) | ||
drop_table :criterion_options if ActiveRecord::Base.connection.table_exists?(:criterion_options) | ||
|
||
if ActiveRecord::Base.connection.column_exists?(:task_comments, :feedback_comment_template_id) | ||
remove_reference :task_comments, :feedback_comment_template, index: true | ||
end | ||
|
||
if ActiveRecord::Base.connection.column_exists?(:task_comments, :criterion_option_id) | ||
remove_reference :task_comments, :criterion_option, index: true | ||
end | ||
end | ||
end |
27 changes: 27 additions & 0 deletions
27
db/migrate/20240814094124_create_feedback_groups_and_templates.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
class CreateFeedbackGroupsAndTemplates < ActiveRecord::Migration[7.0] | ||
def change | ||
create_table :feedback_groups do |t| | ||
t.string :title, null: false | ||
t.integer :order, null: false | ||
|
||
# Foreign keys | ||
t.references :task_definition, null: false, foreign_key: true | ||
end | ||
|
||
add_index :feedback_groups, [:task_definition_id, :order], unique: true | ||
|
||
create_table :feedback_comment_templates do |t| | ||
# Fields | ||
t.string :abbreviation, null: false | ||
t.integer :order, null: false | ||
t.string :chip_text, limit: 20 | ||
t.string :description, null: false | ||
t.string :comment_text, null: false | ||
t.string :summary_text, null: false | ||
|
||
# Foreign keys | ||
t.references :feedback_group, null: false, foreign_key: true | ||
t.references :task_status, foreign_key: true | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 9 additions & 13 deletions
22
test/factories/feedback/feedback_comment_template_factory.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,11 @@ | ||
FactoryBot.define do | ||
factory :feedback_comment_template do | ||
|
||
association :feedback_group | ||
association :task_status | ||
sequence(:abbreviation) { |n| "abbreviation-#{n}" } | ||
sequence(:order) { |n| n } | ||
sequence(:chip_text) { |n| "chip_text-#{n}" } | ||
sequence(:description) { |n| "description-#{n}" } | ||
sequence(:comment_text) { |n| "comment_text-#{n}" } | ||
sequence(:summary_text) { |n| "summary_text-#{n}" } | ||
|
||
|
||
end | ||
factory :feedback_comment_template do | ||
abbreviation { Faker::Lorem.word } | ||
order { Faker::Number.between(from: 1, to: 10) } | ||
chip_text { Faker::Lorem.characters(number: 10) } | ||
description { Faker::Lorem.sentence } | ||
comment_text { Faker::Lorem.paragraph } | ||
summary_text { Faker::Lorem.sentence } | ||
feedback_group # This will allow you to pass an existing feedback_group in your test | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,19 @@ | ||
# Read about factories at https://github.com/thoughtbot/factory_bot | ||
|
||
FactoryBot.define do | ||
|
||
factory :feedback_group do | ||
|
||
association :task_definition | ||
|
||
transient do # transient: not persisted to database | ||
number_of_criterion {0} # `0` criteria created unless otherwise specified | ||
number_of_feedback_comment_templates { 0 } # `0` criteria created unless otherwise specified | ||
# E.g., "FactoryBot.create(:feedback_group, number_of_criterion: 3)" | ||
end | ||
|
||
sequence(:order) { |n| n } | ||
sequence(:title) { |n| "feedback_group-#{n}" } | ||
feedback_comment_template { FactoryBot.create(:feedback_comment_template) } | ||
|
||
# help_text { Faker::Lorem.sentence } | ||
# entry_message { Faker::Lorem.sentence } | ||
# exit_message_good { Faker::Lorem.sentence } | ||
# exit_message_resubmit { Faker::Lorem.sentence } | ||
|
||
after(:create) do |feedback_group, evaluator| | ||
create_list(:criteria, evaluator.number_of_criterion, feedback_group: feedback_group) | ||
create_list(:feedback_comment_templates, evaluator.number_of_feedback_comment_templates, feedback_group: feedback_group) | ||
end | ||
end | ||
end |
83 changes: 0 additions & 83 deletions
83
test/models/feedback/feedback_comment_template_model_test.rb
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
require 'test_helper' | ||
|
||
# | ||
# Contains tests for FeedbackCommentTemplate model objects - not accessed via API | ||
# | ||
class FeedbackCommentTemplateTest < ActiveSupport::TestCase | ||
# class FeedbackCommentTemplate { | ||
# -string: Abbreviation | ||
# -number: Order | ||
# -char[20]: ChipText | ||
# -string: Description | ||
# -string: CommentText | ||
# -string: SummaryText | ||
# -TaskStatus: TaskStatus | ||
# } | ||
|
||
# Set up variables for testing | ||
setup do | ||
@feedback_group = FactoryBot.create(:feedback_group) | ||
|
||
@abbreviation = Faker::Lorem.word | ||
@order = Faker::Number.number(digits: 1) | ||
@chip_text = Faker::Lorem.characters(number: 20) | ||
@description = Faker::Lorem.sentence | ||
@comment_text = Faker::Lorem.sentence | ||
@summary_text = Faker::Lorem.sentence | ||
# @task_status = FactoryBot.create(:task_status) | ||
end | ||
|
||
# Test that you can create a valid feedback comment template | ||
def test_valid_feedback_comment_template_creation | ||
feedback_comment_template = FeedbackCommentTemplate.create!(feedback_group: @feedback_group, abbreviation: @abbreviation, order: @order, chip_text: @chip_text, description: @description, comment_text: @comment_text, summary_text: @summary_text) | ||
|
||
assert feedback_comment_template.valid?, feedback_comment_template.errors.full_messages | ||
assert_equal @abbreviation, feedback_comment_template.abbreviation | ||
assert_equal @order, feedback_comment_template.order | ||
assert_equal @chip_text, feedback_comment_template.chip_text | ||
assert_equal @description, feedback_comment_template.description | ||
assert_equal @comment_text, feedback_comment_template.comment_text | ||
assert_equal @summary_text, feedback_comment_template.summary_text | ||
end | ||
|
||
# Test that you cannot create an invalid feedback comment template | ||
def test_invalid_feedback_comment_template_creation | ||
# Test that feedback comment template is invalid without abbreviation | ||
feedback_comment_template = FeedbackCommentTemplate.new(order: @order, chip_text: @chip_text, description: @description, comment_text: @comment_text, summary_text: @summary_text) | ||
refute feedback_comment_template.valid?, "Feedback comment template is valid without abbreviation" | ||
|
||
# Test that feedback comment template is invalid without order | ||
feedback_comment_template = FeedbackCommentTemplate.new(abbreviation: @abbreviation, chip_text: @chip_text, description: @description, comment_text: @comment_text, summary_text: @summary_text) | ||
refute feedback_comment_template.valid?, "Feedback comment template is valid without order" | ||
|
||
# Test that feedback comment template is invalid without chip text | ||
feedback_comment_template = FeedbackCommentTemplate.new(abbreviation: @abbreviation, order: @order, description: @description, comment_text: @comment_text, summary_text: @summary_text) | ||
refute feedback_comment_template.valid?, "Feedback comment template is valid without chip text" | ||
|
||
# Test that feedback comment template is invalid without description | ||
feedback_comment_template = FeedbackCommentTemplate.new(abbreviation: @abbreviation, order: @order, chip_text: @chip_text, comment_text: @comment_text, summary_text: @summary_text) | ||
refute feedback_comment_template.valid?, "Feedback comment template is valid without description" | ||
|
||
# Test that feedback comment template is invalid without comment text | ||
feedback_comment_template = FeedbackCommentTemplate.new(abbreviation: @abbreviation, order: @order, chip_text: @chip_text, description: @description, summary_text: @summary_text) | ||
refute feedback_comment_template.valid?, "Feedback comment template is valid without comment text" | ||
|
||
# Test that feedback comment template is invalid without summary text | ||
feedback_comment_template = FeedbackCommentTemplate.new(abbreviation: @abbreviation, order: @order, chip_text: @chip_text, description: @description, comment_text: @comment_text) | ||
refute feedback_comment_template.valid?, "Feedback comment template is valid without summary text" | ||
|
||
# Test that feedback comment template is valid with abbreviation, order, chip text, description, comment text, summary text and task status | ||
feedback_comment_template.feedback_group = @feedback_group | ||
feedback_comment_template.abbreviation = @abbreviation | ||
feedback_comment_template.order = @order | ||
feedback_comment_template.chip_text = @chip_text | ||
feedback_comment_template.description = @description | ||
feedback_comment_template.comment_text = @comment_text | ||
feedback_comment_template.summary_text = @summary_text | ||
feedback_comment_template.task_status_id = TaskStatus.discuss | ||
assert feedback_comment_template.valid?, feedback_comment_template.errors.full_messages | ||
end | ||
end |
Oops, something went wrong.