Sent from my iPhone
On Jun 6, 2009, at 10:02 PM, Zach Dennis <zach.den...@gmail.com> wrote:
On Sat, Jun 6, 2009 at 6:34 PM, Charlie Bowman<charlesmbow...@gmail.com
> wrote:
I consider an if statement in the view layer a bug.
Perhaps we can consider it a possible code smell? It's not really a
bug unless it's producing incorrect or unexpected result in the
application's behaviour.
Absolutely true. Not really a bug but I find it helpful to treat it as
such.
I often need to
conditionally render a partial and a helper is a great way to
construct that
condition. Im currently stubing the call to render but I only like
stub
when absolutely necessary.
Helpers can be a great way to organize some of the view's
implementation, although my goal isn't to move every conditional out
of the view, it's to avoid having unnecessary logic in the view. When
I work outside-in I'm able to push logic that doesn't belong in the
view into a presenter or further down to a model with a good method
name. The logic that is left in the view is very minimal and
ultra-simple. I find it easy to spec and it doesn't impede the life or
maintainability of the view.
For example, if I need to display a piece of information for an admin,
but not a normal user then I have no problem doing the "if
current_user.admin?" check in a view:
<% if current_user.admin? %>
Foo bar baz
<% end
def foo_message
"foo bar baz" if current_user.admin?
end
That's how I handle that. If for no other reason but easier testing.
The check itself is already ultra-simple and it reads very well. What
value would we get from moving this to a helper method? It's currently
easy to open the view and know that "Foo bar baz" will only be
rendered for an admin. Does moving this to
"display_foo_bar_baz_for_admin" really give us anything?
There's a cost to creating a helper method for every one-off
condition. There's also a cost for turning every snippet of markup
that shows up in a simple view condition into a partial. The cost is
in the disconnect and separation that comes from doing separating
these pieces that go together as well as the organization nightmare of
a plethora of helper methods and partials.
I like extracting helpers when it provides more value than burden.
When it doesn't I will leave the small, ultra-simple logic in the
view,
Zach
Sent from my iPhone
On Jun 6, 2009, at 12:00 AM, Hans de Graaff <h...@degraaff.org>
wrote:
On Fri, 2009-06-05 at 22:40 -0500, David Chelimsky wrote:
There is no support for rendering in helper specs as of yet. Please
file a feature request if you think there should be. I have,
personally, never rendered from a helper. Anybody else?
We do this for example to render a set of unrelated items into a
single
timeline-based view. The helper sorts out the ordering and renders
each
object in it using a specific partial.
Hans
_______________________________________________
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users
_______________________________________________
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users
--
Zach Dennis
http://www.continuousthinking.com (personal)
http://www.mutuallyhuman.com (hire me)
http://ideafoundry.info/behavior-driven-development (first rate BDD
training)
@zachdennis (twitter)
_______________________________________________
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users
_______________________________________________
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users