-
Notifications
You must be signed in to change notification settings - Fork 240
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
Amy's Chitter #233
base: main
Are you sure you want to change the base?
Amy's Chitter #233
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# Your name | ||
# Amy O'Connor | ||
|
||
Please write your full name here to make it easier to find your pull request. | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,22 @@ | ||
require 'sinatra/base' | ||
require './lib/peep' | ||
|
||
class Chitter < Sinatra::Base | ||
get '/test' do | ||
'Test page' | ||
get '/' do | ||
@peeps = Peep.all | ||
erb :'index' | ||
end | ||
|
||
get '/new' do | ||
erb :"new_peep" | ||
end | ||
|
||
post '/' do | ||
peep = params['peep'] | ||
connection = PG.connect(dbname: 'chitter') | ||
connection.exec("INSERT INTO peeps (message) VALUES('#{peep}')") | ||
Comment on lines
+16
to
+17
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since you already have a |
||
redirect '/' | ||
p "Peep sent!" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. everything clear and neatly laid out There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no repetitions either |
||
end | ||
|
||
run! if app_file == $0 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"result": { | ||
"line": 100.0 | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What does this do? |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
require 'pg' | ||
|
||
class Peep | ||
def self.create | ||
|
||
end | ||
|
||
def self.all | ||
connection = PG.connect(dbname: 'chitter') | ||
result = connection.exec("SELECT * FROM peeps;") | ||
result.map { |peep| peep['message'] } | ||
end | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. class follows the single responsibility principle |
||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
feature 'Viewing all peeps' do | ||
scenario 'visiting the home page' do | ||
visit('/') | ||
peeps = Peep.all | ||
expect(page).to have_content "This is a peep!" | ||
end | ||
end | ||
|
||
feature 'Adding a peep' do | ||
scenario 'Adding a peep to Chitter feed' do | ||
visit('/new') | ||
fill_in('peep', with: "It is a bit warm!") | ||
click_button('Peep') | ||
expect(page).to have_content "It is a bit warm!" | ||
end | ||
end | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice feature tests! It would be good to see a unit test for your |
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this should pass! |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<% @peeps.each do |peep| %> | ||
<%= peep %> <br> | ||
<% end %> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<form action="/" method="post"> | ||
<input type="test" name="peep" /> | ||
<input type="submit" value="Peep" /> | ||
</form> |
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! It's always a good idea to remove test code from code you submit for code review (anywhere, not just at Makers). Make sure you remember to also remove code you added for debugging.