diff --git a/app/views/categories/_category.rhtml b/app/views/categories/_category.rhtml index d56b8d4..dd7b29c 100644 --- a/app/views/categories/_category.rhtml +++ b/app/views/categories/_category.rhtml @@ -5,7 +5,7 @@
<%= link_to _('Add subcategory'), :action => 'new', :parent_id => category %> <%= link_to _('Edit'), :action => 'edit', :id => category %> - <%= link_to _('Remove'), { :action => 'remove', :id => category, }, :post => true, :confirm => (category.children.empty? ? (_('Are you sure you want to remove "%s"?') % category.name) : (_('Are you sure you want to remove "%s" and all its subcategories?') % category.name) ) %> + <%= link_to _('Remove'), { :action => 'remove', :id => category, }, :method => 'post', :confirm => (category.children.empty? ? (_('Are you sure you want to remove "%s"?') % category.name) : (_('Are you sure you want to remove "%s" and all its subcategories?') % category.name) ) %>
diff --git a/app/views/categories/index.rhtml b/app/views/categories/index.rhtml index dc31d1f..5a46265 100644 --- a/app/views/categories/index.rhtml +++ b/app/views/categories/index.rhtml @@ -4,3 +4,4 @@ <%= render :partial => 'category', :collection => @categories %> +<%= link_to _('New category'), :action => 'new' %> diff --git a/test/functional/categories_controller_test.rb b/test/functional/categories_controller_test.rb index 7b7a8bc..e8bf29f 100644 --- a/test/functional/categories_controller_test.rb +++ b/test/functional/categories_controller_test.rb @@ -5,14 +5,61 @@ require 'categories_controller' class CategoriesController; def rescue_action(e) raise e end; end class CategoriesControllerTest < Test::Unit::TestCase + def setup @controller = CategoriesController.new @request = ActionController::TestRequest.new @response = ActionController::TestResponse.new + + @env = Environment.create!(:name => "My test environment") + Environment.stubs(:default).returns(env) + assert (@cat1 = env.categories.create(:name => 'a test category')) + assert (@cat1 = env.categories.create(:name => 'another category')) + end + attr_reader :env, :cat1, :cat2 + + def test_index + get :index + assert_kind_of Array, assigns(:categories) + assert_tag :tag => 'a', :attributes => { :href => '/admin/categories/new'} + end + + def test_edit + cat = Category.new + env.categories.expects(:find).with('1').returns(cat) + get :edit, :id => '1' + assert_response :success + assert_template 'edit' + assert_equal cat, assigns(:category) + end + + def test_edit_save + post :edit, :id => cat1.id, :category => { :name => 'new name for category' } + assert_redirected_to :action => 'index' + assert_equal 'new name for category', Category.find(cat1.id).name end - # Replace this with your real tests. - def test_truth - assert true + def test_new + cat = Category.new + Category.expects(:new).returns(cat) + get :new end + + def test_new_save + assert_difference Category, :count do + post :new, :category => { :name => 'a new category' } + assert_redirected_to :action => 'index' + end + end + + def test_remove + cat = Category.create!(:name => 'a category to be removed', :environment_id => env.id) + post :remove, :id => cat.id + assert_redirected_to :action => 'index' + assert_raise ActiveRecord::RecordNotFound do + Category.find(cat.id) + end + end + + end -- libgit2 0.21.2