lib/branston/test/functional/releases_controller_test.rb in branston-0.6.1 vs lib/branston/test/functional/releases_controller_test.rb in branston-0.6.2
- old
+ new
@@ -1,68 +1,104 @@
require 'test_helper'
class ReleasesControllerTest < ActionController::TestCase
- def setup
- login_as(User.make)
- @release = Release.make
- end
+ context "The ReleasesController" do
+ context "when the user is not logged in" do
+ [:index, :new, :edit].each do |action|
+ context "on GET to #{action.to_s}" do
+ setup do
+ get action
+ end
- test "should get index" do
- get :index
- assert_response :success
- assert_not_nil assigns(:releases)
- end
+ should "redirect to login" do
+ assert_redirected_to new_session_path
+ end
+ end
+ end
- test "should get new" do
- get :new
- assert_response :success
- end
+ context "on PUT to :update" do
+ setup do
+ put :update
+ end
+ should "redirect to login" do
+ assert_redirected_to new_session_path
+ end
+ end
- test "should create release" do
- assert_difference('Release.count') do
- post :create, :release => Release.plan
+ context "on POST to :create" do
+ setup do
+ post :create
+ end
+ should "redirect to login" do
+ assert_redirected_to new_session_path
+ end
+ end
end
- assert_redirected_to release_path(assigns(:release))
- end
+ context "when the user is logged in" do
+ setup do
+ login_as(User.make)
+ @release = Release.make
+ end
- test "should display validation errors with invalid data" do
- assert_no_difference('Release.count') do
- post :create, :release => { :release_date => "30/30/2009", :notes => 'hi' }
- assert_template :new
- end
- end
+ should "should get index" do
+ get :index
+ assert_response :success
+ assert_not_nil assigns(:releases)
+ end
- test "should show release" do
- get :show, :id => @release.to_param
- assert_response :success
- end
+ should "should get new" do
+ get :new
+ assert_response :success
+ end
- test "should get edit" do
- get :edit, :id => @release.to_param
- assert_response :success
- end
+ should "should create release" do
+ assert_difference('Release.count') do
+ post :create, :release => Release.plan
+ end
- test "should update release" do
- assert_no_difference('Release.count') do
- put :update, :id => @release.to_param, :release => Release.plan
- assert_redirected_to release_path(assigns(:release))
- end
- end
+ assert_redirected_to release_path(assigns(:release))
+ end
- test "should display validation errors with invalid data on update" do
- assert_no_difference('Release.count') do
- put :update, :id => @release.to_param, :release => { :release_date => "30/30/2009", :notes => 'hi' }
- assert_template :edit
- end
- end
+ should "should display validation errors with invalid data" do
+ assert_no_difference('Release.count') do
+ post :create, :release => { :release_date => "30/30/2009", :notes => 'hi' }
+ assert_template :new
+ end
+ end
- test "should destroy release" do
- assert_difference('Release.count', -1) do
- delete :destroy, :id => @release.to_param
- end
+ should "should show release" do
+ get :show, :id => @release.to_param
+ assert_response :success
+ end
- assert_redirected_to releases_path
+ should "should get edit" do
+ get :edit, :id => @release.to_param
+ assert_response :success
+ end
+
+ should "should update release" do
+ assert_no_difference('Release.count') do
+ put :update, :id => @release.to_param, :release => Release.plan
+ assert_redirected_to release_path(assigns(:release))
+ end
+ end
+
+ should "should display validation errors with invalid data on update" do
+ assert_no_difference('Release.count') do
+ put :update, :id => @release.to_param, :release => { :release_date => "30/30/2009", :notes => 'hi' }
+ assert_template :edit
+ end
+ end
+
+ should "should destroy release" do
+ assert_difference('Release.count', -1) do
+ delete :destroy, :id => @release.to_param
+ end
+
+ assert_redirected_to releases_path
+ end
+ end
end
end