Skip to content

Commit

Permalink
feat: remove stages/criterion and introduce feedback groups/templates
Browse files Browse the repository at this point in the history
- 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
coskun-kilinc committed Aug 15, 2024
1 parent f8cd0d8 commit a24bdc7
Show file tree
Hide file tree
Showing 14 changed files with 255 additions and 187 deletions.
12 changes: 8 additions & 4 deletions app/models/feedback/feedback_comment_template.rb
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
2 changes: 1 addition & 1 deletion app/models/feedback/feedback_group.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class FeedbackGroup < ApplicationRecord
# Associations
belongs_to :task_definition
has_many :feedback_comment_template, dependent: :destroy
has_many :feedback_comment_templates, dependent: :destroy
has_one :unit, through: :task_definition

# Constraints
Expand Down
2 changes: 1 addition & 1 deletion app/models/task_definition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class TaskDefinition < ApplicationRecord
has_many :group_submissions, dependent: :destroy # Destroying a task definition will also nuke any group submissions
has_many :learning_outcome_task_links, dependent: :destroy # links to learning outcomes
has_many :learning_outcomes, -> { where('learning_outcome_task_links.task_id is NULL') }, through: :learning_outcome_task_links # only link staff relations
has_many :stages, dependent: :destroy
has_many :feedback_groups, dependent: :destroy

has_many :tii_group_attachments, dependent: :destroy
has_many :tii_actions, as: :entity, dependent: :destroy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def change
t.string :comment_text_situation, null: false
t.string :comment_text_next_action

#Foreign keys
# Foreign keys
t.references :criterion_option
t.references :user
end
Expand Down

This file was deleted.

8 changes: 0 additions & 8 deletions db/migrate/20240806060519_create_feedback_groups.rb

This file was deleted.

15 changes: 15 additions & 0 deletions db/migrate/20240814094110_remove_old_feedback_tables.rb
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 db/migrate/20240814094124_create_feedback_groups_and_templates.rb
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
31 changes: 19 additions & 12 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[7.0].define(version: 2024_08_06_060519) do
ActiveRecord::Schema[7.0].define(version: 2024_08_14_094124) do
create_table "activity_types", charset: "utf8", collation: "utf8_unicode_ci", force: :cascade do |t|
t.string "name", null: false
t.string "abbreviation", null: false
Expand Down Expand Up @@ -63,13 +63,24 @@
end

create_table "feedback_comment_templates", charset: "utf8mb4", collation: "utf8mb4_general_ci", force: :cascade do |t|
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
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
t.bigint "feedback_group_id", null: false
t.bigint "task_status_id"
t.index ["feedback_group_id"], name: "index_feedback_comment_templates_on_feedback_group_id"
t.index ["task_status_id"], name: "index_feedback_comment_templates_on_task_status_id"
end

create_table "feedback_groups", charset: "utf8mb4", collation: "utf8mb4_general_ci", force: :cascade do |t|
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "title", null: false
t.integer "order", null: false
t.bigint "task_definition_id", null: false
t.index ["task_definition_id", "order"], name: "index_feedback_groups_on_task_definition_id_and_order", unique: true
t.index ["task_definition_id"], name: "index_feedback_groups_on_task_definition_id"
end

create_table "group_memberships", charset: "utf8", collation: "utf8_unicode_ci", force: :cascade do |t|
Expand Down Expand Up @@ -204,13 +215,6 @@
t.datetime "updated_at", null: false
end

create_table "stages", charset: "utf8mb4", collation: "utf8mb4_general_ci", force: :cascade do |t|
t.string "title", null: false
t.integer "order", null: false
t.bigint "task_definition_id"
t.index ["task_definition_id"], name: "index_stages_on_task_definition_id"
end

create_table "task_comments", charset: "utf8", collation: "utf8_unicode_ci", force: :cascade do |t|
t.bigint "task_id", null: false
t.bigint "user_id", null: false
Expand Down Expand Up @@ -552,4 +556,7 @@
t.index ["user_id"], name: "index_webcals_on_user_id", unique: true
end

add_foreign_key "feedback_comment_templates", "feedback_groups"
add_foreign_key "feedback_comment_templates", "task_statuses"
add_foreign_key "feedback_groups", "task_definitions"
end
22 changes: 9 additions & 13 deletions test/factories/feedback/feedback_comment_template_factory.rb
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
12 changes: 2 additions & 10 deletions test/factories/feedback/feedback_group_factory.rb
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 test/models/feedback/feedback_comment_template_model_test.rb

This file was deleted.

80 changes: 80 additions & 0 deletions test/models/feedback/feedback_comment_template_test.rb
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
Loading

0 comments on commit a24bdc7

Please sign in to comment.