From 00bdbf8ffe102a29dc95064eefc1e62e8e0fdd9e Mon Sep 17 00:00:00 2001 From: jacobtoddmathes Date: Wed, 6 Mar 2024 15:35:56 -0600 Subject: [PATCH 1/3] all rspec tests passing, no rubocop offenses --- rails_root/Gemfile.lock | 178 +++++++++--------- .../survey_questions_controller.rb | 1 + .../survey_responses_controller.rb | 77 ++++---- .../app/helpers/survey_questions_helper.rb | 6 + rails_root/app/models/survey_answer.rb | 1 + rails_root/app/models/survey_profile.rb | 1 + rails_root/app/models/survey_question.rb | 2 + rails_root/app/models/survey_response.rb | 1 + rails_root/db/schema.rb | 7 + .../helpers/survey_questions_helper_spec.rb | 19 +- .../helpers/survey_responses_helper_spec.rb | 4 + rails_root/spec/models/survey_answer_spec.rb | 10 +- .../spec/models/survey_question_spec.rb | 6 +- .../spec/requests/survey_questions_spec.rb | 10 +- 14 files changed, 180 insertions(+), 143 deletions(-) diff --git a/rails_root/Gemfile.lock b/rails_root/Gemfile.lock index 1803cce..c19c44e 100644 --- a/rails_root/Gemfile.lock +++ b/rails_root/Gemfile.lock @@ -1,35 +1,35 @@ GEM remote: https://rubygems.org/ specs: - actioncable (7.1.3) - actionpack (= 7.1.3) - activesupport (= 7.1.3) + actioncable (7.1.3.2) + actionpack (= 7.1.3.2) + activesupport (= 7.1.3.2) nio4r (~> 2.0) websocket-driver (>= 0.6.1) zeitwerk (~> 2.6) - actionmailbox (7.1.3) - actionpack (= 7.1.3) - activejob (= 7.1.3) - activerecord (= 7.1.3) - activestorage (= 7.1.3) - activesupport (= 7.1.3) + actionmailbox (7.1.3.2) + actionpack (= 7.1.3.2) + activejob (= 7.1.3.2) + activerecord (= 7.1.3.2) + activestorage (= 7.1.3.2) + activesupport (= 7.1.3.2) mail (>= 2.7.1) net-imap net-pop net-smtp - actionmailer (7.1.3) - actionpack (= 7.1.3) - actionview (= 7.1.3) - activejob (= 7.1.3) - activesupport (= 7.1.3) + actionmailer (7.1.3.2) + actionpack (= 7.1.3.2) + actionview (= 7.1.3.2) + activejob (= 7.1.3.2) + activesupport (= 7.1.3.2) mail (~> 2.5, >= 2.5.4) net-imap net-pop net-smtp rails-dom-testing (~> 2.2) - actionpack (7.1.3) - actionview (= 7.1.3) - activesupport (= 7.1.3) + actionpack (7.1.3.2) + actionview (= 7.1.3.2) + activesupport (= 7.1.3.2) nokogiri (>= 1.8.5) racc rack (>= 2.2.4) @@ -37,35 +37,35 @@ GEM rack-test (>= 0.6.3) rails-dom-testing (~> 2.2) rails-html-sanitizer (~> 1.6) - actiontext (7.1.3) - actionpack (= 7.1.3) - activerecord (= 7.1.3) - activestorage (= 7.1.3) - activesupport (= 7.1.3) + actiontext (7.1.3.2) + actionpack (= 7.1.3.2) + activerecord (= 7.1.3.2) + activestorage (= 7.1.3.2) + activesupport (= 7.1.3.2) globalid (>= 0.6.0) nokogiri (>= 1.8.5) - actionview (7.1.3) - activesupport (= 7.1.3) + actionview (7.1.3.2) + activesupport (= 7.1.3.2) builder (~> 3.1) erubi (~> 1.11) rails-dom-testing (~> 2.2) rails-html-sanitizer (~> 1.6) - activejob (7.1.3) - activesupport (= 7.1.3) + activejob (7.1.3.2) + activesupport (= 7.1.3.2) globalid (>= 0.3.6) - activemodel (7.1.3) - activesupport (= 7.1.3) - activerecord (7.1.3) - activemodel (= 7.1.3) - activesupport (= 7.1.3) + activemodel (7.1.3.2) + activesupport (= 7.1.3.2) + activerecord (7.1.3.2) + activemodel (= 7.1.3.2) + activesupport (= 7.1.3.2) timeout (>= 0.4.0) - activestorage (7.1.3) - actionpack (= 7.1.3) - activejob (= 7.1.3) - activerecord (= 7.1.3) - activesupport (= 7.1.3) + activestorage (7.1.3.2) + actionpack (= 7.1.3.2) + activejob (= 7.1.3.2) + activerecord (= 7.1.3.2) + activesupport (= 7.1.3.2) marcel (~> 1.0) - activesupport (7.1.3) + activesupport (7.1.3.2) base64 bigdecimal concurrent-ruby (~> 1.0, >= 1.0.2) @@ -113,7 +113,8 @@ GEM cucumber-gherkin (>= 25, < 27) cucumber-messages (>= 20, < 23) cucumber-tag-expressions (~> 5.0, >= 5.0.4) - cucumber-cucumber-expressions (17.0.1) + cucumber-cucumber-expressions (17.0.2) + bigdecimal cucumber-gherkin (26.2.0) cucumber-messages (>= 19.1.4, < 22.1) cucumber-html-formatter (21.2.0) @@ -136,14 +137,14 @@ GEM reline (>= 0.3.8) diff-lcs (1.5.1) docile (1.4.0) - drb (2.2.0) - ruby2_keywords + drb (2.2.1) erubi (1.12.0) ffi (1.16.3) globalid (1.2.1) activesupport (>= 6.1) - i18n (1.14.1) + i18n (1.14.3) concurrent-ruby (~> 1.0) + racc (~> 1.7) importmap-rails (2.0.1) actionpack (>= 6.0.0) activesupport (>= 6.0.0) @@ -165,7 +166,7 @@ GEM net-imap net-pop net-smtp - marcel (1.0.2) + marcel (1.0.4) matrix (0.4.2) mini_mime (1.1.5) minitest (5.22.2) @@ -185,12 +186,8 @@ GEM nio4r (2.7.0) nokogiri (1.16.2-aarch64-linux) racc (~> 1.4) - nokogiri (1.16.2-arm-linux) - racc (~> 1.4) nokogiri (1.16.2-arm64-darwin) racc (~> 1.4) - nokogiri (1.16.2-x86-linux) - racc (~> 1.4) nokogiri (1.16.2-x86_64-darwin) racc (~> 1.4) nokogiri (1.16.2-x86_64-linux) @@ -199,16 +196,16 @@ GEM parser (3.3.0.5) ast (~> 2.4.1) racc - pg (1.5.4) + pg (1.5.6) prettier_print (1.2.1) - prism (0.21.0) + prism (0.24.0) psych (5.1.2) stringio public_suffix (5.0.4) puma (6.4.2) nio4r (~> 2.0) racc (1.7.3) - rack (3.0.9) + rack (3.0.9.1) rack-session (2.0.0) rack (>= 3.0.0) rack-test (2.1.0) @@ -216,20 +213,20 @@ GEM rackup (2.1.0) rack (>= 3) webrick (~> 1.8) - rails (7.1.3) - actioncable (= 7.1.3) - actionmailbox (= 7.1.3) - actionmailer (= 7.1.3) - actionpack (= 7.1.3) - actiontext (= 7.1.3) - actionview (= 7.1.3) - activejob (= 7.1.3) - activemodel (= 7.1.3) - activerecord (= 7.1.3) - activestorage (= 7.1.3) - activesupport (= 7.1.3) + rails (7.1.3.2) + actioncable (= 7.1.3.2) + actionmailbox (= 7.1.3.2) + actionmailer (= 7.1.3.2) + actionpack (= 7.1.3.2) + actiontext (= 7.1.3.2) + actionview (= 7.1.3.2) + activejob (= 7.1.3.2) + activemodel (= 7.1.3.2) + activerecord (= 7.1.3.2) + activestorage (= 7.1.3.2) + activesupport (= 7.1.3.2) bundler (>= 1.15.0) - railties (= 7.1.3) + railties (= 7.1.3.2) rails-dom-testing (2.2.0) activesupport (>= 5.0.0) minitest @@ -237,9 +234,9 @@ GEM rails-html-sanitizer (1.6.0) loofah (~> 2.21) nokogiri (~> 1.14) - railties (7.1.3) - actionpack (= 7.1.3) - activesupport (= 7.1.3) + railties (7.1.3.2) + actionpack (= 7.1.3.2) + activesupport (= 7.1.3.2) irb rackup (>= 1.0.0) rake (>= 12.2) @@ -247,13 +244,13 @@ GEM zeitwerk (~> 2.6) rainbow (3.1.1) rake (13.1.0) - rbi (0.1.8) - prism (>= 0.18.0, < 0.22) + rbi (0.1.9) + prism (>= 0.18.0, < 0.25) sorbet-runtime (>= 0.5.9204) rdoc (6.6.2) psych (>= 4.0.0) regexp_parser (2.9.0) - reline (0.4.2) + reline (0.4.3) io-console (~> 0.5) rexml (3.2.6) rspec-core (3.13.0) @@ -272,8 +269,8 @@ GEM rspec-expectations (~> 3.12) rspec-mocks (~> 3.12) rspec-support (~> 3.12) - rspec-support (3.13.0) - rubocop (1.60.2) + rspec-support (3.13.1) + rubocop (1.62.0) json (~> 2.3) language_server-protocol (>= 3.17.0) parallel (~> 1.10) @@ -281,20 +278,19 @@ GEM rainbow (>= 2.2.2, < 4.0) regexp_parser (>= 1.8, < 3.0) rexml (>= 3.2.5, < 4.0) - rubocop-ast (>= 1.30.0, < 2.0) + rubocop-ast (>= 1.31.1, < 2.0) ruby-progressbar (~> 1.7) unicode-display_width (>= 2.4.0, < 3.0) - rubocop-ast (1.30.0) - parser (>= 3.2.1.0) - rubocop-rails (2.23.1) + rubocop-ast (1.31.1) + parser (>= 3.3.0.4) + rubocop-rails (2.24.0) activesupport (>= 4.2.0) rack (>= 1.1) rubocop (>= 1.33.0, < 2.0) - rubocop-ast (>= 1.30.0, < 2.0) + rubocop-ast (>= 1.31.1, < 2.0) ruby-progressbar (1.13.0) - ruby2_keywords (0.0.5) rubyzip (2.3.2) - selenium-webdriver (4.17.0) + selenium-webdriver (4.18.1) base64 (~> 0.2) rexml (~> 3.2, >= 3.2.5) rubyzip (>= 1.2.2, < 3.0) @@ -305,14 +301,15 @@ GEM simplecov_json_formatter (~> 0.1) simplecov-html (0.12.3) simplecov_json_formatter (0.1.4) - sorbet (0.5.11255) - sorbet-static (= 0.5.11255) - sorbet-runtime (0.5.11255) - sorbet-static (0.5.11255-universal-darwin) - sorbet-static (0.5.11255-x86_64-linux) - sorbet-static-and-runtime (0.5.11255) - sorbet (= 0.5.11255) - sorbet-runtime (= 0.5.11255) + sorbet (0.5.11284) + sorbet-static (= 0.5.11284) + sorbet-runtime (0.5.11284) + sorbet-static (0.5.11284-aarch64-linux) + sorbet-static (0.5.11284-universal-darwin) + sorbet-static (0.5.11284-x86_64-linux) + sorbet-static-and-runtime (0.5.11284) + sorbet (= 0.5.11284) + sorbet-runtime (= 0.5.11284) spoom (1.2.4) erubi (>= 1.10.0) sorbet-static-and-runtime (>= 0.5.10187) @@ -326,9 +323,7 @@ GEM activesupport (>= 5.2) sprockets (>= 3.0.0) sqlite3 (1.7.2-aarch64-linux) - sqlite3 (1.7.2-arm-linux) sqlite3 (1.7.2-arm64-darwin) - sqlite3 (1.7.2-x86-linux) sqlite3 (1.7.2-x86_64-darwin) sqlite3 (1.7.2-x86_64-linux) stimulus-rails (1.3.3) @@ -347,9 +342,9 @@ GEM spoom (~> 1.2.0, >= 1.2.0) thor (>= 1.2.0) yard-sorbet - thor (1.3.0) + thor (1.3.1) timeout (0.4.1) - turbo-rails (2.0.2) + turbo-rails (2.0.4) actionpack (>= 6.0.0) activejob (>= 6.0.0) railties (>= 6.0.0) @@ -368,7 +363,7 @@ GEM websocket-extensions (0.1.5) xpath (3.2.0) nokogiri (~> 1.8) - yard (0.9.34) + yard (0.9.36) yard-sorbet (0.8.1) sorbet-runtime (>= 0.5) yard (>= 0.9) @@ -376,9 +371,8 @@ GEM PLATFORMS aarch64-linux - arm-linux arm64-darwin - x86-linux + universal-darwin x86_64-darwin x86_64-linux diff --git a/rails_root/app/controllers/survey_questions_controller.rb b/rails_root/app/controllers/survey_questions_controller.rb index edabbe3..def2d1d 100644 --- a/rails_root/app/controllers/survey_questions_controller.rb +++ b/rails_root/app/controllers/survey_questions_controller.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true +# This is the controller for the SurveyQuestions class SurveyQuestionsController < ApplicationController before_action :set_survey_question, only: %i[show edit update destroy] diff --git a/rails_root/app/controllers/survey_responses_controller.rb b/rails_root/app/controllers/survey_responses_controller.rb index 2ff7aa4..5ff3bbf 100644 --- a/rails_root/app/controllers/survey_responses_controller.rb +++ b/rails_root/app/controllers/survey_responses_controller.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true +# rubocop:disable Metrics/ClassLength # Controller for survey responses class SurveyResponsesController < ApplicationController before_action :set_survey_data, only: %i[show edit update destroy] @@ -24,49 +25,55 @@ def edit; end # POST /survey_responses or /survey_responses.json def create - # If any of the survey_response_params values are nil, then the form is invalid - if survey_response_params.values.any? { |value| value.nil? || value.empty? } - respond_to do |format| - format.html do - redirect_to new_survey_response_url, notice: 'invalid form', status: :unprocessable_entity - end - format.json { render json: { error: 'invalid form' }, status: :unprocessable_entity } - end + if invalid_form? + handle_invalid_form else - begin - # FIXME: Validation - profile = get_user_profile_from_params(survey_response_params) - # puts "profile: #{profile.inspect}" - rescue ActiveRecord::RecordNotFound - return respond_with_error 'invalid user_id' + create_survey_response + end + end + + def invalid_form? + survey_response_params.values.any? { |value| value.nil? || value.empty? } + end + + def handle_invalid_form + respond_to do |format| + format.html do + redirect_to new_survey_response_url, notice: 'invalid form', status: :unprocessable_entity end - @survey_response = SurveyResponse.new(profile:) - # puts "survey_response: #{@survey_response.inspect}" + format.json { render json: { error: 'invalid form' }, status: :unprocessable_entity } + end + end - # puts "survey_response_params: #{survey_response_params.inspect}" - survey_response_params.each do |question_id, choice| - next if question_id == 'user_id' + def create_survey_response + begin + profile = get_user_profile_from_params(survey_response_params) + rescue ActiveRecord::RecordNotFound + return respond_with_error 'invalid user_id' + end + @survey_response = SurveyResponse.new(profile:) - # puts "question_id: #{question_id}, choice: #{choice}" + create_survey_answers - # print all the questions in the database - # puts "SurveyQuestion.all: #{SurveyQuestion.all.inspect}" + save_survey_response + end - # FIXME: Validation - question = SurveyQuestion.where(id: question_id).first! - # puts "question: #{question.inspect}" - SurveyAnswer.create(choice:, question:, response: @survey_response) - end + def create_survey_answers + survey_response_params.each do |question_id, choice| + next if question_id == 'user_id' - respond_to do |format| - if @survey_response.save - format.html do - puts 'survey response created successfully' - redirect_to survey_response_url(@survey_response), notice: 'Survey response was successfully created.' - end - format.json { render :show, status: :created, location: @survey_response } + question = SurveyQuestion.where(id: question_id).first! + SurveyAnswer.create(choice:, question:, response: @survey_response) + end + end + def save_survey_response + respond_to do |format| + if @survey_response.save + format.html do + redirect_to survey_response_url(@survey_response), notice: 'Survey response was successfully created.' end + format.json { render :show, status: :created, location: @survey_response } end end end @@ -154,3 +161,5 @@ def survey_response_params params.require(:survey_response).permit! # FIXME: Figure out how to use strong params with new model end end + +# rubocop:enable Metrics/ClassLength diff --git a/rails_root/app/helpers/survey_questions_helper.rb b/rails_root/app/helpers/survey_questions_helper.rb index 0d011a5..b26d4c8 100644 --- a/rails_root/app/helpers/survey_questions_helper.rb +++ b/rails_root/app/helpers/survey_questions_helper.rb @@ -1,4 +1,10 @@ # frozen_string_literal: true +# This is the helper for the SurveyQuestionsController module SurveyQuestionsHelper + # survey question helper functions + # returns the question text + def question_text(question) + question.text + end end diff --git a/rails_root/app/models/survey_answer.rb b/rails_root/app/models/survey_answer.rb index a3d8f0d..7572a92 100644 --- a/rails_root/app/models/survey_answer.rb +++ b/rails_root/app/models/survey_answer.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true +# This is the model for the SurveyAnswer class SurveyAnswer < ApplicationRecord belongs_to :question, class_name: 'SurveyQuestion' diff --git a/rails_root/app/models/survey_profile.rb b/rails_root/app/models/survey_profile.rb index b2103f9..f8f672f 100644 --- a/rails_root/app/models/survey_profile.rb +++ b/rails_root/app/models/survey_profile.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true +# This is the model for the SurveyProfile class SurveyProfile < ApplicationRecord has_many :responses, foreign_key: :profile_id, diff --git a/rails_root/app/models/survey_question.rb b/rails_root/app/models/survey_question.rb index 512589f..8f477de 100644 --- a/rails_root/app/models/survey_question.rb +++ b/rails_root/app/models/survey_question.rb @@ -1,4 +1,6 @@ # frozen_string_literal: true +# This is the model for the SurveyQuestion class SurveyQuestion < ApplicationRecord + validates :text, presence: true end diff --git a/rails_root/app/models/survey_response.rb b/rails_root/app/models/survey_response.rb index 98b3f17..d8c4ed9 100644 --- a/rails_root/app/models/survey_response.rb +++ b/rails_root/app/models/survey_response.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true +# This is the model for the SurveyResponse class SurveyResponse < ApplicationRecord has_many :answers, foreign_key: :response_id, diff --git a/rails_root/db/schema.rb b/rails_root/db/schema.rb index 8766439..daf232a 100644 --- a/rails_root/db/schema.rb +++ b/rails_root/db/schema.rb @@ -11,6 +11,13 @@ # It's strongly recommended that you check this file into your version control system. ActiveRecord::Schema[7.1].define(version: 2024_02_28_022158) do + create_table "posts", force: :cascade do |t| + t.string "title" + t.text "body" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + create_table "survey_answers", force: :cascade do |t| t.integer "choice", null: false t.integer "question_id", null: false diff --git a/rails_root/spec/helpers/survey_questions_helper_spec.rb b/rails_root/spec/helpers/survey_questions_helper_spec.rb index 9936d92..62457c0 100644 --- a/rails_root/spec/helpers/survey_questions_helper_spec.rb +++ b/rails_root/spec/helpers/survey_questions_helper_spec.rb @@ -2,16 +2,13 @@ require 'rails_helper' -# Specs in this file have access to a helper object that includes -# the SurveyQuestionsHelper. For example: -# -# describe SurveyQuestionsHelper do -# describe "string concat" do -# it "concats two strings with spaces" do -# expect(helper.concat_strings("this","that")).to eq("this that") -# end -# end -# end RSpec.describe SurveyQuestionsHelper, type: :helper do - pending "add some examples to (or delete) #{__FILE__}" + # survey question helper functions + # returns the question text + describe '#question_text' do + it 'returns the question text' do + question = SurveyQuestion.new(text: 'What is your name?') + expect(helper.question_text(question)).to eq('What is your name?') + end + end end diff --git a/rails_root/spec/helpers/survey_responses_helper_spec.rb b/rails_root/spec/helpers/survey_responses_helper_spec.rb index dd44e98..f72ac1d 100644 --- a/rails_root/spec/helpers/survey_responses_helper_spec.rb +++ b/rails_root/spec/helpers/survey_responses_helper_spec.rb @@ -13,6 +13,8 @@ # end # end +# rubocop:disable Metrics/BlockLength + RSpec.describe SurveyResponsesHelper, type: :helper do # create other models necessary for testing survey_responses_helper @@ -69,3 +71,5 @@ end end end + +# rubocop:enable Metrics/BlockLength diff --git a/rails_root/spec/models/survey_answer_spec.rb b/rails_root/spec/models/survey_answer_spec.rb index 903a9db..4934885 100644 --- a/rails_root/spec/models/survey_answer_spec.rb +++ b/rails_root/spec/models/survey_answer_spec.rb @@ -3,5 +3,13 @@ require 'rails_helper' RSpec.describe SurveyAnswer, type: :model do - pending "add some examples to (or delete) #{__FILE__}" + it 'belongs to a question' do + survey_answer = SurveyAnswer.new + expect(survey_answer).to respond_to(:question) + end + + it 'belongs to a response' do + survey_answer = SurveyAnswer.new + expect(survey_answer).to respond_to(:response) + end end diff --git a/rails_root/spec/models/survey_question_spec.rb b/rails_root/spec/models/survey_question_spec.rb index 6f91b38..a962235 100644 --- a/rails_root/spec/models/survey_question_spec.rb +++ b/rails_root/spec/models/survey_question_spec.rb @@ -3,5 +3,9 @@ require 'rails_helper' RSpec.describe SurveyQuestion, type: :model do - pending "add some examples to (or delete) #{__FILE__}" + it 'validates the presence of text' do + question = SurveyQuestion.new + question.valid? + expect(question.errors[:text]).to include("can't be blank") + end end diff --git a/rails_root/spec/requests/survey_questions_spec.rb b/rails_root/spec/requests/survey_questions_spec.rb index 722cce3..97de3bf 100644 --- a/rails_root/spec/requests/survey_questions_spec.rb +++ b/rails_root/spec/requests/survey_questions_spec.rb @@ -14,16 +14,17 @@ # of tools you can use to make these specs even more expressive, but we're # sticking to rails and rspec-rails APIs to keep things simple and stable. +# rubocop:disable Metrics/BlockLength RSpec.describe '/survey_questions', type: :request do # This should return the minimal set of attributes required to create a valid # SurveyQuestion. As you add validations to SurveyQuestion, be sure to # adjust the attributes here as well. let(:valid_attributes) do - skip('Add a hash of attributes valid for your model') + { text: 'What is your name?', section: 1 } end let(:invalid_attributes) do - skip('Add a hash of attributes invalid for your model') + { text: '', section: 1 } end describe 'GET /index' do @@ -88,14 +89,14 @@ describe 'PATCH /update' do context 'with valid parameters' do let(:new_attributes) do - skip('Add a hash of attributes valid for your model') + { text: 'What is your major?', section: 1 } end it 'updates the requested survey_question' do survey_question = SurveyQuestion.create! valid_attributes patch survey_question_url(survey_question), params: { survey_question: new_attributes } survey_question.reload - skip('Add assertions for updated state') + expect(survey_question.text).to eq('What is your major?') end it 'redirects to the survey_question' do @@ -130,3 +131,4 @@ end end end +# rubocop:enable Metrics/BlockLength From 1ee297de6569ea5a6924019bdb0de260394622ab Mon Sep 17 00:00:00 2001 From: jacobtoddmathes Date: Wed, 6 Mar 2024 15:45:33 -0600 Subject: [PATCH 2/3] done --- .../20240306203543_edit_survey_profiles.rb | 5 ++ rails_root/db/schema.rb | 76 +++++++++---------- rails_root/features/data_model_design.feature | 6 ++ rails_root/features/model_rework.feature | 22 ++++++ .../features/step_definitions/common_steps.rb | 24 +++--- .../data_model_design_steps.rb | 17 ++++- .../step_definitions/model_rework_steps.rb | 60 +++++++++++++++ .../theory_exploration_steps.rb | 4 + .../features/theory_exploration.feature | 5 ++ 9 files changed, 167 insertions(+), 52 deletions(-) create mode 100644 rails_root/db/migrate/20240306203543_edit_survey_profiles.rb create mode 100644 rails_root/features/model_rework.feature create mode 100644 rails_root/features/step_definitions/model_rework_steps.rb diff --git a/rails_root/db/migrate/20240306203543_edit_survey_profiles.rb b/rails_root/db/migrate/20240306203543_edit_survey_profiles.rb new file mode 100644 index 0000000..184d2c0 --- /dev/null +++ b/rails_root/db/migrate/20240306203543_edit_survey_profiles.rb @@ -0,0 +1,5 @@ +class EditSurveyProfiles < ActiveRecord::Migration[7.1] + def change + change_column_null :survey_profiles, :user_id, false + end +end diff --git a/rails_root/db/schema.rb b/rails_root/db/schema.rb index daf232a..1d0ced3 100644 --- a/rails_root/db/schema.rb +++ b/rails_root/db/schema.rb @@ -10,52 +10,52 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.1].define(version: 2024_02_28_022158) do - create_table "posts", force: :cascade do |t| - t.string "title" - t.text "body" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false +ActiveRecord::Schema[7.1].define(version: 20_240_306_203_543) do + create_table 'posts', force: :cascade do |t| + t.string 'title' + t.text 'body' + t.datetime 'created_at', null: false + t.datetime 'updated_at', null: false end - create_table "survey_answers", force: :cascade do |t| - t.integer "choice", null: false - t.integer "question_id", null: false - t.integer "response_id", null: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.index ["question_id"], name: "index_survey_answers_on_question_id" - t.index ["response_id"], name: "index_survey_answers_on_response_id" + create_table 'survey_answers', force: :cascade do |t| + t.integer 'choice', null: false + t.integer 'question_id', null: false + t.integer 'response_id', null: false + t.datetime 'created_at', null: false + t.datetime 'updated_at', null: false + t.index ['question_id'], name: 'index_survey_answers_on_question_id' + t.index ['response_id'], name: 'index_survey_answers_on_response_id' end - create_table "survey_profiles", force: :cascade do |t| - t.integer "user_id" - t.string "first_name" - t.string "last_name" - t.string "campus_name" - t.string "district_name" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.index ["user_id"], name: "index_survey_profiles_on_user_id", unique: true + create_table 'survey_profiles', force: :cascade do |t| + t.integer 'user_id', null: false + t.string 'first_name' + t.string 'last_name' + t.string 'campus_name' + t.string 'district_name' + t.datetime 'created_at', null: false + t.datetime 'updated_at', null: false + t.index ['user_id'], name: 'index_survey_profiles_on_user_id', unique: true end - create_table "survey_questions", force: :cascade do |t| - t.text "text", null: false - t.text "explanation" - t.integer "section", null: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + create_table 'survey_questions', force: :cascade do |t| + t.text 'text', null: false + t.text 'explanation' + t.integer 'section', null: false + t.datetime 'created_at', null: false + t.datetime 'updated_at', null: false end - create_table "survey_responses", force: :cascade do |t| - t.string "share_code" - t.integer "profile_id", null: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.index ["profile_id"], name: "index_survey_responses_on_profile_id" + create_table 'survey_responses', force: :cascade do |t| + t.string 'share_code' + t.integer 'profile_id', null: false + t.datetime 'created_at', null: false + t.datetime 'updated_at', null: false + t.index ['profile_id'], name: 'index_survey_responses_on_profile_id' end - add_foreign_key "survey_answers", "survey_questions", column: "question_id" - add_foreign_key "survey_answers", "survey_responses", column: "response_id" - add_foreign_key "survey_responses", "survey_profiles", column: "profile_id" + add_foreign_key 'survey_answers', 'survey_questions', column: 'question_id' + add_foreign_key 'survey_answers', 'survey_responses', column: 'response_id' + add_foreign_key 'survey_responses', 'survey_profiles', column: 'profile_id' end diff --git a/rails_root/features/data_model_design.feature b/rails_root/features/data_model_design.feature index 989e2ca..0d53dc5 100644 --- a/rails_root/features/data_model_design.feature +++ b/rails_root/features/data_model_design.feature @@ -5,10 +5,16 @@ Feature: Establish Project Data Models Given questions exist And I have a set of invalid attributes When I try to create model instances + | model_name | + | SurveyProfile | + | SurveyResponse | Then the model was not created Scenario: Valid model attributes Given questions exist And I have a set of valid attributes When I try to create model instances + | model_name | + | SurveyProfile | + | SurveyResponse | Then the model was created \ No newline at end of file diff --git a/rails_root/features/model_rework.feature b/rails_root/features/model_rework.feature new file mode 100644 index 0000000..01df79f --- /dev/null +++ b/rails_root/features/model_rework.feature @@ -0,0 +1,22 @@ +Feature: Reworked Project Data Models + Verify the correctness of the data models + + Scenario: Invalid model attributes + Given I have an invalid set of attributes for all models + When I try to create model instances + | model_name | + | SurveyQuestion | + | SurveyProfile | + | SurveyResponse | + | SurveyAnswer | + Then the models were not created + + Scenario: Valid model attributes + Given I have an valid set of attributes for all models + When I try to create model instances + | model_name | + | SurveyQuestion | + | SurveyProfile | + | SurveyResponse | + | SurveyAnswer | + Then the models were created \ No newline at end of file diff --git a/rails_root/features/step_definitions/common_steps.rb b/rails_root/features/step_definitions/common_steps.rb index 4dd412f..340d5c2 100644 --- a/rails_root/features/step_definitions/common_steps.rb +++ b/rails_root/features/step_definitions/common_steps.rb @@ -32,24 +32,26 @@ end Given('I have a set of invalid attributes') do - @survey_profiles_attributes = {} + @model_attributes = {} + @model_attributes['SurveyProfile'] = {} SurveyProfile.column_names.each do |name| - @survey_profiles_attributes[name] = nil if name != 'id' && name != 'created_at' && name != 'updated_at' + @model_attributes['SurveyProfile'][name] = nil if name != 'id' && name != 'created_at' && name != 'updated_at' end - @survey_responses_attributes = {} + + @model_attributes['SurveyResponse'] = {} SurveyResponse.column_names.each do |name| - @survey_responses_attributes[name] = nil if name != 'id' && name != 'created_at' && name != 'updated_at' + @model_attributes['SurveyResponse'][name] = nil if name != 'id' && name != 'created_at' && name != 'updated_at' end end Given('I have a set of valid attributes') do - @survey_profiles_attributes = {} + @model_attributes = {} + + @model_attributes['SurveyProfile'] = {} SurveyProfile.column_names.each do |name| - @survey_profiles_attributes[name] = 10 if name != 'created_at' && name != 'updated_at' + @model_attributes['SurveyProfile'][name] = 10 if name != 'created_at' && name != 'updated_at' end - @survey_responses_attributes = {} - SurveyQuestion.all.each do |question| - @survey_responses_attributes[question.id.to_s] = 1 - end - @survey_responses_attributes['user_id'] = 10 + + @model_attributes['SurveyResponse'] = {} + @model_attributes['SurveyResponse']['profile_id'] = 10 end diff --git a/rails_root/features/step_definitions/data_model_design_steps.rb b/rails_root/features/step_definitions/data_model_design_steps.rb index 8d4a7b7..91a3706 100644 --- a/rails_root/features/step_definitions/data_model_design_steps.rb +++ b/rails_root/features/step_definitions/data_model_design_steps.rb @@ -1,8 +1,19 @@ # frozen_string_literal: true -When('I try to create model instances') do - post survey_profiles_url, survey_profile: @survey_profiles_attributes - post survey_responses_url, survey_response: @survey_responses_attributes +When('I try to create model instances') do |table| + table.hashes.each do |model| + @attributes = @model_attributes[model['model_name']] + + if @attributes.values.any?(&:nil?) + expect do + model['model_name'].constantize.create!(@attributes) + rescue ActiveRecord::RecordInvalid, ActiveRecord::NotNullViolation => e + raise "Expected exception: #{e.class.name}" + end.to raise_error(/Expected exception: (ActiveRecord::RecordInvalid|ActiveRecord::NotNullViolation)/) + else + model['model_name'].constantize.create!(@attributes) + end + end end Then('the model was not created') do diff --git a/rails_root/features/step_definitions/model_rework_steps.rb b/rails_root/features/step_definitions/model_rework_steps.rb new file mode 100644 index 0000000..7da4900 --- /dev/null +++ b/rails_root/features/step_definitions/model_rework_steps.rb @@ -0,0 +1,60 @@ +Given('I have an invalid set of attributes for all models') do + @model_attributes = {} + + @model_attributes['SurveyQuestion'] = {} + SurveyQuestion.column_names.each do |name| + @model_attributes['SurveyQuestion'][name] = nil if name != 'id' && name != 'created_at' && name != 'updated_at' + end + + @model_attributes['SurveyProfile'] = {} + SurveyProfile.column_names.each do |name| + @model_attributes['SurveyProfile'][name] = nil if name != 'id' && name != 'created_at' && name != 'updated_at' + end + + @model_attributes['SurveyResponse'] = {} + SurveyResponse.column_names.each do |name| + @model_attributes['SurveyResponse'][name] = nil if name != 'id' && name != 'created_at' && name != 'updated_at' + end + + @model_attributes['SurveyAnswer'] = {} + SurveyAnswer.column_names.each do |name| + @model_attributes['SurveyAnswer'][name] = nil if name != 'id' && name != 'created_at' && name != 'updated_at' + end +end + +Then('the models were not created') do + expect(SurveyQuestion.last).to be_nil + expect(SurveyProfile.last).to be_nil + expect(SurveyResponse.last).to be_nil + expect(SurveyAnswer.last).to be_nil +end + +Given('I have an valid set of attributes for all models') do + @model_attributes = {} + + @model_attributes['SurveyQuestion'] = {} + SurveyQuestion.column_names.each do |name| + @model_attributes['SurveyQuestion'][name] = 10 if name != 'created_at' && name != 'updated_at' + end + + @model_attributes['SurveyProfile'] = {} + SurveyProfile.column_names.each do |name| + @model_attributes['SurveyProfile'][name] = 10 if name != 'created_at' && name != 'updated_at' + end + + @model_attributes['SurveyResponse'] = {} + @model_attributes['SurveyResponse']['id'] = 10 + @model_attributes['SurveyResponse']['profile_id'] = 10 + + @model_attributes['SurveyAnswer'] = {} + SurveyAnswer.column_names.each do |name| + @model_attributes['SurveyAnswer'][name] = 10 if name != 'created_at' && name != 'updated_at' + end +end + +Then('the models were created') do + expect(SurveyQuestion.last).to be_truthy + expect(SurveyProfile.last).to be_truthy + expect(SurveyResponse.last).to be_truthy + expect(SurveyAnswer.last).to be_truthy +end diff --git a/rails_root/features/step_definitions/theory_exploration_steps.rb b/rails_root/features/step_definitions/theory_exploration_steps.rb index 7e7a782..f426f29 100644 --- a/rails_root/features/step_definitions/theory_exploration_steps.rb +++ b/rails_root/features/step_definitions/theory_exploration_steps.rb @@ -7,3 +7,7 @@ Then('I can read about theory information') do expect(page).to have_content('The Four Factors and the Tetrahedron') end + +Then('I can see the tetrahedron') do + expect(page).to have_css('img') +end diff --git a/rails_root/features/theory_exploration.feature b/rails_root/features/theory_exploration.feature index dcb26d2..540842c 100644 --- a/rails_root/features/theory_exploration.feature +++ b/rails_root/features/theory_exploration.feature @@ -5,3 +5,8 @@ Feature: Theory Exploration Given I am on the site When I visit about page Then I can read about theory information + + Scenario: Verify tetrahedron rendering + Given I am on the site + When I visit about page + Then I can see the tetrahedron From eca0cb64ca797963328813a5f5672b44562c9ee6 Mon Sep 17 00:00:00 2001 From: Andres Santiago Date: Wed, 6 Mar 2024 16:29:58 -0600 Subject: [PATCH 3/3] Fixed schema.rb --- rails_root/db/schema.rb | 64 ++++++++++++++++------------------------- 1 file changed, 24 insertions(+), 40 deletions(-) diff --git a/rails_root/db/schema.rb b/rails_root/db/schema.rb index 7cc8860..8db3a89 100644 --- a/rails_root/db/schema.rb +++ b/rails_root/db/schema.rb @@ -26,52 +26,36 @@ t.datetime "updated_at", null: false t.index ["question_id"], name: "index_survey_answers_on_question_id" t.index ["response_id"], name: "index_survey_answers_on_response_id" -ActiveRecord::Schema[7.1].define(version: 20_240_306_203_543) do - create_table 'posts', force: :cascade do |t| - t.string 'title' - t.text 'body' - t.datetime 'created_at', null: false - t.datetime 'updated_at', null: false end - create_table 'survey_answers', force: :cascade do |t| - t.integer 'choice', null: false - t.integer 'question_id', null: false - t.integer 'response_id', null: false - t.datetime 'created_at', null: false - t.datetime 'updated_at', null: false - t.index ['question_id'], name: 'index_survey_answers_on_question_id' - t.index ['response_id'], name: 'index_survey_answers_on_response_id' - end - - create_table 'survey_profiles', force: :cascade do |t| - t.integer 'user_id', null: false - t.string 'first_name' - t.string 'last_name' - t.string 'campus_name' - t.string 'district_name' - t.datetime 'created_at', null: false - t.datetime 'updated_at', null: false - t.index ['user_id'], name: 'index_survey_profiles_on_user_id', unique: true + create_table "survey_profiles", force: :cascade do |t| + t.integer "user_id", null: false + t.string "first_name" + t.string "last_name" + t.string "campus_name" + t.string "district_name" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["user_id"], name: "index_survey_profiles_on_user_id", unique: true end - create_table 'survey_questions', force: :cascade do |t| - t.text 'text', null: false - t.text 'explanation' - t.integer 'section', null: false - t.datetime 'created_at', null: false - t.datetime 'updated_at', null: false + create_table "survey_questions", force: :cascade do |t| + t.text "text", null: false + t.text "explanation" + t.integer "section", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end - create_table 'survey_responses', force: :cascade do |t| - t.string 'share_code' - t.integer 'profile_id', null: false - t.datetime 'created_at', null: false - t.datetime 'updated_at', null: false - t.index ['profile_id'], name: 'index_survey_responses_on_profile_id' + create_table "survey_responses", force: :cascade do |t| + t.string "share_code" + t.integer "profile_id", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["profile_id"], name: "index_survey_responses_on_profile_id" end - add_foreign_key 'survey_answers', 'survey_questions', column: 'question_id' - add_foreign_key 'survey_answers', 'survey_responses', column: 'response_id' - add_foreign_key 'survey_responses', 'survey_profiles', column: 'profile_id' + add_foreign_key "survey_answers", "survey_questions", column: "question_id" + add_foreign_key "survey_answers", "survey_responses", column: "response_id" + add_foreign_key "survey_responses", "survey_profiles", column: "profile_id" end