From a3d7525d9aa88a787968f6bc362e6293d69ddcc7 Mon Sep 17 00:00:00 2001 From: Adam Townsend Date: Tue, 19 Sep 2023 12:23:38 -0700 Subject: [PATCH 01/15] added rspec, rack test, and cucumber gems --- Gemfile | 6 ++++++ Gemfile.lock | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ app.rb | 1 - 3 files changed, 55 insertions(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index 938fe2e..6649a17 100644 --- a/Gemfile +++ b/Gemfile @@ -11,3 +11,9 @@ gem "roda", "~> 3.72" gem "sequel", "~> 5.72" gem "tilt", "~> 2.2" + +gem "rack-test", "~> 2.1" + +gem "rspec", "~> 3.12" + +gem "cucumber", "~> 9.0" diff --git a/Gemfile.lock b/Gemfile.lock index 1d03b88..e08bff7 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -25,9 +25,35 @@ GEM async (>= 1.25) bigdecimal (3.1.4) build-environment (1.13.0) + builder (3.2.4) 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) falcon (0.42.3) async async-container (~> 0.16.0) @@ -41,11 +67,14 @@ 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) + mini_mime (1.1.5) + multi_test (1.1.0) openssl (3.1.0) process-metrics (0.2.1) console (~> 1.8) @@ -61,13 +90,30 @@ GEM protocol-http (~> 0.23) rack (>= 1.0) rack (3.0.8) + rack-test (2.1.0) + rack (>= 1.3) 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) samovar (2.2.0) console (~> 1.0) mapping (~> 1.0) sequel (5.72.0) bigdecimal + sys-uname (1.2.3) + ffi (~> 1.1) tilt (2.2.0) timers (4.3.5) traces (0.11.1) @@ -76,8 +122,11 @@ PLATFORMS x86_64-freebsd-13 DEPENDENCIES + cucumber (~> 9.0) falcon (~> 0.42.3) + rack-test (~> 2.1) roda (~> 3.72) + rspec (~> 3.12) sequel (~> 5.72) tilt (~> 2.2) diff --git a/app.rb b/app.rb index fbc0383..a7a9ba5 100644 --- a/app.rb +++ b/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') From 935b0c5a9f8f07de129cbc20ea220b76d302c8f6 Mon Sep 17 00:00:00 2001 From: Adam Townsend Date: Tue, 19 Sep 2023 15:40:18 -0700 Subject: [PATCH 02/15] cucumber initialization --- features/support/env.rb | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 features/support/env.rb diff --git a/features/support/env.rb b/features/support/env.rb new file mode 100644 index 0000000..e69de29 From 47f874159242cbd6e7a1c8fde478f7398d2aace4 Mon Sep 17 00:00:00 2001 From: Adam Townsend Date: Fri, 22 Sep 2023 15:11:06 -0700 Subject: [PATCH 03/15] added logic to prevent duplicate url's from being entered, it just fetches the url and load it instead --- app.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app.rb b/app.rb index a7a9ba5..736d0dc 100644 --- a/app.rb +++ b/app.rb @@ -19,8 +19,10 @@ class App < Roda r.post "create" do url = r.params['url'] - code = SecureRandom.urlsafe_base64 4 - links.insert(url: url, code: code) + if nil == links.filter(:url => url).first + code = SecureRandom.urlsafe_base64 5 + links.insert(url: url, code: code) + end @new_link = 'http://' + request.env['HTTP_HOST'] + '/' + links.filter(:url => url).first[:code] view :create end From c0c82e53951ebd9bb649a1af23f2014fb112ac62 Mon Sep 17 00:00:00 2001 From: Adam Townsend Date: Fri, 22 Sep 2023 17:42:50 -0700 Subject: [PATCH 04/15] added some simple styles to make it nicer --- app.rb | 2 +- views/layout.erb | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/app.rb b/app.rb index 736d0dc..9321f03 100644 --- a/app.rb +++ b/app.rb @@ -20,7 +20,7 @@ class App < Roda r.post "create" do url = r.params['url'] if nil == links.filter(:url => url).first - code = SecureRandom.urlsafe_base64 5 + 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] diff --git a/views/layout.erb b/views/layout.erb index 7f6853c..bc24c5c 100644 --- a/views/layout.erb +++ b/views/layout.erb @@ -3,8 +3,10 @@ <%= @page_title || "URL Shortener" %> - -

