Skip to content

Commit

Permalink
Updating cucumber tests (#44)
Browse files Browse the repository at this point in the history
* Changed survey profile user_id to not null

* Updated cucumber tests
  • Loading branch information
Andres-L-Santiago authored Mar 6, 2024
1 parent 23fb37e commit a438cf7
Show file tree
Hide file tree
Showing 9 changed files with 138 additions and 16 deletions.
5 changes: 5 additions & 0 deletions rails_root/db/migrate/20240306203543_edit_survey_profiles.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class EditSurveyProfiles < ActiveRecord::Migration[7.1]
def change
change_column_null :survey_profiles, :user_id, false
end
end
11 changes: 9 additions & 2 deletions rails_root/db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions rails_root/features/data_model_design.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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
22 changes: 22 additions & 0 deletions rails_root/features/model_rework.feature
Original file line number Diff line number Diff line change
@@ -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
24 changes: 13 additions & 11 deletions rails_root/features/step_definitions/common_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
17 changes: 14 additions & 3 deletions rails_root/features/step_definitions/data_model_design_steps.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
60 changes: 60 additions & 0 deletions rails_root/features/step_definitions/model_rework_steps.rb
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 5 additions & 0 deletions rails_root/features/theory_exploration.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit a438cf7

Please sign in to comment.