Guest User

Untitled

a guest
May 14th, 2018
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rails 2.40 KB | None | 0 0
  1. require 'spec_helper'
  2.  
  3. describe UsersController do
  4.   render_views
  5.  
  6.   describe "GET 'show'" do
  7.    
  8.     before(:each) do
  9.       @user = FactoryGirl(:user)
  10.     end
  11.    
  12.     it "should be successful" do
  13.       get :show, :id => @user
  14.       response.should be_success
  15.     end
  16.    
  17.     it "should find the right user" do
  18.       get :show, :id => @user
  19.       assigns(:user).should == @user
  20.     end
  21.    
  22.     it "should have the right title" do
  23.       get :show, :id => @user
  24.       response.should have_selector("title", :content => @user.name)
  25.     end
  26.    
  27.     it "should include the user's name" do
  28.       get :show, :id => @user
  29.       response.should have_selector("h1>img", :class => "gravatar")
  30.     end
  31.   end
  32.  
  33.   describe "GET 'new'" do
  34.     it "returns http success" do
  35.       get :new
  36.       response.should be_success
  37.     end
  38.    
  39.     it "should have the right title" do
  40.       get :new
  41.       response.should have_selector("title", :content => "Sign up")
  42.     end
  43.   end
  44.  
  45.   describe "POST 'create'" do
  46.  
  47.     describe "failure" do
  48.    
  49.       before(:each) do
  50.         @attr = { :name => "", :email => "",
  51.                   :password => "", :password_confirmation => "" }
  52.       end
  53.    
  54.       it "should not create a user" do
  55.         lambda do
  56.           post :create, :user => @attr
  57.         end.should_not change(User, :count)
  58.       end
  59.    
  60.       it "should have the right title" do
  61.         post :create, :user => @attr
  62.         response.should have_selector("title", :content => "Sign up")
  63.       end
  64.    
  65.       it "should render the 'new' page" do
  66.         post :create, :user => @attr
  67.         response.should render_template('new')
  68.       end
  69.     end
  70.    
  71.     describe "success" do
  72.      
  73.       before(:each) do
  74.         @attr = { :name => "User User", :email => "user@example.com",
  75.                   :password => "foobar", :password_confirmation => "foobar" }
  76.       end
  77.      
  78.       it "should create a user" do
  79.         lambda do
  80.           post :create, :user => @attr
  81.         end.should change(User, :count).by(1)
  82.       end
  83.      
  84.       it "should redirect to the user show page" do
  85.         post :create, :user => @attr
  86.         response.should redirect_to(user_path(assigns(:user)))
  87.       end
  88.      
  89.       it "should have a welcome message" do
  90.         post :create, :user => @attr
  91.         flash[:success].should =~ /welcome to the sample app/i
  92.       end
  93.     end
  94.   end
  95. end
Add Comment
Please, Sign In to add comment