From ae727acab29709d0b450ac398f3c6fce41df1c13 Mon Sep 17 00:00:00 2001 From: MrPranklin Date: Sun, 23 Dec 2018 17:07:33 +0100 Subject: [PATCH 01/25] Initial commit to branch --- .gitignore | 19 +++++++++++++++++++ .tic-tac-toe.rb.swp | Bin 12288 -> 0 bytes tic-tac-toe.rb | 2 +- 3 files changed, 20 insertions(+), 1 deletion(-) delete mode 100644 .tic-tac-toe.rb.swp 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/.tic-tac-toe.rb.swp b/.tic-tac-toe.rb.swp deleted file mode 100644 index b3e1b869d79879724a1478a508369f651d3f76b3..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 12288 zcmeI1&u<$=6vw9(lpm!~1vvBodbQQsX&wJaC=H0TAj*$|P%2f0BFBox_Sl|eJ!^Jn zW6~-VBtQbx148@(2nmS`NT62qz<~n?P9TA}aOwdGxNzgZiSO*L*IwII8i`A#S?S}o z-_Fjy_kC~PY?ONW<}Twke`Z#`npxSkoMWsd9oaMXZH{o<-1#$Sw;A_F zIIwg|`0Lv3mAs(7IoEN!qVIa^B`q6sngdr9z4|sY*~?Y|tH6#F2y|<1ao@Rx`AWFd zvzdc*|IE1^O<@OH1*`&A0jq#jz$#!BunJfOtOB>T0=l=0T|x-E<1k*0&%4IX@lSiQ z3RnfK0#*U5fK|XMU=^?mSOu&CRspMkRp1s>fHxT{-Nx9Lx5Ih-|9|lJ|MmMA`w4st zJ^~+rEzk#Rpalfj5B7lH?q%#Va2dP}o&ihXI9LGlU@!Q0A7ih9Rq*pYjC}{Lfp0(w zJOn=6%h)AQ1bJ`(JO~~DpWn^c$KWmSCO8kC2Ty@AI06oXL*R$I7`p;K0b5`hya-+Z zyTR{wGWITb2lzmOW$-Zg`wqtb1b=|5;0m}5&VuK_li(OAfurCE_;C+opMv+nd*A^0 z3%Xthzk=_c$#mqZB zvVLFcMo0Km7rHNmqTF(hxN1`Fe2xO8r9-+SD0~n}pIU+AFgD^5Em0Ns6wD2^@IvC4 zxl}C|Dh1*9C6X2$fS)wpzjy zN|UR^<76Bns(XU3qn`3`Yy$!{#~+#GW;UwC#3SUQE%d5Xy+C8CxT5fFbcB+~eO$hj zxsgCd>*9)fr33d&Rc^Wg^*J2XE@5_5*Mz7isalzPtQLh4#vGM)sO->Z))cK9t&DLM zp~lFO?Q*G5yegD`P#^FHnLjJ^ghR&H?8PMZEhDcfgT$ArtX0=)P;I0*FlG&w;=y_OPXGoY>1W^OtywUPMAGEWqD#LeDg`~G;z<# zV^8vD@eIEah@^=PHYd|YlTC}VeuFE#pctV{SOxTtK{t`wyt^dvnfDvG2y07X2Z*Eg zxN3_*|BMA%QKs_`bPJ7{$TqYl8)6k(M!L|D&9&MV)#B~h__j7oB1O&)4dM1?-VLYk Ge*Xc2r;RTF 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 From 78b7a4d8c7024a976cd7b80d3ce7057854fbe9ac Mon Sep 17 00:00:00 2001 From: MrPranklin Date: Sun, 23 Dec 2018 17:30:43 +0100 Subject: [PATCH 02/25] Installed annotate gem, annotated --- Gemfile | 2 ++ Gemfile.lock | 6 +++++- app/controllers/polynomials_controller.rb | 6 +----- app/models/author.rb | 12 ++++++++++++ app/models/comment.rb | 12 ++++++++++++ app/models/post.rb | 12 ++++++++++++ test/fixtures/authors.yml | 12 ++++++++++++ test/fixtures/comments.yml | 12 ++++++++++++ test/fixtures/posts.yml | 12 ++++++++++++ test/models/author_test.rb | 12 ++++++++++++ test/models/comment_test.rb | 12 ++++++++++++ test/models/post_test.rb | 12 ++++++++++++ 12 files changed, 116 insertions(+), 6 deletions(-) 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/controllers/polynomials_controller.rb b/app/controllers/polynomials_controller.rb index c11d7cf..8f17779 100644 --- a/app/controllers/polynomials_controller.rb +++ b/app/controllers/polynomials_controller.rb @@ -36,8 +36,4 @@ def solve(a, b, c, d) [first - second, first + second] end -<<<<<<< HEAD - -======= ->>>>>>> ac4ea3849ea9d96e14e969ae8b984887d1df1f62 -end \ No newline at end of file +end diff --git a/app/models/author.rb b/app/models/author.rb index e399202..02ea84b 100644 --- a/app/models/author.rb +++ b/app/models/author.rb @@ -1,2 +1,14 @@ +# == 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 +# + class Author < ApplicationRecord end diff --git a/app/models/comment.rb b/app/models/comment.rb index 1d79d25..8127199 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -1,2 +1,14 @@ +# == 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 end diff --git a/app/models/post.rb b/app/models/post.rb index b2a8b46..ecfd584 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -1,2 +1,14 @@ +# == Schema Information +# +# Table name: posts +# +# id :integer not null, primary key +# author_id :integer +# content :text +# published :boolean +# created_at :datetime not null +# updated_at :datetime not null +# + class Post < ApplicationRecord 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..e19100f 100644 --- a/test/fixtures/posts.yml +++ b/test/fixtures/posts.yml @@ -1,3 +1,15 @@ +# == Schema Information +# +# Table name: posts +# +# id :integer not null, primary key +# author_id :integer +# content :text +# published :boolean +# 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/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..3f4ce6e 100644 --- a/test/models/post_test.rb +++ b/test/models/post_test.rb @@ -1,3 +1,15 @@ +# == Schema Information +# +# Table name: posts +# +# id :integer not null, primary key +# author_id :integer +# content :text +# published :boolean +# created_at :datetime not null +# updated_at :datetime not null +# + require 'test_helper' class PostTest < ActiveSupport::TestCase From 76e9412e86756d889469e6131a42227164a8d3e4 Mon Sep 17 00:00:00 2001 From: MrPranklin Date: Sun, 23 Dec 2018 17:52:02 +0100 Subject: [PATCH 03/25] Remove excess controller Removed captcha controller I created for the last assignment which was unnecessary --- app/controllers/captcha_controller.rb | 30 --------------------------- app/models/comment.rb | 1 + app/views/comments/new.html.erb | 2 -- 3 files changed, 1 insertion(+), 32 deletions(-) delete mode 100644 app/controllers/captcha_controller.rb diff --git a/app/controllers/captcha_controller.rb b/app/controllers/captcha_controller.rb deleted file mode 100644 index bc511f5..0000000 --- a/app/controllers/captcha_controller.rb +++ /dev/null @@ -1,30 +0,0 @@ -class CaptchaController < ApplicationController - def new - - end - - def show - @is_valid = params[:captcha] - end - - def create - x = params[:x].to_i - y = params[:y].to_i - z = params[:z].to_i - n = params[:random_number].to_i - - is_valid = check(x, y, z, n) - - redirect_to "/captcha/#{is_valid}" - - end - - def check(x, y, z, n) - if (x + y - z) == n - return 1 - else - return 0 - end - end - -end \ No newline at end of file diff --git a/app/models/comment.rb b/app/models/comment.rb index 8127199..28fca1a 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -11,4 +11,5 @@ # class Comment < ApplicationRecord + validates :content, presence: true, length: { minimum: 2 } end 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!

From b9d84b6ff7c9e3d3ea8b98992dd05d0431c81570 Mon Sep 17 00:00:00 2001 From: MrPranklin Date: Sun, 23 Dec 2018 18:59:12 +0100 Subject: [PATCH 04/25] Created SubReddit model, migrated --- app/models/sub_reddit.rb | 2 ++ db/migrate/20181223172954_create_sub_reddits.rb | 12 ++++++++++++ db/schema.rb | 11 ++++++++++- test/fixtures/sub_reddits.yml | 13 +++++++++++++ test/models/sub_reddit_test.rb | 7 +++++++ 5 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 app/models/sub_reddit.rb create mode 100644 db/migrate/20181223172954_create_sub_reddits.rb create mode 100644 test/fixtures/sub_reddits.yml create mode 100644 test/models/sub_reddit_test.rb diff --git a/app/models/sub_reddit.rb b/app/models/sub_reddit.rb new file mode 100644 index 0000000..3cdd27c --- /dev/null +++ b/app/models/sub_reddit.rb @@ -0,0 +1,2 @@ +class SubReddit < ApplicationRecord`` +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/schema.rb b/db/schema.rb index e4e1ebb..bb804ec 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: 2018_10_26_093242) do +ActiveRecord::Schema.define(version: 2018_12_23_172954) do create_table "authors", force: :cascade do |t| t.string "email" @@ -36,4 +36,13 @@ t.datetime "updated_at", null: false 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.integer "owner_id", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + end diff --git a/test/fixtures/sub_reddits.yml b/test/fixtures/sub_reddits.yml new file mode 100644 index 0000000..fac6984 --- /dev/null +++ b/test/fixtures/sub_reddits.yml @@ -0,0 +1,13 @@ +# 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/models/sub_reddit_test.rb b/test/models/sub_reddit_test.rb new file mode 100644 index 0000000..2bbb25f --- /dev/null +++ b/test/models/sub_reddit_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class SubRedditTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end From fd96cd671fa65a67858499703423e2fc044f46ea Mon Sep 17 00:00:00 2001 From: MrPranklin Date: Sun, 23 Dec 2018 19:11:38 +0100 Subject: [PATCH 05/25] Added columns to posts database --- db/migrate/20181223180058_change_posts.rb | 4 ++++ db/migrate/20181223180730_add_sub_reddit_id_to_posts.rb | 5 +++++ db/migrate/20181223181011_add_title_to_posts.rb | 5 +++++ db/schema.rb | 4 +++- 4 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20181223180058_change_posts.rb create mode 100644 db/migrate/20181223180730_add_sub_reddit_id_to_posts.rb create mode 100644 db/migrate/20181223181011_add_title_to_posts.rb 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/schema.rb b/db/schema.rb index bb804ec..7f60f3a 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: 2018_12_23_172954) do +ActiveRecord::Schema.define(version: 2018_12_23_181011) do create_table "authors", force: :cascade do |t| t.string "email" @@ -34,6 +34,8 @@ t.boolean "published" t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.integer "sub_reddit_id" + t.string "title" end create_table "sub_reddits", force: :cascade do |t| From 0d8d9e34935bb327c31b36064795c5eac0bf889e Mon Sep 17 00:00:00 2001 From: MrPranklin Date: Sun, 23 Dec 2018 19:27:48 +0100 Subject: [PATCH 06/25] Change drop_authors, add create_users Change change method in drop_author to up, added down method --- app/models/author.rb | 14 -------------- app/models/user.rb | 2 ++ db/migrate/20181223181438_drop_authors.rb | 15 +++++++++++++++ db/migrate/20181223181746_create_users.rb | 10 ++++++++++ db/schema.rb | 17 ++++++++--------- test/fixtures/users.yml | 9 +++++++++ test/models/user_test.rb | 7 +++++++ 7 files changed, 51 insertions(+), 23 deletions(-) delete mode 100644 app/models/author.rb create mode 100644 app/models/user.rb create mode 100644 db/migrate/20181223181438_drop_authors.rb create mode 100644 db/migrate/20181223181746_create_users.rb create mode 100644 test/fixtures/users.yml create mode 100644 test/models/user_test.rb diff --git a/app/models/author.rb b/app/models/author.rb deleted file mode 100644 index 02ea84b..0000000 --- a/app/models/author.rb +++ /dev/null @@ -1,14 +0,0 @@ -# == 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 -# - -class Author < ApplicationRecord -end diff --git a/app/models/user.rb b/app/models/user.rb new file mode 100644 index 0000000..379658a --- /dev/null +++ b/app/models/user.rb @@ -0,0 +1,2 @@ +class User < ApplicationRecord +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/schema.rb b/db/schema.rb index 7f60f3a..0484d1e 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,15 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2018_12_23_181011) 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_23_181746) do create_table "comments", force: :cascade do |t| t.integer "post_id" @@ -47,4 +39,11 @@ t.datetime "updated_at", null: false 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 + end + end diff --git a/test/fixtures/users.yml b/test/fixtures/users.yml new file mode 100644 index 0000000..d0a6628 --- /dev/null +++ b/test/fixtures/users.yml @@ -0,0 +1,9 @@ +# 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/user_test.rb b/test/models/user_test.rb new file mode 100644 index 0000000..82f61e0 --- /dev/null +++ b/test/models/user_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class UserTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end From 0df4306164b4363f0dfb9396db52260c4bc081c3 Mon Sep 17 00:00:00 2001 From: MrPranklin Date: Sun, 23 Dec 2018 20:17:54 +0100 Subject: [PATCH 07/25] ocnvert comment associations to references' --- app/models/comment.rb | 3 +++ app/models/post.rb | 3 +++ app/models/user.rb | 4 ++++ ...vert_comment_association_fields_to_references.rb | 13 +++++++++++++ db/schema.rb | 8 +++++--- 5 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 db/migrate/20181223185329_convert_comment_association_fields_to_references.rb diff --git a/app/models/comment.rb b/app/models/comment.rb index 28fca1a..97e455a 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -11,5 +11,8 @@ # 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 ecfd584..77048b7 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # == Schema Information # # Table name: posts @@ -11,4 +13,5 @@ # class Post < ApplicationRecord + has_many :comments end diff --git a/app/models/user.rb b/app/models/user.rb index 379658a..56ed4b0 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,2 +1,6 @@ class User < ApplicationRecord + has_many :comments, foreign_key: author_id + + validates :email, uniqueness: true, presence: true + validates :username, uniqueness: true, presence: true 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/schema.rb b/db/schema.rb index 0484d1e..920b8af 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,14 +10,16 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2018_12_23_181746) do +ActiveRecord::Schema.define(version: 2018_12_23_185329) 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| From 80dc0fb297762895818c5edd6971567c8c62d0ad Mon Sep 17 00:00:00 2001 From: MrPranklin Date: Sun, 23 Dec 2018 20:35:48 +0100 Subject: [PATCH 08/25] Finish tutorial --- app/models/user.rb | 3 +-- db/migrate/20181223192850_add_posts_title_index.rb | 4 ++++ ...181223192922_add_users_email_and_username_unique_index.rb | 5 +++++ db/schema.rb | 3 ++- 4 files changed, 12 insertions(+), 3 deletions(-) create mode 100644 db/migrate/20181223192850_add_posts_title_index.rb create mode 100644 db/migrate/20181223192922_add_users_email_and_username_unique_index.rb diff --git a/app/models/user.rb b/app/models/user.rb index 56ed4b0..7875e2a 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,6 +1,5 @@ class User < ApplicationRecord has_many :comments, foreign_key: author_id - validates :email, uniqueness: true, presence: true - validates :username, uniqueness: true, presence: true + validates :email, uniqueness:{ scope: :username } , presence: true 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..3c7d09f --- /dev/null +++ b/db/migrate/20181223192850_add_posts_title_index.rb @@ -0,0 +1,4 @@ +class AddPostsTitleIndex < ActiveRecord::Migration[5.2] + def change + 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/schema.rb b/db/schema.rb index 920b8af..974db71 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: 2018_12_23_185329) do +ActiveRecord::Schema.define(version: 2018_12_23_192922) do create_table "comments", force: :cascade do |t| t.text "content" @@ -46,6 +46,7 @@ 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 From 5f062cb186b1011de17cbdcb1a0d6c6ba6fa1513 Mon Sep 17 00:00:00 2001 From: MrPranklin Date: Mon, 24 Dec 2018 18:40:26 +0100 Subject: [PATCH 09/25] Add things missed in chapter, spelling --- app/models/user.rb | 4 ++-- db/migrate/20181223192850_add_posts_title_index.rb | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/models/user.rb b/app/models/user.rb index 7875e2a..767fe55 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,5 +1,5 @@ class User < ApplicationRecord - has_many :comments, foreign_key: author_id + has_many :comments, foreign_key: 'author_id' - validates :email, uniqueness:{ scope: :username } , presence: true + validates :email, uniqueness: { scope: :username } , presence: true end diff --git a/db/migrate/20181223192850_add_posts_title_index.rb b/db/migrate/20181223192850_add_posts_title_index.rb index 3c7d09f..0600886 100644 --- a/db/migrate/20181223192850_add_posts_title_index.rb +++ b/db/migrate/20181223192850_add_posts_title_index.rb @@ -1,4 +1,5 @@ class AddPostsTitleIndex < ActiveRecord::Migration[5.2] def change + add_index :posts, :title end end From 28880e96a66152d7f601395a6c78b078eb49dd1a Mon Sep 17 00:00:00 2001 From: MrPranklin Date: Mon, 24 Dec 2018 21:18:42 +0100 Subject: [PATCH 10/25] FInished 6th task in 5th assignment --- app/models/post.rb | 19 ++++++++++------- app/models/sub_reddit.rb | 21 ++++++++++++++++++- app/models/user.rb | 12 +++++++++++ ...er_subreddit_owner_id_to_user_reference.rb | 9 ++++++++ ...81224195359_change_title_column_in_post.rb | 5 +++++ ...20181224200032_change_author_id_in_post.rb | 5 +++++ ...01047_add_sub_reddit_id_column_in_posts.rb | 6 ++++++ test/fixtures/posts.yml | 14 +++++++------ test/fixtures/sub_reddits.yml | 13 ++++++++++++ test/fixtures/users.yml | 11 ++++++++++ test/models/post_test.rb | 14 +++++++------ test/models/sub_reddit_test.rb | 13 ++++++++++++ test/models/user_test.rb | 11 ++++++++++ 13 files changed, 133 insertions(+), 20 deletions(-) create mode 100644 db/migrate/20181224193704_conver_subreddit_owner_id_to_user_reference.rb create mode 100644 db/migrate/20181224195359_change_title_column_in_post.rb create mode 100644 db/migrate/20181224200032_change_author_id_in_post.rb create mode 100644 db/migrate/20181224201047_add_sub_reddit_id_column_in_posts.rb diff --git a/app/models/post.rb b/app/models/post.rb index 77048b7..06f594d 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -1,17 +1,22 @@ # frozen_string_literal: true - # == Schema Information # # Table name: posts # -# id :integer not null, primary key -# author_id :integer -# content :text -# published :boolean -# created_at :datetime not null -# updated_at :datetime not null +# id :integer not null, primary key +# author_id :integer +# content :text +# published :boolean +# created_at :datetime not null +# updated_at :datetime not null +# sub_reddit_id :integer +# title :string # class Post < ApplicationRecord has_many :comments + 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 index 3cdd27c..4bf0163 100644 --- a/app/models/sub_reddit.rb +++ b/app/models/sub_reddit.rb @@ -1,2 +1,21 @@ -class SubReddit < ApplicationRecord`` +# == 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 +# owner_id :integer not null +# created_at :datetime not null +# updated_at :datetime not null +# + +class SubReddit < ApplicationRecord + belongs_to :user + has_many :posts + + validates :title, presence: true, uniqueness: true + validates :owner, presence: true + validates :description, presence: true end diff --git a/app/models/user.rb b/app/models/user.rb index 767fe55..e5c40d4 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,5 +1,17 @@ +# == 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 validates :email, uniqueness: { scope: :username } , presence: true 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..220d9a5 --- /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 }, null: false + 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..1e63662 --- /dev/null +++ b/db/migrate/20181224195359_change_title_column_in_post.rb @@ -0,0 +1,5 @@ +class ChangeTitleColumnInPost < ActiveRecord::Migration[5.2] + def change + change_column :posts, :title, :string, null: false, default: '' + 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..d508138 --- /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..2ae6a90 --- /dev/null +++ b/db/migrate/20181224201047_add_sub_reddit_id_column_in_posts.rb @@ -0,0 +1,6 @@ +class AddSubRedditIdColumnInPosts < ActiveRecord::Migration[5.2] + def change + add_column :posts, :sub_reddit_id, :integer, null: false + add_reference :posts, :sub_reddit_id, foreign_key: { to_table: :sub_reddits, on_delete: cascade } + end +end diff --git a/test/fixtures/posts.yml b/test/fixtures/posts.yml index e19100f..9016b7f 100644 --- a/test/fixtures/posts.yml +++ b/test/fixtures/posts.yml @@ -2,12 +2,14 @@ # # Table name: posts # -# id :integer not null, primary key -# author_id :integer -# content :text -# published :boolean -# created_at :datetime not null -# updated_at :datetime not null +# id :integer not null, primary key +# author_id :integer +# content :text +# published :boolean +# created_at :datetime not null +# updated_at :datetime not null +# sub_reddit_id :integer +# title :string # # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html diff --git a/test/fixtures/sub_reddits.yml b/test/fixtures/sub_reddits.yml index fac6984..0acc860 100644 --- a/test/fixtures/sub_reddits.yml +++ b/test/fixtures/sub_reddits.yml @@ -1,3 +1,16 @@ +# == 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 +# owner_id :integer 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: diff --git a/test/fixtures/users.yml b/test/fixtures/users.yml index d0a6628..343c7e8 100644 --- a/test/fixtures/users.yml +++ b/test/fixtures/users.yml @@ -1,3 +1,14 @@ +# == 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: diff --git a/test/models/post_test.rb b/test/models/post_test.rb index 3f4ce6e..69ce070 100644 --- a/test/models/post_test.rb +++ b/test/models/post_test.rb @@ -2,12 +2,14 @@ # # Table name: posts # -# id :integer not null, primary key -# author_id :integer -# content :text -# published :boolean -# created_at :datetime not null -# updated_at :datetime not null +# id :integer not null, primary key +# author_id :integer +# content :text +# published :boolean +# created_at :datetime not null +# updated_at :datetime not null +# sub_reddit_id :integer +# title :string # require 'test_helper' diff --git a/test/models/sub_reddit_test.rb b/test/models/sub_reddit_test.rb index 2bbb25f..cd0e547 100644 --- a/test/models/sub_reddit_test.rb +++ b/test/models/sub_reddit_test.rb @@ -1,3 +1,16 @@ +# == 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 +# owner_id :integer not null +# created_at :datetime not null +# updated_at :datetime not null +# + require 'test_helper' class SubRedditTest < ActiveSupport::TestCase diff --git a/test/models/user_test.rb b/test/models/user_test.rb index 82f61e0..e38639a 100644 --- a/test/models/user_test.rb +++ b/test/models/user_test.rb @@ -1,3 +1,14 @@ +# == 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 From 9feae30efbc90f6f71fae39062649d1b6d26369c Mon Sep 17 00:00:00 2001 From: MrPranklin Date: Mon, 24 Dec 2018 22:18:09 +0100 Subject: [PATCH 11/25] Add upvote model, important changes Important changes: add missing indices, finished 7th task --- app/models/upvote.rb | 7 +++++++ ...nver_subreddit_owner_id_to_user_reference.rb | 2 +- ...4201047_add_sub_reddit_id_column_in_posts.rb | 5 ++++- db/migrate/20181224203824_create_upvotes.rb | 17 +++++++++++++++++ .../20181224210219_add_missing_indices.rb | 6 ++++++ test/fixtures/upvotes.yml | 9 +++++++++ test/models/upvote_test.rb | 7 +++++++ 7 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 app/models/upvote.rb create mode 100644 db/migrate/20181224203824_create_upvotes.rb create mode 100644 db/migrate/20181224210219_add_missing_indices.rb create mode 100644 test/fixtures/upvotes.yml create mode 100644 test/models/upvote_test.rb diff --git a/app/models/upvote.rb b/app/models/upvote.rb new file mode 100644 index 0000000..2a6f496 --- /dev/null +++ b/app/models/upvote.rb @@ -0,0 +1,7 @@ +class Upvote < ApplicationRecord + belongs_to :user + belongs_to :post + + validates :post, presence: true + validates :creator, uniqueness: true, presence: true +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 index 220d9a5..4ee7187 100644 --- a/db/migrate/20181224193704_conver_subreddit_owner_id_to_user_reference.rb +++ b/db/migrate/20181224193704_conver_subreddit_owner_id_to_user_reference.rb @@ -2,7 +2,7 @@ class ConverSubredditOwnerIdToUserReference < ActiveRecord::Migration[5.2] def change - remove_column :sub_reddits, :owner_id + add_column :sub_reddits, :owner add_reference :sub_reddits, :owner, foreign_key: { to_table: :users, on_delete: :cascade }, null: false 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 index 2ae6a90..c527496 100644 --- a/db/migrate/20181224201047_add_sub_reddit_id_column_in_posts.rb +++ b/db/migrate/20181224201047_add_sub_reddit_id_column_in_posts.rb @@ -1,6 +1,9 @@ +# frozen_string_literal: true + class AddSubRedditIdColumnInPosts < ActiveRecord::Migration[5.2] def change add_column :posts, :sub_reddit_id, :integer, null: false - add_reference :posts, :sub_reddit_id, foreign_key: { to_table: :sub_reddits, on_delete: cascade } + add_reference :posts, :sub_reddit_id, + 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..f799da1 --- /dev/null +++ b/db/migrate/20181224210219_add_missing_indices.rb @@ -0,0 +1,6 @@ +class AddMissingIndices < ActiveRecord::Migration[5.2] + def change + add_index :posts, :title, unique: true + add_index :sub_reddits :title, unique: true + end +end diff --git a/test/fixtures/upvotes.yml b/test/fixtures/upvotes.yml new file mode 100644 index 0000000..2228d06 --- /dev/null +++ b/test/fixtures/upvotes.yml @@ -0,0 +1,9 @@ +# 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/models/upvote_test.rb b/test/models/upvote_test.rb new file mode 100644 index 0000000..f851b9f --- /dev/null +++ b/test/models/upvote_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class UpvoteTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end From f14a7c142b65da6f8278da4b7d5b0c0521687073 Mon Sep 17 00:00:00 2001 From: MrPranklin Date: Mon, 24 Dec 2018 22:28:00 +0100 Subject: [PATCH 12/25] Add associations --- app/models/post.rb | 2 ++ app/models/user.rb | 2 ++ 2 files changed, 4 insertions(+) diff --git a/app/models/post.rb b/app/models/post.rb index 06f594d..b4a0237 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -15,6 +15,8 @@ class Post < ApplicationRecord has_many :comments + has_many :upvotes + belongs_to :user belongs_to :sub_reddits validates :title, presence: true, uniqueness: true diff --git a/app/models/user.rb b/app/models/user.rb index e5c40d4..fa6f404 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -12,6 +12,8 @@ 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 From 5d299430270666ad58a648c86200f6124a326d29 Mon Sep 17 00:00:00 2001 From: MrPranklin Date: Tue, 25 Dec 2018 20:42:16 +0100 Subject: [PATCH 13/25] Migrated all tasks, annotated --- app/models/post.rb | 4 ++-- app/models/sub_reddit.rb | 2 +- app/models/upvote.rb | 13 ++++++++++ ...er_subreddit_owner_id_to_user_reference.rb | 4 ++-- ...81224195359_change_title_column_in_post.rb | 5 +++- ...20181224200032_change_author_id_in_post.rb | 2 +- ...01047_add_sub_reddit_id_column_in_posts.rb | 4 ++-- .../20181224210219_add_missing_indices.rb | 3 +-- db/schema.rb | 24 +++++++++++++++---- test/fixtures/posts.yml | 4 ++-- test/fixtures/sub_reddits.yml | 2 +- test/fixtures/upvotes.yml | 13 ++++++++++ test/models/post_test.rb | 4 ++-- test/models/sub_reddit_test.rb | 2 +- test/models/upvote_test.rb | 13 ++++++++++ 15 files changed, 78 insertions(+), 21 deletions(-) diff --git a/app/models/post.rb b/app/models/post.rb index b4a0237..885d34b 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -4,13 +4,13 @@ # Table name: posts # # id :integer not null, primary key -# author_id :integer +# 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 -# title :string # class Post < ApplicationRecord diff --git a/app/models/sub_reddit.rb b/app/models/sub_reddit.rb index 4bf0163..1325347 100644 --- a/app/models/sub_reddit.rb +++ b/app/models/sub_reddit.rb @@ -6,9 +6,9 @@ # title :string not null # description :text not null # private :boolean default(FALSE), not null -# owner_id :integer not null # created_at :datetime not null # updated_at :datetime not null +# owner_id :integer # class SubReddit < ApplicationRecord diff --git a/app/models/upvote.rb b/app/models/upvote.rb index 2a6f496..871287d 100644 --- a/app/models/upvote.rb +++ b/app/models/upvote.rb @@ -1,3 +1,16 @@ +# == 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 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 index 4ee7187..77e91e0 100644 --- a/db/migrate/20181224193704_conver_subreddit_owner_id_to_user_reference.rb +++ b/db/migrate/20181224193704_conver_subreddit_owner_id_to_user_reference.rb @@ -2,8 +2,8 @@ class ConverSubredditOwnerIdToUserReference < ActiveRecord::Migration[5.2] def change - add_column :sub_reddits, :owner + remove_column :sub_reddits, :owner_id add_reference :sub_reddits, :owner, - foreign_key: { to_table: :users, on_delete: :cascade }, null: false + 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 index 1e63662..e1da7bd 100644 --- a/db/migrate/20181224195359_change_title_column_in_post.rb +++ b/db/migrate/20181224195359_change_title_column_in_post.rb @@ -1,5 +1,8 @@ class ChangeTitleColumnInPost < ActiveRecord::Migration[5.2] def change - change_column :posts, :title, :string, null: false, default: '' + # 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 index d508138..ccc40a3 100644 --- a/db/migrate/20181224200032_change_author_id_in_post.rb +++ b/db/migrate/20181224200032_change_author_id_in_post.rb @@ -1,5 +1,5 @@ class ChangeAuthorIdInPost < ActiveRecord::Migration[5.2] def change - change_column :posts, :author_id, :integer null: false + 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 index c527496..c6794a8 100644 --- a/db/migrate/20181224201047_add_sub_reddit_id_column_in_posts.rb +++ b/db/migrate/20181224201047_add_sub_reddit_id_column_in_posts.rb @@ -2,8 +2,8 @@ class AddSubRedditIdColumnInPosts < ActiveRecord::Migration[5.2] def change - add_column :posts, :sub_reddit_id, :integer, null: false - add_reference :posts, :sub_reddit_id, + 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/20181224210219_add_missing_indices.rb b/db/migrate/20181224210219_add_missing_indices.rb index f799da1..e554d73 100644 --- a/db/migrate/20181224210219_add_missing_indices.rb +++ b/db/migrate/20181224210219_add_missing_indices.rb @@ -1,6 +1,5 @@ class AddMissingIndices < ActiveRecord::Migration[5.2] def change - add_index :posts, :title, unique: true - add_index :sub_reddits :title, unique: true + add_index :sub_reddits, :title, unique: true end end diff --git a/db/schema.rb b/db/schema.rb index 974db71..b518f5c 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: 2018_12_23_192922) do +ActiveRecord::Schema.define(version: 2018_12_24_210219) do create_table "comments", force: :cascade do |t| t.text "content" @@ -23,22 +23,38 @@ 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.string "title" + 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.integer "owner_id", 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| diff --git a/test/fixtures/posts.yml b/test/fixtures/posts.yml index 9016b7f..a5b7f19 100644 --- a/test/fixtures/posts.yml +++ b/test/fixtures/posts.yml @@ -3,13 +3,13 @@ # Table name: posts # # id :integer not null, primary key -# author_id :integer +# 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 -# title :string # # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html diff --git a/test/fixtures/sub_reddits.yml b/test/fixtures/sub_reddits.yml index 0acc860..69e888a 100644 --- a/test/fixtures/sub_reddits.yml +++ b/test/fixtures/sub_reddits.yml @@ -6,9 +6,9 @@ # title :string not null # description :text not null # private :boolean default(FALSE), not null -# owner_id :integer 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 diff --git a/test/fixtures/upvotes.yml b/test/fixtures/upvotes.yml index 2228d06..05ed48c 100644 --- a/test/fixtures/upvotes.yml +++ b/test/fixtures/upvotes.yml @@ -1,3 +1,16 @@ +# == 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: diff --git a/test/models/post_test.rb b/test/models/post_test.rb index 69ce070..9bc1365 100644 --- a/test/models/post_test.rb +++ b/test/models/post_test.rb @@ -3,13 +3,13 @@ # Table name: posts # # id :integer not null, primary key -# author_id :integer +# 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 -# title :string # require 'test_helper' diff --git a/test/models/sub_reddit_test.rb b/test/models/sub_reddit_test.rb index cd0e547..4bd3438 100644 --- a/test/models/sub_reddit_test.rb +++ b/test/models/sub_reddit_test.rb @@ -6,9 +6,9 @@ # title :string not null # description :text not null # private :boolean default(FALSE), not null -# owner_id :integer not null # created_at :datetime not null # updated_at :datetime not null +# owner_id :integer # require 'test_helper' diff --git a/test/models/upvote_test.rb b/test/models/upvote_test.rb index f851b9f..b0c0ac3 100644 --- a/test/models/upvote_test.rb +++ b/test/models/upvote_test.rb @@ -1,3 +1,16 @@ +# == 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 From a8181008bacc7fc9615308b400207c8ee54641fa Mon Sep 17 00:00:00 2001 From: MrPranklin Date: Tue, 25 Dec 2018 20:57:15 +0100 Subject: [PATCH 14/25] Destroy authors, create user controller and rest --- .../{authors.coffee => user.coffee} | 0 .../stylesheets/{authors.scss => user.scss} | 2 +- app/controllers/authors_controller.rb | 74 ------------------- app/controllers/user_controller.rb | 2 + app/helpers/authors_helper.rb | 2 - app/helpers/user_helper.rb | 2 + app/views/authors/_author.json.jbuilder | 2 - app/views/authors/_form.html.erb | 15 ---- app/views/authors/edit.html.erb | 6 -- app/views/authors/index.html.erb | 31 -------- app/views/authors/index.json.jbuilder | 1 - app/views/authors/new.html.erb | 5 -- app/views/authors/show.html.erb | 19 ----- app/views/authors/show.json.jbuilder | 1 - test/controllers/authors_controller_test.rb | 48 ------------ test/controllers/user_controller_test.rb | 7 ++ 16 files changed, 12 insertions(+), 205 deletions(-) rename app/assets/javascripts/{authors.coffee => user.coffee} (100%) rename app/assets/stylesheets/{authors.scss => user.scss} (64%) delete mode 100644 app/controllers/authors_controller.rb create mode 100644 app/controllers/user_controller.rb delete mode 100644 app/helpers/authors_helper.rb create mode 100644 app/helpers/user_helper.rb delete mode 100644 app/views/authors/_author.json.jbuilder delete mode 100644 app/views/authors/_form.html.erb delete mode 100644 app/views/authors/edit.html.erb delete mode 100644 app/views/authors/index.html.erb delete mode 100644 app/views/authors/index.json.jbuilder delete mode 100644 app/views/authors/new.html.erb delete mode 100644 app/views/authors/show.html.erb delete mode 100644 app/views/authors/show.json.jbuilder delete mode 100644 test/controllers/authors_controller_test.rb create mode 100644 test/controllers/user_controller_test.rb diff --git a/app/assets/javascripts/authors.coffee b/app/assets/javascripts/user.coffee similarity index 100% rename from app/assets/javascripts/authors.coffee rename to app/assets/javascripts/user.coffee diff --git a/app/assets/stylesheets/authors.scss b/app/assets/stylesheets/user.scss similarity index 64% rename from app/assets/stylesheets/authors.scss rename to app/assets/stylesheets/user.scss index 7adde77..7c5eca9 100644 --- a/app/assets/stylesheets/authors.scss +++ b/app/assets/stylesheets/user.scss @@ -1,3 +1,3 @@ -// Place all the styles related to the Authors controller here. +// Place all the styles related to the user 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/user_controller.rb b/app/controllers/user_controller.rb new file mode 100644 index 0000000..11046fd --- /dev/null +++ b/app/controllers/user_controller.rb @@ -0,0 +1,2 @@ +class UserController < ApplicationController +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/user_helper.rb b/app/helpers/user_helper.rb new file mode 100644 index 0000000..0147c3f --- /dev/null +++ b/app/helpers/user_helper.rb @@ -0,0 +1,2 @@ +module UserHelper +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

- - - - - - - - - - - - - <% @authors.each do |author| %> - - - - - - - - - <% end %> - -
EmailAliasDate of birth
<%= 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?' } %>
- -
- -<%= 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/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/user_controller_test.rb b/test/controllers/user_controller_test.rb new file mode 100644 index 0000000..314cd5a --- /dev/null +++ b/test/controllers/user_controller_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class UserControllerTest < ActionDispatch::IntegrationTest + # test "the truth" do + # assert true + # end +end From d5a17fd56d8d91f0712fdbe21635721c348a567b Mon Sep 17 00:00:00 2001 From: MrPranklin Date: Tue, 25 Dec 2018 21:20:37 +0100 Subject: [PATCH 15/25] Add title and subreddit print --- app/views/posts/show.html.erb | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/app/views/posts/show.html.erb b/app/views/posts/show.html.erb index 4f7dfc6..a5e73a2 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 %> From b14bd2e467c80fc12227bf027784bddb74a03fe8 Mon Sep 17 00:00:00 2001 From: MrPranklin Date: Tue, 25 Dec 2018 22:17:51 +0100 Subject: [PATCH 16/25] Remove old, wrong solutions --- app/views/captcha/new.html.erb | 16 ---------------- app/views/captcha/show.html.erb | 2 -- 2 files changed, 18 deletions(-) delete mode 100644 app/views/captcha/new.html.erb delete mode 100644 app/views/captcha/show.html.erb diff --git a/app/views/captcha/new.html.erb b/app/views/captcha/new.html.erb deleted file mode 100644 index 65fc2bb..0000000 --- a/app/views/captcha/new.html.erb +++ /dev/null @@ -1,16 +0,0 @@ -

Solve captcha

- -<%= form_tag "/captcha", method: :post do %> - -

x + y - z = <%= @random_number %>

- - <% [:x, :y, :z].each do |var| %> -

- <%= label_tag(var, "#{var}:") %> - <%= number_field nil, var %> -

- <% end %> - - - -<% end %> \ No newline at end of file diff --git a/app/views/captcha/show.html.erb b/app/views/captcha/show.html.erb deleted file mode 100644 index 253d46b..0000000 --- a/app/views/captcha/show.html.erb +++ /dev/null @@ -1,2 +0,0 @@ -

Solve captcha show

- From 2a29c9dd2aec609ec0952c2180c291919d4c04e8 Mon Sep 17 00:00:00 2001 From: MrPranklin Date: Tue, 25 Dec 2018 22:24:15 +0100 Subject: [PATCH 17/25] Tried to change input for post creation --- app/controllers/posts_controller.rb | 2 +- app/views/posts/index.html.erb | 6 +++++- app/views/posts/new.html.erb | 11 ++++++++++- 3 files changed, 16 insertions(+), 3 deletions(-) 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/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..496860b 100644 --- a/app/views/posts/new.html.erb +++ b/app/views/posts/new.html.erb @@ -1,5 +1,14 @@

New Post

-<%= render 'form', post: @post %> +<%= 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 %> + + <%= f.button :button %> +<% end %> <%= link_to 'Back', posts_path %> From 957b52011000c96ee3cb317ad2e775e8986e349d Mon Sep 17 00:00:00 2001 From: MrPranklin Date: Tue, 25 Dec 2018 22:44:32 +0100 Subject: [PATCH 18/25] Really dumb way of refactoring --- app/assets/javascripts/{user.coffee => users.coffee} | 0 app/assets/stylesheets/{user.scss => users.scss} | 2 +- app/controllers/user_controller.rb | 2 -- app/controllers/users_controller.rb | 5 +++++ app/helpers/user_helper.rb | 2 -- app/helpers/users_helper.rb | 2 ++ app/views/users/index.html.erb | 1 + config/routes.rb | 2 ++ .../{user_controller_test.rb => users_controller_test.rb} | 2 +- 9 files changed, 12 insertions(+), 6 deletions(-) rename app/assets/javascripts/{user.coffee => users.coffee} (100%) rename app/assets/stylesheets/{user.scss => users.scss} (64%) delete mode 100644 app/controllers/user_controller.rb create mode 100644 app/controllers/users_controller.rb delete mode 100644 app/helpers/user_helper.rb create mode 100644 app/helpers/users_helper.rb create mode 100644 app/views/users/index.html.erb rename test/controllers/{user_controller_test.rb => users_controller_test.rb} (56%) diff --git a/app/assets/javascripts/user.coffee b/app/assets/javascripts/users.coffee similarity index 100% rename from app/assets/javascripts/user.coffee rename to app/assets/javascripts/users.coffee diff --git a/app/assets/stylesheets/user.scss b/app/assets/stylesheets/users.scss similarity index 64% rename from app/assets/stylesheets/user.scss rename to app/assets/stylesheets/users.scss index 7c5eca9..1efc835 100644 --- a/app/assets/stylesheets/user.scss +++ b/app/assets/stylesheets/users.scss @@ -1,3 +1,3 @@ -// Place all the styles related to the user 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/user_controller.rb b/app/controllers/user_controller.rb deleted file mode 100644 index 11046fd..0000000 --- a/app/controllers/user_controller.rb +++ /dev/null @@ -1,2 +0,0 @@ -class UserController < ApplicationController -end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb new file mode 100644 index 0000000..90f3499 --- /dev/null +++ b/app/controllers/users_controller.rb @@ -0,0 +1,5 @@ +class UsersController < ApplicationController + def index + + end +end diff --git a/app/helpers/user_helper.rb b/app/helpers/user_helper.rb deleted file mode 100644 index 0147c3f..0000000 --- a/app/helpers/user_helper.rb +++ /dev/null @@ -1,2 +0,0 @@ -module UserHelper -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/views/users/index.html.erb b/app/views/users/index.html.erb new file mode 100644 index 0000000..61241b9 --- /dev/null +++ b/app/views/users/index.html.erb @@ -0,0 +1 @@ +

Users

diff --git a/config/routes.rb b/config/routes.rb index 96c2f69..f8284d6 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -11,4 +11,6 @@ get 'polynomials/:id', to: 'polynomials#show' post 'polynomials', to: 'polynomials#create' + get 'users', to: 'users#index' + end diff --git a/test/controllers/user_controller_test.rb b/test/controllers/users_controller_test.rb similarity index 56% rename from test/controllers/user_controller_test.rb rename to test/controllers/users_controller_test.rb index 314cd5a..6c3da77 100644 --- a/test/controllers/user_controller_test.rb +++ b/test/controllers/users_controller_test.rb @@ -1,6 +1,6 @@ require 'test_helper' -class UserControllerTest < ActionDispatch::IntegrationTest +class UsersControllerTest < ActionDispatch::IntegrationTest # test "the truth" do # assert true # end From df5f665bde1b6e4f6e0b7f256daf7732728472c3 Mon Sep 17 00:00:00 2001 From: MrPranklin Date: Tue, 25 Dec 2018 22:58:45 +0100 Subject: [PATCH 19/25] Add mock routes for users --- app/controllers/users_controller.rb | 12 +++++++++++- app/views/users/index.html.erb | 2 ++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 90f3499..0533d39 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1,5 +1,15 @@ +# frozen_string_literal: true + class UsersController < ApplicationController def index - + @users = User.all + end + + def show + @user = params[:id] + end + + def new + @user = User.new end end diff --git a/app/views/users/index.html.erb b/app/views/users/index.html.erb index 61241b9..7dad7fd 100644 --- a/app/views/users/index.html.erb +++ b/app/views/users/index.html.erb @@ -1 +1,3 @@

Users

+ +<%= @users %> From 5a4f6c9307b9b0daa9040f82cff1fe3145f69221 Mon Sep 17 00:00:00 2001 From: MrPranklin Date: Tue, 25 Dec 2018 23:51:02 +0100 Subject: [PATCH 20/25] Configure user routes, views and controller --- app/controllers/users_controller.rb | 2 +- app/views/users/index.html.erb | 24 ++++++++++++++++++++++- config/routes.rb | 3 ++- test/controllers/users_controller_test.rb | 8 +++++--- 4 files changed, 31 insertions(+), 6 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 0533d39..c0f657f 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -6,7 +6,7 @@ def index end def show - @user = params[:id] + @user = User.find_by( id: params[:id] ) end def new diff --git a/app/views/users/index.html.erb b/app/views/users/index.html.erb index 7dad7fd..75c1fd4 100644 --- a/app/views/users/index.html.erb +++ b/app/views/users/index.html.erb @@ -1,3 +1,25 @@

Users

+ + + + + + + + + + + -<%= @users %> + + <% @users.each do |user| %> + + + i + + <% end %> + + < diff --git a/config/routes.rb b/config/routes.rb index f8284d6..7ca4861 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -12,5 +12,6 @@ post 'polynomials', to: 'polynomials#create' get 'users', to: 'users#index' - + get 'users/:id', to: 'users#show' + get 'users/new', to: 'users#new' end diff --git a/test/controllers/users_controller_test.rb b/test/controllers/users_controller_test.rb index 6c3da77..acf708a 100644 --- a/test/controllers/users_controller_test.rb +++ b/test/controllers/users_controller_test.rb @@ -1,7 +1,9 @@ require 'test_helper' class UsersControllerTest < ActionDispatch::IntegrationTest - # test "the truth" do - # assert true - # end + test "should get show" do + get users_show_url + assert_response :success + end + end From 485ada5543aee11f9f9f727c105ca6703bcce071 Mon Sep 17 00:00:00 2001 From: MrPranklin Date: Tue, 25 Dec 2018 23:54:36 +0100 Subject: [PATCH 21/25] Added message to post show view --- app/views/posts/new.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/posts/new.html.erb b/app/views/posts/new.html.erb index 496860b..058ea47 100644 --- a/app/views/posts/new.html.erb +++ b/app/views/posts/new.html.erb @@ -1,5 +1,5 @@

New Post

- +

Not working

<%= simple_form_for Post.new do |f| %> <%= f.input :id %> <%= f.input :author_id %> From 417b21c7844f8172380084a8baed847c839824a5 Mon Sep 17 00:00:00 2001 From: MrPranklin Date: Wed, 26 Dec 2018 00:16:28 +0100 Subject: [PATCH 22/25] Added print to views --- app/views/users/new.html.erb | 9 +++++++++ app/views/users/show.html.erb | 26 ++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 app/views/users/new.html.erb create mode 100644 app/views/users/show.html.erb 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..4cd01ad --- /dev/null +++ b/app/views/users/show.html.erb @@ -0,0 +1,26 @@ +

+ User: + <%= @user.id %> +

+ +

+ Email: + <%= @user.email %> +

+ +

+ Username: + <%= @user.username %> +

+ +

+ Created at: + <%= @user.created_at %> +

+ +

+ Updated at: + <%= @user.updated_at %> +

+ + From 2b173f96dc66487c5d09c431b69ceb9e7ecbc297 Mon Sep 17 00:00:00 2001 From: MrPranklin Date: Wed, 26 Dec 2018 00:23:44 +0100 Subject: [PATCH 23/25] Add newly added columns to print --- app/views/comments/index.html.erb | 8 +++++++- app/views/comments/show.html.erb | 10 ++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) 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 %>
User IDEmailUsernameCreated atUpdated at
<%= user.id %> + <%= user.email %><%= user.username %><%= user.created_at %> + <%= user.updated_at %> +
+ + @@ -18,6 +22,8 @@ + + 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 %> From fd2c1e4c7ef956285d4a83937d40da754a8cb814 Mon Sep 17 00:00:00 2001 From: MrPranklin Date: Wed, 26 Dec 2018 00:24:53 +0100 Subject: [PATCH 24/25] Removed empty line --- app/views/users/show.html.erb | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index 4cd01ad..d33e835 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -22,5 +22,3 @@ Updated at: <%= @user.updated_at %>

- - From 0a23b168481ab36d9f27c3b5f009f05e81ddb3b0 Mon Sep 17 00:00:00 2001 From: Filip Pranklin Date: Thu, 17 Jan 2019 18:51:44 +0100 Subject: [PATCH 25/25] Change belongs_to :user to :owner --- app/models/sub_reddit.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/sub_reddit.rb b/app/models/sub_reddit.rb index 1325347..4fb8d70 100644 --- a/app/models/sub_reddit.rb +++ b/app/models/sub_reddit.rb @@ -12,7 +12,7 @@ # class SubReddit < ApplicationRecord - belongs_to :user + belongs_to :owner, class_name: 'User' has_many :posts validates :title, presence: true, uniqueness: true
Post Author ContentCreated at:Updated at:
<%= 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?' } %>