Skip to content

Commit

Permalink
As a user, I can see that I am logged in when playing !Light (MLH#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
theycallmeswift authored Jun 26, 2017
1 parent c462405 commit ed474b7
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 3 deletions.
4 changes: 1 addition & 3 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,4 @@ task default: :spec
Rake::TestTask.new(:spec) do |t|
t.ruby_opts = ['-W1']
t.test_files = FileList['spec/*_spec.rb']
end


end
1 change: 1 addition & 0 deletions no_light_sinatra.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class NoLightSinatra < Sinatra::Base
get '/auth/mlh/callback' do
auth = request.env["omniauth.auth"]
session[:user_id] = auth["uid"]
session[:full_name] = "#{auth[:info][:first_name]} #{auth[:info][:last_name]}"
next_page = session[:redirect]

if next_page
Expand Down
14 changes: 14 additions & 0 deletions public/css/extended.css
Original file line number Diff line number Diff line change
Expand Up @@ -238,4 +238,18 @@ form {

margin-right: 50px;
width: 220px;
}

/** LAYOUT **/

.current-user {
bottom: 10px;
color: white;
font-size: 0.75rem;
position: fixed;
right: 10px;
}

.current-user a {
color: #FF69B4;
}
17 changes: 17 additions & 0 deletions spec/visitor_can_authorize_with_my_mlh_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,23 @@ def app
last_request.path.must_equal("/hacktheplanet")
end

it 'displays the users name' do
sign_in!

visit '/hacktheplanet'

page.find('.current-user span').text.must_equal "You are playing !Light as Grace Hopper."
end

it 'allows a user to logout' do
sign_in!
visit '/hacktheplanet'

click_link "Logout"

page.has_css?('.current-user').must_equal false
end

it 'redirects authorized users to the previous page' do
visit '/hacktheplanet-test'

Expand Down
5 changes: 5 additions & 0 deletions views/layout.erb
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,10 @@

<%= erb :javascripts unless ENV['RACK_ENV'] == 'test' %>

<% if session[:user_id] %>
<p class="current-user">
<span>You are playing !Light as <%= session[:full_name] %>.</span> (<a href="/logout">Logout</a>)
</p>
<% end %>
</body>
</html>

0 comments on commit ed474b7

Please sign in to comment.