add Question

This commit is contained in:
João Geonizeli
2022-07-21 09:59:20 -03:00
parent ff815e15f6
commit 9c5b53679d
7 changed files with 211 additions and 5 deletions

View File

@@ -26,6 +26,9 @@ gem "bootsnap", require: false
# Use Active Storage variants [https://guides.rubyonrails.org/active_storage_overview.html#transforming-images] # Use Active Storage variants [https://guides.rubyonrails.org/active_storage_overview.html#transforming-images]
# gem "image_processing", "~> 1.2" # gem "image_processing", "~> 1.2"
gem "pundit", "~> 2.2"
gem "enumerize", "~> 2.5"
gem "activeadmin", "~> 2.13" gem "activeadmin", "~> 2.13"
gem "sassc-rails" gem "sassc-rails"
@@ -37,6 +40,7 @@ group :development, :test do
gem "dotenv-rails", "~> 2.7" gem "dotenv-rails", "~> 2.7"
gem "rspec-rails", "~> 5.1" gem "rspec-rails", "~> 5.1"
gem "factory_bot_rails", "~> 6.2" gem "factory_bot_rails", "~> 6.2"
gem "faker", "~> 2.21"
gem "debug", platforms: %i[ mri mingw x64_mingw ] gem "debug", platforms: %i[ mri mingw x64_mingw ]
end end
@@ -50,7 +54,3 @@ end
group :test do group :test do
gem "shoulda-matchers", "~> 5.1" gem "shoulda-matchers", "~> 5.1"
end end
gem "faker", "~> 2.21"
gem "pundit", "~> 2.2"

View File

@@ -104,6 +104,8 @@ GEM
dotenv-rails (2.7.6) dotenv-rails (2.7.6)
dotenv (= 2.7.6) dotenv (= 2.7.6)
railties (>= 3.2) railties (>= 3.2)
enumerize (2.5.0)
activesupport (>= 3.2)
erubi (1.10.0) erubi (1.10.0)
factory_bot (6.2.1) factory_bot (6.2.1)
activesupport (>= 5.0.0) activesupport (>= 5.0.0)
@@ -329,6 +331,7 @@ DEPENDENCIES
debug debug
devise (~> 4.8) devise (~> 4.8)
dotenv-rails (~> 2.7) dotenv-rails (~> 2.7)
enumerize (~> 2.5)
factory_bot_rails (~> 6.2) factory_bot_rails (~> 6.2)
faker (~> 2.21) faker (~> 2.21)
importmap-rails importmap-rails

55
app/models/question.rb Normal file
View File

@@ -0,0 +1,55 @@
# == Schema Information
#
# Table name: questions
#
# id :bigint not null, primary key
# alternatives :jsonb not null
# authorship :string
# authorship_year :string
# bloom_taxonomy :string
# body :text
# check_type :string
# difficulty :string
# explanation :text
# instruction :text
# intention :text
# references :text
# status :string default("draft"), not null
# support :text
# created_at :datetime not null
# updated_at :datetime not null
# subject_id :bigint
# user_id :bigint not null
#
# Indexes
#
# index_questions_on_subject_id (subject_id)
# index_questions_on_user_id (user_id)
#
# Foreign Keys
#
# fk_rails_... (subject_id => subjects.id)
# fk_rails_... (user_id => users.id)
#
class Question < ApplicationRecord
extend Enumerize
belongs_to :user
belongs_to :subject, optional: true
enumerize :status, in: %i[draft waiting_review with_requested_changes approved registered]
enumerize :difficulty, in: %i[easy medium hard]
enumerize :bloom_taxonomy, in: %i[remember understand apply analyze evaluate create]
enumerize :check_type, in: %i[
unique_answer
incomplete_affirmation
multiple_answer
negative_focus
assertion_and_reason
gap
interpretation
association
ordering_or_ranking
constant_alternatives
]
end

View File

@@ -0,0 +1,23 @@
class CreateQuestions < ActiveRecord::Migration[7.0]
def change
create_table :questions do |t|
t.references :user, null: false, foreign_key: true
t.references :subject, null: true, foreign_key: true
t.jsonb :alternatives, null: false, default: []
t.string :authorship
t.string :authorship_year
t.string :bloom_taxonomy
t.text :body
t.string :check_type
t.string :difficulty
t.text :explanation
t.text :instruction
t.text :intention
t.text :references
t.string :status, null: false, default: 'draft'
t.text :support
t.timestamps
end
end
end

