diff options
| author | mo k <mo@mokhan.ca> | 2012-09-10 21:16:54 -0600 |
|---|---|---|
| committer | mo k <mo@mokhan.ca> | 2012-09-10 21:16:54 -0600 |
| commit | 157c63e34ead02ed0ba919e2bb1feacef10d7a61 (patch) | |
| tree | 76ba156241bd8d37ec0bd0b9c04bd9bea70c313b /spec/controllers/tutorials_controller_spec.rb | |
| parent | b5883cac7e0eff94c2edfc4dc0ac933fc8e857d5 (diff) | |
fix the tutorial specs.
Diffstat (limited to 'spec/controllers/tutorials_controller_spec.rb')
| -rw-r--r-- | spec/controllers/tutorials_controller_spec.rb | 46 |
1 files changed, 17 insertions, 29 deletions
diff --git a/spec/controllers/tutorials_controller_spec.rb b/spec/controllers/tutorials_controller_spec.rb index 7559c194..78cf3251 100644 --- a/spec/controllers/tutorials_controller_spec.rb +++ b/spec/controllers/tutorials_controller_spec.rb @@ -1,23 +1,5 @@ require 'spec_helper' -# This spec was generated by rspec-rails when you ran the scaffold generator. -# It demonstrates how one might use RSpec to specify the controller code that -# was generated by Rails when you ran the scaffold generator. -# -# It assumes that the implementation code is generated by the rails scaffold -# generator. If you are using any extension libraries to generate different -# controller code, this generated spec may or may not pass. -# -# It only uses APIs available in rails and/or rspec-rails. There are a number -# of tools you can use to make these specs even more expressive, but we're -# sticking to rails and rspec-rails APIs to keep things simple and stable. -# -# Compared to earlier versions of this generator, there is very limited use of -# stubs and message expectations in this spec. Stubs are only used when there -# is no simpler way to get a handle on the object needed for the example. -# Message expectations are only used when there is no simpler way to specify -# that an instance is receiving a specific message. - describe TutorialsController do # This should return the minimal set of attributes required to create a valid @@ -34,9 +16,15 @@ describe TutorialsController do {} end + let(:user){ FactoryGirl.create(:user) } + + before (:each) do + request.env['warden'] = mock(Warden, :authenticate => user, :authenticate! => user) + end + describe "GET index" do it "assigns all tutorials as @tutorials" do - tutorial = Tutorial.create! valid_attributes + tutorial = user.tutorials.create! valid_attributes get :index, {}, valid_session assigns(:tutorials).should eq([tutorial]) end @@ -44,7 +32,7 @@ describe TutorialsController do describe "GET show" do it "assigns the requested tutorial as @tutorial" do - tutorial = Tutorial.create! valid_attributes + tutorial = user.tutorials.create! valid_attributes get :show, {:id => tutorial.to_param}, valid_session assigns(:tutorial).should eq(tutorial) end @@ -59,7 +47,7 @@ describe TutorialsController do describe "GET edit" do it "assigns the requested tutorial as @tutorial" do - tutorial = Tutorial.create! valid_attributes + tutorial = user.tutorials.create! valid_attributes get :edit, {:id => tutorial.to_param}, valid_session assigns(:tutorial).should eq(tutorial) end @@ -81,7 +69,7 @@ describe TutorialsController do it "redirects to the created tutorial" do post :create, {:tutorial => valid_attributes}, valid_session - response.should redirect_to(Tutorial.last) + response.should redirect_to(tutorials_path) end end @@ -105,7 +93,7 @@ describe TutorialsController do describe "PUT update" do describe "with valid params" do it "updates the requested tutorial" do - tutorial = Tutorial.create! valid_attributes + tutorial = user.tutorials.create! valid_attributes # Assuming there are no other tutorials in the database, this # specifies that the Tutorial created on the previous line # receives the :update_attributes message with whatever params are @@ -115,13 +103,13 @@ describe TutorialsController do end it "assigns the requested tutorial as @tutorial" do - tutorial = Tutorial.create! valid_attributes + tutorial = user.tutorials.create! valid_attributes put :update, {:id => tutorial.to_param, :tutorial => valid_attributes}, valid_session assigns(:tutorial).should eq(tutorial) end it "redirects to the tutorial" do - tutorial = Tutorial.create! valid_attributes + tutorial = user.tutorials.create! valid_attributes put :update, {:id => tutorial.to_param, :tutorial => valid_attributes}, valid_session response.should redirect_to(tutorial) end @@ -129,7 +117,7 @@ describe TutorialsController do describe "with invalid params" do it "assigns the tutorial as @tutorial" do - tutorial = Tutorial.create! valid_attributes + tutorial = user.tutorials.create! valid_attributes # Trigger the behavior that occurs when invalid params are submitted Tutorial.any_instance.stub(:save).and_return(false) put :update, {:id => tutorial.to_param, :tutorial => {}}, valid_session @@ -137,7 +125,7 @@ describe TutorialsController do end it "re-renders the 'edit' template" do - tutorial = Tutorial.create! valid_attributes + tutorial = user.tutorials.create! valid_attributes # Trigger the behavior that occurs when invalid params are submitted Tutorial.any_instance.stub(:save).and_return(false) put :update, {:id => tutorial.to_param, :tutorial => {}}, valid_session @@ -148,14 +136,14 @@ describe TutorialsController do describe "DELETE destroy" do it "destroys the requested tutorial" do - tutorial = Tutorial.create! valid_attributes + tutorial = user.tutorials.create! valid_attributes expect { delete :destroy, {:id => tutorial.to_param}, valid_session }.to change(Tutorial, :count).by(-1) end it "redirects to the tutorials list" do - tutorial = Tutorial.create! valid_attributes + tutorial = user.tutorials.create! valid_attributes delete :destroy, {:id => tutorial.to_param}, valid_session response.should redirect_to(tutorials_url) end |
