diff --git a/config/routes.rb b/config/routes.rb index 47cc16e..215d60c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true Rails.application.routes.draw do - # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html + get '/:slug', to: 'links#show', as: :short end diff --git a/test/fixtures/links.yml b/test/fixtures/links.yml index f68344d..5b1f7e4 100644 --- a/test/fixtures/links.yml +++ b/test/fixtures/links.yml @@ -1,11 +1,11 @@ # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html one: - slug: MyString - url: MyString + slug: ktr4ms + url: 'https://google.com' click_counter: 1 two: - slug: MyString - url: MyString + slug: qwu62l + url: 'https://gapfish.com' click_counter: 1 diff --git a/test/models/link_test.rb b/test/models/link_test.rb index f0e7d1b..d2cc694 100644 --- a/test/models/link_test.rb +++ b/test/models/link_test.rb @@ -10,7 +10,29 @@ class LinkTest < ActiveSupport::TestCase test 'should not save a link with a invalid url' do link = Link.new - link.url = 'google.com' + link.url = 'test.com' assert_not link.save, 'Saved the link with invalid url format' end + + test 'should create a link with a valid url' do + link = Link.new + link.url = 'https://test.com' + assert link.save, 'Link with valid url not saved' + end + + test 'should generate a slug on save a new link' do + link = links(:one) + assert link.slug, 'Slug not generated on save a new link' + end + + test 'should get shorten url of existing url' do + link = links(:one) + url = link.url + assert Link.shorten(url), 'Shorten url not found' + end + + test 'should get shorten url and create a link' do + url = 'https://test.com' + assert Link.shorten(url), 'Link not created' + end end