Skip to content

Commit

Permalink
Allow a guest to sign in
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuaclayton committed Sep 17, 2012
1 parent 56bbe68 commit d612b16
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 1 deletion.
9 changes: 9 additions & 0 deletions app/controllers/sessions_controller.rb
@@ -0,0 +1,9 @@
class SessionsController < ApplicationController
def new
end

def create
cookies[:current_user] = params[:user][:email]
redirect_to root_path
end
end
2 changes: 1 addition & 1 deletion app/views/layouts/application.html.erb
Expand Up @@ -7,7 +7,7 @@
<%= csrf_meta_tags %>
</head>
<body>

<p class='current-user'><%= cookies[:current_user] %></p>
<%= yield %>

</body>
Expand Down
1 change: 1 addition & 0 deletions app/views/pages/homepage.html.erb
@@ -1 +1,2 @@
<p data-role="site-description">This is an awesome todo app where you can manage things</p>
<%= link_to 'Log In', new_session_path %>
5 changes: 5 additions & 0 deletions app/views/sessions/new.html.erb
@@ -0,0 +1,5 @@
<%= form_for :user, url: session_path do |form| %>
<%= form.label :email %>
<%= form.text_field :email %>
<%= form.submit 'Sign Up' %>
<% end %>
1 change: 1 addition & 0 deletions config/routes.rb
@@ -1,3 +1,4 @@
Todos::Application.routes.draw do
root to: 'high_voltage/pages', action: :show, id: 'homepage'
resource :session, only: [:new, :create]
end
24 changes: 24 additions & 0 deletions db/schema.rb
@@ -0,0 +1,24 @@
# encoding: UTF-8
# This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
#
# Note that this schema.rb definition is the authoritative source for your
# database schema. If you need to create the application database on another
# system, you should be using db:schema:load, not running all the migrations
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
# you'll amass, the slower it'll run and the greater likelihood for issues).
#
# It's strongly recommended to check this file into your version control system.

ActiveRecord::Schema.define(:version => 20120716210041) do

create_table "todos", :force => true do |t|
t.text "description"
t.string "owner_email"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.datetime "completed_at"
end

end
9 changes: 9 additions & 0 deletions features/step_definitions/sign_up_steps.rb
@@ -0,0 +1,9 @@
When /^I sign up as "(.*?)"$/ do |email|
click_link 'Log In'
fill_in 'Email', with: email
click_button 'Sign Up'
end

Then /^I should be signed in as "(.*?)"$/ do |email|
page.should have_css 'p.current-user', text: email
end
5 changes: 5 additions & 0 deletions features/view_the_homepage.feature
Expand Up @@ -6,3 +6,8 @@ Feature: View the homepage
Scenario: Learn about the application
When I go to the homepage
Then I should be able to gather information about the site

Scenario: Sign up for an account
When I go to the homepage
And I sign up as "john@example.com"
Then I should be signed in as "john@example.com"

0 comments on commit d612b16

Please sign in to comment.