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

15/07/22 #236

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

15/07/22 #236

wants to merge 1 commit into from

Conversation

erb16
Copy link

@erb16 erb16 commented Jul 18, 2022

Your name

Emily Bayliss

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"

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!

Comment on lines +2 to +22

class Peep
def self.all
if ENV['ENVIRONMENT'] == 'test'
connection = PG.connect(dbname: 'chitter_test')
else
connection = PG.connect(dbname: 'chitter')
end

result = connection.exec("SELECT * FROM peeps")
result.map { |peep| peep['message'] }
end

def self.create(peep:, timestamp:)
if ENV['ENVIRONMENT'] == 'test'
connection = PG.connect(dbname: 'chitter_test')
else
connection = PG.connect(dbname: 'chitter')
end

connection.exec("INSERT INTO peeps (message, timestamp) VALUES('#{peep}', #{timestamp})")
Copy link

Choose a reason for hiding this comment

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

nice and easy to read

@@ -0,0 +1,8 @@
feature 'Viewing peeps' do
scenario 'viewing related timestamp' do
Copy link

Choose a reason for hiding this comment

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

It seems like this test is just for viewing the peeps rather than timestamps, as the expected outcome is just a lil peep peep. I'm guessing you were halfway through adapting an existing test?

Copy link
Contributor

Choose a reason for hiding this comment

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

Nice observation @Amy-O ! I agree, right now this test is not testing what it says it does.

Comment on lines +6 to +15
# connection = PG.connect(dbname: 'chitter_test')

# # Add the test data
# connection.exec("INSERT INTO peeps VALUES(1, 'Peep one');")
# connection.exec("INSERT INTO peeps VALUES(2, 'Peep two');")
# connection.exec("INSERT INTO peeps VALUES(3, 'Peep three');")

# Bookmark.create(website: "http://www.makersacademy.com")
# Bookmark.create(website: "http://www.destroyallsoftware.com")
# Bookmark.create(website: "http://www.google.com")
Copy link

Choose a reason for hiding this comment

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

I didn't think to add the bookmark stuff in comments for easier comparison! smart

Copy link
Contributor

@siellsiell siellsiell left a comment

Choose a reason for hiding this comment

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

Hey Emily,

This is a good attempt at this challenge, well done! You've got good feature tests. Next time, make sure you add unit tests as well so that you can test your Peep class in isolation. I've left some more detailed comments below.

Simo


get '/peeps' do
@peeps = Peep.all
# @time = Peep.time
Copy link
Contributor

Choose a reason for hiding this comment

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

It's always a good idea to remove commented out code from code you submit for code review (anywhere, not just at Makers)

@@ -0,0 +1,2 @@
-- To both chitter and chitter_test databases:
ALTER TABLE peeps ADD COLUMN timestamp VARCHAR(60);
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice use of the timestamp column type!

Comment on lines +16 to +20
if ENV['ENVIRONMENT'] == 'test'
connection = PG.connect(dbname: 'chitter_test')
else
connection = PG.connect(dbname: 'chitter')
end
Copy link
Contributor

Choose a reason for hiding this comment

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

You're using this same piece of code in more than one place in this file. How might you get rid of this duplication?

@@ -0,0 +1,8 @@
feature 'Viewing peeps' do
scenario 'viewing related timestamp' do
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice observation @Amy-O ! I agree, right now this test is not testing what it says it does.

visit('/peeps/add')
fill_in('peep', with: 'Peep peep!')
click_button('Post')
expect(page).to have_content ""
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't we be expecting the page to have "Peep peep!" as content?

@@ -41,6 +42,11 @@
RSpec.configure do |config|
config.before(:each) do
setup_test_database

# new_time = Time.local(2008, 9, 1, 12, 0, 0)
# Timecop.freeze(new_time)
Copy link
Contributor

Choose a reason for hiding this comment

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

I see you were trying to use Timecop to freeze the time during tests. Maybe it was tricky getting it to work? An alternative that doesn't require an additional gem is to use mocking, e.g.:

@now = Time.now
allow(Time).to receive(:now).and_return(@now)

end

post '/peeps' do
Peep.create(peep: params[:peep], timestamp: params[:timestamp])
Copy link
Contributor

Choose a reason for hiding this comment

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

Passing the time in here is one way to do it but it's vulnerable to bugs. For example:

  • the user may click "submit" some time after the page was generated from your erb view, so the time of the peep will be inaccurate
  • the user can influence the time by sending their own POST requests and putting in a bogus time (e.g. to get their peep to show first even though it's old)

For such reasons, it's best to generate timestamps in your Model when you're about to add the peep to the database so that you're sure it will be accurate. I see that you were thinking along those lines in your commented out code in the chitter.rb. You were on the right track!

To control the time in tests, you can stub the return value of Time.now (see another comment further down).

@@ -0,0 +1,5 @@
<ul>
<% @peeps.each do |peep| %>
<li><%=peep%></li>
Copy link
Contributor

Choose a reason for hiding this comment

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

All the rest of your code is there to fulfil user story 3 (showing the timestamp) -- did you run out of time or did you get blocked?

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.

None yet

3 participants