Skip to content

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

Open
agagotowiec wants to merge 11 commits into
makersacademy:mainfrom
agagotowiec:main
Open

1,2,3,4 user stories done#215
agagotowiec wants to merge 11 commits into
makersacademy:mainfrom
agagotowiec:main

Conversation

@agagotowiec
Copy link
Copy Markdown

@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
Copy Markdown

@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
Copy Markdown

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

Comment thread app.rb
get '/test' do
'Test page'
get '/' do
'Chitter App'
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

detail - remove unused line

Comment thread app.rb
require 'sinatra/base'
require './lib/post'

class Chitter < Sinatra::Base
Copy link
Copy Markdown

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 thread lib/post.rb
Comment on lines +14 to +18
if ENV['ENVIRONMENT'] == 'test'
connection = PG.connect(dbname: 'chitter_test')
else
connection = PG.connect(dbname: 'chitter')
end
Copy link
Copy Markdown

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

Comment thread lib/post.rb
else
connection = PG.connect(dbname: 'chitter')
end
result = connection.exec("SELECT * FROM peeps ORDER BY date DESC")
Copy link
Copy Markdown

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.

Comment thread lib/post.rb
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])
Copy link
Copy Markdown

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
Copy Markdown

@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