URL Shortener

- <%== yield %> + +
+

URL Shortener

+ <%== yield %> +
From 8cabe5c7b6a2dcc0df41907e4976e17bed4bec49 Mon Sep 17 00:00:00 2001 From: Adam Townsend Date: Fri, 22 Sep 2023 18:26:38 -0700 Subject: [PATCH 05/15] more layout updates --- views/create.erb | 4 ++-- views/home.erb | 5 ++--- views/layout.erb | 4 ++-- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/views/create.erb b/views/create.erb index b70ceb7..a77d2f8 100644 --- a/views/create.erb +++ b/views/create.erb @@ -1,2 +1,2 @@ -Home -

<%= @new_link %>

+

Home

+

<%= @new_link %>

diff --git a/views/home.erb b/views/home.erb index b57e374..1fe8d37 100644 --- a/views/home.erb +++ b/views/home.erb @@ -1,5 +1,4 @@
- - - + +
diff --git a/views/layout.erb b/views/layout.erb index bc24c5c..1ed018a 100644 --- a/views/layout.erb +++ b/views/layout.erb @@ -3,8 +3,8 @@ <%= @page_title || "URL Shortener" %> - -
+ +

URL Shortener

<%== yield %>
From d2a411d94cf686cbd21792a90936fa3595c02ccd Mon Sep 17 00:00:00 2001 From: Adam Townsend Date: Fri, 22 Sep 2023 18:31:32 -0700 Subject: [PATCH 06/15] url validation --- views/home.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/views/home.erb b/views/home.erb index 1fe8d37..6e7cada 100644 --- a/views/home.erb +++ b/views/home.erb @@ -1,4 +1,4 @@
- +
From 57790ff464d29659d53ac923f923a38281ddf6b2 Mon Sep 17 00:00:00 2001 From: Adam Townsend Date: Sun, 24 Sep 2023 10:19:45 -0700 Subject: [PATCH 07/15] custom validation message --- views/home.erb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/views/home.erb b/views/home.erb index 6e7cada..61a803f 100644 --- a/views/home.erb +++ b/views/home.erb @@ -1,4 +1,11 @@
- +
From 868ed81b97e6e6cb9a093107502c463d86c3bb19 Mon Sep 17 00:00:00 2001 From: Adam Townsend Date: Sun, 24 Sep 2023 11:29:22 -0700 Subject: [PATCH 08/15] set min height so box stays the same between views --- views/layout.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/views/layout.erb b/views/layout.erb index 1ed018a..e1b8a4b 100644 --- a/views/layout.erb +++ b/views/layout.erb @@ -4,7 +4,7 @@ -
+

URL Shortener

<%== yield %>
From 3e6500ae1cea868694e5c28b5f7e6e3867f53e3a Mon Sep 17 00:00:00 2001 From: Adam Townsend Date: Mon, 25 Sep 2023 11:06:59 -0700 Subject: [PATCH 09/15] removed rails gem, not sure why it was in there to begin with --- Gemfile | 2 -- 1 file changed, 2 deletions(-) diff --git a/Gemfile b/Gemfile index 6649a17..c4688d7 100644 --- a/Gemfile +++ b/Gemfile @@ -2,8 +2,6 @@ source "https://rubygems.org" -# gem "rails" - gem "falcon", "~> 0.42.3" gem "roda", "~> 3.72" From 097645cd711a42c94565f987a75f6af6c1d57502 Mon Sep 17 00:00:00 2001 From: Adam Townsend Date: Mon, 25 Sep 2023 13:58:40 -0700 Subject: [PATCH 10/15] added word break to output view, removed custome validation messages on form --- views/create.erb | 2 +- views/home.erb | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/views/create.erb b/views/create.erb index a77d2f8..2cf03d4 100644 --- a/views/create.erb +++ b/views/create.erb @@ -1,2 +1,2 @@

