From a438cf76f9be2ff6ddd04b2a48d92c0755a7a9ad Mon Sep 17 00:00:00 2001 From: Andres Santiago <61444430+Andres-L-Santiago@users.noreply.github.com> Date: Wed, 6 Mar 2024 15:06:44 -0600 Subject: [PATCH] Updating cucumber tests (#44) * Changed survey profile user_id to not null * Updated cucumber tests --- .../20240306203543_edit_survey_profiles.rb | 5 ++ rails_root/db/schema.rb | 11 +++- 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, 138 insertions(+), 16 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 8766439..8db3a89 100644 --- a/rails_root/db/schema.rb +++ b/rails_root/db/schema.rb @@ -10,7 +10,14 @@ # # 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 +ActiveRecord::Schema[7.1].define(version: 2024_03_06_203543) 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 @@ -22,7 +29,7 @@ end create_table "survey_profiles", force: :cascade do |t| - t.integer "user_id" + t.integer "user_id", null: false t.string "first_name" t.string "last_name" t.string "campus_name" 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