Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Branch c #2

Merged
merged 11 commits into from
Jul 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
AllCops:
Exclude:
- "db/**/*"
- "bin/*"
- "config/**/*"
- "Guardfile"
- "Rakefile"
- "README.md"
- "node_modules/**/*"

DisplayCopNames: true

Layout/LineLength:
Max: 120
Metrics/MethodLength:
Include:
- "app/controllers/*"
- "app/models/*"
Max: 20
Metrics/AbcSize:
Include:
- "app/controllers/*"
- "app/models/*"
Max: 50
Metrics/ClassLength:
Max: 150
Metrics/BlockLength:
ExcludedMethods: ['describe']
Max: 30

Style/Documentation:
Enabled: false
Style/ClassAndModuleChildren:
Enabled: false
Style/EachForSimpleLoop:
Enabled: false
Style/AndOr:
Enabled: false
Style/DefWithParentheses:
Enabled: false
Style/FrozenStringLiteralComment:
EnforcedStyle: never

Layout/HashAlignment:
EnforcedColonStyle: key
Layout/ExtraSpacing:
AllowForAlignment: false
Layout/MultilineMethodCallIndentation:
Enabled: true
EnforcedStyle: indented
Lint/RaiseException:
Enabled: false
Lint/StructNewOverride:
Enabled: false
Style/HashEachMethods:
Enabled: false
Style/HashTransformKeys:
Enabled: false
Style/HashTransformValues:
Enabled: false
24 changes: 24 additions & 0 deletions .stickler.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# add the linters you want stickler to use for this project
linters:
rubocop:
display_cop_names: true
# indicate where is the config file for rubocop
config: './rubocop.yml'

# add the files here you want to be ignored by stickler
files:
ignore:
- "bin/*"
- "test/*"
- "db/*"
- "config/*"
- "Guardfile"
- "Gemfile"
- "Rakefile"
- "README.md"
- "node_modules/**/*"

# PLEASE DO NOT enable auto fixing options
# if you need extra support from you linter - do it in your local env as described in README for this config

# find full documentation here: https://stickler-ci.com/docs
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,4 @@ end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
gem 'rubocop'
20 changes: 20 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ GEM
archive-zip (0.12.0)
io-like (~> 0.3.0)
arel (9.0.0)
ast (2.4.1)
bindex (0.8.1)
bootsnap (1.4.6)
msgpack (~> 1.0)
Expand Down Expand Up @@ -103,6 +104,9 @@ GEM
nio4r (2.5.2)
nokogiri (1.10.10)
mini_portile2 (~> 2.4.0)
parallel (1.19.2)
parser (2.7.1.4)
ast (~> 2.4.1)
public_suffix (4.0.5)
puma (3.12.6)
rack (2.2.3)
Expand Down Expand Up @@ -132,11 +136,25 @@ GEM
method_source
rake (>= 0.8.7)
thor (>= 0.19.0, < 2.0)
rainbow (3.0.0)
rake (13.0.1)
rb-fsevent (0.10.4)
rb-inotify (0.10.1)
ffi (~> 1.0)
regexp_parser (1.7.1)
rexml (3.2.4)
rubocop (0.88.0)
parallel (~> 1.10)
parser (>= 2.7.1.1)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.7)
rexml
rubocop-ast (>= 0.1.0, < 1.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 2.0)
rubocop-ast (0.2.0)
parser (>= 2.7.0.1)
ruby-progressbar (1.10.1)
ruby_dep (1.5.0)
rubyzip (2.3.0)
sass (3.7.4)
Expand Down Expand Up @@ -175,6 +193,7 @@ GEM
thread_safe (~> 0.1)
uglifier (4.2.0)
execjs (>= 0.3.0, < 3)
unicode-display_width (1.7.0)
web-console (3.7.0)
actionview (>= 5.0)
activemodel (>= 5.0)
Expand All @@ -199,6 +218,7 @@ DEPENDENCIES
listen (>= 3.0.5, < 3.2)
puma (~> 3.11)
rails (~> 5.2.4, >= 5.2.4.3)
rubocop
sass-rails (~> 5.0)
selenium-webdriver
spring
Expand Down
61 changes: 48 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,59 @@
# README
# PROJECT: BUILDING WITH ACTIVE RECORD

This README would normally document whatever steps are necessary to get the
application up and running.

Things you may want to cover:
This project builds on active records, models, and associations to create a Micro-Reddit app similar to Reddit.
Here a user can create a post and / or add comments to another user's post.
The project was created without adding a user interface.

* Ruby version

* System dependencies
## Built With

