-
Notifications
You must be signed in to change notification settings - Fork 235
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
Pull request - Stephanie #226
Open
stephaniesomade
wants to merge
7
commits into
makersacademy:main
Choose a base branch
from
stephaniesomade:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
b47be5b
Setting up the databases
stephaniesomade fed847b
Added all method to Messages Class
stephaniesomade 4142b09
Bookmark class in MVC
stephaniesomade 7498e7a
Adding peep userstory
stephaniesomade 5971263
Added post and view buttons
stephaniesomade 8526dfa
Wrapped data in objects
stephaniesomade 1347a24
Added user class and db
stephaniesomade File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,35 @@ | ||
require 'sinatra/base' | ||
require './lib/messages' | ||
|
||
class Chitter < Sinatra::Base | ||
enable :sessions | ||
configure do | ||
enable :reloader | ||
end | ||
|
||
get '/test' do | ||
'Test page' | ||
end | ||
|
||
get '/chitter' do | ||
erb :index | ||
end | ||
|
||
get '/peeps' do | ||
@messages = Messages.all | ||
erb :allpeeps | ||
end | ||
|
||
get '/drafts' do | ||
erb :post | ||
end | ||
|
||
post '/postpeep' do | ||
peep = params['message'] | ||
Messages.create(message: peep) | ||
redirect('/chitter') | ||
end | ||
|
||
|
||
run! if app_file == $0 | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
require 'pg' | ||
|
||
class Messages | ||
|
||
def self.all | ||
if ENV['ENVIRONMENT'] == 'test' | ||
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. could you not use the db setup helper here to remove this if else statement? |
||
connection = PG.connect(dbname: 'chitter_test') | ||
else | ||
connection = PG.connect(dbname: 'chitter') | ||
end | ||
result = connection.exec('SELECT * FROM peeps;') | ||
result.map { |message| message['message'] } | ||
end | ||
|
||
def self.create(message:) | ||
if ENV['ENVIRONMENT'] == 'test' | ||
connection = PG.connect(dbname: 'chitter_test') | ||
else | ||
connection = PG.connect(dbname: 'chitter') | ||
end | ||
connection.exec("INSERT INTO peeps (message) VALUES('#{message}')") | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
feature 'Viewing added peeps' do | ||
scenario 'adds peeps to the list' do | ||
visit('/chitter') | ||
click_button('Post a Peep') | ||
|
||
expect(current_path).to eq '/drafts' | ||
|
||
fill_in('message', with: 'This is my first peep!') | ||
click_button('Submit') | ||
expect(current_path).to eq '/chitter' | ||
click_button('View all Peeps') | ||
|
||
expect(page).to have_content "This is my first peep!" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
require 'pg' | ||
|
||
feature 'Viewing messages' do | ||
scenario 'shows all messages' do | ||
|
||
connection = PG.connect(dbname: 'chitter_test') | ||
|
||
Messages.create(message: 'Update - I am in Paris') | ||
Messages.create(message: 'Just got back from the park!') | ||
Messages.create(message: 'Hi Chitter.') | ||
|
||
visit ('/peeps') | ||
|
||
expect(current_path).to eq '/peeps' | ||
expect(page).to have_content 'Update - I am in Paris' | ||
expect(page).to have_content 'Just got back from the park!' | ||
expect(page).to have_content 'Hi Chitter.' | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
require 'messages' | ||
require 'pg' | ||
|
||
describe Messages do | ||
describe '.all' do | ||
it 'returns a list of messages' do | ||
connection = PG.connect(dbname: 'chitter_test') | ||
|
||
Messages.create(message: 'Hello') | ||
Messages.create(message: 'Hi!') | ||
Messages.create(message: 'Hiya.') | ||
|
||
messages = Messages.all | ||
|
||
expect(messages.length).to eq 3 | ||
expect(messages).to include "Hello" | ||
expect(messages).to include "Hi!" | ||
expect(messages).to include "Hiya." | ||
end | ||
end | ||
|
||
describe '.create' do | ||
it 'creates a new posted peep' do | ||
Messages.create(message: "This is my first peep!") | ||
|
||
expect(Messages.all).to include 'This is my first peep!' | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<h1>All Peeps:</h1> | ||
<ul> | ||
<% @messages.each do |message| %> | ||
<li><%= message %></li> | ||
<% end %> | ||
</ul> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<h1>Welcome to Chitter:</h1> | ||
<form action="/peeps" method="get"> | ||
<input type="submit" value="View all Peeps"/> | ||
</form> | ||
|
||
<form action="/drafts" method='get'> | ||
<input type="submit" value="Post a Peep"> | ||
</form> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<h1>Post a Peep:</h1> | ||
<form action='/postpeep' method='post'> | ||
<input type="text" name="message"/> | ||
<input type="submit" value="Submit" /> | ||
</form> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This route might be clearer and stick to conventions better if it were called '/peep/new'