summaryrefslogtreecommitdiff
path: root/lib/generators/nifty/scaffold/templates/tests/testunit
diff options
context:
space:
mode:
authorStefan Wintermeyer <stefan.wintermeyer@amooma.de>2012-12-17 12:01:45 +0100
committerStefan Wintermeyer <stefan.wintermeyer@amooma.de>2012-12-17 12:01:45 +0100
commitb80bd744ad873f6fc43018bc4bfb90677de167bd (patch)
tree072c4b0e33d442528555b82c415f5e7a1712b2b0 /lib/generators/nifty/scaffold/templates/tests/testunit
parent3e706c2025ecc5523e81ad649639ef2ff75e7bac (diff)
Start of GS5.
Diffstat (limited to 'lib/generators/nifty/scaffold/templates/tests/testunit')
-rw-r--r--lib/generators/nifty/scaffold/templates/tests/testunit/actions/create.rb11
-rw-r--r--lib/generators/nifty/scaffold/templates/tests/testunit/actions/destroy.rb6
-rw-r--r--lib/generators/nifty/scaffold/templates/tests/testunit/actions/edit.rb4
-rw-r--r--lib/generators/nifty/scaffold/templates/tests/testunit/actions/index.rb4
-rw-r--r--lib/generators/nifty/scaffold/templates/tests/testunit/actions/new.rb4
-rw-r--r--lib/generators/nifty/scaffold/templates/tests/testunit/actions/show.rb4
-rw-r--r--lib/generators/nifty/scaffold/templates/tests/testunit/actions/update.rb11
-rw-r--r--lib/generators/nifty/scaffold/templates/tests/testunit/controller.rb49
-rw-r--r--lib/generators/nifty/scaffold/templates/tests/testunit/model.rb7
9 files changed, 100 insertions, 0 deletions
diff --git a/lib/generators/nifty/scaffold/templates/tests/testunit/actions/create.rb b/lib/generators/nifty/scaffold/templates/tests/testunit/actions/create.rb
new file mode 100644
index 0000000..5a6d2ac
--- /dev/null
+++ b/lib/generators/nifty/scaffold/templates/tests/testunit/actions/create.rb
@@ -0,0 +1,11 @@
+ def test_create_invalid
+ <%= class_name %>.any_instance.stubs(:valid?).returns(false)
+ post :create
+ assert_template 'new'
+ end
+
+ def test_create_valid
+ <%= class_name %>.any_instance.stubs(:valid?).returns(true)
+ post :create
+ assert_redirected_to <%= item_path_for_test('url') %>
+ end
diff --git a/lib/generators/nifty/scaffold/templates/tests/testunit/actions/destroy.rb b/lib/generators/nifty/scaffold/templates/tests/testunit/actions/destroy.rb
new file mode 100644
index 0000000..adedf91
--- /dev/null
+++ b/lib/generators/nifty/scaffold/templates/tests/testunit/actions/destroy.rb
@@ -0,0 +1,6 @@
+ def test_destroy
+ <%= instance_name %> = <%= class_name %>.first
+ delete :destroy, :id => <%= instance_name %>
+ assert_redirected_to <%= items_url %>
+ assert !<%= class_name %>.exists?(<%= instance_name %>.id)
+ end
diff --git a/lib/generators/nifty/scaffold/templates/tests/testunit/actions/edit.rb b/lib/generators/nifty/scaffold/templates/tests/testunit/actions/edit.rb
new file mode 100644
index 0000000..55ed24a
--- /dev/null
+++ b/lib/generators/nifty/scaffold/templates/tests/testunit/actions/edit.rb
@@ -0,0 +1,4 @@
+ def test_edit
+ get :edit, :id => <%= class_name %>.first
+ assert_template 'edit'
+ end
diff --git a/lib/generators/nifty/scaffold/templates/tests/testunit/actions/index.rb b/lib/generators/nifty/scaffold/templates/tests/testunit/actions/index.rb
new file mode 100644
index 0000000..22d3bad
--- /dev/null
+++ b/lib/generators/nifty/scaffold/templates/tests/testunit/actions/index.rb
@@ -0,0 +1,4 @@
+ def test_index
+ get :index
+ assert_template 'index'
+ end
diff --git a/lib/generators/nifty/scaffold/templates/tests/testunit/actions/new.rb b/lib/generators/nifty/scaffold/templates/tests/testunit/actions/new.rb
new file mode 100644
index 0000000..c551327
--- /dev/null
+++ b/lib/generators/nifty/scaffold/templates/tests/testunit/actions/new.rb
@@ -0,0 +1,4 @@
+ def test_new
+ get :new
+ assert_template 'new'
+ end
diff --git a/lib/generators/nifty/scaffold/templates/tests/testunit/actions/show.rb b/lib/generators/nifty/scaffold/templates/tests/testunit/actions/show.rb
new file mode 100644
index 0000000..b74f371
--- /dev/null
+++ b/lib/generators/nifty/scaffold/templates/tests/testunit/actions/show.rb
@@ -0,0 +1,4 @@
+ def test_show
+ get :show, :id => <%= class_name %>.first
+ assert_template 'show'
+ end
diff --git a/lib/generators/nifty/scaffold/templates/tests/testunit/actions/update.rb b/lib/generators/nifty/scaffold/templates/tests/testunit/actions/update.rb
new file mode 100644
index 0000000..b588bfc
--- /dev/null
+++ b/lib/generators/nifty/scaffold/templates/tests/testunit/actions/update.rb
@@ -0,0 +1,11 @@
+ def test_update_invalid
+ <%= class_name %>.any_instance.stubs(:valid?).returns(false)
+ put :update, :id => <%= class_name %>.first
+ assert_template 'edit'
+ end
+
+ def test_update_valid
+ <%= class_name %>.any_instance.stubs(:valid?).returns(true)
+ put :update, :id => <%= class_name %>.first
+ assert_redirected_to <%= item_path_for_test('url') %>
+ end
diff --git a/lib/generators/nifty/scaffold/templates/tests/testunit/controller.rb b/lib/generators/nifty/scaffold/templates/tests/testunit/controller.rb
new file mode 100644
index 0000000..8b99836
--- /dev/null
+++ b/lib/generators/nifty/scaffold/templates/tests/testunit/controller.rb
@@ -0,0 +1,49 @@
+require 'test_helper'
+
+class <%= plural_class_name %>ControllerTest < ActionController::TestCase
+ setup do
+ <%= item_path :instance_variable => true %> = <%= plural_name %>(:one)
+ end
+
+ test "should get index" do
+ get :index
+ assert_response :success
+ assert_not_nil assigns(:<%= plural_name %>)
+ end
+
+ test "should get new" do
+ get :new
+ assert_response :success
+ end
+
+ test "should create <%= item_path %>" do
+ assert_difference('<%= class_name %>.count') do
+ post :create, <%= item_path %>: @<%= item_path %>.attributes
+ end
+
+ assert_redirected_to <%= item_path %>_path(assigns(:<%= item_path %>))
+ end
+
+ test "should show <%= item_path %>" do
+ get :show, id: @<%= item_path %>.to_param
+ assert_response :success
+ end
+
+ test "should get edit" do
+ get :edit, id: @<%= item_path %>.to_param
+ assert_response :success
+ end
+
+ test "should update <%= item_path %>" do
+ put :update, id: @<%= item_path %>.to_param, <%= item_path %>: @<%= item_path %>.attributes
+ assert_redirected_to <%= item_path %>_path(assigns(:<%= item_path %>))
+ end
+
+ test "should destroy <%= item_path %>" do
+ assert_difference('<%= class_name %>.count', -1) do
+ delete :destroy, id: @<%= item_path %>.to_param
+ end
+
+ assert_redirected_to <%= plural_name %>_path
+ end
+end
diff --git a/lib/generators/nifty/scaffold/templates/tests/testunit/model.rb b/lib/generators/nifty/scaffold/templates/tests/testunit/model.rb
new file mode 100644
index 0000000..09b835c
--- /dev/null
+++ b/lib/generators/nifty/scaffold/templates/tests/testunit/model.rb
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class <%= class_name %>Test < ActiveSupport::TestCase
+ def test_should_be_valid
+ assert <%= class_name %>.new.valid?
+ end
+end