CSC/ECE 517 Spring 2024 - E2416. Reimplement the Question hierarchy
This wiki page is for the description of changes made under E2416 OSS assignment for Spring 2024, CSC/ECE 517
Expertiza
Expertiza is an open-source project built using Ruby on Rails. It provides a platform for instructors and students to manage, submit, and evaluate assignments and projects. Instructors can create, edit, and grade assignments, while students can collaborate in teams, submit their work, and review peers' submissions.
Objective
Firstly, by removing unnecessary partials, the goal is to streamline the codebase and eliminate redundancy. The initial implementation used partials to structure HTML, but upon analysis, it was found that the distinct functionalities of each question type made these partials redundant. By removing them, the code becomes more concise, easier to maintain, and less prone to inconsistencies.
Secondly, transitioning from returning HTML to delivering JSON objects from the models offers several advantages. This shift aims to enhance efficiency, readability, and maintainability. JSON objects are more lightweight than HTML representations, facilitating faster data transmission and reducing server load. Additionally, JSON is a widely accepted format for data interchange in modern web applications, enhancing compatibility and enabling seamless integration with various front-end frameworks or technologies.
Next, we aim to implement other question types like scale, dropdown, and multiple choice. While these types share commonalities in displaying alternatives and allowing user selection, they also have differences, such as the requirement for a numeric sequence in Scale questions. Our objective is to write a unified piece of code to handle all three question types efficiently. Rigorous testing ensures that these modifications maintain system reliability and functionality, identifying and addressing potential issues while improving performance and adaptability to modern web development practices.
Problem Statement
The current implementation of the question hierarchy within Expertiza contains unclear variables, method names, and incomplete functionality at certain places. Additionally, many methods produce complex and lengthy HTML strings, making the codebase difficult to maintain. Objective: The project aims to enhance the question hierarchy component to improve code readability, comprehensibility, and maintainability.
Explanation of the feature
The Question class and its subclasses are pivotal components utilized in Expertiza for implementing rubric items, quiz questions, and survey questions. This feature offers a versatile framework for constructing various types of questions within the platform. The hierarchy of question types within Expertiza is delineated as follows:
- Choice questions offer users a selection of answers to choose from, categorized into scored and unscored subtypes.
- ScoredQuestion are assigned a point value, contributing to the final score of the questionnaire. Subtypes include:
- Scale: Presents a set of answer options covering a range of opinions, often represented numerically.
- Criterion: Allows setting a score value AND explaining it with a text comment.
- UnscoredQuestion do not influence the final score of the questionnaire. Subtypes include:
- Dropdown: Presents a list of options in a dropdown menu format.
- Multiple Choice: Provides users with multiple options for selection, available as single-select (radio buttons) or multi-select (checkboxes).
- Checkbox: Allows users to select multiple options from a list.
- ScoredQuestion are assigned a point value, contributing to the final score of the questionnaire. Subtypes include:
- Text Response questions enable users to input their answers directly, bypassing predefined choices. Subtypes include:
- Text Area: A text box with adjustable height and width.
- Text Field: A single-line input field with fixed dimensions.
- Upload file empowers users to upload files containing valid input to utilize as questionnaires. Additionally, users can export questionnaires to a .csv file format for further analysis and sharing.
UML diagram
Commonalities and Reimplementation Goals
Dropdown, MultipleChoice, and Scale questions share common functionality in Expertiza. They all provide users with a set of alternatives to choose from. However, they also have distinct characteristics that set them apart:
- Commonalities:
- Display alternatives for user selection.
- Allow users to choose one option.
- Differences:
- Scale: Requires a numeric sequence of choices.
- Dropdown and MultipleChoice: May have selections that aren't necessarily numeric.
To streamline the implementation and enhance code quality, the following goals have been outlined for reimplementation:
- Goals:
- Improved Variable and Method Naming: Enhance clarity and accuracy in representing functionality.
- Inclusion of Comments: Provide comprehensive comments for better code understanding and maintenance.
- Implementation of Partials: Utilize partials to manage HTML strings efficiently, reducing redundancy and improving maintainability (DRY principle).
- Addition of RSpec Test Cases: Ensure the functionality of existing tests and incorporate new test cases where applicable to bolster code robustness and reliability.
Enhancements and Additions to Question Handling
- Question Construction Functionality:
The application now features advanced functionality for constructing new questions within questionnaires. This enhancement streamlines the creation process by allowing users to specify essential parameters such as text content, question type, sequence, and break flags. With this feature, users can efficiently design questionnaires tailored to their specific needs, promoting flexibility and customization.
- UploadFile Model Introduction:
A significant addition to the application is the UploadFile model, extending the capabilities of the existing question framework. This model inherits from the Question superclass, providing a robust foundation for managing file upload questions. With UploadFile, users can easily edit and view question text, ensuring seamless interaction with file-based questions and enhancing the overall user experience.
- Database Schema Enhancements:
To support a diverse range of questions and questionnaire types, the database schema underwent significant enhancements. New tables were introduced to manage different question types and questionnaire structures, ensuring structured data management. These schema enhancements lay the groundwork for efficient data storage and retrieval, contributing to improved performance and scalability of the application.
- TextResponse Question Type:
The introduction of the TextResponse question type enriches the diversity of questions available within the application. This model extends question functionality by incorporating validation for size attributes and implementing methods for editing and viewing question text. Through comprehensive testing, the TextResponse question type ensures reliability and robustness in handling text-based responses.
- TextArea and TextField Models:
The application's support for text-based questions is further enhanced with the introduction of the TextArea and TextField models. These models facilitate the management of text area and text field questions, offering methods for completing and viewing completed questions. Comprehensive testing and validation of size attributes ensure seamless interaction with text-based questions, promoting accurate data collection.
- Criterion Model and QuestionAdvice Model:
To expand the application's capabilities, the Criterion and QuestionAdvice models were introduced. The Criterion model extends the functionality of scored questions, incorporating validation for size attributes and implementing methods for editing, viewing, and completing questions. Additionally, the QuestionAdvice model enables the management of advice associated with questions, enhancing the user experience by providing valuable insights and recommendations.
Files modified and added: Reimplementation
During the reimplementation process, several files underwent modifications and additions to ensure the functionality of the models. The objective was to streamline interdependencies, particularly concerning questionnaires and questions, aligning them with the project's objectives.
Reimplemented Repository[1]
Below is a categorized list of files that were modified or added as part of the reimplementation effort:
Phase 1:
- Parent Files:
- questionnaire.rb: Modifications were made to this file to accommodate changes in questionnaire functionality.
- question.rb: Adjustments were applied to support updated question functionalities.
- schema.rb: Changes were reflected in the database schema to align with the updated model structures.
- Scored and Unscored Section Files:
- scored_question.rb: This file underwent modifications to enhance functionality related to scored questions.
- unscored_question.rb: Adjustments were made to support unscored question functionalities.
- criterion.rb: New functionalities and validations were added to enhance the criterion question type.
- Text Response Files:
- text_response.rb: Modifications were made to support the text response question type with enhanced functionalities.
- text_area_spec.rb: Tests were added or modified to ensure the proper functioning of text area questions.
- text_field.rb: Adjustments were made to enhance functionalities related to text field questions.
- text_field_spec.rb: Tests were added or modified to validate the behavior of text field questions.
- Upload Files:
- upload_file.rb: New functionalities were added to support file upload question types.
- upload_file_spec.rb: Tests were added or modified to ensure the proper functioning of file upload functionalities.
Phase 2:
- Parent Files:
- checkbox.rb: Added a new class for managing checkbox questions, including methods for editing, completing, and viewing completed questions.
- unscored_question.rb: Created a new class for unscored questions, inheriting from `ChoiceQuestion`, with placeholder methods for editing, viewing question text, completing, and viewing completed questions.
- question_helper.rb: Introduced helper methods for common functionalities across different question types.
- dropdown.rb: Added a new class for managing dropdown questions, inheriting from UnscoredQuestion, with methods for editing, completing, and viewing completed questions.
- multiple_choice.rb: Added a new class for managing multiple choice questions, inheriting from QuizQuestion, with methods for editing, completing, and viewing completed questions.
- multiple_choice_radio.rb: Added a new class for managing multiple choice radio button questions, inheriting from QuizQuestion, with methods for editing, completing, and viewing completed questions.
- unscored_question.rb: Created a new class for unscored questions, inheriting from ChoiceQuestion, with placeholder methods for editing, viewing question text, completing, and viewing completed questions.
- question_helper.rb: Introduced helper methods for common functionalities across different question types.
- Scored and Unscored Section Files:
- scale.rb: Implemented a new class for managing scale questions, inheriting from `ScoredQuestion`, with methods for editing, viewing question text, completing, and viewing completed questions.
- app/models/unscored_question.rb: Added a new class inheriting from `ChoiceQuestion`, including placeholder methods for editing, viewing question text, completing, and viewing completed questions.
- Text Response Files:
- text_response.rb: Enhanced the text response question type with improved functionalities for completion and viewing completed questions.
- text_area_spec.rb: Updated or added tests to ensure proper functionality of text area questions.
- text_field.rb: Made adjustments to improve functionalities related to text field questions.
- text_field_spec.rb: Added or modified tests to validate the behavior of text field questions.
- Upload Files:
- upload_file.rb: Implemented new functionalities to support file upload question types.
- upload_file_spec.rb: Modified or added tests to ensure proper functionality of file upload functionalities.
- checkbox_spec.rb: Introduced tests for the Checkbox class, covering methods for editing, completing, and viewing completed questions.
- Helper File:
- app/helpers/question_helper.rb: Enhanced with additional methods to support common functionalities across different question types.
- Scale Spec File:
- scale_spec.rb: Added tests to validate the behavior of the Scale class, including editing, viewing question text, completing, and viewing completed questions.
- Multiple Choice Spec Files:
- multiple_choice_spec.rb: Added tests to validate the behavior of the MultipleChoice class, including editing, completing, and viewing completed questions.
- multiple_choice_radio_spec.rb: Added tests to validate the behavior of the MultipleChoiceRadio class, including editing, completing, and viewing completed questions.
- dropdown_spec.rb: Added tests to validate the behavior of the Dropdown class, including editing, completing, and viewing completed questions.
Screenshots for implementation in Phase 1:
The `Criterion` class, inheriting from `ScoredQuestion` and featuring a validation for `size` presence, manages criterion-based questions within the framework. Its `edit` method generates JSON for editing a criterion question, while `view_question_text` provides JSON for viewing the question's text and related information. The `complete` method constructs JSON for completing the criterion question, considering dropdown or scale type questions. Helper methods `dropdown_criterion_question` and `scale_criterion_question` handle the construction of response options for respective types. Additionally, the private `advices_criterion_question` method prepares advice sections for the criterion question based on question advices.
The `QuestionAdvice` model, inheriting from `ApplicationRecord`, represents advice associated with questions. It belongs to a `question`. The `export_fields` method retrieves field names for exporting purposes. The `export` method exports advice data to a CSV file based on the provided parent questionnaire ID. The `to_json_by_question_id` method retrieves advice data in JSON format for a given question ID, organizing it by score and advice.
The `TextArea` class, inheriting from `Question`, handles functionalities related to text area questions within the question framework. Its `complete` method generates JSON for completing a text area question, including count, comments, and default size information. The `view_completed_question` method prepares JSON for viewing a completed text area question, providing count and comment details.
The `TextField` class, inheriting from `Question`, manages functionalities for text field questions within the question framework. It validates the presence of the `size` attribute. The `complete` method generates JSON for completing a text field question, providing label, type, name, id, and value information. The `view_completed_question` method prepares JSON for viewing a completed text field question, including type, label, value, and break_before information, if applicable.
The `TextResponse` class, inheriting from `Question`, focuses on managing text-based response questions within the framework. It validates the presence of the `size` attribute. The `edit` method generates JSON for editing a text response question, including elements for removing the question, editing sequence, question content, question type, and text area size. The `view_question_text` method provides JSON for viewing the text content of the question, its type, weight, and a placeholder for non-applicable fields.
The `UploadFile` class, inheriting from `Question`, manages functionalities related to uploading files within the question framework. Its `edit` method generates JSON for editing an upload file question, including elements for removing the question, editing sequence, question content, and disabled input for question type. The `view_question_text` method provides JSON for viewing the text content of the question, its type, weight, and ID, with a placeholder for non-applicable fields. The `complete` and `view_completed_question` methods are left as placeholders, awaiting implementation for completing and viewing completed questions by students.
Screenshots for implementation in Phase 2:
The `Checkbox` class extends from `UnscoredQuestion` and is responsible for handling checkbox-type questions in the application. The `edit` method constructs a JSON object containing various components necessary for editing a checkbox question, including a remove button, sequence input, question text area, question type, and weight. The `view_question_text` method generates a JSON object representing the text content, question type, weight, and the state of being checked or unchecked. For completing a checkbox question, the `complete` method constructs a JSON object with inputs, labels, scripts, and conditional column headers based on the previous and next questions. The `view_completed_question` method returns a JSON object containing the previous question, the answer with its corresponding image and content, and conditional statements for column headers. This class demonstrates how to handle checkbox-type questions, including editing, completing, and viewing completed questions, while considering the sequence and type of adjacent questions for proper navigation and display.
The `UnscoredQuestion` class inherits from `ChoiceQuestion` and serves as a superclass for various unscored question types in the application. It defines placeholder methods for editing, viewing question text, completing, and viewing completed questions. These methods are intended to be overridden by subclasses to implement specific behavior for each unscored question type, such as dropdown, multiple choice, or checkbox questions. This class provides a common interface and structure for unscored questions while allowing flexibility for customization based on the specific requirements of each question type.
The `edit_common` method in the `QuestionHelper` module is a utility function for generating a JSON object commonly used for editing questions. It takes parameters such as a label, minimum and maximum question scores, text content, weight, and type, and constructs a JSON object with these attributes. This method is applicable to scale and dropdown questions as it allows for the generation of JSON objects needed for editing these types of questions. For scale questions, the `edit_common` method can be used to generate JSON objects with attributes specific to scales, such as minimum and maximum question scores. Similarly, for dropdown questions, the method can be used to generate JSON objects with attributes relevant to dropdowns, such as text content and weight.
The `view_question_text_common` method, on the other hand, is another helper function that generates a JSON object commonly used for viewing question text. It takes parameters such as text content, type, weight, and score range, and constructs a JSON object with these attributes. This method can also be applicable to scale and dropdown questions for displaying the question text along with relevant information such as type, weight, and score range. This enables consistent rendering of question text across different question types within the application.
The `Scale` class extends from `ScoredQuestion` and incorporates the `QuestionHelper` module. It represents a scale-type question in the application. The `edit` method utilizes the `edit_common` helper method to construct a JSON object for editing the scale question, including attributes such as label, text content, weight, and type. Similarly, the `view_question_text` method uses the `view_question_text_common` helper method to generate a JSON object for viewing the scale question text with relevant attributes. The `complete` method constructs JSON with scale options based on the defined score range and the provided answer. The `view_completed_question` method returns a JSON object indicating the count, answer, and questionnaire maximum if the question has been answered; otherwise, it returns a message indicating that the question was not answered. Additionally, the `score_range` method is private and calculates the range of scores based on the minimum and maximum labels, or the minimum and maximum question scores. This class demonstrates the utilization of helper methods to facilitate consistent generation of JSON objects for scale questions across various functionalities within the application.
The `Dropdown` class inherits from `UnscoredQuestion` and includes the `QuestionHelper` module. It represents a dropdown question type in the application. The `edit` method utilizes the `edit_common` helper method from the `QuestionHelper` module to generate a JSON object for editing the dropdown question, including attributes such as label, text content, weight, and type. Similarly, the `view_question_text` method utilizes the `view_question_text_common` helper method to construct a JSON object for viewing the dropdown question text with relevant attributes. The `complete` method generates JSON with dropdown options based on the count of options and the provided answer. Additionally, there's a method `complete_for_alternatives` which allows completion for alternative options. Lastly, the `view_completed_question` method returns a JSON object indicating the selected option or if the question remains unanswered. This class demonstrates the integration of helper methods to facilitate consistent generation of JSON objects for editing, viewing, completing, and viewing completed dropdown questions.
The `MultipleChoiceCheckbox` class represents a type of quiz question that allows users to select multiple correct answers using checkboxes. The `edit` method retrieves the question's details and choices from the database and formats them into JSON for editing purposes, including the question text, weight, and choices. Similarly, the `complete` method constructs JSON containing the question text and choices for completing the question. For viewing completed questions, the `view_completed_question` method retrieves the user's answers along with the correct choices and formats them into JSON. Additionally, the `isvalid` method checks the validity of the question, ensuring that it has text and at least one correct answer selected. If any validation errors are found, an error message is returned in JSON format along with a validity indicator. Overall, these methods handle various aspects of managing multiple-choice checkbox quiz questions, from editing and completing to validating their correctness and integrity.
The `QuizQuestion` class inherits from the `Question` class and represents a generic type of quiz question. It establishes a one-to-many association with `QuizQuestionChoice` instances, allowing for multiple choices associated with each quiz question. The `edit` method is left empty, presumably intended to be implemented in subclasses to customize editing behavior for specific types of quiz questions. The `view_question_text` method formats the quiz question's details, including the question text, type, weight, and choices, into JSON format for viewing purposes. The `complete` method is also left empty, likely to be implemented in subclasses for handling completion actions. Similarly, the `view_completed_question` method, which is also empty, may be implemented in subclasses to handle the viewing of completed questions, potentially including user answers if provided. Overall, this class serves as a foundation for implementing various types of quiz questions with customizable editing, completion, and viewing functionalities.
The `MultipleChoiceRadio` class represents a model for multiple-choice radio questions in a quiz. It inherits from `QuizQuestion` and includes methods for editing, completing, viewing completed questions, and validating the question's correctness. In the `edit` method, it retrieves choices associated with the question ID and constructs JSON containing the question's ID, text, weight, and choices with their IDs, texts, correctness, and positions. The `complete` method generates JSON for the question ID, text, and choices. For viewing completed questions, the `view_completed_question` method fetches choices, user responses, and correctness information, and constructs JSON accordingly. Finally, the `isvalid` method checks the validity of the question and its choices, ensuring that the question text is present, each choice has text, and exactly one correct answer is selected. It returns JSON indicating the validity status and any error messages.
Test Plan
Our testing plan incorporates a comprehensive approach using RSpec to ensure the integrity, functionality, and adherence to project goals of the implemented changes in the models. Building upon previous testing strategies, we continue to focus on key aspects of the code while introducing new tests tailored to the specific functionalities introduced or modified.
Previous Testing Approach:
In our previous testing strategy, we emphasized rigorous examination of the reimplementation, particularly focusing on the validation of modified models within the question hierarchy. This involved verifying the correctness of essential methods defined within the model class, ensuring their presence for the proper operation of the model. Tests were designed to assess the generation of HTML strings for various parameters, correctness of underlying methods, and the ability to produce HTML code for different scenarios. We also evaluated the handling of various question types and the generation of HTML representations for completed and unanswered questions. This approach, coupled with general model validations, formed a robust testing framework, guaranteeing the reimplementation's integrity and alignment with project goals.
Current Testing Strategy:
Building upon the foundation laid by the previous testing strategy, our current approach focuses on ensuring consistency in the return of JSON objects within model methods across various test files. This involves validating the correctness and structure of returned JSON objects for different scenarios, such as editing, completing, and viewing questions. Tests are designed to examine methods such as edit, complete, view_completed_question, and is_valid present in various model files. Each test constructs expected JSON objects based on created instances or mock data and evaluates the generated JSON against these expected formats. We meticulously check for attribute correctness, structure integrity, and validation message accuracy. By consistently executing these tests across multiple model files, our objective is to guarantee that the JSON responses are accurate, consistent, and align with the intended functionality, irrespective of the specific model instance being tested.
Incorporation of RSpec:
Our testing plan leverages the capabilities of RSpec to ensure that the code behaves as expected and adheres to the defined specifications. Through RSpec-driven testing, we enhance the maintainability and readability of our codebase while reducing complexities associated with previous implementations. Each test case is carefully crafted to cover various scenarios, edge cases, and input combinations, providing thorough coverage of the implemented functionalities. Additionally, testing the rendering of HTML or partial templates, wherever applicable, is incorporated to confirm the correct generation of views. This comprehensive approach ensures the model's integrity, functionality, and adherence to project goals, enhancing the overall quality of our codebase.
The automated testcases implemented are as follows :
Phase 1:
This RSpec test suite assesses the behavior of the `UploadFile` model in a Rails application. It checks the `edit` method's JSON output for editing questions, ensuring correct structure and inclusion of necessary elements like a "Remove" link and input fields for sequence, ID, and question content. Similarly, it verifies the JSON returned by `view_question_text` for displaying questions. Pending tests for `complete` and `view_completed_question` methods indicate that their logic is yet to be tested.
In this RSpec test suite for the `TextArea` model, two contexts are defined within the `complete` method. The first context evaluates the generation of JSON output when a count is provided, verifying the correct action and size parameters. It also checks if existing comments are included in the JSON. The second context assesses JSON generation with default size when the count is not provided. In the `view_completed_question` method, a context is specified for scenarios where both count and an answer are provided, confirming the expected JSON structure and comment inclusion.
In the RSpec test suite for the `TextField` model, two contexts are specified within the `complete` method. The first context evaluates the JSON data generation for a paragraph with a label and input fields when a count is provided, verifying the correct action, type, and name parameters. The second context assesses JSON data generation with a pre-filled comment value when both count and answer are provided. In the `view_completed_question` method, two contexts are defined. The first context confirms the formatted JSON for the completed question when the question type is 'TextField' and `break_before` is true, ensuring the correct type and break_before values. The second context verifies the JSON formatting when the question type is not 'TextField' or `break_before` is false, ensuring the correct break_before value is included in the output.
The RSpec test suite for the `TextResponse` model validates the `edit` and `view_question_text` methods. In the `edit` method's context, the test ensures that the returned JSON contains the correct action and includes elements for editing the question. Similarly, in the `view_question_text` method's context, the test verifies that the returned JSON includes the correct action and elements representing the question text, question type, and weight. Each expectation ensures that the JSON output aligns with the expected structure and content.
The RSpec test suite for the `UploadFile` model validates the `edit`, `view_question_text`, `complete`, and `view_completed_question` methods. In the `edit` method's context, it ensures that the returned JSON for editing has the correct structure and includes essential elements such as the remove link, input fields for sequence and ID, textarea for editing content, and disabled input field for question type. Moreover, it checks that the weight element is not included explicitly as it's not applicable. In the `view_question_text` method's context, it verifies that the returned JSON for displaying a question contains the correct action and elements representing the question content, type, ID, and sequence. The remaining contexts prompt the developer to write tests for the `complete` and `view_completed_question` methods to ensure their implementation logic is correctly implemented.
Phase 2:
The RSpec test suite for the `Checkbox` model thoroughly examines its `edit`, `complete`, `view_question_text`, and `view_completed_question` methods. In the `edit` method's context, it ensures that the returned JSON structure includes essential elements such as the remove button, sequence input field, question textarea, question type, and weight placeholder. The `complete` method's contexts test its behavior when an answer is provided and when no answer is provided, verifying that the expected completion structure is returned and that the checkbox is appropriately checked or unchecked. The `view_question_text` and `view_completed_question` methods are tested to ensure that they return the expected JSON representations of the checkbox question and its completed state.
The RSpec test suite for the `Scale` model comprehensively evaluates its `edit`, `view_question_text`, `complete`, and `view_completed_question` methods. In the `edit` method's context, it confirms that the returned JSON object contains essential attributes such as question text, type, weight, and score range. The `view_question_text` method's context ensures that the JSON returned includes the question text, type, weight, and score range. The `complete` method is tested to return JSON with scale options, indicating the selected answer. Lastly, the `view_completed_question` method's contexts verify that it returns the appropriate JSON response when the question has been answered and when it hasn't been answered, providing relevant information or a message accordingly.
This RSpec test suite verifies the functionality of the `Dropdown` model in a Ruby on Rails application. It includes tests for the `edit`, `view_question_text`, `complete`, and `complete_for_alternatives` methods. The `edit` method constructs a JSON object representing the form for editing a dropdown question, while `view_question_text` generates JSON for displaying the question's text, type, weight, and score range. The `complete` method generates JSON for a select input with options based on the provided count and answer, marking the selected answer if provided. Similarly, `complete_for_alternatives` generates JSON options with the selected alternative marked when given an array of alternatives and an answer. Overall, these tests ensure that the `Dropdown` model functions correctly in managing dropdown questions, handling editing, viewing, and completion operations as expected.
The `MultipleChoiceCheckbox` model is tested using RSpec to ensure its functionality. In the `#edit` method test, it verifies that the JSON structure returned for editing contains the expected information such as the question's ID, text, weight, and choices with their respective IDs, texts, correctness, and positions. The `#isvalid` method is tested to validate the correctness of multiple-choice checkbox questions. Various scenarios are covered, including cases where the question or choices lack text, where no choices are marked as correct, where only one choice is marked as correct (which should not be the case for this question type), and where multiple choices are marked as correct (which is valid). The tests ensure that the validation logic correctly identifies and reports errors or valid status based on the provided information.
The `MultipleChoiceRadio` model is tested using RSpec to ensure its functionality. In the `#edit` method test, it verifies that the JSON structure returned for editing contains the expected information such as the question's ID, text, weight, and choices with their respective IDs, texts, correctness, and positions. The `#complete` method is tested to ensure it returns JSON for a quiz question with choices when given a valid question ID. In the `#view_completed_question` method test, it checks whether the response includes correctness information when the user's answer is correct. Finally, the `#isvalid` method is tested to validate the correctness of multiple-choice radio questions. Two scenarios are covered: one where the choice information is valid and another where one of the options lacks text, resulting in an error message. The tests ensure that the model behaves as expected in various scenarios.
Outcomes and overview
This document presents the completed changes to the question hierarchy module, encompassing model enhancements and updated test cases. Through rigorous development and testing efforts, we have successfully implemented JSON object returns for every question type within our hierarchy and validated their functionality across multiple test scenarios. The achieved outcomes promise improved maintainability, heightened performance, and strict adherence to coding standards. The outlined implementation plan and comprehensive testing strategy serve to mitigate risks and facilitate a seamless transition to the refined system.
Key Achievements:
- Model Refactoring: We have meticulously refactored the question hierarchy module, introducing new models and enhancing existing ones to ensure streamlined functionality and improved data management.
- Test Case Updates: Extensive updates to our test suite have been made, covering various aspects of model behavior and JSON object generation for different question types. These updates validate the correctness, consistency, and adherence to specifications of our model implementations.
- JSON Object Returns: Each question type within our hierarchy now returns JSON objects as expected, facilitating seamless interaction with the system and providing structured data representations for client-side processing.
Expected Benefits:
- Improved Maintainability: The refactored models and updated test suite contribute to a more maintainable codebase, making it easier to implement future changes and enhancements.
- Enhanced Performance: The streamlined functionality and optimized code structure promise improved performance, ensuring efficient operation of the question hierarchy module.
- Adherence to Coding Standards: By adhering to coding standards and best practices throughout the development process, we ensure the consistency and quality of our codebase, promoting better collaboration and code readability.
Team
- Mentors
- Prof. Edward F. Gehringer
- Muhammad Ali Qureshi
- Members
- Akhil Namboodiri
- Vishwa Gandhi
- Jaiwin Shah
References
- Expertiza[2]
- Previous team repository[3]
- Active Record Migrations[4]
- Migrating changes made on model[5]
- Layouts and Rendering in Rails[6]
- RSpec Testing[7]