26
db/schema.rb generated
View File

@@ -10,7 +10,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[7.0].define(version: 2022_07_21_123327) do ActiveRecord::Schema[7.0].define(version: 2022_07_21_124944) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
@@ -42,6 +42,28 @@ ActiveRecord::Schema[7.0].define(version: 2022_07_21_123327) do
t.index ["name"], name: "index_categories_on_name", unique: true t.index ["name"], name: "index_categories_on_name", unique: true
end end
create_table "questions", force: :cascade do |t|
t.bigint "user_id", null: false
t.bigint "subject_id"
t.jsonb "alternatives", default: [], null: false
t.string "authorship"
t.string "authorship_year"
t.string "bloom_taxonomy"
t.text "body"
t.string "check_type"
t.string "difficulty"
t.text "explanation"
t.text "instruction"
t.text "intention"
t.text "references"
t.string "status", default: "draft", null: false
t.text "support"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["subject_id"], name: "index_questions_on_subject_id"
t.index ["user_id"], name: "index_questions_on_user_id"
end
create_table "subjects", force: :cascade do |t| create_table "subjects", force: :cascade do |t|
t.string "name" t.string "name"
t.bigint "category_id", null: false t.bigint "category_id", null: false
@@ -66,6 +88,8 @@ ActiveRecord::Schema[7.0].define(version: 2022_07_21_123327) do
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
end end
add_foreign_key "questions", "subjects"
add_foreign_key "questions", "users"
add_foreign_key "subjects", "axes" add_foreign_key "subjects", "axes"
add_foreign_key "subjects", "categories" add_foreign_key "subjects", "categories"
end end

View File

@@ -0,0 +1,58 @@
# == Schema Information
#
# Table name: questions
#
# id :bigint not null, primary key
# alternatives :jsonb not null
# authorship :string
# authorship_year :string
# bloom_taxonomy :string
# body :text
# check_type :string
# difficulty :string
# explanation :text
# instruction :text
# intention :text
# references :text
# status :string default("draft"), not null
# support :text
# created_at :datetime not null
# updated_at :datetime not null
# subject_id :bigint
# user_id :bigint not null
#
# Indexes
#
# index_questions_on_subject_id (subject_id)
# index_questions_on_user_id (user_id)
#
# Foreign Keys
#
# fk_rails_... (subject_id => subjects.id)
# fk_rails_... (user_id => users.id)
#
FactoryBot.define do
factory :question do
introduction { "question title" }
instruction { "html raw" }
support { "html raw" }
body { "html raw" }
alternatives do
[{ text: "html raw", correct: true },
{ text: "html raw", correct: false },
{ text: "html raw", correct: false },
{ text: "html raw", correct: false },
{ text: "html raw", correct: false }]
end
explanation { "html raw" }
references { "html raw" }
status { "registered" }
difficulty { "easy" }
check_type { "unique_answer" }
bloom_taxonomy { "understand" }
authorship_year { "2020" }
authorship { "UNIFESO" }
user
subject
end
end

View File

@@ -0,0 +1,43 @@
# == Schema Information
#
# Table name: questions
#
# id :bigint not null, primary key
# alternatives :jsonb not null
# authorship :string
# authorship_year :string
# bloom_taxonomy :string
# body :text
# check_type :string
# difficulty :string
# explanation :text
# instruction :text
# intention :text
# references :text
# status :string default("draft"), not null
# support :text
# created_at :datetime not null
# updated_at :datetime not null
# subject_id :bigint
# user_id :bigint not null
#
# Indexes
#
# index_questions_on_subject_id (subject_id)
# index_questions_on_user_id (user_id)
#
# Foreign Keys
#
# fk_rails_... (subject_id => subjects.id)
# fk_rails_... (user_id => users.id)
#
require 'rails_helper'
RSpec.describe Question, type: :model do
describe "associations" do
it { is_expected.to(belong_to(:user)) }
it { is_expected.to(belong_to(:subject).optional(true)) }
# it { is_expected.to(have_many(:review_requests)) }
# it { is_expected.to(have_many(:review_messages)) }
end
end