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

Pablo Joyce chitter challenge #2174

Open
wants to merge 80 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
80 commits
Select commit Hold shift + click to select a range
5ccef5b
chitter plan setup
pablisch Apr 6, 2023
9956e10
limited project setup
pablisch Apr 6, 2023
04ddf5e
Project files setup. Rackup error.
pablisch Apr 7, 2023
e4c30e0
app.rb not seeing peep methods. RSpec tests ok
pablisch Apr 7, 2023
a9307db
all tests pass. peep & user #s not seen by app.rb
pablisch Apr 7, 2023
fb90cd7
setup pages. peep/user #s working. tests pass
pablisch Apr 8, 2023
f9417d0
create peep part coded. Test passing
pablisch Apr 8, 2023
6a3a0e4
Added hidden input to add_peep.erb for user_id val
pablisch Apr 9, 2023
60390cf
Working again after anomalous errors
pablisch Apr 9, 2023
5821da3
basic register process working and tested
pablisch Apr 9, 2023
5f73b84
Part way through vaildation. tests passing.
pablisch Apr 10, 2023
3ff7f2b
pablisch Apr 10, 2023
964a449
Valdiation complete except unique
pablisch Apr 10, 2023
8eda5ca
unique email and username validation and tests
pablisch Apr 10, 2023
cca3382
installed bcrypt
pablisch Apr 10, 2023
4d53c3e
Added bcrypt code that has broken tests
pablisch Apr 10, 2023
1144a1a
Edited PWs in seeds tables to hashes. Tests good
pablisch Apr 10, 2023
2897786
reverse bcrypt. some css.
pablisch Apr 10, 2023
5f5a03e
Some small css and index.erb changes
pablisch Apr 11, 2023
0a2a574
Fixed issue of wrong db being used
pablisch Apr 11, 2023
fa32980
seeds edit and about to start bcrypt again
pablisch Apr 11, 2023
45dd4d3
bcrypt implemented and working
pablisch Apr 11, 2023
44653c7
Merge pull request #1 from pablisch/bcrypt
pablisch Apr 11, 2023
11fb2be
mostly css changes and erb page layout
pablisch Apr 11, 2023
7e3e7f6
Playing around with time format
pablisch Apr 11, 2023
8f77719
css almost done. tests passing
pablisch Apr 11, 2023
378b67a
updated tables
pablisch Apr 11, 2023
87684c9
setup for deploy
pablisch Apr 11, 2023
9ea5c6f
updated database_connect for Render
pablisch Apr 11, 2023
28e1758
commented out all uses of logged var
pablisch Apr 11, 2023
0047743
deploy unsuccessful. changes reversed.
pablisch Apr 11, 2023
c8da0b6
images moved
pablisch Apr 12, 2023
dd80942
shortened route paths. Tests all working
pablisch Apr 13, 2023
98178ce
edit logged to session user_id
pablisch Apr 13, 2023
195030b
commented out all instances of settings.logged
pablisch Apr 13, 2023
ad1e613
Database connection set to deploy
pablisch Apr 13, 2023
dbf2c85
remove p test from peep repo rb
pablisch Apr 13, 2023
6e16997
Removed all logged mentions from app.rb
pablisch Apr 13, 2023
316a1f1
Removed logged from add peep erb
pablisch Apr 13, 2023
cc3669b
Removed last 'logged' from index erb
pablisch Apr 13, 2023
54e41ec
indent changes in index.erb
pablisch Apr 13, 2023
0fd6fe2
conditional correction in index.rb
pablisch Apr 13, 2023
a45ff71
Removed settings.logged from register & login erb
pablisch Apr 13, 2023
77e969b
replaced Sinatra validation var for session var
pablisch Apr 13, 2023
251ad3d
Edit database connection for deploy
pablisch Apr 13, 2023
0cb10f7
Disposed of settings.message. The last Sinatra var
pablisch Apr 13, 2023
b64a3e9
css styling for buttons and input fields
pablisch Apr 13, 2023
4d5e967
Added padding to below error messages
pablisch Apr 13, 2023
2f4c3ce
extra padding for header elements
pablisch Apr 13, 2023
94a3411
15px padding below panel p
pablisch Apr 13, 2023
b9954d3
panel p margin 10px
pablisch Apr 13, 2023
53625b8
text box margins
pablisch Apr 14, 2023
da5e800
extra margin bottom for text boxes
pablisch Apr 14, 2023
8d7e703
margin left for text boxes
pablisch Apr 14, 2023
e2337b2
correct margin for new peep page
pablisch Apr 14, 2023
c69b125
adjustment to new peep page margins
pablisch Apr 14, 2023
ec5acbe
Added hover colour for nav links
pablisch Apr 14, 2023
4b4646f
button hover colour change
pablisch Apr 14, 2023
4a4c1be
nav h1 hover white
pablisch Apr 14, 2023
a58df1d
DB connection set for local view
pablisch Apr 14, 2023
5f57bdf
small css edits to nav
pablisch Apr 14, 2023
3586557
db connect to deploy
pablisch Apr 14, 2023
94a0c34
text input field alignment
pablisch Apr 14, 2023
853d26f
Comment out render deploy database connect code
pablisch Apr 19, 2023
73f3ef2
Fixed test and edits to README
pablisch Jun 23, 2023
cbe4f45
More README and chitter_plan updates
pablisch Jun 23, 2023
53e9a3f
Final, for now, README edit
pablisch Jun 23, 2023
3f71018
main README edit
pablisch Jun 23, 2023
b0e66c1
Merge branch 'main' into local-server
pablisch Jun 23, 2023
975a2d7
Merge pull request #2 from pablisch/local-server
pablisch Jun 23, 2023
6fde111
Added links and two images to readme
pablisch Jun 27, 2023
d054c50
Added images for test and coverage
pablisch Jun 27, 2023
8bad1fb
Format test
pablisch Jun 27, 2023
66ce8d4
Format test
pablisch Jun 27, 2023
b93f21f
Format test
pablisch Jun 27, 2023
948055e
Format test
pablisch Jun 27, 2023
755b40a
Format test
pablisch Jun 27, 2023
55f9ca9
Added tech symbols
pablisch Jun 27, 2023
212c657
Changed user emails and passwords
pablisch Jul 15, 2023
eb65387
Updated tables and seeds
pablisch Jul 15, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,14 @@ end
group :development, :test do
gem 'rubocop', '1.20'
end

