Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Finished first cut of the User model
- Loading branch information
Showing
16 changed files
with
238 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# == Schema Information | ||
# | ||
# Table name: users | ||
# | ||
# id :integer not null, primary key | ||
# name :string(255) | ||
# email :string(255) | ||
# created_at :datetime | ||
# updated_at :datetime | ||
# | ||
|
||
class User < ActiveRecord::Base | ||
attr_accessible :name, :email | ||
|
||
email_regex = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i | ||
|
||
validates :name, :presence => true, | ||
:length => { :maximum => 50} | ||
|
||
validates :email, :presence => true, | ||
:format => { :with => email_regex }, | ||
:uniqueness => { :case_sensitive => false } | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<%= @user.name %>, <%= @user.email %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#!/usr/bin/env ruby | ||
# | ||
# This file was generated by Bundler. | ||
# | ||
# The application 'annotate' is installed as part of a gem, and | ||
# this file is here to facilitate running it. | ||
# | ||
|
||
require 'pathname' | ||
ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile", | ||
Pathname.new(__FILE__).realpath) | ||
|
||
require 'rubygems' | ||
require 'bundler/setup' | ||
|
||
load Gem.bin_path('annotate', 'annotate') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
SampleApp::Application.routes.draw do | ||
get "users/new" | ||
resources :users | ||
|
||
match '/signup', :to => 'users#new' | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
class CreateUsers < ActiveRecord::Migration | ||
def self.up | ||
create_table :users do |t| | ||
t.string :name | ||
t.string :email | ||
|
||
t.timestamps | ||
end | ||
end | ||
|
||
def self.down | ||
drop_table :users | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class AddEmailUniquenessIndex < ActiveRecord::Migration | ||
def self.up | ||
add_index :users, :email, :unique => true | ||
end | ||
|
||
def self.down | ||
remove_index :users, :email | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# 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 => 20120310091333) do | ||
|
||
create_table "users", :force => true do |t| | ||
t.string "name" | ||
t.string "email" | ||
t.datetime "created_at" | ||
t.datetime "updated_at" | ||
end | ||
|
||
add_index "users", ["email"], :name => "index_users_on_email", :unique => true | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
require 'spec_helper' | ||
|
||
# Specs in this file have access to a helper object that includes | ||
# the UsersHelper. For example: | ||
# | ||
# describe UsersHelper do | ||
# describe "string concat" do | ||
# it "concats two strings with spaces" do | ||
# helper.concat_strings("this","that").should == "this that" | ||
# end | ||
# end | ||
# end | ||
describe UsersHelper do | ||
pending "add some examples to (or delete) #{__FILE__}" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# == Schema Information | ||
# | ||
# Table name: users | ||
# | ||
# id :integer not null, primary key | ||
# name :string(255) | ||
# email :string(255) | ||
# created_at :datetime | ||
# updated_at :datetime | ||
# | ||
|
||
require 'spec_helper' | ||
|
||
describe User do | ||
|
||
before(:each) do | ||
@attr = { :name => "Example User", :email => "user@example.com"} | ||
end | ||
|
||
it "should create a new instance given valid attributes" do | ||
User.create!(@attr) | ||
end | ||
|
||
it "should require a name" do | ||
no_name_user = User.new(@attr.merge(:name => "")) | ||
no_name_user.should_not be_valid | ||
end | ||
|
||
it "should reject names that are too long" do | ||
long_name = "a" * 51 | ||
long_name_user = User.new(@attr.merge(:name => long_name)) | ||
long_name_user.should_not be_valid | ||
end | ||
|
||
it "should accept valid email addresses" do | ||
addresses = %w[user@foo.com THE_USER@foo.bar.org first.last@foo.jp] | ||
addresses.each do |address| | ||
valid_email_user = User.new(@attr.merge(:email => address)) | ||
valid_email_user.should be_valid | ||
end | ||
end | ||
|
||
it "should reject invalid email addresses" do | ||
addresses = %w[user@foo,com user_at_foo.org example.user@foo.] | ||
addresses.each do |address| | ||
invalid_email_user = User.new(@attr.merge(:email => address)) | ||
invalid_email_user.should_not be_valid | ||
end | ||
end | ||
|
||
it "should reject duplicate email addresses" do | ||
# Put a user with given email address into the database. | ||
User.create!(@attr) | ||
user_with_duplicate_email = User.new(@atter) | ||
user_with_duplicate_email.should_not be_valid | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
require 'spec_helper' | ||
|
||
describe "users/new.html.erb" do | ||
pending "add some examples to (or delete) #{__FILE__}" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# Logfile created on 2012-03-08 13:19:08 +0900 by logger.rb/25413 | ||
REQUESTING PAGE: GET / with {} and HTTP headers {} | ||
REQUESTING PAGE: GET /about with {} and HTTP headers {"HTTP_REFERER"=>"/"} | ||
REQUESTING PAGE: GET /help with {} and HTTP headers {"HTTP_REFERER"=>"/about"} | ||
REQUESTING PAGE: GET /contact with {} and HTTP headers {"HTTP_REFERER"=>"/help"} | ||
REQUESTING PAGE: GET / with {} and HTTP headers {"HTTP_REFERER"=>"/contact"} | ||
REQUESTING PAGE: GET /signup with {} and HTTP headers {"HTTP_REFERER"=>"/"} | ||
REQUESTING PAGE: GET / with {} and HTTP headers {} | ||
REQUESTING PAGE: GET /about with {} and HTTP headers {"HTTP_REFERER"=>"/"} | ||
REQUESTING PAGE: GET /help with {} and HTTP headers {"HTTP_REFERER"=>"/about"} | ||
REQUESTING PAGE: GET /contact with {} and HTTP headers {"HTTP_REFERER"=>"/help"} | ||
REQUESTING PAGE: GET / with {} and HTTP headers {"HTTP_REFERER"=>"/contact"} | ||
REQUESTING PAGE: GET /signup with {} and HTTP headers {"HTTP_REFERER"=>"/"} | ||
REQUESTING PAGE: GET / with {} and HTTP headers {} | ||
REQUESTING PAGE: GET /about with {} and HTTP headers {"HTTP_REFERER"=>"/"} | ||
REQUESTING PAGE: GET /help with {} and HTTP headers {"HTTP_REFERER"=>"/about"} | ||
REQUESTING PAGE: GET /contact with {} and HTTP headers {"HTTP_REFERER"=>"/help"} | ||
REQUESTING PAGE: GET / with {} and HTTP headers {"HTTP_REFERER"=>"/contact"} | ||
REQUESTING PAGE: GET /signup with {} and HTTP headers {"HTTP_REFERER"=>"/"} | ||
REQUESTING PAGE: GET / with {} and HTTP headers {} | ||
REQUESTING PAGE: GET /about with {} and HTTP headers {"HTTP_REFERER"=>"/"} | ||
REQUESTING PAGE: GET /help with {} and HTTP headers {"HTTP_REFERER"=>"/about"} | ||
REQUESTING PAGE: GET /contact with {} and HTTP headers {"HTTP_REFERER"=>"/help"} | ||
REQUESTING PAGE: GET / with {} and HTTP headers {"HTTP_REFERER"=>"/contact"} | ||
REQUESTING PAGE: GET /signup with {} and HTTP headers {"HTTP_REFERER"=>"/"} | ||
REQUESTING PAGE: GET / with {} and HTTP headers {} | ||
REQUESTING PAGE: GET /about with {} and HTTP headers {"HTTP_REFERER"=>"/"} | ||
REQUESTING PAGE: GET /help with {} and HTTP headers {"HTTP_REFERER"=>"/about"} | ||
REQUESTING PAGE: GET /contact with {} and HTTP headers {"HTTP_REFERER"=>"/help"} | ||
REQUESTING PAGE: GET / with {} and HTTP headers {"HTTP_REFERER"=>"/contact"} | ||
REQUESTING PAGE: GET /signup with {} and HTTP headers {"HTTP_REFERER"=>"/"} | ||
REQUESTING PAGE: GET / with {} and HTTP headers {} | ||
REQUESTING PAGE: GET /about with {} and HTTP headers {"HTTP_REFERER"=>"/"} | ||
REQUESTING PAGE: GET /help with {} and HTTP headers {"HTTP_REFERER"=>"/about"} | ||
REQUESTING PAGE: GET /contact with {} and HTTP headers {"HTTP_REFERER"=>"/help"} | ||
REQUESTING PAGE: GET / with {} and HTTP headers {"HTTP_REFERER"=>"/contact"} | ||
REQUESTING PAGE: GET /signup with {} and HTTP headers {"HTTP_REFERER"=>"/"} | ||
REQUESTING PAGE: GET / with {} and HTTP headers {} | ||
REQUESTING PAGE: GET /about with {} and HTTP headers {"HTTP_REFERER"=>"/"} | ||
REQUESTING PAGE: GET /help with {} and HTTP headers {"HTTP_REFERER"=>"/about"} | ||
REQUESTING PAGE: GET /contact with {} and HTTP headers {"HTTP_REFERER"=>"/help"} | ||
REQUESTING PAGE: GET / with {} and HTTP headers {"HTTP_REFERER"=>"/contact"} | ||
REQUESTING PAGE: GET /signup with {} and HTTP headers {"HTTP_REFERER"=>"/"} | ||
REQUESTING PAGE: GET / with {} and HTTP headers {} | ||
REQUESTING PAGE: GET /about with {} and HTTP headers {"HTTP_REFERER"=>"/"} | ||
REQUESTING PAGE: GET /help with {} and HTTP headers {"HTTP_REFERER"=>"/about"} | ||
REQUESTING PAGE: GET /contact with {} and HTTP headers {"HTTP_REFERER"=>"/help"} | ||
REQUESTING PAGE: GET / with {} and HTTP headers {"HTTP_REFERER"=>"/contact"} | ||
REQUESTING PAGE: GET /signup with {} and HTTP headers {"HTTP_REFERER"=>"/"} |