From 50d54cfea5304db57249d3e9f3d2a413607e8456 Mon Sep 17 00:00:00 2001 From: Sashi Kumar Date: Fri, 9 Jun 2017 23:48:07 +0530 Subject: [PATCH] Boilerplate-II : Cleanup migrations & misc --- .editorconfig | 10 ++++ Gemfile | 3 +- Gemfile.lock | 32 +++++++----- app/channels/application_cable/channel.rb | 4 -- app/channels/application_cable/connection.rb | 4 -- ...s_controller.rb => comments_controller.rb} | 4 +- app/controllers/discussions_controller.rb | 18 +++++++ app/controllers/posts_controller.rb | 18 +++++++ app/controllers/tags_controller.rb | 3 -- app/models/category.rb | 1 + app/models/comment.rb | 3 ++ app/models/discussion.rb | 2 + app/models/post.rb | 2 + app/models/question.rb | 2 - app/serializers/comment_serializer.rb | 2 + app/serializers/discussion_serializer.rb | 2 + app/serializers/post_serializer.rb | 2 + app/serializers/question_serializer.rb | 2 - config/routes.rb | 10 ++-- .../20170608181811_create_categories.rb | 4 +- db/migrate/20170608183355_create_questions.rb | 19 ------- .../20170609163534_create_discussions.rb | 20 ++++++++ db/migrate/20170609164329_create_posts.rb | 17 +++++++ db/migrate/20170609170202_create_comments.rb | 12 +++++ db/schema.rb | 51 +++++++++++++++---- test/fixtures/comments.yml | 11 ++++ test/fixtures/discussions.yml | 11 ++++ test/fixtures/posts.yml | 11 ++++ test/models/comment_test.rb | 7 +++ test/models/discussion_test.rb | 7 +++ test/models/post_test.rb | 7 +++ 31 files changed, 233 insertions(+), 68 deletions(-) create mode 100644 .editorconfig delete mode 100644 app/channels/application_cable/channel.rb delete mode 100644 app/channels/application_cable/connection.rb rename app/controllers/{questions_controller.rb => comments_controller.rb} (64%) create mode 100644 app/controllers/discussions_controller.rb create mode 100644 app/controllers/posts_controller.rb create mode 100644 app/models/comment.rb create mode 100644 app/models/discussion.rb create mode 100644 app/models/post.rb delete mode 100644 app/models/question.rb create mode 100644 app/serializers/comment_serializer.rb create mode 100644 app/serializers/discussion_serializer.rb create mode 100644 app/serializers/post_serializer.rb delete mode 100644 app/serializers/question_serializer.rb delete mode 100644 db/migrate/20170608183355_create_questions.rb create mode 100644 db/migrate/20170609163534_create_discussions.rb create mode 100644 db/migrate/20170609164329_create_posts.rb create mode 100644 db/migrate/20170609170202_create_comments.rb create mode 100644 test/fixtures/comments.yml create mode 100644 test/fixtures/discussions.yml create mode 100644 test/fixtures/posts.yml create mode 100644 test/models/comment_test.rb create mode 100644 test/models/discussion_test.rb create mode 100644 test/models/post_test.rb diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..3106427 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,10 @@ +root = true + + +[*] +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true +indent_style = space +indent_size = 2 diff --git a/Gemfile b/Gemfile index 6185189..5a3e80d 100644 --- a/Gemfile +++ b/Gemfile @@ -9,8 +9,9 @@ gem 'rack-cors' gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby] gem 'active_model_serializers', '0.10.5' gem 'rubocop' -gem 'elasticsearch' gem 'dalli' +gem 'devise_token_auth' +gem 'ancestry' group :development, :test do gem 'byebug', platforms: [:mri, :mingw, :x64_mingw] diff --git a/Gemfile.lock b/Gemfile.lock index 2e0076c..ce75374 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -43,6 +43,8 @@ GEM i18n (~> 0.7) minitest (~> 5.1) tzinfo (~> 1.1) + ancestry (3.0.0) + activerecord (>= 3.2.0) arel (8.0.0) ast (2.3.0) bcrypt (3.1.11) @@ -52,17 +54,16 @@ GEM activesupport concurrent-ruby (1.0.5) dalli (2.7.6) - elasticsearch (2.0.2) - elasticsearch-api (= 2.0.2) - elasticsearch-transport (= 2.0.2) - elasticsearch-api (2.0.2) - multi_json - elasticsearch-transport (2.0.2) - faraday - multi_json + devise (4.3.0) + bcrypt (~> 3.0) + orm_adapter (~> 0.1) + railties (>= 4.1.0, < 5.2) + responders + warden (~> 1.2.3) + devise_token_auth (0.1.42) + devise (> 3.5.2, <= 4.3) + rails (< 6) erubi (1.6.0) - faraday (0.12.1) - multipart-post (>= 1.2, < 3) ffi (1.9.18) globalid (0.4.0) activesupport (>= 4.2.0) @@ -82,11 +83,10 @@ GEM mime-types-data (3.2016.0521) mini_portile2 (2.2.0) minitest (5.10.2) - multi_json (1.12.1) - multipart-post (2.0.0) nio4r (2.1.0) nokogiri (1.8.0) mini_portile2 (~> 2.2.0) + orm_adapter (0.5.0) parallel (1.11.2) parser (2.4.0.0) ast (~> 2.2) @@ -127,6 +127,9 @@ GEM rb-inotify (0.9.8) ffi (>= 0.5.0) redis (3.3.3) + responders (2.4.0) + actionpack (>= 4.2.0, < 5.3) + railties (>= 4.2.0, < 5.3) rubocop (0.49.1) parallel (~> 1.10) parser (>= 2.3.3.1, < 3.0) @@ -153,6 +156,8 @@ GEM tzinfo (1.2.3) thread_safe (~> 0.1) unicode-display_width (1.2.1) + warden (1.2.7) + rack (>= 1.0) websocket-driver (0.6.5) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.2) @@ -162,10 +167,11 @@ PLATFORMS DEPENDENCIES active_model_serializers (= 0.10.5) + ancestry bcrypt (~> 3.1.7) byebug dalli - elasticsearch + devise_token_auth listen (>= 3.0.5, < 3.2) pg (~> 0.18) puma (~> 3.7) diff --git a/app/channels/application_cable/channel.rb b/app/channels/application_cable/channel.rb deleted file mode 100644 index d672697..0000000 --- a/app/channels/application_cable/channel.rb +++ /dev/null @@ -1,4 +0,0 @@ -module ApplicationCable - class Channel < ActionCable::Channel::Base - end -end diff --git a/app/channels/application_cable/connection.rb b/app/channels/application_cable/connection.rb deleted file mode 100644 index 0ff5442..0000000 --- a/app/channels/application_cable/connection.rb +++ /dev/null @@ -1,4 +0,0 @@ -module ApplicationCable - class Connection < ActionCable::Connection::Base - end -end diff --git a/app/controllers/questions_controller.rb b/app/controllers/comments_controller.rb similarity index 64% rename from app/controllers/questions_controller.rb rename to app/controllers/comments_controller.rb index 1bdcb4a..fc2f3f7 100644 --- a/app/controllers/questions_controller.rb +++ b/app/controllers/comments_controller.rb @@ -1,4 +1,4 @@ -class QuestionsController < ApplicationController +class CommentsController < ApplicationController def create end @@ -15,4 +15,4 @@ def update def destroy end -end +end \ No newline at end of file diff --git a/app/controllers/discussions_controller.rb b/app/controllers/discussions_controller.rb new file mode 100644 index 0000000..8c096d9 --- /dev/null +++ b/app/controllers/discussions_controller.rb @@ -0,0 +1,18 @@ +class DiscussionsController < ApplicationController + + def create + end + + def index + end + + def show + end + + def update + end + + def destroy + end + +end \ No newline at end of file diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb new file mode 100644 index 0000000..6e5fae4 --- /dev/null +++ b/app/controllers/posts_controller.rb @@ -0,0 +1,18 @@ +class PostsController < ApplicationController + + def create + end + + def index + end + + def show + end + + def update + end + + def destroy + end + +end \ No newline at end of file diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb index af557b0..dfa4498 100644 --- a/app/controllers/tags_controller.rb +++ b/app/controllers/tags_controller.rb @@ -9,9 +9,6 @@ def index def show end - def update - end - def destroy end diff --git a/app/models/category.rb b/app/models/category.rb index 54cb6ae..e4e441b 100644 --- a/app/models/category.rb +++ b/app/models/category.rb @@ -1,2 +1,3 @@ class Category < ApplicationRecord + has_ancestry end diff --git a/app/models/comment.rb b/app/models/comment.rb new file mode 100644 index 0000000..61dfb93 --- /dev/null +++ b/app/models/comment.rb @@ -0,0 +1,3 @@ +class Comment < ApplicationRecord + has_ancestry +end diff --git a/app/models/discussion.rb b/app/models/discussion.rb new file mode 100644 index 0000000..0f69fb1 --- /dev/null +++ b/app/models/discussion.rb @@ -0,0 +1,2 @@ +class Discussion < ApplicationRecord +end diff --git a/app/models/post.rb b/app/models/post.rb new file mode 100644 index 0000000..b2a8b46 --- /dev/null +++ b/app/models/post.rb @@ -0,0 +1,2 @@ +class Post < ApplicationRecord +end diff --git a/app/models/question.rb b/app/models/question.rb deleted file mode 100644 index b77b6a9..0000000 --- a/app/models/question.rb +++ /dev/null @@ -1,2 +0,0 @@ -class Question < ApplicationRecord -end diff --git a/app/serializers/comment_serializer.rb b/app/serializers/comment_serializer.rb new file mode 100644 index 0000000..e90b041 --- /dev/null +++ b/app/serializers/comment_serializer.rb @@ -0,0 +1,2 @@ +class CommentSerializer < BaseSerializer +end \ No newline at end of file diff --git a/app/serializers/discussion_serializer.rb b/app/serializers/discussion_serializer.rb new file mode 100644 index 0000000..d62920e --- /dev/null +++ b/app/serializers/discussion_serializer.rb @@ -0,0 +1,2 @@ +class DiscussionSerializer < BaseSerializer +end diff --git a/app/serializers/post_serializer.rb b/app/serializers/post_serializer.rb new file mode 100644 index 0000000..211e196 --- /dev/null +++ b/app/serializers/post_serializer.rb @@ -0,0 +1,2 @@ +class PostSerializer < BaseSerializer +end diff --git a/app/serializers/question_serializer.rb b/app/serializers/question_serializer.rb deleted file mode 100644 index 923e6d4..0000000 --- a/app/serializers/question_serializer.rb +++ /dev/null @@ -1,2 +0,0 @@ -class QuestionSerializer < BaseSerializer -end diff --git a/config/routes.rb b/config/routes.rb index af27a52..cfc61e6 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,12 +1,12 @@ Rails.application.routes.draw do api_routes = proc do - resources :questions do - end - resources :categories do - end - resources :tag do + resources :discussions do + resources :posts end + resources :comments + resources :categories + resources :tags end scope '/api', defaults: { version: 'v1', format: 'json' }, constraints: { format: /(json|$^)/ } do diff --git a/db/migrate/20170608181811_create_categories.rb b/db/migrate/20170608181811_create_categories.rb index e250f2f..e2feb03 100644 --- a/db/migrate/20170608181811_create_categories.rb +++ b/db/migrate/20170608181811_create_categories.rb @@ -3,12 +3,12 @@ def change create_table :categories do |t| t.string :name, limit: 30, null: false t.text :description - t.integer :parent_id, null: false + t.string :ancestry t.references :user, index: true, foreign_key: true t.timestamps end add_index :categories, :name, unique: true - add_foreign_key :categories, :categories, column: :parent_id + add_index :categories, :ancestry end end diff --git a/db/migrate/20170608183355_create_questions.rb b/db/migrate/20170608183355_create_questions.rb deleted file mode 100644 index 675d00b..0000000 --- a/db/migrate/20170608183355_create_questions.rb +++ /dev/null @@ -1,19 +0,0 @@ -class CreateQuestions < ActiveRecord::Migration[5.1] - def change - create_table :questions do |t| - t.text :name, null: false - t.text :description, null: false - t.references :user, index: true, foreign_key: true - t.integer :upvote_count, default: 0 - t.integer :downvote_count, default: 0 - t.integer :answer_count, default: 0 - t.integer :follow_count, default: 0 - t.integer :views, default: 0 - t.float :score, default: 0 - t.boolean :deleted, default: false - t.boolean :spam, default: false - - t.timestamps - end - end -end diff --git a/db/migrate/20170609163534_create_discussions.rb b/db/migrate/20170609163534_create_discussions.rb new file mode 100644 index 0000000..33333fe --- /dev/null +++ b/db/migrate/20170609163534_create_discussions.rb @@ -0,0 +1,20 @@ +class CreateDiscussions < ActiveRecord::Migration[5.1] + def change + create_table :discussions do |t| + t.text :title, null: false + t.text :description, null: false + t.references :user, index: true, foreign_key: true + t.integer :upvotes_count, default: 0 + t.integer :downvotes_count, default: 0 + t.integer :posts_count, default: 0 + t.integer :comments_count, default: 0 + t.integer :follows_count, default: 0 + t.integer :views, default: 0 + t.float :score, default: 0 + t.boolean :pinned, default: false + t.boolean :deleted, default: false + t.boolean :spam, default: false + + t.timestamps end + end +end diff --git a/db/migrate/20170609164329_create_posts.rb b/db/migrate/20170609164329_create_posts.rb new file mode 100644 index 0000000..bd75384 --- /dev/null +++ b/db/migrate/20170609164329_create_posts.rb @@ -0,0 +1,17 @@ +class CreatePosts < ActiveRecord::Migration[5.1] + def change + create_table :posts do |t| + t.text :content, null: false + t.references :user, index: true, foreign_key: true + t.integer :upvotes_count, default: 0 + t.integer :downvotes_count, default: 0 + t.integer :comments_count, default: 0 + t.integer :views, default: 0 + t.float :score, default: 0 + t.boolean :deleted, default: false + t.boolean :spam, default: false + + t.timestamps + end + end +end diff --git a/db/migrate/20170609170202_create_comments.rb b/db/migrate/20170609170202_create_comments.rb new file mode 100644 index 0000000..48b2690 --- /dev/null +++ b/db/migrate/20170609170202_create_comments.rb @@ -0,0 +1,12 @@ +class CreateComments < ActiveRecord::Migration[5.1] + def change + create_table :comments do |t| + t.text :content, null: false + t.string :ancestry + t.references :user, index: true, foreign_key: true + + t.timestamps + end + add_index :comments, :ancestry + end +end diff --git a/db/schema.rb b/db/schema.rb index 6cb57fe..53f98fa 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20170608183355) do +ActiveRecord::Schema.define(version: 20170609170202) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -18,29 +18,57 @@ create_table "categories", force: :cascade do |t| t.string "name", limit: 30, null: false t.text "description" - t.integer "parent_id", null: false + t.string "ancestry" t.bigint "user_id" t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.index ["ancestry"], name: "index_categories_on_ancestry" t.index ["name"], name: "index_categories_on_name", unique: true t.index ["user_id"], name: "index_categories_on_user_id" end - create_table "questions", force: :cascade do |t| - t.text "name", null: false + create_table "comments", force: :cascade do |t| + t.text "content", null: false + t.string "ancestry" + t.bigint "user_id" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["ancestry"], name: "index_comments_on_ancestry" + t.index ["user_id"], name: "index_comments_on_user_id" + end + + create_table "discussions", force: :cascade do |t| + t.text "title", null: false t.text "description", null: false t.bigint "user_id" - t.integer "upvote_count", default: 0 - t.integer "downvote_count", default: 0 - t.integer "answer_count", default: 0 - t.integer "follow_count", default: 0 + t.integer "upvotes_count", default: 0 + t.integer "downvotes_count", default: 0 + t.integer "posts_count", default: 0 + t.integer "comments_count", default: 0 + t.integer "follows_count", default: 0 + t.integer "views", default: 0 + t.float "score", default: 0.0 + t.boolean "pinned", default: false + t.boolean "deleted", default: false + t.boolean "spam", default: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["user_id"], name: "index_discussions_on_user_id" + end + + create_table "posts", force: :cascade do |t| + t.text "content", null: false + t.bigint "user_id" + t.integer "upvotes_count", default: 0 + t.integer "downvotes_count", default: 0 + t.integer "comments_count", default: 0 t.integer "views", default: 0 t.float "score", default: 0.0 t.boolean "deleted", default: false t.boolean "spam", default: false t.datetime "created_at", null: false t.datetime "updated_at", null: false - t.index ["user_id"], name: "index_questions_on_user_id" + t.index ["user_id"], name: "index_posts_on_user_id" end create_table "tags", force: :cascade do |t| @@ -64,7 +92,8 @@ t.index ["email"], name: "index_users_on_email", unique: true end - add_foreign_key "categories", "categories", column: "parent_id" add_foreign_key "categories", "users" - add_foreign_key "questions", "users" + add_foreign_key "comments", "users" + add_foreign_key "discussions", "users" + add_foreign_key "posts", "users" end diff --git a/test/fixtures/comments.yml b/test/fixtures/comments.yml new file mode 100644 index 0000000..80aed36 --- /dev/null +++ b/test/fixtures/comments.yml @@ -0,0 +1,11 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +# This model initially had no columns defined. If you add columns to the +# model remove the '{}' from the fixture names and add the columns immediately +# below each fixture, per the syntax in the comments below +# +one: {} +# column: value +# +two: {} +# column: value diff --git a/test/fixtures/discussions.yml b/test/fixtures/discussions.yml new file mode 100644 index 0000000..80aed36 --- /dev/null +++ b/test/fixtures/discussions.yml @@ -0,0 +1,11 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +# This model initially had no columns defined. If you add columns to the +# model remove the '{}' from the fixture names and add the columns immediately +# below each fixture, per the syntax in the comments below +# +one: {} +# column: value +# +two: {} +# column: value diff --git a/test/fixtures/posts.yml b/test/fixtures/posts.yml new file mode 100644 index 0000000..80aed36 --- /dev/null +++ b/test/fixtures/posts.yml @@ -0,0 +1,11 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +# This model initially had no columns defined. If you add columns to the +# model remove the '{}' from the fixture names and add the columns immediately +# below each fixture, per the syntax in the comments below +# +one: {} +# column: value +# +two: {} +# column: value diff --git a/test/models/comment_test.rb b/test/models/comment_test.rb new file mode 100644 index 0000000..b6d6131 --- /dev/null +++ b/test/models/comment_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class CommentTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/models/discussion_test.rb b/test/models/discussion_test.rb new file mode 100644 index 0000000..8ee987f --- /dev/null +++ b/test/models/discussion_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class DiscussionTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/models/post_test.rb b/test/models/post_test.rb new file mode 100644 index 0000000..6d9d463 --- /dev/null +++ b/test/models/post_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class PostTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end