Skip to content

Commit

Permalink
Added a User factory and tests for the show page
Browse files Browse the repository at this point in the history
  • Loading branch information
ketan21 committed Jul 12, 2012
1 parent ff47ecf commit 30b63bd
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 24 deletions.
5 changes: 3 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ end
gem 'jquery-rails'

group :development do
gem 'rspec-rails', '2.10.0'
gem 'rspec-rails', '2.11.0'
gem 'annotated-rails'
end

Expand All @@ -23,6 +23,7 @@ group :production do
end

group :test do
gem 'rspec', '2.10.0'
gem 'rspec', '2.11.0'
gem 'webrat'
gem 'factory_girl_rails'
end
42 changes: 24 additions & 18 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,14 @@ GEM
erubis (2.7.0)
execjs (1.4.0)
multi_json (~> 1.0)
factory_girl (3.5.0)
activesupport (>= 3.0.0)
factory_girl_rails (3.5.0)
factory_girl (~> 3.5.0)
railties (>= 3.0.0)
hike (1.2.1)
i18n (0.6.0)
journey (1.0.3)
journey (1.0.4)
jquery-rails (2.0.2)
railties (>= 3.2.0, < 5.0)
thor (~> 0.14)
Expand All @@ -54,10 +59,10 @@ GEM
i18n (>= 0.4.0)
mime-types (~> 1.16)
treetop (~> 1.4.8)
mime-types (1.18)
mime-types (1.19)
multi_json (1.3.6)
nokogiri (1.5.3)
pg (0.13.2)
nokogiri (1.5.5)
pg (0.14.0)
polyglot (0.3.3)
rack (1.4.1)
rack-cache (1.2)
Expand All @@ -84,20 +89,20 @@ GEM
rake (0.9.2.2)
rdoc (3.12)
json (~> 1.4)
rspec (2.10.0)
rspec-core (~> 2.10.0)
rspec-expectations (~> 2.10.0)
rspec-mocks (~> 2.10.0)
rspec-core (2.10.1)
rspec-expectations (2.10.0)
rspec (2.11.0)
rspec-core (~> 2.11.0)
rspec-expectations (~> 2.11.0)
rspec-mocks (~> 2.11.0)
rspec-core (2.11.0)
rspec-expectations (2.11.1)
diff-lcs (~> 1.1.3)
rspec-mocks (2.10.1)
rspec-rails (2.10.0)
rspec-mocks (2.11.1)
rspec-rails (2.11.0)
actionpack (>= 3.0)
activesupport (>= 3.0)
railties (>= 3.0)
rspec (~> 2.10.0)
sass (3.1.19)
rspec (~> 2.11.0)
sass (3.1.20)
sass-rails (3.2.5)
railties (~> 3.2.0)
sass (>= 3.1.10)
Expand All @@ -114,9 +119,9 @@ GEM
polyglot
polyglot (>= 0.3.1)
tzinfo (0.3.33)
uglifier (1.2.4)
uglifier (1.2.6)
execjs (>= 0.3.0)
multi_json (>= 1.0.2)
multi_json (~> 1.3)
webrat (0.7.3)
nokogiri (>= 1.2.0)
rack (>= 1.0)
Expand All @@ -128,11 +133,12 @@ PLATFORMS
DEPENDENCIES
annotated-rails
coffee-rails (~> 3.2.1)
factory_girl_rails
jquery-rails
pg
rails (= 3.2.2)
rspec (= 2.10.0)
rspec-rails (= 2.10.0)
rspec (= 2.11.0)
rspec-rails (= 2.11.0)
sass-rails (~> 3.2.3)
spork
sqlite3
Expand Down
5 changes: 5 additions & 0 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
class UsersController < ApplicationController

def show
@user = User.find(params[:id])
@title = @user.name + "<script>"
end

def new
@title = "Sign Up"
end
Expand Down
3 changes: 3 additions & 0 deletions app/views/users/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<h1>
<%= @user.name %>
</h1>
7 changes: 5 additions & 2 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
SampleApp::Application.routes.draw do
get "users/new"

resources :users

root :to => 'pages#home'

match '/contact', :to => 'pages#contact'
match '/help', :to => 'pages#help'
match '/about', :to => 'pages#about'
match '/signup', :to => 'users#new'
root :to => 'pages#home'


# The priority is based upon order of creation:
# first created -> highest priority.
Expand Down
22 changes: 20 additions & 2 deletions spec/controllers/users_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,32 @@
describe UsersController do
render_views

describe 'GET "show"' do

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

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

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

end

describe "GET 'new'" do
it "returns http success" do
get 'new'
get :new
response.should be_success
end

it 'should have the right title' do
get 'new'
get :new
response.should have_selector('title', :content => "Sign Up")
end
end
Expand Down
8 changes: 8 additions & 0 deletions spec/factories.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FactoryGirl.define do
factory :user do
name "Ketan Deshmukh"
email "ketan.davvindore@gmail.com"
password "foobar"
password_confirmation "foobar"
end
end

0 comments on commit 30b63bd

Please sign in to comment.