Coder Social home page Coder Social logo

aj8gh / chitter-challenge Goto Github PK

View Code? Open in Web Editor NEW

This project forked from makersacademy/chitter-challenge

0.0 0.0 0.0 3.95 MB

Twitter clone web app Built with Ruby and Sinatra - Test driven with RSpec and Capybara

Ruby 80.19% HTML 16.17% CSS 3.64%

chitter-challenge's Introduction

Chitter

Build Status Coverage Status Maintainability

Version 1.0.0 deployed through Heroku: Chitter

feed-scroll

Ruby version

  • 2.7.2

Dependencies

  • bcrypt
  • capybara
  • coveralls_reborn (~> 0.20.0)
  • pg
  • puma
  • rack
  • rake
  • rspec
  • rubocop (= 0.79.0)
  • simplecov
  • simplecov-console
  • sinatra-flash
  • sinatra

Getting Started

Initial Setup

  • You will need Ruby installed, this project uses version 2.7.2

    • Use of a version manager tool such as RVM is recommended
    • You can find documentation for installing RVM here
  • Clone this repository and navigate to the root of the project

git clone git@github:AJ8GH/chitter-challenge.git
cd chitter-challenge
  • Install bundler if you do not already have it and install project dependenices
gem install bundler
bundle install
  • This app uses a PostgreSQL database, so you will need to install and set up Postgres

    • Using a package manager such as Homebrew is recommended
    • You can install Homebrew here
    • Then install PostgreSQL with: brew install postgresql
    • After Homebrew has downloaded PostgreSQL it will show you some installation instructions: follow them!
    • Next run: brew services start postgresql to keep PostgreSQL running in the background
  • Create the test and development databases and migrate the table schema

rake db:create:all
rake db:migrate:all

These rake tasks will create 2 databases, chitter and chitter_test, and migrate the db schema for each. Full details on the database schema can be found in db/migrations folder.

Running Tests

  • Ensure you are in the root directory
    • To run entire test suite, run: rspec
    • To run only feature tests, run: rspec spec/features
    • To run only unit tests, run: rspec spec/models
    • To run individual spec files: rspec spec/<directory_name>/<file_name>

Notes on the test suite:

  • App has been development using outside in TDD, writing a feature test based on a user story, then implementing the feature to make the test pass.
  • Capybara is used for feature testing and rspec is used for unit testing
  • Tests are configured to output documentation format
  • Suite is configured to automatically connect to the test database before running
  • Test database is 'cleaned' after each test

Usage

To use the app in the local development environment, start the server with rackup. Then head to localhost, port 9292

To use the deployed version of the app, click here

Public interface

Models:

post

Public class methods:

.create

Creates a new instance and saves data in database, takes 2 keyword arguments - content: (string) and user_id: (integer)

post = Post.create(content: 'Hello World!', user_id: 1)
post.content
 # => Hello World!

post.user_id
# => 1
.all

Returns arrray of all instances of the class. Takes no arguments

Post.all
# => [post1, post2, ...]
.delete

Deletes the instance from database, takes id: (integer) as keyword argument

Post.delete(id: 7)
.find

Finds the post by its id, takes id: (integer) as keyword argument

Post.find(id: 7)
.update

Updates post content, takes id: (integer) and content: (string) as keyword arguments

post.content
# => '!dlroW olleH'
post.id
# => 1

Post.update(id: 1, content: 'Hello World!')

post.content
# => 'Hello World!'
.user_posts

Returns all posts of that user, takes user_id: (integer) as keyword argument

Post.user_posts(user_id: 1)
# => '[user_post1, user_post2, ...]'

User

Example usage

Check your posts in reverse chronological order - no need to be signed in for this feature.

Sign in to access more features such as posting and editing posts and account details.

signing-in

If you're new to Chitter, you'll need to sign up to start posting. Your password will be stored safely.

sign-up-and-post

Edit and delete your posts any time.

edit-post

As well as your user account data.

edit-delete-account

Reflections

Design and approach

  • I set out to build a an app which ticks boxes for:

    • CRUD features
    • Use of ORM with postgres database
    • Polished look using CSS
    • RESTful routing
    • Encryption of passwords and authentication of users using sessions
    • Adhering to MVC standards and separation of concerns / SRP.
  • User Stories have all been hit, bar email notifications. Instead I prioritised implementing all of the CRUD features for the user info and posts.

  • I went for an approach of using ORM and wrapping my database connection in a class. - I applied rake tasks to handle everything to do with environment and db setup. I setup tasks for connecting to the correct database depending on the environmnent, cleaning the database and creating and migrating the database.

Test and development environments

  • Raketask db:connect automatically connects to the correct database depending on which environment the app is running in, and outputs a confirmation to the terminal. connection-to-test
  • Bcrypt is set up with minimum cost factor in the test environment, so as not to slow down the tests. In development and Production this is higher for additional security.
BCrypt::Engine.cost = 1
  • Test database is cleaned automatically after each test to eliminate test data pollution

Extending the application

Future features include:

  • Email notifications
  • Replies and favourites
  • Building a frontend interface with React or vanilla JS

User Stories

As a Maker
So that I can let people know what I am doing
I want to post a message (post) to chitter

As a maker
So that I can see what others are saying
I want to see all posts in reverse chronological order

As a Maker
So that I can better appreciate the context of a post
I want to see the time at which it was made

As a Maker
So that I can post messages on Chitter as me
I want to sign up for Chitter

As a Maker
So that only I can post messages on Chitter as me
I want to log in to Chitter

As a Maker
So that I can avoid others posting messages on Chitter as me
I want to log out of Chitter

As a Maker
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 post

homepage

chitter-challenge's People

Contributors

aj8gh avatar tansaku avatar jamesjoshuahill avatar neoeno avatar ptolemybarnes avatar tatsiana-makers avatar anitacanita avatar david-mears avatar sjmog avatar domvernon avatar silvabox avatar chrisjbatts avatar edwardandress avatar dearshrewdwit avatar samjones1001 avatar soph-g avatar spike01 avatar sdorunga avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.