From 9ca92f42ac51beb2c96d8cefb6dc39a7920209cd Mon Sep 17 00:00:00 2001 From: John Chester Date: Fri, 9 Jun 2017 16:45:18 -0400 Subject: [PATCH 1/2] Completed releases 0, 1, and 2 --- source/.DS_Store | Bin 0 -> 8196 bytes source/Gemfile | 2 - source/app/.DS_Store | Bin 0 -> 6148 bytes source/app/assets/javascripts/application.js | 1 - source/app/controllers/urls_controller.rb | 35 ++++++++++++++++++ source/app/models/.DS_Store | Bin 0 -> 6148 bytes source/app/models/ur_lindex.rb | 2 + source/app/models/url.rb | 18 +++++++++ source/app/views/layouts/application.html.erb | 4 +- source/app/views/urls/index.html.erb | 26 +++++++++++++ source/config/routes.rb | 5 +++ source/db/.DS_Store | Bin 0 -> 6148 bytes .../db/migrate/20170609180109_create_urls.rb | 11 ++++++ .../20170609192743_create_ur_lindices.rb | 9 +++++ source/db/schema.rb | 29 +++++++++++++++ source/spec/models/original_and_count_spec.rb | 5 +++ source/spec/models/ur_lindex_spec.rb | 5 +++ source/spec/models/url_spec.rb | 5 +++ 18 files changed, 152 insertions(+), 5 deletions(-) create mode 100644 source/.DS_Store create mode 100644 source/app/.DS_Store create mode 100644 source/app/models/.DS_Store create mode 100644 source/app/models/ur_lindex.rb create mode 100644 source/app/models/url.rb create mode 100644 source/app/views/urls/index.html.erb create mode 100644 source/db/.DS_Store create mode 100644 source/db/migrate/20170609180109_create_urls.rb create mode 100644 source/db/migrate/20170609192743_create_ur_lindices.rb create mode 100644 source/db/schema.rb create mode 100644 source/spec/models/original_and_count_spec.rb create mode 100644 source/spec/models/ur_lindex_spec.rb create mode 100644 source/spec/models/url_spec.rb diff --git a/source/.DS_Store b/source/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..abf42920cd616ba5860e2be19c11421e637d5837 GIT binary patch literal 8196 zcmeHM%Wl&^6ulFN)KNiXfoPWAAhC#0N`Nj9QV6L~7f6U8SO9A6*tAw%J4&1e2tnEK z55OPrDSQDR!Uw>)GecxMDZ8SoosnkFc;?)BoO#$cAtKQk`1g__} z6iT|}I#9r#lD-!u9-eATTvK2aFbWt2i~>dhqrllv0Pk!L_6hHORclhCfKlK=D!})H zgUHy{I9DjI4kXeA0G3fK1M>3YALwuau&r^f5G4pgnF5um&@P71zJpNasBdfjT%j^2 zA$vwUx@Vz16ro)Y;Yd1(wnCE{1&jjA3b5~PkxK&_>_j>L{XS}L{+2ijq~nR9UmDRl9n{e$zWhCcV^6$D@urd?lYkKk#(^d6Gnnyz9LPgUN2~ z+M^^+-7pS@8T#v&VeBW9PBM=Dk!DE@W;oNE6 zo6T%{=AZspAHLlytA`*7I@*3_`Ii!tYm5D^D<^x6$C;R*eEifit0iD0h3^4u 4.0.0' # Use jquery as the JavaScript library gem 'jquery-rails' -# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks -gem 'turbolinks' # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder gem 'jbuilder', '~> 2.0' # bundle exec rake doc:rails generates the API under doc/api. diff --git a/source/app/.DS_Store b/source/app/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..6323a053e347ea1cae638abad669bbdd3b5f0d0e GIT binary patch literal 6148 zcmeHK&2G~`5T0$*#GyjufYcuMg2W+*lmI=TN>(U`-jIUe0I0QVi&%2KQS8)$5abK* z(DDX63Qy1n=>xzwy9>%+5eI}&v}4VFv%52E@3((mA`-oEv`5q;A`i+~yM<(ha6Rji zY}gWx6S|Fp@}pFphN%jdyj_7~z%lT@F~DoLP66e3VwzvSyeT|^-v6#efBH6^lA;Wr zBVdXrhBdqDIqK`5MTKQPw0p(3aF`}}(dk@?jm_Ftz2P;RUh}s1wm(p1zX*zP-U~*r zbuNkG(AqDQN`Kiw_%eyh>7!k!rt~8^~rU`G2j^ZI}GstAfb%D#mb=GI*{lq0I-H) zEwK3qfMcXZ-(qDDH4tG!fhJVgD~2%PD3{jHw^$i8;Uw(kL)bS9dqWZW?Py`Qnrw^D|7SPf|L22T&N1K^SStoZ?XZ8?LznE?y3{#7YbEpq%EEq?K^=m` i9>?0?qj(pp1$B}Qpl`7ClPX$teZ3R^O(iXb^FZq|5 zEb=`iyHp?*_^%4sY<0a_a(DG^{kBitwT11LO{Tn24vqfSBY;12j-2>lj2HRLYbuU` TnniJ^6Z0Y9f@GHp{DJ~+* Source - <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %> - <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %> + <%= stylesheet_link_tag 'application', media: 'all' %> + <%= javascript_include_tag 'application' %> <%= csrf_meta_tags %> diff --git a/source/app/views/urls/index.html.erb b/source/app/views/urls/index.html.erb new file mode 100644 index 0000000..4e0b673 --- /dev/null +++ b/source/app/views/urls/index.html.erb @@ -0,0 +1,26 @@ +

