-
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
new fork to fix clone error #225
Open
PhilipCarr1
wants to merge
1
commit into
makersacademy:main
Choose a base branch
from
PhilipCarr1: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 all commits
Commits
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ ruby '3.0.2' | |
|
||
gem 'pg' | ||
gem 'sinatra' | ||
gem 'sinatra-contrib' | ||
|
||
group :test do | ||
gem 'capybara' | ||
|
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,66 +1,31 @@ | ||
## Chitter Challenge | ||
## How to install Chitter | ||
|
||
* Challenge time: until the end of the day | ||
* Feel free to use google, your notes, books etc but please work on your own | ||
* Please raise a pull request when you start this challenge, and keep pushing updates as and when you make commits throughout the day | ||
* There is _no expectation_ to finish all or any of the user stories, please use this time to reflect on where you feel you are with the skill and what may support your learning. | ||
* If you get blocked, please reflect on what blocked you and any strategies you adopted that helped you make progress. | ||
|
||
We are going to write a small Twitter clone that will allow the users to post messages to a public stream. | ||
- Clone this repo into a local repository | ||
|
||
## Set up | ||
|
||
To setup the database: | ||
|
||
* Connect to psql | ||
* Create the database using the psql command `CREATE DATABASE chitter;` | ||
* Connect to the database using the psql command `\c chitter`; | ||
* Run the query we have saved in the file 01_create_chitter_table.sql | ||
* Populate your table with a row by running `INSERT INTO peeps (message) values ('This is a peep!');` | ||
- Connect to psql | ||
- Create the database using the psql command `CREATE DATABASE chitter;` | ||
- Connect to the database using the psql command `\c chitter`; | ||
- Run the query we have saved in the file db/migrations/01_create_chitter_table.sql | ||
- Populate your table with a row by running `INSERT INTO peeps (message) values ('This is a peep!');` | ||
|
||
To check you have everything set up ok, please take a look at the peeps table inside the chitter database. You should see one row in there. | ||
To check you have everything set up ok, please take a look at the peeps table inside the chitter database. You should see one row in there. | ||
|
||
To setup the test database: | ||
* Connect to psql | ||
* Create the database using the psql | ||
command `CREATE DATABASE chitter_test;`; | ||
* Connect to the database using the psql command `\c chitter_test` | ||
* Run the query we have saved in the file 01_create_chitter_table.sql | ||
|
||
* `bundle install` | ||
* `rspec` | ||
|
||
You should see 1 passing test. | ||
|
||
## User stories | ||
|
||
``` | ||
As a Maker | ||
So that I can see what people are doing | ||
I want to see all the messages (peeps) | ||
in a browser | ||
``` | ||
- Connect to psql | ||
- Create the database using the psql | ||
command `CREATE DATABASE chitter_test;`; | ||
- Connect to the database using the psql command `\c chitter_test` | ||
- Run the query we have saved in the file db/migrations/01_create_chitter_table.sql | ||
|
||
``` | ||
As a Maker | ||
So that I can let people know what I am doing | ||
I want to post a message (peep) to chitter | ||
``` | ||
- `bundle install' | ||
|
||
``` | ||
As a Maker | ||
So that I can see when people are doing things | ||
I want to see the date the message was posted | ||
``` | ||
(Hint the database table will need to change to store the date too) | ||
## Run Chitter | ||
|
||
``` | ||
As a Maker | ||
So that I can easily see the latest peeps | ||
I want to see a list of peeps in reverse chronological order | ||
``` | ||
``` | ||
As a Maker | ||
So that I can find relevant peeps | ||
I want to filter on a specific keyword | ||
``` | ||
- 'ruby app.rb' | ||
- Go to http://localhost:4567/ in your web browser | ||
- To stop viewing Chitter, press CTRL+C twice in the Terminal. |
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,33 @@ | ||
require 'sinatra' | ||
require 'sinatra/base' | ||
require 'sinatra/reloader' | ||
require_relative 'database_connection_setup' | ||
require './lib/peeps' | ||
|
||
class Chitter < Sinatra::Base | ||
|
||
configure :development do | ||
register Sinatra::Reloader | ||
end | ||
|
||
get '/test' do | ||
'Test page' | ||
end | ||
|
||
get '/' do | ||
@peeps = Peeps.all | ||
erb :index | ||
end | ||
|
||
post '/add' do | ||
Peeps.create(peep: params[:peep]) | ||
redirect '/' | ||
end | ||
|
||
post '/search' do | ||
@peeps = Peeps.search_by_keyword(keyword: params[:search]) | ||
erb :search | ||
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,7 @@ | ||
require './lib/database_connection' | ||
|
||
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. Nice extraction |
||
DatabaseConnection.setup('chitter_test') | ||
else | ||
DatabaseConnection.setup('chitter') | ||
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 |
---|---|---|
@@ -1 +1 @@ | ||
CREATE TABLE peeps(id SERIAL PRIMARY KEY, message VARCHAR(60)); | ||
CREATE TABLE peeps(id SERIAL PRIMARY KEY, message VARCHAR(60), date DATE NOT NULL DEFAULT CURRENT_DATE); |
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 @@ | ||
require 'pg' | ||
|
||
class DatabaseConnection | ||
def self.setup(db_name) | ||
@connection = PG.connect(dbname: db_name) | ||
end | ||
|
||
class << self | ||
attr_reader :connection | ||
end | ||
|
||
def self.query(sql) | ||
@connection.exec(sql) | ||
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,43 @@ | ||
require_relative 'database_connection' | ||
|
||
class Peeps | ||
|
||
attr_reader :id, :peep, :date | ||
|
||
def initialize(id:, peep:, date:) | ||
@id = id | ||
@peep = peep | ||
@date = date | ||
end | ||
|
||
def self.create(peep:) | ||
result = DatabaseConnection.query( | ||
"INSERT INTO peeps (message) VALUES ('#{peep}') RETURNING id, message, date;" | ||
) | ||
Peeps.new(id: result[0]['id'], peep: result[0]['message'], date: result[0]['date']) | ||
end | ||
|
||
def self.all | ||
result = DatabaseConnection.query("SELECT * FROM peeps") | ||
result.map do |peep| | ||
Peeps.new( | ||
id: peep['id'], | ||
peep: peep['message'], | ||
date: peep['date'] | ||
) | ||
end | ||
end | ||
|
||
def self.search_by_keyword(keyword:) | ||
result = DatabaseConnection.query( | ||
"SELECT * FROM peeps WHERE message LIKE '%#{keyword}%';" | ||
) | ||
result.map do |peep| | ||
Peeps.new( | ||
id: peep['id'], | ||
peep: peep['message'], | ||
date: peep['date'] | ||
) | ||
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,102 @@ | ||
* { | ||
font-family: roboto; | ||
color: #232323; | ||
max-width: 960px; | ||
margin: auto; | ||
} | ||
|
||
h1 { | ||
font-size: 3em; | ||
font-style: normal; | ||
color: blue; | ||
} | ||
|
||
ul.no-bullets { | ||
list-style-type: none; | ||
margin: 0; | ||
padding: 0; | ||
} | ||
|
||
.top-header { | ||
display: flex; | ||
width: 100%; | ||
position: fixed; | ||
top: 0; | ||
z-index: 1; | ||
border-bottom: 1px solid lightgrey; | ||
background-color: white; | ||
} | ||
|
||
.header-items { | ||
width: 100%; | ||
display: flex; | ||
justify-content: space-between; | ||
align-items: center; | ||
margin-right: 1em; | ||
} | ||
|
||
.main-content { | ||
position: relative; | ||
margin-top: 75px; | ||
} | ||
|
||
.new-peep { | ||
position: fixed; | ||
margin-top: 5px; | ||
width: 100%; | ||
background-color: white; | ||
z-index: 1; | ||
} | ||
|
||
.peep-container { | ||
margin-top: 50px; | ||
border: 1px solid lightgray; | ||
} | ||
|
||
.peep { | ||
font-size: large; | ||
border-bottom: solid; | ||
border-width: 2px; | ||
border-color: lightgray; | ||
padding: 50px; | ||
} | ||
|
||
.peep-text { | ||
text-align: left; | ||
} | ||
|
||
.date-text { | ||
margin-left: 20px; | ||
font-size: small; | ||
font-weight: lighter; | ||
} | ||
|
||
.input { | ||
padding: 10px; | ||
border: 1px solid lightgray; | ||
border-radius: 5px; | ||
margin-bottom: 10px; | ||
} | ||
|
||
.chitter-button { | ||
background-color: blue; | ||
color: white; | ||
border: none; | ||
border-radius: 5px; | ||
padding: 10px; | ||
text-align: center; | ||
text-decoration: none; | ||
display: inline-block; | ||
margin: 4px 2px; | ||
cursor: pointer; | ||
transition-duration: 0.4s; | ||
} | ||
|
||
.chitter-button:hover { | ||
background-color: goldenrod; | ||
} | ||
|
||
.chitter-button:active { | ||
box-shadow: 0 0 0 0 goldenrod; | ||
transform: scale(96%); | ||
} |
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,21 @@ | ||
require 'database_connection' | ||
|
||
describe DatabaseConnection do | ||
describe '#setup' do | ||
it 'sets up a connection to the database with PG' do | ||
expect(PG).to receive(:connect).with(dbname: 'chitter_test') | ||
|
||
DatabaseConnection.setup('chitter_test') | ||
end | ||
end | ||
|
||
describe '#query' do | ||
it 'executes a query via PG' do | ||
connection = DatabaseConnection.setup('chitter_test') | ||
|
||
expect(connection).to receive(:exec).with('SELECT * FROM peeps;') | ||
|
||
DatabaseConnection.query('SELECT * FROM peeps;') | ||
end | ||
end | ||
end |
Empty file.
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 @@ | ||
feature 'post a peep' do | ||
scenario 'the user can post a peep' do | ||
visit('/') | ||
fill_in('peep', with: "I posted a peep!") | ||
click_button('Peep!') | ||
expect(page).to have_content "I posted a 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,14 @@ | ||
feature 'filter peeps by keyword' do | ||
scenario 'the user can filter peeps by keyword' do | ||
Peeps.create(peep: 'This is a peep!') | ||
Peeps.create(peep: 'This is another peep!') | ||
Peeps.create(peep: 'This is a third peep!') | ||
|
||
visit('/') | ||
fill_in('search', with: 'third') | ||
click_button('Search') | ||
expect(page).to have_content 'This is a third peep!' | ||
expect(page).to have_no_content 'This is a peep!' | ||
expect(page).to have_no_content 'This is another 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,9 @@ | ||
require_relative '../setup_test_database' | ||
|
||
feature 'viewing peeps' do | ||
scenario 'the user can view peeps on the homepage with the date posted' do | ||
add_row_to_test_database | ||
visit('/') | ||
expect(page).to have_content "This is a peep! Posted on 2022-04-01." | ||
end | ||
end |
Oops, something went wrong.
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.
You can delete this