-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Ongoing development #2184
base: main
Are you sure you want to change the base?
Ongoing development #2184
Changes from all commits
964089c
1140ddb
4ae1a85
94bc429
ae0ebcb
479f06e
119c04e
e37f82c
25c5fbf
494f44f
0a3d9df
614f57c
48d060f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ | |
|
||
# Local cache of Rubocop remote config | ||
.rubocop-* | ||
seeds_chitter.sql |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,123 +1,5 @@ | ||
Chitter Challenge | ||
My Chitter Challenge | ||
================= | ||
|
||
* Feel free to use Google, your notes, books, etc. but work on your own | ||
* If you refer to the solution of another coach or student, please put a link to that in your README | ||
* If you have a partial solution, **still check in a partial solution** | ||
* You must submit a pull request to this repo with your code by 10am Monday morning | ||
 | ||
|
||
Challenge: | ||
------- | ||
|
||
As usual please start by forking this repo. | ||
|
||
We are going to write a small Twitter clone that will allow the users to post messages to a public stream. | ||
|
||
Features: | ||
------- | ||
|
||
``` | ||
STRAIGHT UP | ||
|
||
As a Maker | ||
So that I can let people know what I am doing | ||
I want to post a message (peep) to chitter | ||
|
||
As a maker | ||
So that I can see what others are saying | ||
I want to see all peeps in reverse chronological order | ||
|
||
As a Maker | ||
So that I can better appreciate the context of a peep | ||
I want to see the time at which it was made | ||
|
||
As a Maker | ||
So that I can post messages on Chitter as me | ||
I want to sign up for Chitter | ||
|
||
HARDER | ||
|
||
As a Maker | ||
So that only I can post messages on Chitter as me | ||
I want to log in to Chitter | ||
|
||
As a Maker | ||
So that I can avoid others posting messages on Chitter as me | ||
I want to log out of Chitter | ||
|
||
ADVANCED | ||
|
||
As a Maker | ||
So that I can stay constantly tapped in to the shouty box of Chitter | ||
I want to receive an email if I am tagged in a Peep | ||
``` | ||
|
||
Technical Approach: | ||
----- | ||
|
||
In the last two weeks, you integrated a database using the `pg` gem and Repository classes. You also implemented small web applications using Sinatra, RSpec, HTML and ERB views to make dynamic webpages. You can continue to use this approach when building Chitter Challenge. | ||
|
||
You can refer to the [guidance on Modelling and Planning a web application](https://github.com/makersacademy/web-applications/blob/main/pills/modelling_and_planning_web_application.md), to help you in planning the different web pages you will need to implement this challenge. If you'd like to deploy your app to Heroku so other people can use it, [you can follow this guidance](https://github.com/makersacademy/web-applications/blob/main/html_challenges/07_deploying.md). | ||
|
||
If you'd like more technical challenge now, try using an [Object Relational Mapper](https://en.wikipedia.org/wiki/Object-relational_mapping) as the database interface, instead of implementing your own Repository classes. | ||
|
||
Some useful resources: | ||
**Ruby Object Mapper** | ||
- [ROM](https://rom-rb.org/) | ||
|
||
**ActiveRecord** | ||
- [ActiveRecord ORM](https://guides.rubyonrails.org/active_record_basics.html) | ||
- [Sinatra & ActiveRecord setup](https://learn.co/lessons/sinatra-activerecord-setup) | ||
|
||
Notes on functionality: | ||
------ | ||
|
||
* You don't have to be logged in to see the peeps. | ||
* Makers sign up to chitter with their email, password, name and a username (e.g. [email protected], password123, Sam Morgan, sjmog). | ||
* The username and email are unique. | ||
* Peeps (posts to chitter) have the name of the maker and their user handle. | ||
* Your README should indicate the technologies used, and give instructions on how to install and run the tests. | ||
|
||
Bonus: | ||
----- | ||
|
||
If you have time you can implement the following: | ||
|
||
* In order to start a conversation as a maker I want to reply to a peep from another maker. | ||
|
||
And/Or: | ||
|
||
* Work on the CSS to make it look good. | ||
|
||
Good luck and let the chitter begin! | ||
|
||
Code Review | ||
----------- | ||
|
||
In code review we'll be hoping to see: | ||
|
||
* All tests passing | ||
* High [Test coverage](https://github.com/makersacademy/course/blob/main/pills/test_coverage.md) (>95% is good) | ||
* The code is elegant: every class has a clear responsibility, methods are short etc. | ||
|
||
Reviewers will potentially be using this [code review rubric](docs/review.md). Referring to this rubric in advance may make the challenge somewhat easier. You should be the judge of how much challenge you want at this moment. | ||
|
||
Notes on test coverage | ||
---------------------- | ||
|
||
Please ensure you have the following **AT THE TOP** of your spec_helper.rb in order to have test coverage stats generated | ||
on your pull request: | ||
|
||
```ruby | ||
require 'simplecov' | ||
require 'simplecov-console' | ||
|
||
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new([ | ||
SimpleCov::Formatter::Console, | ||
# Want a nice code coverage website? Uncomment this next line! | ||
# SimpleCov::Formatter::HTMLFormatter | ||
]) | ||
SimpleCov.start | ||
``` | ||
|
||
You can see your test coverage when you run your tests. If you want this in a graphical form, uncomment the `HTMLFormatter` line and see what happens! |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
require 'sinatra' | ||
require "sinatra/reloader" | ||
require 'sinatra/activerecord' | ||
require_relative './lib/peep' | ||
require_relative './lib/user' | ||
require_relative 'lib/database_connection' | ||
require 'bcrypt' | ||
|
||
# Need to edit database_connection later so this would work when deployed | ||
set :database, { adapter: "postgresql", database: "chitter_test" } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah noticed this! is this because you didn't want to fill up you deployed database with a load of rubbish when testing in rack-up? not sure if this is best practice? |
||
|
||
class Application < Sinatra::Base | ||
configure :development do | ||
register Sinatra::Reloader | ||
register Sinatra::ActiveRecordExtension | ||
also_reload 'lib/peep.rb' | ||
also_reload 'lib/user.rb' | ||
also_reload 'style.css' | ||
end | ||
|
||
get '/' do | ||
@peeps = Peep.all | ||
return erb(:index) | ||
end | ||
|
||
|
||
# look at other http methods - patch (db update/edit), delete | ||
get '/new-peep' do | ||
return erb(:new_peep) | ||
end | ||
|
||
# usually use /peep as convention - restful API | ||
post '/new-peep' do | ||
#params[:content] | ||
peep = Peep.create(content: params[:content]) | ||
return erb(:peeped) | ||
# Need to add user id of person logged in and the created_date_time | ||
end | ||
|
||
get '/new-user' do | ||
return erb(:new_user) | ||
end | ||
|
||
post '/new-user' do | ||
user = User.create( | ||
username: params[:username], | ||
email: params[:email], | ||
full_name: params[:full_name], | ||
password: password_encryption(params[:password]) | ||
) | ||
return erb(:user_created) | ||
end | ||
|
||
get '/login' do | ||
return erb(:login) | ||
end | ||
|
||
post '/login' do | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you need to have another method in this section decryption method (to take the encrypted password in the database and convert it back to the original password) Dont worry the BCrypt gem does all the work just need to learn the method! stored_password = BCrypt::Password.new(user.password) not sure if that makes any sense or even if I'm correct tho but can't login when deploying the code on localhost! |
||
user = User.find_by( email: params[:email], password: params[:password]) | ||
if user == nil | ||
return 'Incorrect email/password' | ||
else | ||
|
||
return redirect('/') | ||
end | ||
end | ||
|
||
private | ||
def password_encryption(password) | ||
encrypted_password = BCrypt::Password.create(password) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Like how you've made the password method private. |
||
end | ||
end | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# file: config.ru | ||
require './app' | ||
run Application |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OMG! this was a brave set to make. looking forward to you explaining it to me.