Compare commits

..

16 Commits

Author SHA1 Message Date
bucky 1e9a066cd1 Merge pull request 'tests' (#6) from tests into master
Reviewed-on: #6
2023-10-01 12:26:20 -07:00
Adam Townsend a1ea2a09ec expanded click button to click any button for easier use 2023-10-01 12:14:41 -07:00
Adam Townsend 445236d735 2nd scenario
+ added a scenario for submitting the button with no text  in url field
+ simplified the visit when clause to be used with any url
+ edited create route redirect if url param is empty (backend validation
  for required URL field)
+ added when clause for clicking submit button
+ added then clause for current path/page
2023-10-01 12:10:30 -07:00
Adam Townsend 94026bdad2 added more parts for the first scenario and updated code to work with the changes 2023-09-30 18:39:30 -07:00
Adam Townsend b827f72f25 ignore vim swap files 2023-09-30 18:38:56 -07:00
Adam Townsend a34b788ff4 added testing stuff, and wrote first successful test! 2023-09-30 14:33:24 -07:00
Adam Townsend 097645cd71 added word break to output view, removed custome validation messages on
form
2023-09-25 13:58:40 -07:00
Adam Townsend 3e6500ae1c removed rails gem, not sure why it was in there to begin with 2023-09-25 11:06:59 -07:00
Adam Townsend 868ed81b97 set min height so box stays the same between views 2023-09-24 11:29:22 -07:00
Adam Townsend 57790ff464 custom validation message 2023-09-24 10:19:45 -07:00
Adam Townsend d2a411d94c url validation 2023-09-22 18:31:32 -07:00
Adam Townsend 8cabe5c7b6 more layout updates 2023-09-22 18:26:38 -07:00
Adam Townsend c0c82e5395 added some simple styles to make it nicer 2023-09-22 17:42:50 -07:00
Adam Townsend 47f8741592 added logic to prevent duplicate url's from being entered, it just
fetches the url and load it instead
2023-09-22 15:11:06 -07:00
Adam Townsend 935b0c5a9f cucumber initialization 2023-09-19 15:40:18 -07:00
Adam Townsend a3d7525d9a added rspec, rack test, and cucumber gems 2023-09-19 12:23:38 -07:00
10 changed files with 174 additions and 13 deletions

1
.gitignore vendored 100644
View File

@ -0,0 +1 @@
*.sw*

14
Gemfile
View File

@ -2,8 +2,6 @@
source "https://rubygems.org"
# gem "rails"
gem "falcon", "~> 0.42.3"
gem "roda", "~> 3.72"
@ -11,3 +9,15 @@ gem "roda", "~> 3.72"
gem "sequel", "~> 5.72"
gem "tilt", "~> 2.2"
gem "cucumber", "~> 9.0"
gem "sqlite3", "~> 1.6"
gem "erubi", "~> 1.12"
gem "capybara", "~> 3.39"
gem "rspec", "~> 3.12"
gem "selenium-webdriver", "~> 4.13"

View File

@ -1,6 +1,8 @@
GEM
remote: https://rubygems.org/
specs:
addressable (2.8.5)
public_suffix (>= 2.0.2, < 6.0)
async (2.6.4)
console (~> 1.10)
fiber-annotation
@ -25,9 +27,45 @@ GEM
async (>= 1.25)
bigdecimal (3.1.4)
build-environment (1.13.0)
builder (3.2.4)
capybara (3.39.2)
addressable
matrix
mini_mime (>= 0.1.3)
nokogiri (~> 1.8)
rack (>= 1.6.0)
rack-test (>= 0.6.3)
regexp_parser (>= 1.5, < 3.0)
xpath (~> 3.2)
console (1.23.2)
fiber-annotation
fiber-local
cucumber (9.0.2)
builder (~> 3.2, >= 3.2.4)
cucumber-ci-environment (~> 9.2, >= 9.2.0)
cucumber-core (~> 11.1, >= 11.1.0)
cucumber-cucumber-expressions (~> 16.1, >= 16.1.2)
cucumber-gherkin (>= 24, < 26.2.1)
cucumber-html-formatter (~> 20.4, >= 20.4.0)
cucumber-messages (>= 19, < 23)
diff-lcs (~> 1.5, >= 1.5.0)
mini_mime (~> 1.1, >= 1.1.5)
multi_test (~> 1.1, >= 1.1.0)
sys-uname (~> 1.2, >= 1.2.3)
cucumber-ci-environment (9.2.0)
cucumber-core (11.1.0)
cucumber-gherkin (>= 24, < 27)
cucumber-messages (>= 19, < 22)
cucumber-tag-expressions (~> 4.1, >= 4.1.0)
cucumber-cucumber-expressions (16.1.2)
cucumber-gherkin (26.2.0)
cucumber-messages (>= 19.1.4, < 22.1)
cucumber-html-formatter (20.4.0)
cucumber-messages (>= 18.0, < 22.1)
cucumber-messages (21.0.1)
cucumber-tag-expressions (4.1.0)
diff-lcs (1.5.0)
erubi (1.12.0)
falcon (0.42.3)
async
async-container (~> 0.16.0)
@ -41,11 +79,19 @@ GEM
process-metrics (~> 0.2.0)
protocol-rack (~> 0.1)
samovar (~> 2.1)
ffi (1.15.5)
fiber-annotation (0.2.0)
fiber-local (1.0.0)
io-event (1.3.2)
localhost (1.1.10)
mapping (1.1.1)
matrix (0.4.2)
mini_mime (1.1.5)
mini_portile2 (2.8.4)
multi_test (1.1.0)
nokogiri (1.15.4)
mini_portile2 (~> 2.8.2)
racc (~> 1.4)
openssl (3.1.0)
process-metrics (0.2.1)
console (~> 1.8)
@ -60,25 +106,62 @@ GEM
protocol-rack (0.2.6)
protocol-http (~> 0.23)
rack (>= 1.0)
public_suffix (5.0.3)
racc (1.7.1)
rack (3.0.8)
rack-test (2.1.0)
rack (>= 1.3)
regexp_parser (2.8.1)
rexml (3.2.6)
roda (3.72.0)
rack
rspec (3.12.0)
rspec-core (~> 3.12.0)
rspec-expectations (~> 3.12.0)
rspec-mocks (~> 3.12.0)
rspec-core (3.12.2)
rspec-support (~> 3.12.0)
rspec-expectations (3.12.3)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.12.0)
rspec-mocks (3.12.6)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.12.0)
rspec-support (3.12.1)
rubyzip (2.3.2)
samovar (2.2.0)
console (~> 1.0)
mapping (~> 1.0)
selenium-webdriver (4.13.1)
rexml (~> 3.2, >= 3.2.5)
rubyzip (>= 1.2.2, < 3.0)
websocket (~> 1.0)
sequel (5.72.0)
bigdecimal
sqlite3 (1.6.6)
mini_portile2 (~> 2.8.0)
sys-uname (1.2.3)
ffi (~> 1.1)
tilt (2.2.0)
timers (4.3.5)
traces (0.11.1)
websocket (1.2.10)
xpath (3.2.0)
nokogiri (~> 1.8)
PLATFORMS
x86_64-freebsd-13
DEPENDENCIES
capybara (~> 3.39)
cucumber (~> 9.0)
erubi (~> 1.12)
falcon (~> 0.42.3)
roda (~> 3.72)
rspec (~> 3.12)
selenium-webdriver (~> 4.13)
sequel (~> 5.72)
sqlite3 (~> 1.6)
tilt (~> 2.2)
BUNDLED WITH

