tests #6
|
|
@ -0,0 +1 @@
|
|||
*.sw*
|
||||
14
Gemfile
14
Gemfile
|
|
@ -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"
|
||||
|
|
|
|||
83
Gemfile.lock
83
Gemfile.lock
|
|
@ -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
|
||||
|
|
|
|||
8
app.rb
8
app.rb
|
|
@ -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']
|
||||
code = SecureRandom.urlsafe_base64 4
|
||||
links.insert(url: url, code: code)
|
||||
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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
@ -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>
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
|
|
|
|||
|
|
@ -3,8 +3,10 @@
|
|||
<title><%= @page_title || "URL Shortener" %></title>
|
||||
<link rel="icon" href="data:,">
|
||||
</head>
|
||||
<body>
|
||||
<h1>URL Shortener</h1>
|
||||
<%== yield %>
|
||||
<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>
|
||||
|
|
|
|||
Loading…
Reference in New Issue