Bitly Clone

+ + + + + + + + + <% @urls.each do |url| %> + + + + + + + <% end %> +
Destination:Short Url:Clicks:
<%= url.original %><%= link_to url.shortened, urls_click_link_path(url) %><%= url.click_count %><%= link_to 'Delete', url_path(url), method: :delete %>
+ +<%= form_for :url do |f| %> +

+ <%= f.label :'Enter Url:' %>
+ <%= f.text_field :original %> + <%= f.submit %> +

+<% end %> \ No newline at end of file diff --git a/source/config/routes.rb b/source/config/routes.rb index 3f66539..733d8ab 100644 --- a/source/config/routes.rb +++ b/source/config/routes.rb @@ -1,4 +1,9 @@ Rails.application.routes.draw do + get 'urls/click_link' => 'urls#click_link' + + resources :urls + + root 'urls#index' # The priority is based upon order of creation: first created -> highest priority. # See how all your routes lay out with "rake routes". diff --git a/source/db/.DS_Store b/source/db/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..0cbababf149029a3b2f249ee41d9a2145759c65a GIT binary patch literal 6148 zcmeHKTTc@~6g~r0wp?VnR3Q4Wk(iJ`NU6uHpw8*0|x~G}>&YsIm=i8i_9RMJyYHUufoZ$cI}yJ6 z*mjF-C&j96(HG-n%wQ99#YB01aDP9MxG`oVZpIJBjQy#p_?R)7xOH%#X#>|Mrqk=? z-M#(i2QOZWWdp&jPe`}II=n%pffT#2t(HmN)tC82*N+z3-qG20sax;q?d$39iN#`< z2V#RmLs#;8pJf)dN*@2qv&>;$%Bj+ol4lpQ6|-QwrCdOt1zCHK=Jno&&_}fRZ!4&okW;P3^8ZrbV3vH^qX0m3br|t-#!jNBKxO8+E>x;hAre%i-jF zT^W&z4#QHxqe&-=E^}!#I-JZXqXwgJ2Ohu@Y{4G9g12x8@8JV{hOh90w2>iljf|2> zGEHX4eUc{gBtssOM>4ym{z9+Tr;tci5F1|TcGhzp=9bXIv!Ylr1=z%DDPt9kV=Y*x z>wpYk)XA#RFoWW+hTGRV96xIfZ0p##@VJ^pk%FB%j)lUH;z4Xe&}VQ3F{!X75iKa;hk&3V>_P_qC :model do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/source/spec/models/ur_lindex_spec.rb b/source/spec/models/ur_lindex_spec.rb new file mode 100644 index 0000000..29bbb69 --- /dev/null +++ b/source/spec/models/ur_lindex_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe UrLindex, :type => :model do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/source/spec/models/url_spec.rb b/source/spec/models/url_spec.rb new file mode 100644 index 0000000..209ca4c --- /dev/null +++ b/source/spec/models/url_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe Url, :type => :model do + pending "add some examples to (or delete) #{__FILE__}" +end From c12a48072b6f16283feb048e518ae2acc6573d90 Mon Sep 17 00:00:00 2001 From: John Chester Date: Mon, 12 Jun 2017 10:31:29 -0400 Subject: [PATCH 2/2] Release 3 --- source/app/controllers/urls_controller.rb | 13 +++++++++---- source/app/models/url.rb | 8 ++++---- source/app/views/urls/index.html.erb | 12 ++++++++++-- source/db/migrate/.DS_Store | Bin 0 -> 6148 bytes 4 files changed, 23 insertions(+), 10 deletions(-) create mode 100644 source/db/migrate/.DS_Store diff --git a/source/app/controllers/urls_controller.rb b/source/app/controllers/urls_controller.rb index bd684e1..a7f8d33 100644 --- a/source/app/controllers/urls_controller.rb +++ b/source/app/controllers/urls_controller.rb @@ -1,16 +1,21 @@ class UrlsController < ApplicationController - def new - end def index @urls = Url.all end + def new + end + def create @url = Url.new(url_params) - @url.save - redirect_to '/' + if @url.save + redirect_to '/' + else + @urls = Url.all + render 'index' + end end def destroy diff --git a/source/app/models/url.rb b/source/app/models/url.rb index 6e9e177..c02e9da 100644 --- a/source/app/models/url.rb +++ b/source/app/models/url.rb @@ -1,7 +1,7 @@ class Url < ActiveRecord::Base - validates :original, presence: true, - length: { minimum: 1 }, - format: {with: /\A((http|https):\/\/).*\Z/} + validates :original, presence: true + validates :original, length: { minimum: 1 } + validates :original, format: {with: /\A((http|https):\/\/).*\Z/} before_save :shortify @@ -11,7 +11,7 @@ def shortify if self.shortened == nil self.click_count = 0 begin - self.shortened = "https://bit.ly/" + SecureRandom.hex(4) + self.shortened = "https://bit.ly/" + SecureRandom.hex(3) end while Url.where(shortened: self.shortened).exists? end end diff --git a/source/app/views/urls/index.html.erb b/source/app/views/urls/index.html.erb index 4e0b673..4f62629 100644 --- a/source/app/views/urls/index.html.erb +++ b/source/app/views/urls/index.html.erb @@ -6,7 +6,7 @@ Short Url: Clicks: - + <% @urls.each do |url| %> <%= url.original %> @@ -23,4 +23,12 @@ <%= f.text_field :original %> <%= f.submit %>

-<% end %> \ No newline at end of file +<% end %> + +
+ <% if @url %> +

+ <%= "Please enter a valid URL starting with 'http://' or 'https://'" if @url.errors.any? %> +

+ <% end %> +
diff --git a/source/db/migrate/.DS_Store b/source/db/migrate/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..cf6553bb9c6b2656fd2ddf78f5b00e448d7683d7 GIT binary patch literal 6148 zcmeHKJxc>Y5PhpD0yZgagexqpB&T8wHb;nswLjqET`YvdfSUgPj=xgh+gX*T*VwYx;R(mY=DORoO}A;7MHF7L9lb`O1srBF&*_`t45!)5 zHFMwN0c+}(_40LIzSN1uTsZ^IfHU9>I0HXofM>R3yl3dz8E^)ife!|>KNM`jDq(LJ zw+<>@pEW)bN@(jMEG!aM34241P=bXLEi|MjMzC=Di!`rF*c)0nLafX@sq*{dCB*9V z7jZg5W$4-&a0Z49>{@rC^Z$y!O!kpK4Dp^b;0*jT2Eu50vt00_(%Jg$^K{l0Y%4a2 q=Jhftv