Skip to content

Commit

Permalink
Added user name and email presence validation and model rspec test
Browse files Browse the repository at this point in the history
  • Loading branch information
safalmj committed Sep 4, 2012
1 parent 389e2ed commit 53c974c
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 21 deletions.
34 changes: 14 additions & 20 deletions Gemfile.lock
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ GEM
activesupport (3.2.6) activesupport (3.2.6)
i18n (~> 0.6) i18n (~> 0.6)
multi_json (~> 1.0) multi_json (~> 1.0)
addressable (2.2.8) addressable (2.3.2)
annotate (2.5.0) annotate (2.5.0)
rake rake
arel (3.0.2) arel (3.0.2)
Expand All @@ -41,8 +41,8 @@ GEM
rack-test (>= 0.5.4) rack-test (>= 0.5.4)
selenium-webdriver (~> 2.0) selenium-webdriver (~> 2.0)
xpath (~> 0.1.4) xpath (~> 0.1.4)
childprocess (0.3.3) childprocess (0.3.5)
ffi (~> 1.0.6) ffi (~> 1.0, >= 1.0.6)
coffee-rails (3.2.2) coffee-rails (3.2.2)
coffee-script (>= 2.2.0) coffee-script (>= 2.2.0)
railties (~> 3.2.0) railties (~> 3.2.0)
Expand All @@ -54,7 +54,7 @@ GEM
erubis (2.7.0) erubis (2.7.0)
execjs (1.4.0) execjs (1.4.0)
multi_json (~> 1.0) multi_json (~> 1.0)
ffi (1.0.11) ffi (1.1.5)
guard (1.3.2) guard (1.3.2)
listen (>= 0.4.2) listen (>= 0.4.2)
thor (>= 0.14.6) thor (>= 0.14.6)
Expand All @@ -64,19 +64,16 @@ GEM
guard (>= 0.8.4) guard (>= 0.8.4)
spork (>= 0.8.4) spork (>= 0.8.4)
hike (1.2.1) hike (1.2.1)
i18n (0.6.0) i18n (0.6.1)
journey (1.0.4) journey (1.0.4)
jquery-rails (2.0.2) jquery-rails (2.1.1)
railties (>= 3.2.0, < 5.0) railties (>= 3.1.0, < 5.0)
thor (~> 0.14) thor (~> 0.14)
json (1.7.4) json (1.7.5)
libnotify (0.5.9) libnotify (0.5.9)
libwebsocket (0.1.4) libwebsocket (0.1.5)
addressable addressable
listen (0.4.7) listen (0.5.0)
rb-fchange (~> 0.0.5)
rb-fsevent (~> 0.9.1)
rb-inotify (~> 0.8.8)
mail (2.4.4) mail (2.4.4)
i18n (>= 0.4.0) i18n (>= 0.4.0)
mime-types (~> 1.16) mime-types (~> 1.16)
Expand Down Expand Up @@ -109,9 +106,6 @@ GEM
rdoc (~> 3.4) rdoc (~> 3.4)
thor (>= 0.14.6, < 2.0) thor (>= 0.14.6, < 2.0)
rake (0.9.2.2) rake (0.9.2.2)
rb-fchange (0.0.5)
ffi
rb-fsevent (0.9.1)
rb-inotify (0.8.8) rb-inotify (0.8.8)
ffi (>= 0.5.0) ffi (>= 0.5.0)
rdoc (3.12) rdoc (3.12)
Expand All @@ -130,7 +124,7 @@ GEM
railties (>= 3.0) railties (>= 3.0)
rspec (~> 2.10.0) rspec (~> 2.10.0)
rubyzip (0.9.9) rubyzip (0.9.9)
sass (3.1.20) sass (3.2.1)
sass-rails (3.2.5) sass-rails (3.2.5)
railties (~> 3.2.0) railties (~> 3.2.0)
sass (>= 3.1.10) sass (>= 3.1.10)
Expand All @@ -146,15 +140,15 @@ GEM
rack (~> 1.0) rack (~> 1.0)
tilt (~> 1.1, != 1.3.0) tilt (~> 1.1, != 1.3.0)
sqlite3 (1.3.5) sqlite3 (1.3.5)
thor (0.15.4) thor (0.16.0)
tilt (1.3.3) tilt (1.3.3)
treetop (1.4.10) treetop (1.4.10)
polyglot polyglot
polyglot (>= 0.3.1) polyglot (>= 0.3.1)
tzinfo (0.3.33) tzinfo (0.3.33)
uglifier (1.2.7) uglifier (1.3.0)
execjs (>= 0.3.0) execjs (>= 0.3.0)
multi_json (~> 1.3) multi_json (~> 1.0, >= 1.0.2)
xpath (0.1.4) xpath (0.1.4)
nokogiri (~> 1.3) nokogiri (~> 1.3)


Expand Down
3 changes: 3 additions & 0 deletions app/models/user.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -11,4 +11,7 @@


class User < ActiveRecord::Base class User < ActiveRecord::Base
attr_accessible :email, :name attr_accessible :email, :name

validates :name, :presence => true
validates :email, :presence => true
end end
1 change: 1 addition & 0 deletions db/schema.rb
Original file line number Original file line Diff line number Diff line change
@@ -1,3 +1,4 @@
# encoding: UTF-8
# This file is auto-generated from the current state of the database. Instead # 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 # of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition. # incrementally modify your database, and then regenerate this schema definition.
Expand Down
18 changes: 17 additions & 1 deletion spec/models/user_spec.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -12,5 +12,21 @@
require 'spec_helper' require 'spec_helper'


describe User do describe User do
pending "add some examples to (or delete) #{__FILE__}" before { @user = User.new(:name => "Safal", :email => "safal@gmail.com") }

subject { @user }
it { should respond_to(:name)}
it { should respond_to(:email)}

it { should be_valid}

describe "when user is not present" do
before { @user.name = " "}
it { should_not be_valid }
end

describe "when email is not present" do
before { @user.email = " "}
it { should_not be_valid }
end
end end

0 comments on commit 53c974c

Please sign in to comment.