Skip to content

Commit

Permalink
Add UserSessions scaffold with AuthLogic model
Browse files Browse the repository at this point in the history
  • Loading branch information
gabebw committed Jun 15, 2010
1 parent a6371c2 commit 5fa5361
Show file tree
Hide file tree
Showing 14 changed files with 217 additions and 1 deletion.
34 changes: 34 additions & 0 deletions app/controllers/user_sessions_controller.rb
@@ -0,0 +1,34 @@
class UserSessionsController < ApplicationController
# GET /user_sessions/new
# GET /user_sessions/new.xml
def new
@user_session = UserSession.new

respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @user_session }
end
end

# POST /user_sessions
# POST /user_sessions.xml
def create
@user_session = UserSession.new(params[:user_session])

if @user_session.save
flash[:notice] = "Successfully logged in."
redirect_to root_url
else
render :action => "new"
end
end

# DELETE /user_sessions/1
# DELETE /user_sessions/1.xml
def destroy
@user_session = UserSession.find # no arguments -> current session
@user_session.destroy
flash[:notice] = "Successfully logged out."
redirect_to root_url
end
end
2 changes: 2 additions & 0 deletions app/helpers/user_sessions_helper.rb
@@ -0,0 +1,2 @@
module UserSessionsHelper
end
17 changes: 17 additions & 0 deletions app/views/layouts/user_sessions.html.erb
@@ -0,0 +1,17 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
<title>UserSessions: <%= controller.action_name %></title>
<%= stylesheet_link_tag 'scaffold' %>
</head>
<body>

<p style="color: green"><%= flash[:notice] %></p>

<%= yield %>

</body>
</html>
20 changes: 20 additions & 0 deletions app/views/user_sessions/edit.html.erb
@@ -0,0 +1,20 @@
<h1>Editing user_session</h1>

<% form_for(@user_session) do |f| %>
<%= f.error_messages %>

<p>
<%= f.label :username %><br />
<%= f.text_field :username %>
</p>
<p>
<%= f.label :password %><br />
<%= f.text_field :password %>
</p>
<p>
<%= f.submit 'Update' %>
</p>
<% end %>
<%= link_to 'Show', @user_session %> |
<%= link_to 'Back', user_sessions_path %>
22 changes: 22 additions & 0 deletions app/views/user_sessions/index.html.erb
@@ -0,0 +1,22 @@
<h1>Listing user_sessions</h1>

<table>
<tr>
<th>Username</th>
<th>Password</th>
</tr>

<% @user_sessions.each do |user_session| %>
<tr>
<td><%=h user_session.username %></td>
<td><%=h user_session.password %></td>
<td><%= link_to 'Show', user_session %></td>
<td><%= link_to 'Edit', edit_user_session_path(user_session) %></td>
<td><%= link_to 'Destroy', user_session, :confirm => 'Are you sure?', :method => :delete %></td>
</tr>
<% end %>
</table>

<br />

<%= link_to 'New user_session', new_user_session_path %>
19 changes: 19 additions & 0 deletions app/views/user_sessions/new.html.erb
@@ -0,0 +1,19 @@
<h1>New user_session</h1>

<% form_for(@user_session) do |f| %>
<%= f.error_messages %>

<p>
<%= f.label :username %><br />
<%= f.text_field :username %>
</p>
<p>
<%= f.label :password %><br />
<%= f.text_field :password %>
</p>
<p>
<%= f.submit 'Create' %>
</p>
<% end %>
<%= link_to 'Back', user_sessions_path %>
13 changes: 13 additions & 0 deletions app/views/user_sessions/show.html.erb
@@ -0,0 +1,13 @@
<p>
<b>Username:</b>
<%=h @user_session.username %>
</p>

<p>
<b>Password:</b>
<%=h @user_session.password %>
</p>


<%= link_to 'Edit', edit_user_session_path(@user_session) %> |
<%= link_to 'Back', user_sessions_path %>
2 changes: 2 additions & 0 deletions config/routes.rb
@@ -1,4 +1,6 @@
ActionController::Routing::Routes.draw do |map|
map.resources :user_sessions

map.resources :users

map.resources :shows, :has_many => :episodes
Expand Down
14 changes: 14 additions & 0 deletions db/migrate/20100615040754_create_user_sessions.rb
@@ -0,0 +1,14 @@
class CreateUserSessions < ActiveRecord::Migration
def self.up
create_table :user_sessions do |t|
t.string :username
t.string :password

t.timestamps
end
end

def self.down
drop_table :user_sessions
end
end
9 changes: 8 additions & 1 deletion db/schema.rb
Expand Up @@ -9,7 +9,7 @@
#
# It's strongly recommended to check this file into your version control system.

ActiveRecord::Schema.define(:version => 20100615034818) do
ActiveRecord::Schema.define(:version => 20100615040754) do

create_table "episodes", :force => true do |t|
t.string "name"
Expand All @@ -26,6 +26,13 @@
t.datetime "updated_at"
end

create_table "user_sessions", :force => true do |t|
t.string "username"
t.string "password"
t.datetime "created_at"
t.datetime "updated_at"
end

create_table "users", :force => true do |t|
t.string "username"
t.string "email"
Expand Down
9 changes: 9 additions & 0 deletions test/fixtures/user_sessions.yml
@@ -0,0 +1,9 @@
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html

one:
username: MyString
password: MyString

two:
username: MyString
password: MyString
45 changes: 45 additions & 0 deletions test/functional/user_sessions_controller_test.rb
@@ -0,0 +1,45 @@
require 'test_helper'

class UserSessionsControllerTest < ActionController::TestCase
test "should get index" do
get :index
assert_response :success
assert_not_nil assigns(:user_sessions)
end

test "should get new" do
get :new
assert_response :success
end

test "should create user_session" do
assert_difference('UserSession.count') do
post :create, :user_session => { }
end

assert_redirected_to user_session_path(assigns(:user_session))
end

test "should show user_session" do
get :show, :id => user_sessions(:one).to_param
assert_response :success
end

test "should get edit" do
get :edit, :id => user_sessions(:one).to_param
assert_response :success
end

test "should update user_session" do
put :update, :id => user_sessions(:one).to_param, :user_session => { }
assert_redirected_to user_session_path(assigns(:user_session))
end

test "should destroy user_session" do
assert_difference('UserSession.count', -1) do
delete :destroy, :id => user_sessions(:one).to_param
end

assert_redirected_to user_sessions_path
end
end
4 changes: 4 additions & 0 deletions test/unit/helpers/user_sessions_helper_test.rb
@@ -0,0 +1,4 @@
require 'test_helper'

class UserSessionsHelperTest < ActionView::TestCase
end
8 changes: 8 additions & 0 deletions test/unit/user_session_test.rb
@@ -0,0 +1,8 @@
require 'test_helper'

class UserSessionTest < ActiveSupport::TestCase
# Replace this with your real tests.
test "the truth" do
assert true
end
end

0 comments on commit 5fa5361

Please sign in to comment.