Miranda Frudd - chitter challenge (unfinished)#235
Conversation
…o chitter_test db, but it wouldn't work as the data kept disappearing.
siellsiell
left a comment
There was a problem hiding this comment.
Hey Miranda,
I know you felt some confusion about how to connect an app to a database, but you were actually really close to connecting it all up -- all the ingredients are there. I left a few comments with some pointers.
Let me know if you have any questions! You can reply to my comments on this PR or DM me.
Simo
| fill_in 'Message', with: 'First Message' | ||
| click_on 'Submit' | ||
| visit '/messages' | ||
| expect(page).to have_content "First Message" |
There was a problem hiding this comment.
This is a good example of a feature test, well done!
| # context "so that I can create a new message" do | ||
| # it "#create adds a new message" do | ||
| # message = Message.create(message: 'Another message') | ||
| # expect(message.message).to eq "Another message" |
There was a problem hiding this comment.
You were really close! One way to check that create has really added the message to the database would be to call Message.all after calling create and check that your message is now part of the result set.
There was a problem hiding this comment.
Thank you! I think I understand how the class variables can be used to query the database now. I think I was trying to add class objects to the database but that's not right - I needed to gather params from a form and add them to a row of the database table using an SQL query within my class
| end | ||
|
|
||
| post '/messages' do | ||
| # Message.create(message: params[:message]) |
There was a problem hiding this comment.
It looks like you were thinking of creating the message in your POST route above (the commented out bit), which is good. Where would the right place be to retrieve it the message again so that you can display it to the user? You already have all the methods you need to achieve that in your Message class!
There was a problem hiding this comment.
I should have used Message.all to display the messages from the db table in the get route
| if ENV['ENVIRONMENT'] == 'test' | ||
| connection = PG.connect(dbname: 'chitter_test') | ||
| else | ||
| connection = PG.connect(dbname: 'chitter') | ||
| end |
There was a problem hiding this comment.
You're using this same piece of code in more than one place in this file. How might you get rid of this duplication?
Your name
Miranda Frudd
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
-> yes but I've mainly used what was already given to us
Here is a pill that can help you write a great README!