* Configuration
- Ruby 2.7.0
- Rails 5.2.4.3
- VSCode

* Database creation
## Getting start

* Database initialization
* In order to start with the project:
* You need to have Rails environment installed,
[Click here for instructions](https://guides.rubyonrails.org/getting_started.html)
* Clone this repository
* Run the rails server
* $ rails server
* Run rails db:migrate. It creates the database with the corresponding tables, columns and associations
* $ rails db:migrate
* You can test it in the console by running
* $ rails console
* Check User, Post or Comment to see the structure of each model

* How to run the test suite

* Services (job queues, cache servers, search engines, etc.)

* Deployment instructions

* ...

## Authors


👤 **Morah Paul**

- GitHub:[@github/chinweokwu](https://github.com/chinweokwu)
- Linkedin:[Morah Paul](https://www.linkedin.com/)


👤 **Oksana Petrova**

- GitHub:[@github/Laguna1](https://github.com/Laguna1)
- Linkedin:[linkedin/OksanaPetrova](https://www.linkedin.com/in/oksana-petrova/)
- Twitter:[@OksanaP48303303](https://twitter.com/OksanaP48303303)



## 🤝 Contributing

Contributions, issues, and feature requests are welcome!

Feel free to check the [issues page]().

## Show your support

Give a ⭐️ if you like this project!

6 changes: 6 additions & 0 deletions app/models/comment.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class Comment < ApplicationRecord
belongs_to :user
belongs_to :post

validates :body, presence: true
end
7 changes: 7 additions & 0 deletions app/models/post.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class Post < ApplicationRecord
validates :title, presence: true
validates :body, presence: true

belongs_to :user
has_many :comments
end
8 changes: 8 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class User < ApplicationRecord
validates :username, presence: true, length: { maximum: 25 }
validates :email, presence: true
validates :password, presence: true, length: { in: 5..16 }

has_many :posts
has_many :comments
end
13 changes: 13 additions & 0 deletions db/migrate/20200722195118_create_users.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class CreateUsers < ActiveRecord::Migration[5.2]
def change
create_table :users do |t|
t.string :username
t.string :email
t.string :password

t.timestamps
end
add_index :users, :username, unique: true
add_index :users, :email, unique: true
end
end
11 changes: 11 additions & 0 deletions db/migrate/20200722203852_create_posts.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class CreatePosts < ActiveRecord::Migration[5.2]
def change
create_table :posts do |t|
t.string :title
t.text :body
t.references :user, foreign_key: true

t.timestamps
end
end
end
11 changes: 11 additions & 0 deletions db/migrate/20200723111645_create_comments.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class CreateComments < ActiveRecord::Migration[5.2]
def change
create_table :comments do |t|
t.text :body
t.references :user, foreign_key: true
t.references :post, foreign_key: true

t.timestamps
end
end
end
44 changes: 44 additions & 0 deletions db/schema.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
#
# Note that this schema.rb definition is the authoritative source for your
# database schema. If you need to create the application database on another
# system, you should be using db:schema:load, not running all the migrations
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
# you'll amass, the slower it'll run and the greater likelihood for issues).
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2020_07_23_111645) do

create_table "comments", force: :cascade do |t|
t.text "body"
t.integer "user_id"
t.integer "post_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["post_id"], name: "index_comments_on_post_id"
t.index ["user_id"], name: "index_comments_on_user_id"
end

create_table "posts", force: :cascade do |t|
t.string "title"
t.text "body"
t.integer "user_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["user_id"], name: "index_posts_on_user_id"
end

create_table "users", force: :cascade do |t|
t.string "username"
t.string "email"
t.string "password"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["email"], name: "index_users_on_email", unique: true
t.index ["username"], name: "index_users_on_username", unique: true
end

end
11 changes: 11 additions & 0 deletions test/fixtures/comments.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html

one:
body: MyText
user: one
post: one

two:
body: MyText
user: two
post: two
11 changes: 11 additions & 0 deletions test/fixtures/posts.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html

one:
title: MyString
body: MyText
user: one

two:
title: MyString
body: MyText
user: two
11 changes: 11 additions & 0 deletions test/fixtures/users.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html

one:
username: MyString
email: MyString
password: MyString

two:
username: MyString
email: MyString
password: MyString
7 changes: 7 additions & 0 deletions test/models/comment_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'test_helper'

class CommentTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end
7 changes: 7 additions & 0 deletions test/models/post_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'test_helper'

class PostTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end
7 changes: 7 additions & 0 deletions test/models/user_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'test_helper'

class UserTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end