gem "pg", "~> 1.4"

gem "sinatra", "~> 3.0"
gem "sinatra-contrib", "~> 3.0"
gem "webrick", "~> 1.8"
gem "rack-test", "~> 2.1"

gem "rackup", "~> 1.0"

gem "bcrypt", "~> 3.1"
37 changes: 37 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,24 @@ GEM
specs:
ansi (1.5.0)
ast (2.4.2)
bcrypt (3.1.18)
diff-lcs (1.4.4)
docile (1.4.0)
multi_json (1.15.0)
mustermann (3.0.0)
ruby2_keywords (~> 0.0.1)
parallel (1.20.1)
parser (3.0.2.0)
ast (~> 2.4.1)
pg (1.4.6)
rack (2.2.6.4)
rack-protection (3.0.5)
rack
rack-test (2.1.0)
rack (>= 1.3)
rackup (1.0.0)
rack (< 3)
webrick
rainbow (3.0.0)
regexp_parser (2.1.1)
rexml (3.2.5)
Expand Down Expand Up @@ -36,6 +49,7 @@ GEM
rubocop-ast (1.11.0)
parser (>= 3.0.1.1)
ruby-progressbar (1.11.0)
ruby2_keywords (0.0.5)
simplecov (0.21.2)
docile (~> 1.1)
simplecov-html (~> 0.11)
Expand All @@ -46,18 +60,41 @@ GEM
terminal-table
simplecov-html (0.12.3)
simplecov_json_formatter (0.1.3)
sinatra (3.0.5)
mustermann (~> 3.0)
rack (~> 2.2, >= 2.2.4)
rack-protection (= 3.0.5)
tilt (~> 2.0)
sinatra-contrib (3.0.5)
multi_json
mustermann (~> 3.0)
rack-protection (= 3.0.5)
sinatra (= 3.0.5)
tilt (~> 2.0)
terminal-table (3.0.1)
unicode-display_width (>= 1.1.1, < 3)
tilt (2.1.0)
unicode-display_width (2.0.0)
webrick (1.8.1)

