Skip to content

Commit

Permalink
Route helpers (*_path, etc.) now work
Browse files Browse the repository at this point in the history
  • Loading branch information
docwhat committed Sep 29, 2011
1 parent 36489de commit 1ed14a1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lib/rspec/rails/example/widget_example_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,16 @@ module InstanceMethods
def rendered
@last_invoke
end


def method_missing(method, *args, &block)
# Send the route helpers to the application router.
if @routes && @routes.named_routes.helpers.include?(method)
@controller.send(method, *args, &block)
else
super
end
end

attr_reader :controller, :routes
include ::Apotomo::WidgetShortcuts
end
Expand Down
7 changes: 7 additions & 0 deletions spec/rspec-apotomo/widget_example_group_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ def apotomo_event_path(*args)
it "should render a view" do
render_widget(:dummy).text.should == "Hey from DummyWidget! I should be mixed in properly from @routes\n"
end

it "should support _path helpers from the controller" do
# We have to stub include so that things determine the route exists.
Rails.application.routes.named_routes.helpers.stub(:include?).and_return(:true)
@controller.should_receive(:test_path).at_least(:once)
test_path
end
end

context "- ::has_widget" do
Expand Down

2 comments on commit 1ed14a1

@apotonick
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just include the @routes.named_routes.helpers module into the test instance?

@docwhat
Copy link
Collaborator Author

@docwhat docwhat commented on 1ed14a1 Oct 4, 2011

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rails seems to only use the pattern I'm using. In addition, I tried several ways of including it, but it didn't work.

Please sign in to comment.