diff --git a/.gitignore b/.gitignore
index 451245a..11b4fb3 100644
--- a/.gitignore
+++ b/.gitignore
@@ -32,3 +32,22 @@
# Ignore master key for decrypting credentials and more.
/config/master.key
+
+# ---Vim stuff---
+# Swap
+[._]*.s[a-v][a-z]
+[._]*.sw[a-p]
+[._]s[a-rt-v][a-z]
+[._]ss[a-gi-z]
+[._]sw[a-p]
+
+# Session
+Session.vim
+
+# Temporary
+.netrwhist
+*~
+# Auto-generated tag files
+tags
+# Persistent undo
+[._]*.un~
diff --git a/Gemfile b/Gemfile
index cf797e1..0318878 100644
--- a/Gemfile
+++ b/Gemfile
@@ -63,3 +63,5 @@ end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
+
+gem 'annotate'
diff --git a/Gemfile.lock b/Gemfile.lock
index 5bc7a1a..893460f 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -44,6 +44,9 @@ GEM
tzinfo (~> 1.1)
addressable (2.5.2)
public_suffix (>= 2.0.2, < 4.0)
+ annotate (2.7.4)
+ activerecord (>= 3.2, < 6.0)
+ rake (>= 10.4, < 13.0)
archive-zip (0.11.0)
io-like (~> 0.3.0)
arel (9.0.0)
@@ -209,6 +212,7 @@ PLATFORMS
ruby
DEPENDENCIES
+ annotate
bootstrap
byebug
capybara (>= 2.15)
@@ -236,4 +240,4 @@ RUBY VERSION
ruby 2.5.1p57
BUNDLED WITH
- 1.16.6
+ 1.17.2
diff --git a/app/assets/javascripts/authors.coffee b/app/assets/javascripts/users.coffee
similarity index 100%
rename from app/assets/javascripts/authors.coffee
rename to app/assets/javascripts/users.coffee
diff --git a/app/assets/stylesheets/authors.scss b/app/assets/stylesheets/users.scss
similarity index 64%
rename from app/assets/stylesheets/authors.scss
rename to app/assets/stylesheets/users.scss
index 7adde77..1efc835 100644
--- a/app/assets/stylesheets/authors.scss
+++ b/app/assets/stylesheets/users.scss
@@ -1,3 +1,3 @@
-// Place all the styles related to the Authors controller here.
+// Place all the styles related to the users controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
diff --git a/app/controllers/authors_controller.rb b/app/controllers/authors_controller.rb
deleted file mode 100644
index 9d1a53f..0000000
--- a/app/controllers/authors_controller.rb
+++ /dev/null
@@ -1,74 +0,0 @@
-class AuthorsController < ApplicationController
- before_action :set_author, only: [:show, :edit, :update, :destroy]
-
- # GET /authors
- # GET /authors.json
- def index
- @authors = Author.all
- end
-
- # GET /authors/1
- # GET /authors/1.json
- def show
- end
-
- # GET /authors/new
- def new
- @author = Author.new
- end
-
- # GET /authors/1/edit
- def edit
- end
-
- # POST /authors
- # POST /authors.json
- def create
- @author = Author.new(author_params)
-
- respond_to do |format|
- if @author.save
- format.html { redirect_to @author, notice: 'Author was successfully created.' }
- format.json { render :show, status: :created, location: @author }
- else
- format.html { render :new }
- format.json { render json: @author.errors, status: :unprocessable_entity }
- end
- end
- end
-
- # PATCH/PUT /authors/1
- # PATCH/PUT /authors/1.json
- def update
- respond_to do |format|
- if @author.update(author_params)
- format.html { redirect_to @author, notice: 'Author was successfully updated.' }
- format.json { render :show, status: :ok, location: @author }
- else
- format.html { render :edit }
- format.json { render json: @author.errors, status: :unprocessable_entity }
- end
- end
- end
-
- # DELETE /authors/1
- # DELETE /authors/1.json
- def destroy
- @author.destroy
- respond_to do |format|
- format.html { redirect_to authors_url, notice: 'Author was successfully destroyed.' }
- format.json { head :no_content }
- end
- end
-
- private
- # Use callbacks to share common setup or constraints between actions.
- def set_author
- @author = Author.find(params[:id])
- end
-
- # Never trust parameters from the scary internet, only allow the white list through.
- def author_params
- params.require(:author).permit(:email, :alias, :date_of_birth)
- end
-end
diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb
index 42c6ba7..eeda414 100644
--- a/app/controllers/posts_controller.rb
+++ b/app/controllers/posts_controller.rb
@@ -69,6 +69,6 @@ def set_post
# Never trust parameters from the scary internet, only allow the white list through.
def post_params
- params.require(:post).permit(:author_id, :content, :published)
+ params.require(:post).permit(:author_id, :title, :sub_reddit_id, :content, :published)
end
end
diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb
new file mode 100644
index 0000000..c0f657f
--- /dev/null
+++ b/app/controllers/users_controller.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+class UsersController < ApplicationController
+ def index
+ @users = User.all
+ end
+
+ def show
+ @user = User.find_by( id: params[:id] )
+ end
+
+ def new
+ @user = User.new
+ end
+end
diff --git a/app/helpers/authors_helper.rb b/app/helpers/authors_helper.rb
deleted file mode 100644
index f22e1f9..0000000
--- a/app/helpers/authors_helper.rb
+++ /dev/null
@@ -1,2 +0,0 @@
-module AuthorsHelper
-end
diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb
new file mode 100644
index 0000000..2310a24
--- /dev/null
+++ b/app/helpers/users_helper.rb
@@ -0,0 +1,2 @@
+module UsersHelper
+end
diff --git a/app/models/author.rb b/app/models/author.rb
deleted file mode 100644
index e399202..0000000
--- a/app/models/author.rb
+++ /dev/null
@@ -1,2 +0,0 @@
-class Author < ApplicationRecord
-end
diff --git a/app/models/comment.rb b/app/models/comment.rb
index 1d79d25..97e455a 100644
--- a/app/models/comment.rb
+++ b/app/models/comment.rb
@@ -1,2 +1,18 @@
+# == Schema Information
+#
+# Table name: comments
+#
+# id :integer not null, primary key
+# post_id :integer
+# author_id :integer
+# content :text
+# created_at :datetime not null
+# updated_at :datetime not null
+#
+
class Comment < ApplicationRecord
+ belongs_to :post
+ belongs_to :author, class_name: 'User'
+
+ validates :content, presence: true, length: { minimum: 2 }
end
diff --git a/app/models/post.rb b/app/models/post.rb
index b2a8b46..885d34b 100644
--- a/app/models/post.rb
+++ b/app/models/post.rb
@@ -1,2 +1,24 @@
+# frozen_string_literal: true
+# == Schema Information
+#
+# Table name: posts
+#
+# id :integer not null, primary key
+# author_id :integer not null
+# content :text
+# published :boolean
+# created_at :datetime not null
+# updated_at :datetime not null
+# title :string default(""), not null
+# sub_reddit_id :integer
+#
+
class Post < ApplicationRecord
+ has_many :comments
+ has_many :upvotes
+ belongs_to :user
+ belongs_to :sub_reddits
+
+ validates :title, presence: true, uniqueness: true
+ validates :sub_reddit_id, presence: true
end
diff --git a/app/models/sub_reddit.rb b/app/models/sub_reddit.rb
new file mode 100644
index 0000000..4fb8d70
--- /dev/null
+++ b/app/models/sub_reddit.rb
@@ -0,0 +1,21 @@
+# == Schema Information
+#
+# Table name: sub_reddits
+#
+# id :integer not null, primary key
+# title :string not null
+# description :text not null
+# private :boolean default(FALSE), not null
+# created_at :datetime not null
+# updated_at :datetime not null
+# owner_id :integer
+#
+
+class SubReddit < ApplicationRecord
+ belongs_to :owner, class_name: 'User'
+ has_many :posts
+
+ validates :title, presence: true, uniqueness: true
+ validates :owner, presence: true
+ validates :description, presence: true
+end
diff --git a/app/models/upvote.rb b/app/models/upvote.rb
new file mode 100644
index 0000000..871287d
--- /dev/null
+++ b/app/models/upvote.rb
@@ -0,0 +1,20 @@
+# == Schema Information
+#
+# Table name: upvotes
+#
+# id :integer not null, primary key
+# creator :string not null
+# post :string not null
+# created_at :datetime not null
+# updated_at :datetime not null
+# creator_id :integer
+# post_id :integer
+#
+
+class Upvote < ApplicationRecord
+ belongs_to :user
+ belongs_to :post
+
+ validates :post, presence: true
+ validates :creator, uniqueness: true, presence: true
+end
diff --git a/app/models/user.rb b/app/models/user.rb
new file mode 100644
index 0000000..fa6f404
--- /dev/null
+++ b/app/models/user.rb
@@ -0,0 +1,19 @@
+# == Schema Information
+#
+# Table name: users
+#
+# id :integer not null, primary key
+# email :string not null
+# username :string not null
+# created_at :datetime not null
+# updated_at :datetime not null
+#
+
+class User < ApplicationRecord
+ has_many :comments, foreign_key: 'author_id'
+ has_many :sub_reddits
+ has_many :posts
+ has_many :upvotes
+
+ validates :email, uniqueness: { scope: :username } , presence: true
+end
diff --git a/app/views/authors/_author.json.jbuilder b/app/views/authors/_author.json.jbuilder
deleted file mode 100644
index 0b36388..0000000
--- a/app/views/authors/_author.json.jbuilder
+++ /dev/null
@@ -1,2 +0,0 @@
-json.extract! author, :id, :email, :alias, :date_of_birth, :created_at, :updated_at
-json.url author_url(author, format: :json)
diff --git a/app/views/authors/_form.html.erb b/app/views/authors/_form.html.erb
deleted file mode 100644
index e83779a..0000000
--- a/app/views/authors/_form.html.erb
+++ /dev/null
@@ -1,15 +0,0 @@
-
-<%= simple_form_for(@author) do |f| %>
- <%= f.error_notification %>
- <%= f.error_notification message: f.object.errors[:base].to_sentence if f.object.errors[:base].present? %>
-
-
- <%= f.input :email %>
- <%= f.input :alias %>
- <%= f.input :date_of_birth %>
-
-
-
- <%= f.button :submit %>
-
-<% end %>
diff --git a/app/views/authors/edit.html.erb b/app/views/authors/edit.html.erb
deleted file mode 100644
index 041b168..0000000
--- a/app/views/authors/edit.html.erb
+++ /dev/null
@@ -1,6 +0,0 @@
-Editing Author
-
-<%= render 'form', author: @author %>
-
-<%= link_to 'Show', @author %> |
-<%= link_to 'Back', authors_path %>
diff --git a/app/views/authors/index.html.erb b/app/views/authors/index.html.erb
deleted file mode 100644
index c1da269..0000000
--- a/app/views/authors/index.html.erb
+++ /dev/null
@@ -1,31 +0,0 @@
-<%= notice %>
-
-Authors
-
-
-
-
- | Email |
- Alias |
- Date of birth |
- |
-
-
-
-
- <% @authors.each do |author| %>
-
- | <%= author.email %> |
- <%= author.alias %> |
- <%= author.date_of_birth %> |
- <%= link_to 'Show', author %> |
- <%= link_to 'Edit', edit_author_path(author) %> |
- <%= link_to 'Destroy', author, method: :delete, data: { confirm: 'Are you sure?' } %> |
-
- <% end %>
-
-
-
-
-
-<%= link_to 'New Author', new_author_path %>
diff --git a/app/views/authors/index.json.jbuilder b/app/views/authors/index.json.jbuilder
deleted file mode 100644
index 17aa0f4..0000000
--- a/app/views/authors/index.json.jbuilder
+++ /dev/null
@@ -1 +0,0 @@
-json.array! @authors, partial: 'authors/author', as: :author
diff --git a/app/views/authors/new.html.erb b/app/views/authors/new.html.erb
deleted file mode 100644
index 05a813d..0000000
--- a/app/views/authors/new.html.erb
+++ /dev/null
@@ -1,5 +0,0 @@
-New Author
-
-<%= render 'form', author: @author %>
-
-<%= link_to 'Back', authors_path %>
diff --git a/app/views/authors/show.html.erb b/app/views/authors/show.html.erb
deleted file mode 100644
index bc9f7bd..0000000
--- a/app/views/authors/show.html.erb
+++ /dev/null
@@ -1,19 +0,0 @@
-<%= notice %>
-
-
- Email:
- <%= @author.email %>
-
-
-
- Alias:
- <%= @author.alias %>
-
-
-
- Date of birth:
- <%= @author.date_of_birth %>
-
-
-<%= link_to 'Edit', edit_author_path(@author) %> |
-<%= link_to 'Back', authors_path %>
diff --git a/app/views/authors/show.json.jbuilder b/app/views/authors/show.json.jbuilder
deleted file mode 100644
index 2fadc05..0000000
--- a/app/views/authors/show.json.jbuilder
+++ /dev/null
@@ -1 +0,0 @@
-json.partial! "authors/author", author: @author
diff --git a/app/views/comments/index.html.erb b/app/views/comments/index.html.erb
index cedf4e1..9376dd2 100644
--- a/app/views/comments/index.html.erb
+++ b/app/views/comments/index.html.erb
@@ -1,13 +1,17 @@
<%= notice %>
Comments
-
+<% @comments.each do |comment| %>
+
+<% end %>
| Post |
Author |
Content |
+ Created at: |
+ Updated at: |
|
@@ -18,6 +22,8 @@
<%= comment.post_id %> |
<%= comment.author_id %> |
<%= comment.content %> |
+ <%= comment.created_at %> |
+ <%= comment.updated_at %> |
<%= link_to 'Show', comment %> |
<%= link_to 'Edit', edit_comment_path(comment) %> |
<%= link_to 'Destroy', comment, method: :delete, data: { confirm: 'Are you sure?' } %> |
diff --git a/app/views/comments/new.html.erb b/app/views/comments/new.html.erb
index 0dd76fc..f8b43b6 100644
--- a/app/views/comments/new.html.erb
+++ b/app/views/comments/new.html.erb
@@ -3,5 +3,3 @@
<%= render 'form', comment: @comment %>
<%= link_to 'Back', comments_path %>
-
-Solve captcha!
diff --git a/app/views/comments/show.html.erb b/app/views/comments/show.html.erb
index d63d894..0926bf3 100644
--- a/app/views/comments/show.html.erb
+++ b/app/views/comments/show.html.erb
@@ -15,5 +15,15 @@
<%= @comment.content %>
+
+ Created at:
+ <%= @comment.created_at %>
+
+
+
+ Updated at:
+ <%= @comment.updated_at %>
+
+
<%= link_to 'Edit', edit_comment_path(@comment) %> |
<%= link_to 'Back', comments_path %>
diff --git a/app/views/posts/index.html.erb b/app/views/posts/index.html.erb
index 5fbeac6..d4eb0c1 100644
--- a/app/views/posts/index.html.erb
+++ b/app/views/posts/index.html.erb
@@ -8,6 +8,8 @@
Author |
Content |
Published |
+ Title |
+ Subredditid |
|
@@ -17,7 +19,9 @@
| <%= post.author_id %> |
<%= post.content %> |
- <%= post.published %> |
+ <%= post.published %> | i
+ <%= post.title %> |
+ <%= post.sub_reddit_id %> |
<%= link_to 'Show', post %> |
<%= link_to 'Edit', edit_post_path(post) %> |
<%= link_to 'Destroy', post, method: :delete, data: { confirm: 'Are you sure?' } %> |
diff --git a/app/views/posts/new.html.erb b/app/views/posts/new.html.erb
index fb1e2a1..058ea47 100644
--- a/app/views/posts/new.html.erb
+++ b/app/views/posts/new.html.erb
@@ -1,5 +1,14 @@
New Post
+Not working
+<%= simple_form_for Post.new do |f| %>
+ <%= f.input :id %>
+ <%= f.input :author_id %>
+ <%= f.input :sub_reddit_id %>
+ <%= f.input :title %>
+ <%= f.input :content %>
+ <%= f.input :published %>
-<%= render 'form', post: @post %>
+ <%= f.button :button %>
+<% end %>
<%= link_to 'Back', posts_path %>
diff --git a/app/views/posts/show.html.erb b/app/views/posts/show.html.erb
index 11bef4f..ba188a1 100644
--- a/app/views/posts/show.html.erb
+++ b/app/views/posts/show.html.erb
@@ -15,6 +15,17 @@
<%= @post.published %>
+
+ Title:
+ <%= @post.title %>
+
+
+
+ Subreddit:
+ <%= @post.sub_reddit_id %>
+
+
+
<%= link_to 'Edit', edit_post_path(@post) %> |
<%= link_to 'Back', posts_path %>
diff --git a/app/views/users/index.html.erb b/app/views/users/index.html.erb
new file mode 100644
index 0000000..75c1fd4
--- /dev/null
+++ b/app/views/users/index.html.erb
@@ -0,0 +1,25 @@
+Users
+
+
+
+ | User ID |
+ Email |
+ Username |
+ Created at |
+ Updated at |
+ |
+
+
+
+
+ <% @users.each do |user| %>
+
+ | <%= user.id %>
+ | <%= user.email %> |
+ <%= user.username %> | i
+ <%= user.created_at %>
+ | <%= user.updated_at %>
+ |
+ <% end %>
+
+ <
diff --git a/app/views/users/new.html.erb b/app/views/users/new.html.erb
new file mode 100644
index 0000000..36fa751
--- /dev/null
+++ b/app/views/users/new.html.erb
@@ -0,0 +1,9 @@
+New user
+Currently not working, just a sketch
+
+<%= simple_form_for User.new do |f| %>
+ <%= f.input :email %>
+ <%= f.input :username %>
+ <%= f.button :button %>
+
+<% end %>
diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb
new file mode 100644
index 0000000..d33e835
--- /dev/null
+++ b/app/views/users/show.html.erb
@@ -0,0 +1,24 @@
+
+ User:
+ <%= @user.id %>
+
+
+
+ Email:
+ <%= @user.email %>
+
+
+
+ Username:
+ <%= @user.username %>
+
+
+
+ Created at:
+ <%= @user.created_at %>
+
+
+
+ Updated at:
+ <%= @user.updated_at %>
+
diff --git a/config/routes.rb b/config/routes.rb
index a26c5ff..994b795 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -4,6 +4,10 @@
resources :comments
resources :posts
resources :authors
-
+
resources :polynomials, only: [:show, :new, :create]
+
+ get 'users', to: 'users#index'
+ get 'users/:id', to: 'users#show'
+ get 'users/new', to: 'users#new'
end
diff --git a/db/migrate/20181223172954_create_sub_reddits.rb b/db/migrate/20181223172954_create_sub_reddits.rb
new file mode 100644
index 0000000..55c7acd
--- /dev/null
+++ b/db/migrate/20181223172954_create_sub_reddits.rb
@@ -0,0 +1,12 @@
+class CreateSubReddits < ActiveRecord::Migration[5.2]
+ def change
+ create_table :sub_reddits do |t|
+ t.string :title, null: false
+ t.text :description, null: false
+ t.boolean :private, null: false, default: false
+ t.integer :owner_id, null: false
+
+ t.timestamps
+ end
+ end
+end
diff --git a/db/migrate/20181223180058_change_posts.rb b/db/migrate/20181223180058_change_posts.rb
new file mode 100644
index 0000000..10a1dcb
--- /dev/null
+++ b/db/migrate/20181223180058_change_posts.rb
@@ -0,0 +1,4 @@
+class ChangePosts < ActiveRecord::Migration[5.2]
+ def change
+ end
+end
diff --git a/db/migrate/20181223180730_add_sub_reddit_id_to_posts.rb b/db/migrate/20181223180730_add_sub_reddit_id_to_posts.rb
new file mode 100644
index 0000000..a202daf
--- /dev/null
+++ b/db/migrate/20181223180730_add_sub_reddit_id_to_posts.rb
@@ -0,0 +1,5 @@
+class AddSubRedditIdToPosts < ActiveRecord::Migration[5.2]
+ def change
+ add_column :posts, :sub_reddit_id, :integer
+ end
+end
diff --git a/db/migrate/20181223181011_add_title_to_posts.rb b/db/migrate/20181223181011_add_title_to_posts.rb
new file mode 100644
index 0000000..bedeafa
--- /dev/null
+++ b/db/migrate/20181223181011_add_title_to_posts.rb
@@ -0,0 +1,5 @@
+class AddTitleToPosts < ActiveRecord::Migration[5.2]
+ def change
+ add_column :posts, :title, :string
+ end
+end
diff --git a/db/migrate/20181223181438_drop_authors.rb b/db/migrate/20181223181438_drop_authors.rb
new file mode 100644
index 0000000..700501a
--- /dev/null
+++ b/db/migrate/20181223181438_drop_authors.rb
@@ -0,0 +1,15 @@
+class DropAuthors < ActiveRecord::Migration[5.2]
+ def up
+ drop_table :authors
+ end
+
+ def down
+ create_table :authors do |t|
+ t.string :email
+ t.string :alias
+ t.datetime :date_of_birth
+
+ t.timestamps
+ end
+ end
+end
diff --git a/db/migrate/20181223181746_create_users.rb b/db/migrate/20181223181746_create_users.rb
new file mode 100644
index 0000000..9ea2073
--- /dev/null
+++ b/db/migrate/20181223181746_create_users.rb
@@ -0,0 +1,10 @@
+class CreateUsers < ActiveRecord::Migration[5.2]
+ def change
+ create_table :users do |t|
+ t.string :email, null: false
+ t.string :username, null: false
+
+ t.timestamps
+ end
+ end
+end
diff --git a/db/migrate/20181223185329_convert_comment_association_fields_to_references.rb b/db/migrate/20181223185329_convert_comment_association_fields_to_references.rb
new file mode 100644
index 0000000..44f5cc4
--- /dev/null
+++ b/db/migrate/20181223185329_convert_comment_association_fields_to_references.rb
@@ -0,0 +1,13 @@
+# frozen_string_literal: true
+
+class ConvertCommentAssociationFieldsToReferences < ActiveRecord::Migration[5.2]
+ def change
+ remove_column :comments, :post_id
+ add_reference :comments, :post,
+ foreign_key: { on_delete: :cascade }
+
+ remove_column :comments, :author_id
+ add_reference :comments, :author,
+ foreign_key: { to_table: :users, on_delete: :cascade }
+ end
+end
diff --git a/db/migrate/20181223192850_add_posts_title_index.rb b/db/migrate/20181223192850_add_posts_title_index.rb
new file mode 100644
index 0000000..0600886
--- /dev/null
+++ b/db/migrate/20181223192850_add_posts_title_index.rb
@@ -0,0 +1,5 @@
+class AddPostsTitleIndex < ActiveRecord::Migration[5.2]
+ def change
+ add_index :posts, :title
+ end
+end
diff --git a/db/migrate/20181223192922_add_users_email_and_username_unique_index.rb b/db/migrate/20181223192922_add_users_email_and_username_unique_index.rb
new file mode 100644
index 0000000..7e5b9f2
--- /dev/null
+++ b/db/migrate/20181223192922_add_users_email_and_username_unique_index.rb
@@ -0,0 +1,5 @@
+class AddUsersEmailAndUsernameUniqueIndex < ActiveRecord::Migration[5.2]
+ def change
+ add_index :users, [ :email, :username ], unique: true
+ end
+end
diff --git a/db/migrate/20181224193704_conver_subreddit_owner_id_to_user_reference.rb b/db/migrate/20181224193704_conver_subreddit_owner_id_to_user_reference.rb
new file mode 100644
index 0000000..77e91e0
--- /dev/null
+++ b/db/migrate/20181224193704_conver_subreddit_owner_id_to_user_reference.rb
@@ -0,0 +1,9 @@
+# frozen_string_literal: true
+
+class ConverSubredditOwnerIdToUserReference < ActiveRecord::Migration[5.2]
+ def change
+ remove_column :sub_reddits, :owner_id
+ add_reference :sub_reddits, :owner,
+ foreign_key: { to_table: :users, on_delete: :cascade }
+ end
+end
diff --git a/db/migrate/20181224195359_change_title_column_in_post.rb b/db/migrate/20181224195359_change_title_column_in_post.rb
new file mode 100644
index 0000000..e1da7bd
--- /dev/null
+++ b/db/migrate/20181224195359_change_title_column_in_post.rb
@@ -0,0 +1,8 @@
+class ChangeTitleColumnInPost < ActiveRecord::Migration[5.2]
+ def change
+ # I believe I had to first remove this column because I had nulls in old column
+ remove_column :posts, :title
+ add_column :posts, :title, :string, null: false, default: ""
+ add_index :posts, :title, unique: true
+ end
+end
diff --git a/db/migrate/20181224200032_change_author_id_in_post.rb b/db/migrate/20181224200032_change_author_id_in_post.rb
new file mode 100644
index 0000000..ccc40a3
--- /dev/null
+++ b/db/migrate/20181224200032_change_author_id_in_post.rb
@@ -0,0 +1,5 @@
+class ChangeAuthorIdInPost < ActiveRecord::Migration[5.2]
+ def change
+ change_column :posts, :author_id, :integer, null: false
+ end
+end
diff --git a/db/migrate/20181224201047_add_sub_reddit_id_column_in_posts.rb b/db/migrate/20181224201047_add_sub_reddit_id_column_in_posts.rb
new file mode 100644
index 0000000..c6794a8
--- /dev/null
+++ b/db/migrate/20181224201047_add_sub_reddit_id_column_in_posts.rb
@@ -0,0 +1,9 @@
+# frozen_string_literal: true
+
+class AddSubRedditIdColumnInPosts < ActiveRecord::Migration[5.2]
+ def change
+ remove_column :posts, :sub_reddit_id
+ add_reference :posts, :sub_reddit,
+ foreign_key: { to_table: :sub_reddits, on_delete: :cascade }
+ end
+end
diff --git a/db/migrate/20181224203824_create_upvotes.rb b/db/migrate/20181224203824_create_upvotes.rb
new file mode 100644
index 0000000..8474bf0
--- /dev/null
+++ b/db/migrate/20181224203824_create_upvotes.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+class CreateUpvotes < ActiveRecord::Migration[5.2]
+ def change
+ create_table :upvotes do |t|
+ t.string :creator, null: false
+ t.string :post, null: false
+
+ t.timestamps
+ end
+ add_reference :upvotes, :creator,
+ foreign_key: { to_table: :users, on_delete: :cascade }
+ add_reference :upvotes, :post,
+ foreign_key: { to_table: :posts, on_delete: :cascade }
+ add_index :upvotes, :creator, unique: true
+ end
+end
diff --git a/db/migrate/20181224210219_add_missing_indices.rb b/db/migrate/20181224210219_add_missing_indices.rb
new file mode 100644
index 0000000..e554d73
--- /dev/null
+++ b/db/migrate/20181224210219_add_missing_indices.rb
@@ -0,0 +1,5 @@
+class AddMissingIndices < ActiveRecord::Migration[5.2]
+ def change
+ add_index :sub_reddits, :title, unique: true
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index e4e1ebb..b518f5c 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -10,30 +10,59 @@
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema.define(version: 2018_10_26_093242) do
-
- create_table "authors", force: :cascade do |t|
- t.string "email"
- t.string "alias"
- t.datetime "date_of_birth"
- t.datetime "created_at", null: false
- t.datetime "updated_at", null: false
- end
+ActiveRecord::Schema.define(version: 2018_12_24_210219) do
create_table "comments", force: :cascade do |t|
- t.integer "post_id"
- t.integer "author_id"
t.text "content"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
+ t.integer "post_id"
+ t.integer "author_id"
+ t.index ["author_id"], name: "index_comments_on_author_id"
+ t.index ["post_id"], name: "index_comments_on_post_id"
end
create_table "posts", force: :cascade do |t|
- t.integer "author_id"
+ t.integer "author_id", null: false
t.text "content"
t.boolean "published"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
+ t.string "title", default: "", null: false
+ t.integer "sub_reddit_id"
+ t.index ["sub_reddit_id"], name: "index_posts_on_sub_reddit_id"
+ t.index ["title"], name: "index_posts_on_title", unique: true
+ end
+
+ create_table "sub_reddits", force: :cascade do |t|
+ t.string "title", null: false
+ t.text "description", null: false
+ t.boolean "private", default: false, null: false
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
+ t.integer "owner_id"
+ t.index ["owner_id"], name: "index_sub_reddits_on_owner_id"
+ t.index ["title"], name: "index_sub_reddits_on_title", unique: true
+ end
+
+ create_table "upvotes", force: :cascade do |t|
+ t.string "creator", null: false
+ t.string "post", null: false
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
+ t.integer "creator_id"
+ t.integer "post_id"
+ t.index ["creator"], name: "index_upvotes_on_creator", unique: true
+ t.index ["creator_id"], name: "index_upvotes_on_creator_id"
+ t.index ["post_id"], name: "index_upvotes_on_post_id"
+ end
+
+ create_table "users", force: :cascade do |t|
+ t.string "email", null: false
+ t.string "username", null: false
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
+ t.index ["email", "username"], name: "index_users_on_email_and_username", unique: true
end
end
diff --git a/test/controllers/authors_controller_test.rb b/test/controllers/authors_controller_test.rb
deleted file mode 100644
index ae8f867..0000000
--- a/test/controllers/authors_controller_test.rb
+++ /dev/null
@@ -1,48 +0,0 @@
-require 'test_helper'
-
-class AuthorsControllerTest < ActionDispatch::IntegrationTest
- setup do
- @author = authors(:one)
- end
-
- test "should get index" do
- get authors_url
- assert_response :success
- end
-
- test "should get new" do
- get new_author_url
- assert_response :success
- end
-
- test "should create author" do
- assert_difference('Author.count') do
- post authors_url, params: { author: { alias: @author.alias, date_of_birth: @author.date_of_birth, email: @author.email } }
- end
-
- assert_redirected_to author_url(Author.last)
- end
-
- test "should show author" do
- get author_url(@author)
- assert_response :success
- end
-
- test "should get edit" do
- get edit_author_url(@author)
- assert_response :success
- end
-
- test "should update author" do
- patch author_url(@author), params: { author: { alias: @author.alias, date_of_birth: @author.date_of_birth, email: @author.email } }
- assert_redirected_to author_url(@author)
- end
-
- test "should destroy author" do
- assert_difference('Author.count', -1) do
- delete author_url(@author)
- end
-
- assert_redirected_to authors_url
- end
-end
diff --git a/test/controllers/users_controller_test.rb b/test/controllers/users_controller_test.rb
new file mode 100644
index 0000000..acf708a
--- /dev/null
+++ b/test/controllers/users_controller_test.rb
@@ -0,0 +1,9 @@
+require 'test_helper'
+
+class UsersControllerTest < ActionDispatch::IntegrationTest
+ test "should get show" do
+ get users_show_url
+ assert_response :success
+ end
+
+end
diff --git a/test/fixtures/authors.yml b/test/fixtures/authors.yml
index 91f5591..675af52 100644
--- a/test/fixtures/authors.yml
+++ b/test/fixtures/authors.yml
@@ -1,3 +1,15 @@
+# == Schema Information
+#
+# Table name: authors
+#
+# id :integer not null, primary key
+# email :string
+# alias :string
+# date_of_birth :datetime
+# created_at :datetime not null
+# updated_at :datetime not null
+#
+
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
diff --git a/test/fixtures/comments.yml b/test/fixtures/comments.yml
index 4c83ced..1e3e2aa 100644
--- a/test/fixtures/comments.yml
+++ b/test/fixtures/comments.yml
@@ -1,3 +1,15 @@
+# == Schema Information
+#
+# Table name: comments
+#
+# id :integer not null, primary key
+# post_id :integer
+# author_id :integer
+# content :text
+# created_at :datetime not null
+# updated_at :datetime not null
+#
+
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
diff --git a/test/fixtures/posts.yml b/test/fixtures/posts.yml
index bbf0d34..a5b7f19 100644
--- a/test/fixtures/posts.yml
+++ b/test/fixtures/posts.yml
@@ -1,3 +1,17 @@
+# == Schema Information
+#
+# Table name: posts
+#
+# id :integer not null, primary key
+# author_id :integer not null
+# content :text
+# published :boolean
+# created_at :datetime not null
+# updated_at :datetime not null
+# title :string default(""), not null
+# sub_reddit_id :integer
+#
+
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
diff --git a/test/fixtures/sub_reddits.yml b/test/fixtures/sub_reddits.yml
new file mode 100644
index 0000000..69e888a
--- /dev/null
+++ b/test/fixtures/sub_reddits.yml
@@ -0,0 +1,26 @@
+# == Schema Information
+#
+# Table name: sub_reddits
+#
+# id :integer not null, primary key
+# title :string not null
+# description :text not null
+# private :boolean default(FALSE), not null
+# created_at :datetime not null
+# updated_at :datetime not null
+# owner_id :integer
+#
+
+# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
+
+one:
+ title: MyString
+ description: MyText
+ private: false
+ owner_id: 1
+
+two:
+ title: MyString
+ description: MyText
+ private: false
+ owner_id: 1
diff --git a/test/fixtures/upvotes.yml b/test/fixtures/upvotes.yml
new file mode 100644
index 0000000..05ed48c
--- /dev/null
+++ b/test/fixtures/upvotes.yml
@@ -0,0 +1,22 @@
+# == Schema Information
+#
+# Table name: upvotes
+#
+# id :integer not null, primary key
+# creator :string not null
+# post :string not null
+# created_at :datetime not null
+# updated_at :datetime not null
+# creator_id :integer
+# post_id :integer
+#
+
+# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
+
+one:
+ creator: MyString
+ post: MyString
+
+two:
+ creator: MyString
+ post: MyString
diff --git a/test/fixtures/users.yml b/test/fixtures/users.yml
new file mode 100644
index 0000000..343c7e8
--- /dev/null
+++ b/test/fixtures/users.yml
@@ -0,0 +1,20 @@
+# == Schema Information
+#
+# Table name: users
+#
+# id :integer not null, primary key
+# email :string not null
+# username :string not null
+# created_at :datetime not null
+# updated_at :datetime not null
+#
+
+# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
+
+one:
+ email: MyString
+ username: MyString
+
+two:
+ email: MyString
+ username: MyString
diff --git a/test/models/author_test.rb b/test/models/author_test.rb
index 92b5e1f..3827faf 100644
--- a/test/models/author_test.rb
+++ b/test/models/author_test.rb
@@ -1,3 +1,15 @@
+# == Schema Information
+#
+# Table name: authors
+#
+# id :integer not null, primary key
+# email :string
+# alias :string
+# date_of_birth :datetime
+# created_at :datetime not null
+# updated_at :datetime not null
+#
+
require 'test_helper'
class AuthorTest < ActiveSupport::TestCase
diff --git a/test/models/comment_test.rb b/test/models/comment_test.rb
index b6d6131..886eb68 100644
--- a/test/models/comment_test.rb
+++ b/test/models/comment_test.rb
@@ -1,3 +1,15 @@
+# == Schema Information
+#
+# Table name: comments
+#
+# id :integer not null, primary key
+# post_id :integer
+# author_id :integer
+# content :text
+# created_at :datetime not null
+# updated_at :datetime not null
+#
+
require 'test_helper'
class CommentTest < ActiveSupport::TestCase
diff --git a/test/models/post_test.rb b/test/models/post_test.rb
index 6d9d463..9bc1365 100644
--- a/test/models/post_test.rb
+++ b/test/models/post_test.rb
@@ -1,3 +1,17 @@
+# == Schema Information
+#
+# Table name: posts
+#
+# id :integer not null, primary key
+# author_id :integer not null
+# content :text
+# published :boolean
+# created_at :datetime not null
+# updated_at :datetime not null
+# title :string default(""), not null
+# sub_reddit_id :integer
+#
+
require 'test_helper'
class PostTest < ActiveSupport::TestCase
diff --git a/test/models/sub_reddit_test.rb b/test/models/sub_reddit_test.rb
new file mode 100644
index 0000000..4bd3438
--- /dev/null
+++ b/test/models/sub_reddit_test.rb
@@ -0,0 +1,20 @@
+# == Schema Information
+#
+# Table name: sub_reddits
+#
+# id :integer not null, primary key
+# title :string not null
+# description :text not null
+# private :boolean default(FALSE), not null
+# created_at :datetime not null
+# updated_at :datetime not null
+# owner_id :integer
+#
+
+require 'test_helper'
+
+class SubRedditTest < ActiveSupport::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end
diff --git a/test/models/upvote_test.rb b/test/models/upvote_test.rb
new file mode 100644
index 0000000..b0c0ac3
--- /dev/null
+++ b/test/models/upvote_test.rb
@@ -0,0 +1,20 @@
+# == Schema Information
+#
+# Table name: upvotes
+#
+# id :integer not null, primary key
+# creator :string not null
+# post :string not null
+# created_at :datetime not null
+# updated_at :datetime not null
+# creator_id :integer
+# post_id :integer
+#
+
+require 'test_helper'
+
+class UpvoteTest < ActiveSupport::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end
diff --git a/test/models/user_test.rb b/test/models/user_test.rb
new file mode 100644
index 0000000..e38639a
--- /dev/null
+++ b/test/models/user_test.rb
@@ -0,0 +1,18 @@
+# == Schema Information
+#
+# Table name: users
+#
+# id :integer not null, primary key
+# email :string not null
+# username :string not null
+# created_at :datetime not null
+# updated_at :datetime not null
+#
+
+require 'test_helper'
+
+class UserTest < ActiveSupport::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end
diff --git a/tic-tac-toe.rb b/tic-tac-toe.rb
index b9cc19b..d1bc5f1 100644
--- a/tic-tac-toe.rb
+++ b/tic-tac-toe.rb
@@ -86,4 +86,4 @@ def player_turn(player_name, playing_board) #main function
print"Draw!"
exit(1)
end
-end
\ No newline at end of file
+end