-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Models for contexts, questions, and responses
- Loading branch information
1 parent
0d31bfe
commit ec3b143
Showing
11 changed files
with
165 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# A Context reflects a demographic category. | ||
class Context < ApplicationRecord | ||
|
||
validates_presence_of :name | ||
validates_presence_of :display_name | ||
validates_uniqueness_of :name | ||
|
||
has_many :questions | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
class Response < ApplicationRecord | ||
|
||
belongs_to :survey_response | ||
belongs_to :question | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class CreateContexts < ActiveRecord::Migration[7.2] | ||
def change | ||
create_table :contexts do |t| | ||
t.string :name | ||
t.string :display_name | ||
t.timestamps | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
class PopulateDefaultContexts < ActiveRecord::Migration[7.2] | ||
def change | ||
Context.create(name: "age", display_name: "Age") | ||
Context.create(name: "class", display_name: "Class") | ||
Context.create(name: "race-ethnicity", display_name: "Race/Ethnicity") | ||
Context.create(name: "religion", display_name: "Religion") | ||
Context.create(name: "disability", display_name: "Disability") | ||
Context.create(name: "neurodiversity", display_name: "Neurodiversity") | ||
Context.create(name: "gender", display_name: "Gender") | ||
Context.create(name: "lgbtqia", display_name: "LGBTQIA+ Status") | ||
Context.create(name: "pronouns", display_name: "Pronouns") | ||
Context.create(name: "pronoun_feelings", display_name: "Pronoun Feelings") | ||
Context.create(name: "identity_affinities", display_name: "Identity Affinities") | ||
Context.create(name: "identity_reflection", display_name: "Identity Reflection") | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
class CreateQuestions < ActiveRecord::Migration[7.2] | ||
def change | ||
create_table :questions do |t| | ||
t.string :key | ||
t.string :label | ||
t.boolean :is_experience, default: false | ||
t.boolean :is_identity, default: false | ||
t.boolean :is_feeling, default: false | ||
t.boolean :is_affinity, default: false | ||
t.boolean :is_reflection, default: false | ||
t.timestamps | ||
end | ||
add_reference :questions, :context, null: true, foreign_key: true | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
class PopulateDefaultQuestions < ActiveRecord::Migration[7.2] | ||
def change | ||
Question.create(key: 'age_given', label: "Age", is_identity: true, context_id: Context.find_by(name: 'age').id) | ||
Question.create(key: 'age_exp', label: "Experience with Age", is_experience: true, context_id: Context.find_by(name: 'age').id) | ||
Question.create(key: 'klass_given', label: "Class", is_identity: true, context_id: Context.find_by(name: 'class').id) | ||
Question.create(key: 'klass_exp', label: "Experience with Class", is_experience: true, context_id: Context.find_by(name: 'class').id) | ||
Question.create(key: 'race_ethnicity_given', label: "Race/Ethnicity", is_identity: true, context_id: Context.find_by(name: 'race-ethnicity').id) | ||
Question.create(key: 'race_ethnicity_exp', label: "Experience with Race/Ethnicity", is_experience: true, context_id: Context.find_by(name: 'race-ethnicity').id) | ||
Question.create(key: 'religion_given', label: "Religion", is_identity: true, context_id: Context.find_by(name: 'religion').id) | ||
Question.create(key: 'religion_exp', label: "Experience with Religion", is_experience: true, context_id: Context.find_by(name: 'religion').id) | ||
Question.create(key: 'disability_given', label: "Disability", is_identity: true, context_id: Context.find_by(name: 'disability').id) | ||
Question.create(key: 'disability_exp', label: "Experience with Disability", is_experience: true, context_id: Context.find_by(name: 'disability').id) | ||
Question.create(key: 'neurodiversity_given', label: "Neurodiversity", is_identity: true, context_id: Context.find_by(name: 'neurodiversity').id) | ||
Question.create(key: 'neurodiversity_exp', label: "Experience with Neurodiversity", is_experience: true, context_id: Context.find_by(name: 'neurodiversity').id) | ||
Question.create(key: 'gender_given', label: "Gender", is_identity: true, context_id: Context.find_by(name: 'gender').id) | ||
Question.create(key: 'gender_exp', label: "Experience with Gender", is_experience: true, context_id: Context.find_by(name: 'gender').id) | ||
Question.create(key: 'lgbtqia_given', label: "LGBTQIA+ Status", is_identity: true, context_id: Context.find_by(name: 'lgbtqia').id) | ||
Question.create(key: 'lgbtqia_exp', label: "Experience with LGBTQIA+", is_experience: true, context_id: Context.find_by(name: 'lgbtqia').id) | ||
Question.create(key: 'pronouns_given', label: "Pronouns Given", is_identity: true, context_id: Context.find_by(name: 'pronouns').id) | ||
Question.create(key: 'pronouns_exp', label: "Experience with Pronouns", is_experience: true, context_id: Context.find_by(name: 'pronouns').id) | ||
Question.create(key: 'pronouns_feel', label: "Pronoun Feelings", is_feeling: true, context_id: Context.find_by(name: 'pronoun_feelings').id) | ||
Question.create(key: 'affinity', label: "Identity Affinities", is_affinity: true, context_id: Context.find_by(name: 'identity_affinities').id) | ||
Question.create(key: 'notes', label: "Identity Reflection", is_reflection: true, context_id: Context.find_by(name: 'identity_reflection').id) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class CreateResponses < ActiveRecord::Migration[7.2] | ||
def change | ||
create_table :responses do |t| | ||
t.text :value | ||
t.string :raw_codes, array: true, default: [] | ||
t.timestamps | ||
end | ||
add_reference :responses, :question, null: false, foreign_key: true | ||
add_reference :responses, :survey_response, null: false, foreign_key: true | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
class PopulateResponses < ActiveRecord::Migration[7.2] | ||
def up | ||
SurveyResponse.all.each do |survey_response| | ||
Response.create(question_id: Question.find_by(key: 'age_given').id, survey_response_id: survey_response.id, value: survey_response.age_given, raw_codes: survey_response.age_id_codes) | ||
Response.create(question_id: Question.find_by(key: 'age_exp').id, survey_response_id: survey_response.id, value: survey_response.age_exp, raw_codes: survey_response.age_exp_codes) | ||
Response.create(question_id: Question.find_by(key: 'klass_given').id, survey_response_id: survey_response.id, value: survey_response.klass_given, raw_codes: survey_response.klass_id_codes) | ||
Response.create(question_id: Question.find_by(key: 'klass_exp').id, survey_response_id: survey_response.id, value: survey_response.klass_exp, raw_codes: survey_response.klass_exp_codes) | ||
Response.create(question_id: Question.find_by(key: 'race_ethnicity_given').id, survey_response_id: survey_response.id, value: survey_response.race_ethnicity_given, raw_codes: survey_response.race_ethnicity_id_codes) | ||
Response.create(question_id: Question.find_by(key: 'race_ethnicity_exp').id, survey_response_id: survey_response.id, value: survey_response.race_ethnicity_exp, raw_codes: survey_response.race_ethnicity_exp_codes) | ||
Response.create(question_id: Question.find_by(key: 'religion_given').id, survey_response_id: survey_response.id, value: survey_response.religion_given, raw_codes: survey_response.religion_id_codes) | ||
Response.create(question_id: Question.find_by(key: 'religion_exp').id, survey_response_id: survey_response.id, value: survey_response.religion_exp, raw_codes: survey_response.religion_exp_codes) | ||
Response.create(question_id: Question.find_by(key: 'disability_given').id, survey_response_id: survey_response.id, value: survey_response.disability_given, raw_codes: survey_response.disability_id_codes) | ||
Response.create(question_id: Question.find_by(key: 'disability_exp').id, survey_response_id: survey_response.id, value: survey_response.disability_exp, raw_codes: survey_response.disability_exp_codes) | ||
Response.create(question_id: Question.find_by(key: 'neurodiversity_given').id, survey_response_id: survey_response.id, value: survey_response.neurodiversity_given, raw_codes: survey_response.neurodiversity_id_codes) | ||
Response.create(question_id: Question.find_by(key: 'neurodiversity_exp').id, survey_response_id: survey_response.id, value: survey_response.neurodiversity_exp, raw_codes: survey_response.neurodiversity_exp_codes) | ||
Response.create(question_id: Question.find_by(key: 'gender_given').id, survey_response_id: survey_response.id, value: survey_response.gender_given, raw_codes: survey_response.gender_id_codes) | ||
Response.create(question_id: Question.find_by(key: 'gender_exp').id, survey_response_id: survey_response.id, value: survey_response.gender_exp, raw_codes: survey_response.gender_exp_codes) | ||
Response.create(question_id: Question.find_by(key: 'lgbtqia_given').id, survey_response_id: survey_response.id, value: survey_response.lgbtqia_given, raw_codes: survey_response.lgbtqia_id_codes) | ||
Response.create(question_id: Question.find_by(key: 'lgbtqia_exp').id, survey_response_id: survey_response.id, value: survey_response.lgbtqia_exp, raw_codes: survey_response.lgbtqia_exp_codes) | ||
Response.create(question_id: Question.find_by(key: 'pronouns_given').id, survey_response_id: survey_response.id, value: survey_response.pronouns_given, raw_codes: survey_response.pronouns_id_codes) | ||
Response.create(question_id: Question.find_by(key: 'pronouns_exp').id, survey_response_id: survey_response.id, value: survey_response.pronouns_exp, raw_codes: survey_response.pronouns_exp_codes) | ||
Response.create(question_id: Question.find_by(key: 'pronouns_feel').id, survey_response_id: survey_response.id, value: survey_response.pronouns_feel, raw_codes: survey_response.pronouns_feel_codes) | ||
Response.create(question_id: Question.find_by(key: 'affinity').id, survey_response_id: survey_response.id, value: survey_response.affinity, raw_codes: survey_response.affinity_codes) | ||
end | ||
end | ||
|
||
def down | ||
Response.destroy_all | ||
end | ||
|
||
end | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.