Home

-

<%= @new_link %>

+

<%= @new_link %>

diff --git a/views/home.erb b/views/home.erb index 61a803f..e90e2c6 100644 --- a/views/home.erb +++ b/views/home.erb @@ -2,10 +2,8 @@ + style="padding: 0.5rem;" + required /> From a34b788ff4bf0930a3a8ca255f591a7ba4f2bfa7 Mon Sep 17 00:00:00 2001 From: Adam Townsend Date: Sat, 30 Sep 2023 14:33:24 -0700 Subject: [PATCH 11/15] added testing stuff, and wrote first successful test! --- Gemfile | 10 +++++++-- Gemfile.lock | 36 +++++++++++++++++++++++++++++- features/homepage.feature | 9 ++++++++ features/step_definitions/steps.rb | 15 +++++++++++++ features/support/env.rb | 13 +++++++++++ 5 files changed, 80 insertions(+), 3 deletions(-) create mode 100644 features/homepage.feature create mode 100644 features/step_definitions/steps.rb diff --git a/Gemfile b/Gemfile index c4688d7..6b6e103 100644 --- a/Gemfile +++ b/Gemfile @@ -10,8 +10,14 @@ gem "sequel", "~> 5.72" gem "tilt", "~> 2.2" -gem "rack-test", "~> 2.1" +gem "cucumber", "~> 9.0" + +gem "sqlite3", "~> 1.6" + +gem "erubi", "~> 1.12" + +gem "capybara", "~> 3.39" gem "rspec", "~> 3.12" -gem "cucumber", "~> 9.0" +gem "selenium-webdriver", "~> 4.13" diff --git a/Gemfile.lock b/Gemfile.lock index e08bff7..d856b94 100644 --- a/Gemfile.lock +++ b/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 @@ -26,6 +28,15 @@ GEM 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 @@ -54,6 +65,7 @@ GEM 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) @@ -73,8 +85,13 @@ GEM 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) @@ -89,9 +106,13 @@ 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) @@ -107,27 +128,40 @@ GEM 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) - rack-test (~> 2.1) roda (~> 3.72) rspec (~> 3.12) + selenium-webdriver (~> 4.13) sequel (~> 5.72) + sqlite3 (~> 1.6) tilt (~> 2.2) BUNDLED WITH diff --git a/features/homepage.feature b/features/homepage.feature new file mode 100644 index 0000000..588787a --- /dev/null +++ b/features/homepage.feature @@ -0,0 +1,9 @@ +# features/home.feature + +Feature: Homepage + + Loading the homepage is the initial starting point for this tool + + Scenario: Homepage Loads + Given I visit the homepage + Then I should see "URL Shortener" diff --git a/features/step_definitions/steps.rb b/features/step_definitions/steps.rb new file mode 100644 index 0000000..da975ee --- /dev/null +++ b/features/step_definitions/steps.rb @@ -0,0 +1,15 @@ +# GIVEN + +Given('I visit the homepage') do + visit '/' +end + +# WHEN + + + +# THEN + +Then('I should see {string}') do |string| + page.should have_content "URL Shortener" +end diff --git a/features/support/env.rb b/features/support/env.rb index e69de29..6ee27f9 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -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 From b827f72f25e222862f36132c44aebcae7f4e2793 Mon Sep 17 00:00:00 2001 From: Adam Townsend Date: Sat, 30 Sep 2023 18:38:56 -0700 Subject: [PATCH 12/15] ignore vim swap files --- .gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1ee84da --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.sw* From 94026bdad24fb93d32550ce9f2a0f57e565dc499 Mon Sep 17 00:00:00 2001 From: Adam Townsend Date: Sat, 30 Sep 2023 18:39:30 -0700 Subject: [PATCH 13/15] added more parts for the first scenario and updated code to work with the changes --- features/homepage.feature | 6 ++++-- features/step_definitions/steps.rb | 14 +++++++++++--- views/home.erb | 2 +- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/features/homepage.feature b/features/homepage.feature index 588787a..a6c98ce 100644 --- a/features/homepage.feature +++ b/features/homepage.feature @@ -4,6 +4,8 @@ Feature: Homepage Loading the homepage is the initial starting point for this tool - Scenario: Homepage Loads + Scenario: Homepage Loads with a form Given I visit the homepage - Then I should see "URL Shortener" + Then I should see text "URL Shortener" + And I should see a form field "url" + And I should see a "Submit" button diff --git a/features/step_definitions/steps.rb b/features/step_definitions/steps.rb index da975ee..61271d9 100644 --- a/features/step_definitions/steps.rb +++ b/features/step_definitions/steps.rb @@ -1,7 +1,7 @@ # GIVEN Given('I visit the homepage') do - visit '/' + visit '/' end # WHEN @@ -10,6 +10,14 @@ end # THEN -Then('I should see {string}') do |string| - page.should have_content "URL Shortener" +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 diff --git a/views/home.erb b/views/home.erb index e90e2c6..11e6885 100644 --- a/views/home.erb +++ b/views/home.erb @@ -5,5 +5,5 @@ placeholder="http://www.example.com/" style="padding: 0.5rem;" required /> - + From 445236d735ba3ecbb81a2352f5669064d6c12c76 Mon Sep 17 00:00:00 2001 From: Adam Townsend Date: Sun, 1 Oct 2023 12:10:30 -0700 Subject: [PATCH 14/15] 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 --- app.rb | 1 + features/homepage.feature | 8 +++++++- features/step_definitions/steps.rb | 12 +++++++++--- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/app.rb b/app.rb index 9321f03..4b2b414 100644 --- a/app.rb +++ b/app.rb @@ -19,6 +19,7 @@ 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) diff --git a/features/homepage.feature b/features/homepage.feature index a6c98ce..bd6b761 100644 --- a/features/homepage.feature +++ b/features/homepage.feature @@ -5,7 +5,13 @@ Feature: Homepage Loading the homepage is the initial starting point for this tool Scenario: Homepage Loads with a form - Given I visit the homepage + 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 + diff --git a/features/step_definitions/steps.rb b/features/step_definitions/steps.rb index 61271d9..affa75a 100644 --- a/features/step_definitions/steps.rb +++ b/features/step_definitions/steps.rb @@ -1,12 +1,14 @@ # GIVEN -Given('I visit the homepage') do - visit '/' +Given('I visit the {string} page') do |string| + visit string end # WHEN - +When('I click the submit button') do + click_button "Submit" +end # THEN @@ -21,3 +23,7 @@ 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 From a1ea2a09ec9cc5e95e25759e7eb997a7113aebb2 Mon Sep 17 00:00:00 2001 From: Adam Townsend Date: Sun, 1 Oct 2023 12:14:41 -0700 Subject: [PATCH 15/15] expanded click button to click any button for easier use --- features/homepage.feature | 2 +- features/step_definitions/steps.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/features/homepage.feature b/features/homepage.feature index bd6b761..3322c55 100644 --- a/features/homepage.feature +++ b/features/homepage.feature @@ -12,6 +12,6 @@ Feature: Homepage Scenario: Submitting the form without entering a URL Given I visit the '/' page - When I click the submit button + When I click the "Submit" button Then I should be on "/" page diff --git a/features/step_definitions/steps.rb b/features/step_definitions/steps.rb index affa75a..7698ccb 100644 --- a/features/step_definitions/steps.rb +++ b/features/step_definitions/steps.rb @@ -6,8 +6,8 @@ end # WHEN -When('I click the submit button') do - click_button "Submit" +When('I click the {string} button') do |string| + click_button {string} end # THEN