Skip to content

Commit

Permalink
rails_apps_composer: rspec files
Browse files Browse the repository at this point in the history
  • Loading branch information
Dave Ekhaus committed Apr 20, 2013
1 parent f5b6b8b commit 4b26a73
Show file tree
Hide file tree
Showing 4 changed files with 130 additions and 2 deletions.
2 changes: 1 addition & 1 deletion spec/controllers/home_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
describe HomeController do

describe "GET 'index'" do
it "returns http success" do
it "should be successful" do
get 'index'
response.should be_success
end
Expand Down
24 changes: 24 additions & 0 deletions spec/controllers/users_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
require 'spec_helper'

describe UsersController do

before (:each) do
@user = FactoryGirl.create(:user)
sign_in @user
end

describe "GET 'show'" do

it "should be successful" do
get :show, :id => @user.id
response.should be_success
end

it "should find the right user" do
get :show, :id => @user.id
assigns(:user).should == @user
end

end

end
6 changes: 6 additions & 0 deletions spec/factories/users.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,11 @@

FactoryGirl.define do
factory :user do
name 'Test User'
email '[email protected]'
password 'changeme'
password_confirmation 'changeme'
# required if the Devise Confirmable module is used
confirmed_at Time.now
end
end
100 changes: 99 additions & 1 deletion spec/models/user_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,103 @@
require 'spec_helper'

describe User do
pending "add some examples to (or delete) #{__FILE__}"

before(:each) do
@attr = {
:name => "Example User",
:email => "[email protected]",
:password => "changeme",
:password_confirmation => "changeme"
}
end

it "should create a new instance given a valid attribute" do
User.create!(@attr)
end

it "should require an email address" do
no_email_user = User.new(@attr.merge(:email => ""))
no_email_user.should_not be_valid
end

it "should accept valid email addresses" do
addresses = %w[[email protected] [email protected] [email protected]]
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
User.create!(@attr)
user_with_duplicate_email = User.new(@attr)
user_with_duplicate_email.should_not be_valid
end

it "should reject email addresses identical up to case" do
upcased_email = @attr[:email].upcase
User.create!(@attr.merge(:email => upcased_email))
user_with_duplicate_email = User.new(@attr)
user_with_duplicate_email.should_not be_valid
end

describe "passwords" do

before(:each) do
@user = User.new(@attr)
end

it "should have a password attribute" do
@user.should respond_to(:password)
end

it "should have a password confirmation attribute" do
@user.should respond_to(:password_confirmation)
end
end

describe "password validations" do

it "should require a password" do
User.new(@attr.merge(:password => "", :password_confirmation => "")).
should_not be_valid
end

it "should require a matching password confirmation" do
User.new(@attr.merge(:password_confirmation => "invalid")).
should_not be_valid
end

it "should reject short passwords" do
short = "a" * 5
hash = @attr.merge(:password => short, :password_confirmation => short)
User.new(hash).should_not be_valid
end

end

describe "password encryption" do

before(:each) do
@user = User.create!(@attr)
end

it "should have an encrypted password attribute" do
@user.should respond_to(:encrypted_password)
end

it "should set the encrypted password attribute" do
@user.encrypted_password.should_not be_blank
end

end

end

0 comments on commit 4b26a73

Please sign in to comment.