Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Conditional URL

  • Loading branch information...
commit 7f880090d424f351636856cfe99cfd538cf20a1e 1 parent 18dce7e
@bogdan authored
Showing with 22 additions and 2 deletions.
  1. +3 −2 lib/datagrid/helper.rb
  2. +19 −0 spec/datagrid/helper_spec.rb
View
5 lib/datagrid/helper.rb
@@ -5,8 +5,9 @@ module Helper
def datagrid_format_value(report, column, asset)
value = column.value(asset, report)
- if column.options[:url]
- link_to(value, column.options[:url].call(asset))
+ url = column.options[:url] && column.options[:url].call(asset)
+ if url
+ link_to(value, url)
else
case column.format
when :url
View
19 spec/datagrid/helper_spec.rb
@@ -68,6 +68,25 @@
</tr>
HTML
end
+
+ it "should support urls" do
+ rp = test_report do
+ scope { Entry }
+ column(:name, :url => lambda {|model| model.name})
+ end
+ subject.datagrid_rows(rp, [entry], {}).should equal_to_dom(<<-HTML)
+<tr><td><a href="Star">Star</a></td></tr>
+HTML
+ end
+ it "should support conditional urls" do
+ rp = test_report do
+ scope { Entry }
+ column(:name, :url => lambda {false})
+ end
+ subject.datagrid_rows(rp, [entry], {}).should equal_to_dom(<<-HTML)
+<tr><td>Star</td></tr>
+HTML
+ end
end
describe ".datagrid_order_for" do
Please sign in to comment.
Something went wrong with that request. Please try again.