Guest User

Untitled

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