PLATFORMS
ruby
x86_64-darwin-20
x86_64-darwin-21
x86_64-linux

DEPENDENCIES
bcrypt (~> 3.1)
pg (~> 1.4)
rack-test (~> 2.1)
rackup (~> 1.0)
rspec
rubocop (= 1.20)
simplecov
simplecov-console
sinatra (~> 3.0)
sinatra-contrib (~> 3.0)
webrick (~> 1.8)

RUBY VERSION
ruby 3.0.2p107
Expand Down
178 changes: 129 additions & 49 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
Chitter Challenge
=================
# Chitter Challenge by Pablo Joyce

* Feel free to use Google, your notes, books, etc. but work on your own
* If you refer to the solution of another coach or student, please put a link to that in your README
* If you have a partial solution, **still check in a partial solution**
* You must submit a pull request to this repo with your code by 10am Monday morning
[Getting Started](#getting-started) | [Using the application](#using-the-application) | [Running the tests](#running-the-tests) | [Design](#design) | [Screenshots](#screenshots) | [Technologies used](#technologies-used) | [Notes on test coverage](#notes-on-test-coverage)

Challenge:
-------
<p align="left">
<img src="https://raw.githubusercontent.com/devicons/devicon/master/icons/ruby/ruby-original.svg" alt="ruby" width="40" height="40"/>
<img src="https://raw.githubusercontent.com/devicons/devicon/master/icons/rspec/rspec-original.svg" alt="rspec" width="40" height="40"/>
<img src="https://raw.githubusercontent.com/devicons/devicon/master/icons/postgresql/postgresql-original.svg" alt="postgresql" width="40" height="40"/>
<img src="https://raw.githubusercontent.com/devicons/devicon/master/icons/git/git-original.svg" alt="git" width="40" height="40"/>
<img src="https://raw.githubusercontent.com/devicons/devicon/master/icons/github/github-original.svg" alt="github" width="40" height="40"/>
</p>

As usual please start by forking this repo.
* This project is a solo Ruby project completed at the end of the web applications module of the Makers Academy bootcamp.
* The application is built with the Sinatra web framework, rendering view files using ERB
* The application uses a PostgresSQL database
* The database connection is established in `lib/database_connection.rb` using the `pg` gem
* Seed data for tests is included in `spec/seeds.sql`

We are going to write a small Twitter clone that will allow the users to post messages to a public stream.
## The Brief

Features:
-------
To create a basic Twitter clone that will allow the users to post messages.
We were given the following user stories as a starting point:

```
STRAIGHT UP
Expand Down Expand Up @@ -52,61 +57,130 @@ So that I can stay constantly tapped in to the shouty box of Chitter
I want to receive an email if I am tagged in a Peep
```

Technical Approach:
-----
We were given the following notes on functionality:

In the last two weeks, you integrated a database using the `pg` gem and Repository classes. You also implemented small web applications using Sinatra, RSpec, HTML and ERB views to make dynamic webpages. You can continue to use this approach when building Chitter Challenge.
* You don't have to be logged in to see the peeps.
* Makers sign up to chitter with their email, password, name and a username (e.g. [email protected], password123, Sam Morgan, sjmog).
* The username and email are unique.
* Peeps (posts to chitter) have the name of the maker and their user handle.

You can refer to the [guidance on Modelling and Planning a web application](https://github.com/makersacademy/web-applications/blob/main/pills/modelling_and_planning_web_application.md), to help you in planning the different web pages you will need to implement this challenge. If you'd like to deploy your app to Heroku so other people can use it, [you can follow this guidance](https://github.com/makersacademy/web-applications/blob/main/html_challenges/07_deploying.md).
## Getting Started
[Top](#chitter-challenge-by-pablo-joyce) | [Use](#using-the-application) | [Tests](#running-the-tests) | [Design](#design) | [Screenshots](#screenshots) | [Tech](#technologies-used) | [Coverage](#notes-on-test-coverage)

If you'd like more technical challenge now, try using an [Object Relational Mapper](https://en.wikipedia.org/wiki/Object-relational_mapping) as the database interface, instead of implementing your own Repository classes.
At time of writing, this project has a version deployed on Render at [https://chitter-7pam.onrender.com/](https://chitter-7pam.onrender.com/). Please note that this may take 30 seconds or longer to 'spin up' as it is deployed on a free tier of Render.
At some point in the future, this version may be taken down as Render only allows a single database instance on the free tier.

Some useful resources:
**Ruby Object Mapper**
- [ROM](https://rom-rb.org/)
For the local version, clone this repository to your local machine:
`git clone https://github.com/pablisch/chitter-challenge.git`

**ActiveRecord**
- [ActiveRecord ORM](https://guides.rubyonrails.org/active_record_basics.html)
- [Sinatra & ActiveRecord setup](https://learn.co/lessons/sinatra-activerecord-setup)
Switch to the `local-server` branch:
`git switch local-server`

Notes on functionality:
------
cd to the project and install dependencies:
`bundle install`

* You don't have to be logged in to see the peeps.
* Makers sign up to chitter with their email, password, name and a username (e.g. [email protected], password123, Sam Morgan, sjmog).
* The username and email are unique.
* Peeps (posts to chitter) have the name of the maker and their user handle.
* Your README should indicate the technologies used, and give instructions on how to install and run the tests.
Ensure that your postgres server is accessable at the IP address 127.0.0.1.
Create the postgreSQL databases for running and testing the project:
```bash
createdb chitter
createdb chitter_test
```
Create the tables in the databases:
```bash
psql -h 127.0.0.1 chitter < spec/tables.sql
psql -h 127.0.0.1 chitter_test < spec/tables.sql
```
Populate the test database with seed data:
```bash
psql -h 127.0.0.1 chitter < spec/seeds.sql
psql -h 127.0.0.1 chitter_test < spec/seeds.sql
```
Start the development server:

`rackup`

Access the website in your browser at [localhost:9292](http://localhost:9292/).

## Using the application
[Top](#chitter-challenge-by-pablo-joyce) | [Getting Started](#getting-started) | [Tests](#running-the-tests) | [Design](#design) | [Screenshots](#screenshots) | [Tech](#technologies-used) | [Coverage](#notes-on-test-coverage)

Be default uses can see all messages posted by all users, but cannot post messages.

Follow the link to register as a user, you will then be prompted to redirect to login.

Bonus:
-----
After login, you will be redirected to the home page where you can post a new message. messages posted by all users will appear here in reverse chronological order.

If you have time you can implement the following:
## Running the tests

* In order to start a conversation as a maker I want to reply to a peep from another maker.
`rspec`

And/Or:
All tests should pass with a total code coverage of **99.41%**.

* Work on the CSS to make it look good.
Screenshots of the tests and coverage can be found in the [Coverage](#notes-on-test-coverage) section of this readme.

Good luck and let the chitter begin!
## Design
[Top](#chitter-challenge-by-pablo-joyce) | [Getting Started](#getting-started) | [Use](#using-the-application) | [Tests](#running-the-tests) | [Screenshots](#screenshots) | [Tech](#technologies-used) | [Coverage](#notes-on-test-coverage)

Code Review
-----------
The design planning used at the time of making can be seen in recipes/chitter_plan.md.

In code review we'll be hoping to see:
I started by creating a [diagram of the user experience]([.images/chitter3.png](https://github.com/pablisch/chitter-challenge/blob/main/images/chitter3.png?raw=true)) and incorporated the routes and validations into this diagram:

* All tests passing
* High [Test coverage](https://github.com/makersacademy/course/blob/main/pills/test_coverage.md) (>95% is good)
* The code is elegant: every class has a clear responsibility, methods are short etc.
![chitter user experience diagram](./images/chitter3.png)

Reviewers will potentially be using this [code review rubric](docs/review.md). Referring to this rubric in advance may make the challenge somewhat easier. You should be the judge of how much challenge you want at this moment.
The design itself changed a lot during the design process as the diagramming revealed issues and solved many problems before I started coding.
This gave me a good roadmap from which to build the app.

Notes on test coverage
----------------------
* The application is built with the Sinatra web framework, rendering view files using ERB
* Each database table has a corresponding Ruby class defined with a singular version of the name of the table.
* Each table has an additional 'TABLENAME_repository' class with methods that allow for CRUD operations on the DB.
* The database connection is established in `lib/database_connection.rb` using the `pg` gem
* The database tables have a one-to-many relationship with the users table. This is implemented by storing the user_id in the peeps table.
* Route handling occurs in the `Application` class defined in [./app.rb](./app.rb). [./config.ru](./config.ru) executes the code inside of `Application` when `rackup` is run at the command line.
* Passwords are hashed using the [BCrypt](https://rubygems.org/gems/bcrypt/versions/3.1.12) gem.

Please ensure you have the following **AT THE TOP** of your spec_helper.rb in order to have test coverage stats generated
on your pull request:
## Screenshots
[Top](#chitter-challenge-by-pablo-joyce) | [Getting Started](#getting-started) | [Use](#using-the-application) | [Tests](#running-the-tests) | [Design](#design) | [Tech](#technologies-used) | [Coverage](#notes-on-test-coverage)

Register a new user:

<img src="images/register.png" alt="Register a new user" style="width:600px">

Main screen when logged in:

<img src="images/logged-in.png" alt="Main screen when logged in" style="width:600px">

Create a new peep:

<img src="images/create.png" alt="Create a new peep" style="width:600px">

Display new peep:

<img src="images/new.png" alt="Display new peep" style="width:600px">

## Technologies used
[Top](#chitter-challenge-by-pablo-joyce) | [Getting Started](#getting-started) | [Use](#using-the-application) | [Tests](#running-the-tests) | [Design](#design) | [Screenshots](#screenshots) | [Coverage](#notes-on-test-coverage)

This project uses:
* Ruby
* PostgreSQL
* ERB
* Rackup
* Sinatra
* Webrick
* Git
* GitHub
* Bcrypt

In development, this project also used:
* Postman
* TablePlus
* RSpec

## Notes on test coverage
[Top](#chitter-challenge-by-pablo-joyce) | [Getting Started](#getting-started) | [Use](#using-the-application) | [Tests](#running-the-tests) | [Design](#design) | [Screenshots](#screenshots) | [Tech](#technologies-used)

The following code **at the top** of spec_helper.rb causes test coverage stats to be generated
on pull request:

```ruby
require 'simplecov'
Expand All @@ -120,4 +194,10 @@ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new([
SimpleCov.start
```

You can see your test coverage when you run your tests. If you want this in a graphical form, uncomment the `HTMLFormatter` line and see what happens!
Coverage:

<img src="images/coverage.png" alt="Test coverage" style="width:600px">

Test results:

<img src="images/tests.png" alt="Test results" style="width:500px">
Loading