It is test task of shortest link generator.
Use git to clone the project to your local machine
This project was built using Ruby on Rails
Once you have ruby installed, you will need the bundler gem. To install bundler, simply run:
gem install bundler
After bundler is installed, run the following command from the root directory of the application (you may need to install some dependencies):
bundle install
Ensure that all the variables defined in .env
file have appropriate values for your system. Ask other team member for it.
This part is pretty easy, if you have your configuration set up correctly and your database server is running.
Run the following commands in terminal from the root of the project:
rake db:setup
Later we can use the script bin/setup
to automate all these steps.
Start the redis server using the following command:
redis-server
You can now start web server as well as sidekiq workers using foreman though if release: bundle exec rake db:migrate
is in the Procfile it might give you issues and heroku CLI would be the way to go (see below):
foreman s -p 3000 -f Procfile.dev
OR you can start them individually:
Start the background job server (Sidekiq) with the following command:
bundle exec sidekiq -C config/sidekiq.yml
Start your local webserver with the following:
rails s -p 3000
Install overcommit git hook manager
overcommit --install
Sign configuration file so overcommit is able to read it
overcommit --sign
Now the configured hooks in .overcommit.yml
will run everytime you run git commit
, being RuboCop
the most important one.
If, for any reason, you need to commit changes that fail to pass the rubocop check, you can skip it by running
SKIP=RuboCop git commit
Note: By default, log is not enabled on test environment for better performance. If you want to enable logs, just set the RAILS_ENABLE_TEST_LOG
environment variable to true
.
See spec
directory for configuration. Make sure to test locally first for changes you've made.
bundle exec rspec
To check the documentation, You can visit /api path.
For generate the new shortest link, use the following curl command
curl --request POST '<HOST_BASE_URL>/api/v1/short_links' --data '{ "original_url" : "https://google.com" }'
For get the list of top 100 most frequently accessed URLs, use the following curl command
curl --request GET '<HOST_BASE_URL>/api/v1/short_links'
Note: if you run it locally, replace the <HOST_BASE_URL> with localhost:3000 and if live server then with your live server domain.