Skip to content

Instantly share code, notes, and snippets.

View azuby's full-sized avatar

azuby

  • California, USA
View GitHub Profile
@azuby
azuby / user_spec.rb
Created July 25, 2011 08:20
rspec testing of User controller
require 'spec_helper'
describe User do
before(:each) do
@attr = { :name => "Example User",
:email => "[email protected]",
:password => "secret"
#:password_confirmation => "secret"
}
class User < ActiveRecord::Base
has_secure_password
attr_accessible :name, :email, :password, :password_confirmation
email_regex = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
validates :name, :presence => true,
:length => { :maximum => 50 }
validates :email, :presence => true,
$ rspec spec
........................true
#<User id: 1, name: "Example User", email: "[email protected]", created_at: "2011-07-25 09:17:10", updated_at: "2011-07-25 09:17:10", password_digest: "$2a$10$8rSXunwrcXG7jgn2e6WrE.LaJK3UzyZr5AUjVu1qfg3R...">
.true
#<User id: 1, name: "Example User", email: "[email protected]", created_at: "2011-07-25 09:17:10", updated_at: "2011-07-25 09:17:10", password_digest: "$2a$10$nniZHkVQFHvXlhEeqnSL8.ocNWck/uWpC/5NYheOv/O9...">
.
Finished in 1.86 seconds
26 examples, 0 failures
e 'spec_helper'
describe UsersController do
render_views
describe "GET 'new'" do
it "should be successful" do
get 'new'
response.should be_success
end
require 'spec_helper'
describe User do
# Password encryption tests
describe "password encryption" do
before(:each) do
@attr = { :name => "Example User",
:email => "[email protected]",
Started GET "/" for 127.0.0.1 at 2011-08-03 21:46:53 -0700
ActionView::MissingTemplate (Missing template pages/welcome, application/welcome with {:handlers=>[:erb, :builder], :formats=>[:html], :locale=>[:en, :en]}. Searched in:
):
@azuby
azuby / new.html.erb
Created August 8, 2011 23:43
Sign in form
sessions controller action:
def create
user = User.find_by_email(params[:email])
if user && user.authenticate(params[:password])
session[:user_id] = user.id
redirect_to root_url, :notice => "Successfully signed in."
else
flash.now.alert = "Invalid email or password."
@title = "Sign In"
user views:
NEW ACTION
<section>
<article class="content">
<h1>Sign Up</h1>
<%= form_for(@user) do |f| %>
<%= render 'shared/error_messages' %>
<div class="field">
<%= f.label :first_name, "First Name:" %><br />
class CreateUsers < ActiveRecord::Migration
def change
create_table :users do |t|
t.string :first_name
t.string :last_name
t.string :email
t.string :password_digest
t.string :auth_token
t.timestamps
<section class="signup box">
<h1>Sign Up</h1>
<%= form_for(@user) do |f| %>
<%= render 'shared/error_messages', :object => f.object %>
<div class="field">
<%= f.label :first_name, "First Name:" %><br />
<%= f.text_field :first_name %>
</div>
<div class="field">
<%= f.label :last_name, "Last Name:" %><br />