4
app.rb
View File

@ -2,7 +2,6 @@ require 'roda'
require 'securerandom'
require 'json'
require 'sequel'
require 'logger'
class App < Roda
DB = Sequel.sqlite('db/url_shortener.db')
@ -20,8 +19,11 @@ class App < Roda
r.post "create" do
url = r.params['url']
if url.empty? then r.redirect '/' end
if nil == links.filter(:url => url).first
code = SecureRandom.urlsafe_base64 4
links.insert(url: url, code: code)
end
@new_link = 'http://' + request.env['HTTP_HOST'] + '/' + links.filter(:url => url).first[:code]
view :create
end

View File

@ -0,0 +1,17 @@
# features/home.feature
Feature: Homepage
Loading the homepage is the initial starting point for this tool
Scenario: Homepage Loads with a form
Given I visit the '/' page
Then I should see text "URL Shortener"
And I should see a form field "url"
And I should see a "Submit" button
Scenario: Submitting the form without entering a URL
Given I visit the '/' page
When I click the "Submit" button
Then I should be on "/" page

View File

@ -0,0 +1,29 @@
# GIVEN
Given('I visit the {string} page') do |string|
visit string
end
# WHEN
When('I click the {string} button') do |string|
click_button {string}
end
# THEN
Then('I should see text {string}') do |string|
page.should have_content string
end
Then('I should see a form field {string}') do |string|
page.should have_field string
end
Then('I should see a {string} button') do |string|
page.should have_button string
end
Then('I should be on {string} page') do |string|
page.should have_current_path string
end

View File

@ -0,0 +1,13 @@
require_relative '../../app'
require 'rubygems'
require 'roda'
require 'capybara'
require 'capybara/dsl'
require 'rspec'
Capybara.app = App
include Capybara::DSL
include RSpec::Expectations
include RSpec::Matchers

View File

@ -1,2 +1,2 @@
<a href="/">Home</a>
<h2><a href="<%= @new_link %>" target="_blank"><%= @new_link %></a></h2>
<h2><a href="/" style="color: #555555;">Home</a></h2>
<h3 style="overflow-wrap: break-word; word-wrap: break-word;"><a href="<%= @new_link %>" target="_blank" style="color: #555555;"><%= @new_link %></a></h3>

View File

@ -1,5 +1,9 @@
<form method="POST" action="/create">
<label for "url">URL: </label>
<input type="text" name="url" />
<input type="submit" value="Submit" />
<input type="url"
name="url"
pattern="https?://.+"
placeholder="http://www.example.com/"
style="padding: 0.5rem;"
required />
<button type="submit" style="padding: 0.5rem;">Submit</button>
</form>

View File

@ -3,8 +3,10 @@
<title><%= @page_title || "URL Shortener" %></title>
<link rel="icon" href="data:,">
</head>
<body>
<body style="background: #FEFEFE; font-family: Helvetica, sans-serif; color: #555555;">
<main style="max-width: 30rem; min-width: 18rem; border: 5px solid #999999; border-radius: 20px; margin: auto; padding: 1rem; margin-top: 5rem; text-align: center; min-height: 175px;">
<h1>URL Shortener</h1>
<%== yield %>
</main>
</body>
</html>