Unit testing and redirects within an exception

2014-03-04 Thread Richard Claydon
Hi

I have a unit test here, and it is failing. The headers['location'] key 
does not have a value in it when the Product-edit() method raises the 
exception, even though I still call redirect within the catch. Is this 
expected behavior?

If I put the redirect before or after the try...catch blog, 
the headers['location'] has a value, this problem only seems to occur when 
inside the exception handler.

Can anyone possibly tell me what I might be doing wrong here?

Many thanks
Richard

The test:

$postData = array(
'Product' = array(
'id' = ProductTest::TEST_PRODUCT_ONE, price' = 100
));
$this-testAction('/admin/products/update', array('data' = $postData));
$this-assertContains('/admin/products/edit', $this-headers['Location']);

The controller:


try {
if ($this-Product-edit($this-request-data)) {
return $this-redirect(array('action' = 'edit', 
$this-Product-id));
}
}
catch (DomainException $quotaException) {
$this-Session-setFlash();
return $this-redirect(array('action' = 'edit', 
$this-Product-id));
}

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Component code

2010-09-02 Thread Richard Claydon
Why not pass the Session object to the model?

$this-doSomething($with_this_data, $store_it_here);



On Fri, Sep 3, 2010 at 6:05 AM, Jeremy Burns | Class Outfit 
jeremybu...@classoutfit.com wrote:

 I should mention that I both read from and write to the session...

 Jeremy Burns
 Class Outfit

 jeremybu...@classoutfit.com
 (t) +44 (0) 208 123 3822
 (m) +44 (0) 7973 481949
 Skype: jeremy_burns
 http://www.classoutfit.com

 On 3 Sep 2010, at 06:00, Dave Maharaj wrote:

  Place the code in the model and pass the Session data as vars from the
  controller?
 
 
  -Original Message-
  From: Jeremy Burns [mailto:jeremybu...@classoutfit.com]
  Sent: September-03-10 2:24 AM
  To: CakePHP
  Subject: Component code
 
  I have a chunk of code that appears in two controllers
  (orders_controller and order_items_controller) that is virtually
  identical in each case. I'd like to move it to a single location, so
  this sounds like an ideal candidate for a component.
 
  Part of the code calls a function in the Order model, so whilst one
  calls it via $this-Order-function() the other calls it via $this-
  OrderItem-Order-function(); hence the difference.
 
  I could also consider moving the code into the Order model and calling
  it from both controllers, but unfortunately the code also refers to
  $this-Session, which is not allowed in models.
 
  So I'm stuck. I can't move it to a component because a component can't
  call a model function, and I can't move it to a model because a model
  can't talk to the Session.
 
  Any ideas?
 
  Check out the new CakePHP Questions site http://cakeqs.org and help
 others
  with their CakePHP related questions.
 
  You received this message because you are subscribed to the Google Groups
  CakePHP group.
  To post to this group, send email to cake-php@googlegroups.com
  To unsubscribe from this group, send email to
  cake-php+unsubscr...@googlegroups.comcake-php%2bunsubscr...@googlegroups.comFor
   more options, visit this group at
  http://groups.google.com/group/cake-php?hl=en
 
  Check out the new CakePHP Questions site http://cakeqs.org and help
 others with their CakePHP related questions.
 
  You received this message because you are subscribed to the Google Groups
 CakePHP group.
  To post to this group, send email to cake-php@googlegroups.com
  To unsubscribe from this group, send email to
  cake-php+unsubscr...@googlegroups.comcake-php%2bunsubscr...@googlegroups.comFor
   more options, visit this group at
 http://groups.google.com/group/cake-php?hl=en

 Check out the new CakePHP Questions site http://cakeqs.org and help others
 with their CakePHP related questions.

 You received this message because you are subscribed to the Google Groups
 CakePHP group.
 To post to this group, send email to cake-php@googlegroups.com
 To unsubscribe from this group, send email to
 cake-php+unsubscr...@googlegroups.comcake-php%2bunsubscr...@googlegroups.comFor
  more options, visit this group at
 http://groups.google.com/group/cake-php?hl=en




-- 
Richard Claydon
Director, UGR Works

e: rich...@ugrworks.com
w: http://www.ugrworks.com
t: 0131 208 2398

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en