1
0
Fork 0
mirror of https://github.com/drapergem/draper synced 2023-03-27 23:21:17 -04:00

Add features around url helpers

This commit is contained in:
Steve Klabnik 2012-10-24 07:24:03 -04:00
parent f197ced4ca
commit bfc33537b9
3 changed files with 50 additions and 26 deletions

View file

@ -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 file

@ -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 file

@ -9,32 +9,19 @@ class PostDecorator < Draper::Decorator
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)
# 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
# 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 path_helper_with_model
{:post_path => h.post_path(self.model)}
end
def path_helper_with_model_id
{:post_path => h.post_path(:id => self.model.id)}
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