9. CUCARUBA! MATT YOHO
class WidgetController < AppController
before_filter :find_widget, :only =>
[:show, :edit, :update]
def find_widget
@widget ||= Widget.find(params[:id])
end
end
10. CUCARUBA! MATT YOHO
class WidgetController < AppController
assume :widget
end
11. CUCARUBA! MATT YOHO
class WidgetController < AppController
def user_accout
current_user.account
end
hide_action :user_account
helper_method :user_account
end
12. CUCARUBA! MATT YOHO
class WidgetController < AppController
assume(:account) do
current_user.account
end
end
13. CUCARUBA! MATT YOHO
Specs go a long way, but...
14. CUCARUBA! MATT YOHO
Specs go a long way, but...
Rails dependencies, etc.
18. CUCARUBA! MATT YOHO
~/projects/app/tmp/aruba
templates ./tmp/aruba
rake
task
19. CUCARUBA! MATT YOHO
Feature: Rails Controllers Can Make Assumptions
Scenario: controller invokes assume
Given a file named "app/controllers/widgets_controller.rb" with:
"""
class WidgetsController < ApplicationController
assume(:widget) { Widget.find(params[:id]) }
end
"""
And a file named "app/views/widgets/show.html.erb" with:
"""
<blink><%= widget.name %></blink>
"""
And a file named "features/widget_is_viewed_by_visitor.feature" with:
"""
Feature: Widget is viewed by visitor
Scenario: success
Given a widget named "foobar"
When I view the widget
Then I should see "foobar"
"""
When I run "cucumber features/widget_is_viewed_by_visitor.feature"
Then I should see:
"""
1 scenario (1 passed)
3 steps
"""
20. CUCARUBA! MATT YOHO
Feature: Foo Does Something
Scenario: foo works
Given a file named "foo.feature" with:
"""
Feature: Widget is viewed by visitor
Scenario: success
Given a foo named "bar"
When I view the foo
Then I should see "bar"
"""
When I run "cucumber foo.feature"
Then I should see:
"""
1 scenario (1 passed)
1 step
"""
21. CUCARUBA! MATT YOHO
A little slow, but totally badass.