Skip to content

eatstreet/ruby-sample-app

Repository files navigation

README

Hello! This is a ruby challenge for developers to try out during our interview process.

Please clone this to your machine from this repository. Please do not create a fork, while you will use git on your machine as part of this challenge, you will not be pushing your code to a public space.

Instructions on how to submit your work will be at the end of this readme.

Please do not spend more than 3 hours on this project.

Getting Started

Please clone this repository and use Visual Studio Code to open this project. This project uses Visual Studio Code Remote - Containers so that you can easily develop with the right ruby, rails, etc. all pre installed. To use VSCode Remote Containers, you will need to have Docker installed. We use Docker Desktop and it works well with VSCode for projects like this.

Check that the "Remote - Containers" plugin is installed.

If it isn't then hit the install button and it should look like this

Installing it may require that VS Code gets restarted, look for a pop up in the bottom right for that indication.

Project Setup

When you open this git repository in VSCode you should see the following pop up in the bottom right corner.

Click "Reopen in Container"

In case it disappeared, you can open the command palette (ctr+shift+p / cmd+shift+p) and type in reopen container.

This may take a few minutes as it downloads docker files preloaded with the right ruby and rails version. It will then install dependencies necessary for this project.

It will pop open a terminal saying it has finished and press enter to make it go away.

At the bottom of the screen, if the terminal dissapeared you can click and drag above the blue area to pull up the terminal like a drawer.

You should see

vscode ➜ /workspaces/ruby-sample-app (main ✗) $ 

Now it's time to set up the database by running a migration This will take 20-30 minutes to generate data, go watch some doctor who or make a dinner

Run

bin/rails db:migrate

(The screenshot has the name blog, it should be ruby-sample-app for you, don't worry about being in the right folder, vscode will drop you in the correct place.)

Project Running

Now that the database is ready, you can start the server!

bin/rails server

(The screenshot has the name blog, it should be ruby-sample-app for you, don't worry about being in the right folder, vscode will drop you in the correct place.)

It will pop up automatically that the application is running on port 3000. You'll be able to access it on http://localhost:3000/

At this point you're ready to dive into the ruby project!


Improvements

There's a few things that can be improved with this project! It's a simulation of a blog where users can react to comments, much like hearts on twitter or thumbs up/down on youtube.

The index page http://localhost:3000/ has a list of "blog posts" or "Articles", you can click on them to navigate from the main page to a blog post.

Now if you look at the words they won't make sense. They are randomly chosen! This could be lorem ipsum but that's hardly memorable at all. Changing the generation algorithm is out of scope, the db migration files will stay as is.

On each blog post there are comments! And like each blog, the comments are randomly generated. Further, every comment can have a reaction. See each reaction is individually recorded, much like twitter / youtube each one is tied the user who placed it. There are no users on this simulation, but pretend there are.

Reactions include 👍 👎 🧡 , but are stored as numeric types in the database.

Some pages are slow

So I can visit http://localhost:3000/articles/1 on my machine and it takes a really long time.

A full second to render a page? If I got on the top of H A C K E R - N E W S, my site would go down!

Can you cut that down to under 100ms?

Take a moment to look at other examples, github, facebook, whatever you can think of for this.

JSON API is incomplete

Check this out, if I go to http://localhost:3000/articles/1.json, I can get json out!

{
  "id": 1,
  "title": "why air old set part across",
  "body": "boy like boy set sure too able major your nothing send behind only problem today"
}

Problem is, there's no comments. And even then, no reactions!

What can you do to add more to our JSON API?

Also there's no json for the index page. Can you think of a way to add an index page handler with a response like:

{
  "articles": [
    {
      "id": 1,
      "title": "why air old set part across"
    },
    {
      "id": 2,
      "title": "plan both good"
    }
  ]
}

Administration

Without the complexness of adding users and such, can we get some forms, buttons, whatever in to manage this blog?

Some things I'd like to be able to do:

  • Delete comments! (and all of their reactions)
  • Add comments! Whoa
  • Remove posts (and all of their comments and reactions)
  • Add Posts
  • Add reactions!

Submitting your work

Again, do not push to a public repository. You will be sharing a patch file with us by email. A patch file will show all your changes in one file and allow us to review it on our side.

To create a patch file, you will run

git diff reference HEAD -- > your-name.diff

Where your-name is well.. your name!

Inside it will look something like

diff --git a/app/views/articles/index.html.erb b/app/views/articles/index.html.erb
index 64a9258..58ea98b 100644
--- a/app/views/articles/index.html.erb
+++ b/app/views/articles/index.html.erb
@@ -1,4 +1,4 @@
-<h1>Hello, Rails!</h1>
+<h1>Hello, Ruby on Rails!</h1>

 <h1>Articles</h1>

Then email the hiring manager for this position with the file attached!

We will review your patch and get back to you on the next steps in this process.