Skip to content
This repository has been archived by the owner on Jun 26, 2023. It is now read-only.

Commit

Permalink
Added support for an unless condition.
Browse files Browse the repository at this point in the history
  • Loading branch information
roidrage committed Jun 9, 2009
1 parent 1d66ab0 commit 48722ac
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
9 changes: 7 additions & 2 deletions lib/breadcrumb.rb
Expand Up @@ -4,8 +4,13 @@ class Breadcrumb
include Singleton
Trail = Struct.new(:controller, :action, :trail, :options) do
def condition_met?(obj)
condition = options[:if]
condition.nil? or obj.send(condition)
if options[:if]
obj.send(options[:if])
elsif options[:unless]
!obj.send(options[:unless])
else
true
end
end
end

Expand Down
26 changes: 24 additions & 2 deletions spec/breadcrumbs_helper_spec.rb
Expand Up @@ -176,7 +176,7 @@ def its_true!
crumbs.should == %Q{<a href="http://test.host/search/new">Search Results ()</a>}
end

it "should not consider a trail when it has a condition and it's not met" do
it "should not consider a trail when it has an :if condition and it's not met" do
Breadcrumb.configure do
crumb :search_results, 'Search Results', :current
trail :search, [:create, :new], [:search_results], :if => :is_it_false?
Expand All @@ -187,7 +187,7 @@ def its_true!
crumbs.should == ""
end

it "should consider a trail when it has a condition and it's met" do
it "should consider a trail when it has an :if condition and it's met" do
Breadcrumb.configure do
crumb :search_results, 'Search Results', :current
trail :search, [:create, :new], [:search_results], :if => :its_true!
Expand All @@ -197,6 +197,28 @@ def its_true!
params[:action] = 'new'
crumbs.should == %Q{<a href="http://test.host/search/new">Search Results</a>}
end

it "should not consider a trail when it has an :unless condition and it's not met" do
Breadcrumb.configure do
crumb :search_results, 'Search Results', :current
trail :search, [:create, :new], [:search_results], :unless => :its_true!
end

params[:controller] = 'search'
params[:action] = 'new'
crumbs.should == ""
end

it "should consider a trail when it has an :unless condition and it's met" do
Breadcrumb.configure do
crumb :search_results, 'Search Results', :current
trail :search, [:create, :new], [:search_results], :unless => :is_it_false?
end

params[:controller] = 'search'
params[:action] = 'new'
crumbs.should == %Q{<a href="http://test.host/search/new">Search Results</a>}
end

describe "when fetching parameters" do
it "should support nested parameter attributes" do
Expand Down

0 comments on commit 48722ac

Please sign in to comment.