From 5aa9edb209896172eeeb28629766d7954e54ef28 Mon Sep 17 00:00:00 2001 From: Maximilian Grundke Date: Wed, 6 Sep 2017 15:16:47 +0200 Subject: [PATCH] Add subscription model and link it to RFC --- app/models/request_for_comment.rb | 2 + app/models/subscription.rb | 4 ++ .../20170906124500_create_subscriptions.rb | 11 ++++ db/schema.rb | 51 ++++++++++++++++++- test/factories/subscriptions.rb | 7 +++ test/models/subscription_test.rb | 7 +++ 6 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 app/models/subscription.rb create mode 100644 db/migrate/20170906124500_create_subscriptions.rb create mode 100644 test/factories/subscriptions.rb create mode 100644 test/models/subscription_test.rb diff --git a/app/models/request_for_comment.rb b/app/models/request_for_comment.rb index 22b39b39..193717c6 100644 --- a/app/models/request_for_comment.rb +++ b/app/models/request_for_comment.rb @@ -5,6 +5,8 @@ class RequestForComment < ActiveRecord::Base belongs_to :file, class_name: 'CodeOcean::File' has_many :comments, through: :submission + has_many :subscriptions + has_many :subscribers, through: :subscriptions, source: :user, source_type: ExternalUser scope :unsolved, -> { where(solved: [false, nil]) } diff --git a/app/models/subscription.rb b/app/models/subscription.rb new file mode 100644 index 00000000..abe1b513 --- /dev/null +++ b/app/models/subscription.rb @@ -0,0 +1,4 @@ +class Subscription < ActiveRecord::Base + belongs_to :user, polymorphic: true + belongs_to :request_for_comment +end diff --git a/db/migrate/20170906124500_create_subscriptions.rb b/db/migrate/20170906124500_create_subscriptions.rb new file mode 100644 index 00000000..5dba42ab --- /dev/null +++ b/db/migrate/20170906124500_create_subscriptions.rb @@ -0,0 +1,11 @@ +class CreateSubscriptions < ActiveRecord::Migration + def change + create_table :subscriptions do |t| + t.belongs_to :user, polymorphic: true + t.references :request_for_comment + t.string :type + + t.timestamps null: false + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 81693c1d..1b882e3d 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20170608141612) do +ActiveRecord::Schema.define(version: 20170906124500) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -47,6 +47,30 @@ ActiveRecord::Schema.define(version: 20170608141612) do t.string "oauth_secret", limit: 255 end + create_table "error_template_attributes", force: :cascade do |t| + t.string "key" + t.string "regex" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.text "description" + t.boolean "important" + end + + create_table "error_template_attributes_templates", id: false, force: :cascade do |t| + t.integer "error_template_id", null: false + t.integer "error_template_attribute_id", null: false + end + + create_table "error_templates", force: :cascade do |t| + t.integer "execution_environment_id" + t.string "name" + t.string "signature" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.text "description" + t.text "hint" + end + create_table "errors", force: :cascade do |t| t.integer "execution_environment_id" t.text "message" @@ -268,6 +292,22 @@ ActiveRecord::Schema.define(version: 20170608141612) do t.datetime "updated_at" end + create_table "structured_error_attributes", force: :cascade do |t| + t.integer "structured_error_id" + t.integer "error_template_attribute_id" + t.string "value" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.boolean "match" + end + + create_table "structured_errors", force: :cascade do |t| + t.integer "error_template_id" + t.integer "file_id" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + create_table "submissions", force: :cascade do |t| t.integer "exercise_id" t.float "score" @@ -281,6 +321,15 @@ ActiveRecord::Schema.define(version: 20170608141612) do add_index "submissions", ["exercise_id"], name: "index_submissions_on_exercise_id", using: :btree add_index "submissions", ["user_id"], name: "index_submissions_on_user_id", using: :btree + create_table "subscriptions", force: :cascade do |t| + t.integer "user_id" + t.string "user_type" + t.integer "request_for_comment_id" + t.string "type" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + create_table "tags", force: :cascade do |t| t.string "name", null: false t.datetime "created_at" diff --git a/test/factories/subscriptions.rb b/test/factories/subscriptions.rb new file mode 100644 index 00000000..11c5a67a --- /dev/null +++ b/test/factories/subscriptions.rb @@ -0,0 +1,7 @@ +FactoryGirl.define do + factory :subscription do + user nil + request_for_comments nil + type "" + end +end diff --git a/test/models/subscription_test.rb b/test/models/subscription_test.rb new file mode 100644 index 00000000..a045d1ea --- /dev/null +++ b/test/models/subscription_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class SubscriptionTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end