-
Notifications
You must be signed in to change notification settings - Fork 235
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
1,2,3,4 user stories done #215
base: main
Are you sure you want to change the base?
Conversation
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.
Great layout and easy to read app. No errors noticable
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.
Clear code, nicely separated and organised, well done!
I added a few comments below, let me know if anything doesn't make sense.
get '/test' do | ||
'Test page' | ||
get '/' do | ||
'Chitter App' |
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.
detail - remove unused line
@@ -1,8 +1,24 @@ | |||
require 'sinatra/base' | |||
require './lib/post' | |||
|
|||
class Chitter < Sinatra::Base |
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.
Nice use of RESTful routes!
if ENV['ENVIRONMENT'] == 'test' | ||
connection = PG.connect(dbname: 'chitter_test') | ||
else | ||
connection = PG.connect(dbname: 'chitter') | ||
end |
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.
These lines are present in all your methods that access the db - they could be extracted into a database helper class :)
else | ||
connection = PG.connect(dbname: 'chitter') | ||
end | ||
result = connection.exec("SELECT * FROM peeps ORDER BY date DESC") |
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.
I'm surprised queries without ;
work. I guess the framework adds the ;
. I would still make sure to add it however.
connection = PG.connect(dbname: 'chitter') | ||
end | ||
|
||
result = connection.exec_params("INSERT INTO peeps (date, author, message) VALUES('#{date}', $1, $2) RETURNING id, date, author, message;", [author, message]) |
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.
Nice that you are using exec_params to prevent sql injections here, but I'm wondering why you are not also doing that for the date, especially since the date is sent by the front-end as a param.
It would be different if the date was automatically added in ruby to peeps when they are created, and not coming from the front-end.
I know you form enforces a format for the input, but a malicious user could easily change the front-end html and send data in a different way, so your server should always protect itself from the front-end.
expect(page).to have_content("2022-08-01") | ||
expect(page).to have_content("2022-06-01") | ||
expect(page).to have_content("2022-04-01") |
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.
This doesn't actually check the order of the content. You could use regular expressions here to check that "2022-08-01" is above "2022-06-01", for example with something like
expect(page).to match(/2022-08-01.*2022-06-01/)
However, I think an even better test would check the content of the mew message comes before the content of an older one, this way the test would still pass if you decide to change the formatting of the date, given that the user story is about posts order, not dates :)
Agnieszka Gotowiec
Please write your full name here to make it easier to find your pull request.
User stories
Please list which user stories you've implemented (delete the ones that don't apply).
README checklist
Does your README contains instructions for
Here is a pill that can help you write a great README!