NACK – Link to add a product is not shown, but I can easily access to the controller by http://localhost:3000/products/new?project=1 (project 1 are not approved).

--
Benjamin LAN-SUN-LUK



Le 26/03/09 03:30, « Darryl L. Pierce » <mcpierce@gmail.com> a écrit :

If the project is not approved, then the add product link is not shown
on the page. If the controller method is invoked directly then an error
is shown.

NOTE: the unit test is dependant on the previous patch for #98.

Signed-off-by: Darryl L. Pierce <mcpierce@gmail.com>
---
 app/views/projects/show.html.erb            |    2 +-
 test/functional/products_controller_test.rb |   11 +++++++++++
 2 files changed, 12 insertions(+), 1 deletions(-)

diff --git a/app/views/projects/show.html.erb b/app/views/projects/show.html.erb
index 8d93f4c..8308d80 100644
--- a/app/views/projects/show.html.erb
+++ b/app/views/projects/show.html.erb
@@ -19,7 +19,7 @@
         <%= link_to(image_tag("icons/edit.png", :title => "Edit this project..."),
           edit_project_path(@project)) if @project.can_edit?(@user) %>
         <%= link_to(image_tag("icons/new.png", :title => "Create a new product..."),
-          new_product_path(:project => @project)) if @project.can_create_products?(@user) %>
+          new_product_path(:project => @project)) if @project.can_create_products?(@user) && @project.approved %>
       </td>
     </tr>

diff --git a/test/functional/products_controller_test.rb b/test/functional/products_controller_test.rb
index f690fe6..c4e2753 100644
--- a/test/functional/products_controller_test.rb
+++ b/test/functional/products_controller_test.rb
@@ -27,6 +27,8 @@ class ProductsControllerTest < ActionController::TestCase

   def setup
     @project = projects(:projxp)
+    @unapproved_project = projects(:unapproved_project)
+    raise "Unapproved project cannot be approved!" if @unapproved_project.approved

     @project_owner = @project.owner
     @non_project_owner = users(:mcpierce)
@@ -142,6 +144,15 @@ class ProductsControllerTest < ActionController::TestCase
     assert_redirected_to project_path(@project)
   end

+  # Ensures that a product cannot be created for an unapproved project.
+  def test_new_for_unapproved_project
+    get :new,
+    {:project => @unapproved_project.id },
+    { :user_id => @unapproved_project.owner_id}
+
+    assert_redirected_to project_path(@unapproved_project)
+  end
+
   # Ensures that creating a project works as expected.
   def test_new
     get :new,
--
1.6.0.6

_______________________________________________
projxp-devel mailing list
projxp-devel@lists.fedorahosted.org
https://fedorahosted.org/mailman/listinfo/projxp-devel