/spec/controllers/content_pages_controller_spec.rb

https://github.com/chsh/facebook-wiki-app · Ruby · 157 lines · 109 code · 20 blank · 28 comment · 0 complexity · 71edd422d14e3f21efcdc584f0edc59a MD5 · raw file

  1. require 'spec_helper'
  2. # This spec was generated by rspec-rails when you ran the scaffold generator.
  3. # It demonstrates how one might use RSpec to specify the controller code that
  4. # was generated by Rails when you ran the scaffold generator.
  5. #
  6. # It assumes that the implementation code is generated by the rails scaffold
  7. # generator. If you are using any extension libraries to generate different
  8. # controller code, this generated spec may or may not pass.
  9. #
  10. # It only uses APIs available in rails and/or rspec-rails. There are a number
  11. # of tools you can use to make these specs even more expressive, but we're
  12. # sticking to rails and rspec-rails APIs to keep things simple and stable.
  13. #
  14. # Compared to earlier versions of this generator, there is very limited use of
  15. # stubs and message expectations in this spec. Stubs are only used when there
  16. # is no simpler way to get a handle on the object needed for the example.
  17. # Message expectations are only used when there is no simpler way to specify
  18. # that an instance is receiving a specific message.
  19. describe ContentPagesController do
  20. # This should return the minimal set of attributes required to create a valid
  21. # ContentPage. As you add validations to ContentPage, be sure to
  22. # update the return value of this method accordingly.
  23. def valid_attributes
  24. {}
  25. end
  26. describe "GET index" do
  27. it "assigns all content_pages as @content_pages" do
  28. content_page = ContentPage.create! valid_attributes
  29. get :index
  30. assigns(:content_pages).should eq([content_page])
  31. end
  32. end
  33. describe "GET show" do
  34. it "assigns the requested content_page as @content_page" do
  35. content_page = ContentPage.create! valid_attributes
  36. get :show, :id => content_page.id.to_s
  37. assigns(:content_page).should eq(content_page)
  38. end
  39. end
  40. describe "GET new" do
  41. it "assigns a new content_page as @content_page" do
  42. get :new
  43. assigns(:content_page).should be_a_new(ContentPage)
  44. end
  45. end
  46. describe "GET edit" do
  47. it "assigns the requested content_page as @content_page" do
  48. content_page = ContentPage.create! valid_attributes
  49. get :edit, :id => content_page.id.to_s
  50. assigns(:content_page).should eq(content_page)
  51. end
  52. end
  53. describe "POST create" do
  54. describe "with valid params" do
  55. it "creates a new ContentPage" do
  56. expect {
  57. post :create, :content_page => valid_attributes
  58. }.to change(ContentPage, :count).by(1)
  59. end
  60. it "assigns a newly created content_page as @content_page" do
  61. post :create, :content_page => valid_attributes
  62. assigns(:content_page).should be_a(ContentPage)
  63. assigns(:content_page).should be_persisted
  64. end
  65. it "redirects to the created content_page" do
  66. post :create, :content_page => valid_attributes
  67. response.should redirect_to(ContentPage.last)
  68. end
  69. end
  70. describe "with invalid params" do
  71. it "assigns a newly created but unsaved content_page as @content_page" do
  72. # Trigger the behavior that occurs when invalid params are submitted
  73. ContentPage.any_instance.stub(:save).and_return(false)
  74. post :create, :content_page => {}
  75. assigns(:content_page).should be_a_new(ContentPage)
  76. end
  77. it "re-renders the 'new' template" do
  78. # Trigger the behavior that occurs when invalid params are submitted
  79. ContentPage.any_instance.stub(:save).and_return(false)
  80. post :create, :content_page => {}
  81. response.should render_template("new")
  82. end
  83. end
  84. end
  85. describe "PUT update" do
  86. describe "with valid params" do
  87. it "updates the requested content_page" do
  88. content_page = ContentPage.create! valid_attributes
  89. # Assuming there are no other content_pages in the database, this
  90. # specifies that the ContentPage created on the previous line
  91. # receives the :update_attributes message with whatever params are
  92. # submitted in the request.
  93. ContentPage.any_instance.should_receive(:update_attributes).with({'these' => 'params'})
  94. put :update, :id => content_page.id, :content_page => {'these' => 'params'}
  95. end
  96. it "assigns the requested content_page as @content_page" do
  97. content_page = ContentPage.create! valid_attributes
  98. put :update, :id => content_page.id, :content_page => valid_attributes
  99. assigns(:content_page).should eq(content_page)
  100. end
  101. it "redirects to the content_page" do
  102. content_page = ContentPage.create! valid_attributes
  103. put :update, :id => content_page.id, :content_page => valid_attributes
  104. response.should redirect_to(content_page)
  105. end
  106. end
  107. describe "with invalid params" do
  108. it "assigns the content_page as @content_page" do
  109. content_page = ContentPage.create! valid_attributes
  110. # Trigger the behavior that occurs when invalid params are submitted
  111. ContentPage.any_instance.stub(:save).and_return(false)
  112. put :update, :id => content_page.id.to_s, :content_page => {}
  113. assigns(:content_page).should eq(content_page)
  114. end
  115. it "re-renders the 'edit' template" do
  116. content_page = ContentPage.create! valid_attributes
  117. # Trigger the behavior that occurs when invalid params are submitted
  118. ContentPage.any_instance.stub(:save).and_return(false)
  119. put :update, :id => content_page.id.to_s, :content_page => {}
  120. response.should render_template("edit")
  121. end
  122. end
  123. end
  124. describe "DELETE destroy" do
  125. it "destroys the requested content_page" do
  126. content_page = ContentPage.create! valid_attributes
  127. expect {
  128. delete :destroy, :id => content_page.id.to_s
  129. }.to change(ContentPage, :count).by(-1)
  130. end
  131. it "redirects to the content_pages list" do
  132. content_page = ContentPage.create! valid_attributes
  133. delete :destroy, :id => content_page.id.to_s
  134. response.should redirect_to(content_pages_url)
  135. end
  136. end
  137. end