Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add features around url helpers

  • Loading branch information...
commit bfc33537b92d7524643dae67575458c01c4f4fca 1 parent f197ced
@steveklabnik steveklabnik authored
View
17 features/route_helpers.feature
@@ -0,0 +1,17 @@
+Feature: Route helpers should work in decorators
+
+ Background:
+ Given a post exists
+
+ Scenario:
+ Then a _path helper with the underlying model works
+
+ Scenario:
+ Then a _path helper with the underlying model's id works
+
+ Scenario:
+ Then a _url helper with the underlying model works
+
+ Scenario:
+ Then a _url helper with the underlying model's id works
+
View
20 features/step_definitions/route_steps.rb
@@ -0,0 +1,20 @@
+Given /^a post exists$/ do
+ @post = Post.create
+ @decorator = PostDecorator.decorate(@post)
+end
+
+Then /^a _path helper with the underlying model works$/ do
+ @decorator.path_helper_with_model.should == {:post_path => "/posts/#{@post.id}"}
+end
+
+Then /^a _path helper with the underlying model's id works$/ do
+ @decorator.path_helper_with_model_id.should == {:post_path => "/posts/#{@post.id}"}
+end
+
+Then /^a _url helper with the underlying model works$/ do
+ @decorator.url_helper_with_model.should == {:post_url => "http://www.example.com/posts/#{@post.id}"}
+end
+
+Then /^a _url helper with the underlying model's id works$/ do
+ @decorator.url_helper_with_model_id.should == {:post_url => "http://www.example.com/posts/#{@post.id}"}
+end
View
39 spec/dummy/app/decorators/post_decorator.rb
@@ -9,32 +9,19 @@ def posted_date
end
end
- # Accessing Helpers
- # You can access any helper via a proxy
- #
- # Normal Usage: helpers.number_to_currency(2)
- # Abbreviated : h.number_to_currency(2)
- #
- # Or, optionally enable "lazy helpers" by including this module:
- # include Draper::LazyHelpers
- # Then use the helpers with no proxy:
- # number_to_currency(2)
+ def path_helper_with_model
+ {:post_path => h.post_path(self.model)}
+ end
- # Defining an Interface
- # Control access to the wrapped subject's methods using one of the following:
- #
- # To allow only the listed methods (whitelist):
- # allows :method1, :method2
- #
- # To allow everything except the listed methods (blacklist):
- # denies :method1, :method2
+ def path_helper_with_model_id
+ {:post_path => h.post_path(:id => self.model.id)}
+ end
- # Presentation Methods
- # Define your own instance methods, even overriding accessors
- # generated by ActiveRecord:
- #
- # def created_at
- # h.content_tag :span, attributes["created_at"].strftime("%a %m/%d/%y"),
- # :class => 'timestamp'
- # end
+ def url_helper_with_model
+ {:post_url => h.post_url(self.model)}
+ end
+
+ def url_helper_with_model_id
+ {:post_url => h.post_url(:id => self.model.id)}
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.