summaryrefslogtreecommitdiff
path: root/spec/controllers/tutorials_controller_spec.rb
diff options
context:
space:
mode:
authormo k <mo@mokhan.ca>2012-09-06 07:37:50 -0600
committermo k <mo@mokhan.ca>2012-09-06 07:37:50 -0600
commit72a942dd43935d1ac0b0fc37f93f12ef0bd02330 (patch)
treebd64e0827c78bf88766cd60c583d1789bc16950e /spec/controllers/tutorials_controller_spec.rb
parent4582b91e85aa962e586e92983ee3971a67d52aab (diff)
add tutorial scaffold.
Diffstat (limited to 'spec/controllers/tutorials_controller_spec.rb')
-rw-r--r--spec/controllers/tutorials_controller_spec.rb164
1 files changed, 164 insertions, 0 deletions
diff --git a/spec/controllers/tutorials_controller_spec.rb b/spec/controllers/tutorials_controller_spec.rb
new file mode 100644
index 00000000..7559c194
--- /dev/null
+++ b/spec/controllers/tutorials_controller_spec.rb
@@ -0,0 +1,164 @@
+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
+ # Tutorial. As you add validations to Tutorial, be sure to
+ # update the return value of this method accordingly.
+ def valid_attributes
+ {}
+ end
+
+ # This should return the minimal set of values that should be in the session
+ # in order to pass any filters (e.g. authentication) defined in
+ # TutorialsController. Be sure to keep this updated too.
+ def valid_session
+ {}
+ end
+
+ describe "GET index" do
+ it "assigns all tutorials as @tutorials" do
+ tutorial = Tutorial.create! valid_attributes
+ get :index, {}, valid_session
+ assigns(:tutorials).should eq([tutorial])
+ end
+ end
+
+ describe "GET show" do
+ it "assigns the requested tutorial as @tutorial" do
+ tutorial = Tutorial.create! valid_attributes
+ get :show, {:id => tutorial.to_param}, valid_session
+ assigns(:tutorial).should eq(tutorial)
+ end
+ end
+
+ describe "GET new" do
+ it "assigns a new tutorial as @tutorial" do
+ get :new, {}, valid_session
+ assigns(:tutorial).should be_a_new(Tutorial)
+ end
+ end
+
+ describe "GET edit" do
+ it "assigns the requested tutorial as @tutorial" do
+ tutorial = Tutorial.create! valid_attributes
+ get :edit, {:id => tutorial.to_param}, valid_session
+ assigns(:tutorial).should eq(tutorial)
+ end
+ end
+
+ describe "POST create" do
+ describe "with valid params" do
+ it "creates a new Tutorial" do
+ expect {
+ post :create, {:tutorial => valid_attributes}, valid_session
+ }.to change(Tutorial, :count).by(1)
+ end
+
+ it "assigns a newly created tutorial as @tutorial" do
+ post :create, {:tutorial => valid_attributes}, valid_session
+ assigns(:tutorial).should be_a(Tutorial)
+ assigns(:tutorial).should be_persisted
+ end
+
+ it "redirects to the created tutorial" do
+ post :create, {:tutorial => valid_attributes}, valid_session
+ response.should redirect_to(Tutorial.last)
+ end
+ end
+
+ describe "with invalid params" do
+ it "assigns a newly created but unsaved tutorial as @tutorial" do
+ # Trigger the behavior that occurs when invalid params are submitted
+ Tutorial.any_instance.stub(:save).and_return(false)
+ post :create, {:tutorial => {}}, valid_session
+ assigns(:tutorial).should be_a_new(Tutorial)
+ end
+
+ it "re-renders the 'new' template" do
+ # Trigger the behavior that occurs when invalid params are submitted
+ Tutorial.any_instance.stub(:save).and_return(false)
+ post :create, {:tutorial => {}}, valid_session
+ response.should render_template("new")
+ end
+ end
+ end
+
+ describe "PUT update" do
+ describe "with valid params" do
+ it "updates the requested tutorial" do
+ tutorial = Tutorial.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
+ # submitted in the request.
+ Tutorial.any_instance.should_receive(:update_attributes).with({'these' => 'params'})
+ put :update, {:id => tutorial.to_param, :tutorial => {'these' => 'params'}}, valid_session
+ end
+
+ it "assigns the requested tutorial as @tutorial" do
+ tutorial = Tutorial.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
+ put :update, {:id => tutorial.to_param, :tutorial => valid_attributes}, valid_session
+ response.should redirect_to(tutorial)
+ end
+ end
+
+ describe "with invalid params" do
+ it "assigns the tutorial as @tutorial" do
+ tutorial = Tutorial.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
+ assigns(:tutorial).should eq(tutorial)
+ end
+
+ it "re-renders the 'edit' template" do
+ tutorial = Tutorial.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
+ response.should render_template("edit")
+ end
+ end
+ end
+
+ describe "DELETE destroy" do
+ it "destroys the requested tutorial" do
+ tutorial = Tutorial.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
+ delete :destroy, {:id => tutorial.to_param}, valid_session
+ response.should redirect_to(tutorials_url)
+ end
+ end
+
+end