Skip to content
This repository has been archived by the owner on Jun 5, 2020. It is now read-only.

7 recently used stops #17

Merged
merged 3 commits into from
Jul 10, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ gem 'rails', '4.1.1'
gem 'nokogiri'
gem 'newrelic_rpm'
gem 'bootstrap-sass', '~> 3.1.1'
gem 'coveralls', require: false

group :development do
gem 'sqlite3'
Expand All @@ -20,8 +21,8 @@ end

group :test do
gem 'capybara'
gem "vcr"
gem "webmock"
gem 'vcr'
gem 'webmock'
end

# Gems used only for assets and not required
Expand All @@ -32,7 +33,7 @@ gem 'uglifier'
gem 'jquery-rails'

# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'
# gem 'bcrypt'

# To use Jbuilder templates for JSON
# gem 'jbuilder'
Expand All @@ -44,4 +45,4 @@ gem 'jquery-rails'
# gem 'capistrano'

# To use debugger
# gem 'debugger'
gem 'byebug'
26 changes: 26 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,27 @@ GEM
bootstrap-sass (3.1.1.1)
sass (~> 3.2)
builder (3.2.2)
byebug (3.1.2)
columnize (~> 0.8)
debugger-linecache (~> 1.2)
capybara (2.2.1)
mime-types (>= 1.16)
nokogiri (>= 1.3.3)
rack (>= 1.0.0)
rack-test (>= 0.5.4)
xpath (~> 2.0)
columnize (0.8.9)
coveralls (0.7.0)
multi_json (~> 1.3)
rest-client
simplecov (>= 0.7)
term-ansicolor
thor
crack (0.4.2)
safe_yaml (~> 1.0.0)
debugger-linecache (1.2.0)
diff-lcs (1.2.5)
docile (1.1.5)
erubis (2.7.0)
execjs (2.0.2)
hike (1.2.3)
Expand All @@ -66,6 +78,7 @@ GEM
mini_portile (0.6.0)
minitest (5.3.4)
multi_json (1.10.1)
netrc (0.7.7)
newrelic_rpm (3.8.1.221)
nokogiri (1.6.2.1)
mini_portile (= 0.6.0)
Expand Down Expand Up @@ -95,6 +108,9 @@ GEM
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)
rake (10.3.2)
rest-client (1.7.1)
mime-types (>= 1.16, < 3.0)
netrc (~> 0.7)
rspec-core (2.14.8)
rspec-expectations (2.14.5)
diff-lcs (>= 1.1.3, < 2.0)
Expand All @@ -109,6 +125,11 @@ GEM
rspec-mocks (~> 2.14.0)
safe_yaml (1.0.3)
sass (3.3.7)
simplecov (0.8.2)
docile (~> 1.1.0)
multi_json
simplecov-html (~> 0.8.0)
simplecov-html (0.8.0)
sprockets (2.12.1)
hike (~> 1.2)
multi_json (~> 1.0)
Expand All @@ -119,9 +140,12 @@ GEM
activesupport (>= 3.0)
sprockets (~> 2.8)
sqlite3 (1.3.9)
term-ansicolor (1.3.0)
tins (~> 1.0)
thor (0.19.1)
thread_safe (0.3.3)
tilt (1.4.1)
tins (1.3.0)
treetop (1.4.15)
polyglot
polyglot (>= 0.3.1)
Expand All @@ -142,7 +166,9 @@ PLATFORMS

DEPENDENCIES
bootstrap-sass (~> 3.1.1)
byebug
capybara
coveralls
jquery-rails
newrelic_rpm
nokogiri
Expand Down
26 changes: 25 additions & 1 deletion app/controllers/bustimes_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
class BustimesController < ApplicationController

def busroutes
@busroutes = Bustime.new.busroutes
end
Expand All @@ -13,7 +12,32 @@ def busstops
end

def buspredictions
set_recent_stops_cookie(params[:id], params[:rtnm], params[:dir], params[:stopid], params[:stpnm])
@buspredictions = Bustime.new.buspredictions( params[:id], params[:dir], params[:stopid] )
end

def set_recent_stops_cookie(id, rtnm, dir, stopid, stpnm)
cookies[:recent_stops] = {
value: ActiveSupport::JSON.encode(append_cookie_value(id, rtnm, dir, stopid, stpnm)),
expires: 1.year.from_now
}
end

def read_recent_stops_cookie
begin
ActiveSupport::JSON.decode(cookies[:recent_stops])
rescue TypeError
[]
end
end

def append_cookie_value(id, rtnm, dir, stopid, stpnm)
recent_stops = read_recent_stops_cookie
if recent_stops.count > 5
recent_stops.pop
end
stop = { "route" => id, "route_name" => rtnm, "dir" => dir,
"stopid" => stopid, "stpnm" => stpnm }
recent_stops.unshift(stop).uniq
end
end
12 changes: 12 additions & 0 deletions app/views/bustimes/busroutes.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@
<li class="active">Choose a Route</li>
</ol>

<% if cookies[:recent_stops] %>
<ul class="list-group">
Recent Stops:
<% ActiveSupport::JSON.decode(cookies[:recent_stops]).each do |c| %>
<li class="list-group-item">
<%= link_to("#{c['route']} #{c['route_name']}, #{c['dir']}, #{c['stpnm']}",
buspredictions_path( c['route'], c['route_name'], c['dir'], c['stopid'], c['stpnm'] )) %>
</li>
<% end %>
</ul>
<% end %>

<ul class="list-group">
<% @busroutes.each do |l| %>
<li class="list-group-item">
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

20 changes: 20 additions & 0 deletions spec/requests/bustime_pages_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,26 @@
it "should have more info links to bus detail" do
page.should have_link("More Info", :href => "#modal-4077")
end

describe 'recent stops' do
it 'remembers recently used stops' do
visit root_path
expect(page).to have_content("Recent Stops")
expect(page).to have_link("147 Outer Drive Express, Northbound, Michigan & Huron")
end

it 'only remembers 6 recent stops and removes the least recently used' do
pending
end

it 'only remembers unique recent stops' do
pending
end

it 'moves the most recent stop to the first position' do
pending
end
end
end
end
end
Expand Down
3 changes: 2 additions & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'rspec/autorun'

require 'capybara'
require 'coveralls'
Coveralls.wear!

# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
Expand Down