Skip to content

Commit

Permalink
Merge 61268be into ef94f7e
Browse files Browse the repository at this point in the history
  • Loading branch information
TheNeikos committed Jun 14, 2018
2 parents ef94f7e + 61268be commit 8f6d2ac
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/loaf/controller_extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def _normalize_name(name, instance)
case name
when NilClass
when Proc
name.call(instance)
instance.instance_exec instance, &name
else
name
end
Expand Down
8 changes: 8 additions & 0 deletions spec/integration/breadcrumb_trail_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@
end
end

it "shows breadcrumbs using instance variables" do
visit post_path(1)

within "#breadcrumbs" do
expect(page.html).to include('<a href="/posts/3735928559">3735928559</a>')
end
end

it 'is current when forced' do
visit new_post_path

Expand Down
11 changes: 11 additions & 0 deletions spec/rails_app/app/controllers/posts_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
class Post < Struct.new(:id); end

class PostsController < ApplicationController
before_action :load_post

breadcrumb ->(_) { @special_post.id.to_s },
->(_) { post_path(@special_post.id) }, only: [:show]

def index
breadcrumb 'all_posts', posts_path
end
Expand All @@ -17,4 +22,10 @@ def new
def create
render action: :new
end

private

def load_post
@special_post = ::Post.new(0xDEADBEEF)
end
end

0 comments on commit 8f6d2ac

Please sign in to comment.