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

1,2,3,4 user stories done #215

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open

Conversation

agagotowiec
Copy link

@agagotowiec agagotowiec commented Apr 1, 2022

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).

  • User story 1: "I want to see all the messages (peeps) in a browser"
  • User story 2: "I want to post a message (peep) to chitter"
  • User story 3: "I want to see the date the message was posted"
  • User story 4: "I want to see a list of peeps in reverse chronological order"

README checklist

Does your README contains instructions for

  • how to install,
  • how to run,
  • and how to test your code?

Here is a pill that can help you write a great README!

Copy link

@mohamedadan92 mohamedadan92 left a 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

Copy link

@alicelieutier alicelieutier left a 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'

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

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!

Comment on lines +14 to +18
if ENV['ENVIRONMENT'] == 'test'
connection = PG.connect(dbname: 'chitter_test')
else
connection = PG.connect(dbname: 'chitter')
end

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")

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])

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.

Comment on lines +33 to +35
expect(page).to have_content("2022-08-01")
expect(page).to have_content("2022-06-01")
expect(page).to have_content("2022-04-01")
Copy link

@alicelieutier alicelieutier Apr 4, 2022

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 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants