-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
James McKinney
committed
Jul 4, 2012
1 parent
875494d
commit a4235d5
Showing
1 changed file
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
require 'spec_helper' | ||
|
||
describe ActiveAdmin::ResourceController::Sidebars do | ||
let(:controller){ Admin::PostsController } | ||
|
||
context 'without before_filter' do | ||
before do | ||
ActiveAdmin.register Post | ||
end | ||
|
||
subject { find_before_filter controller, :skip_sidebar! } | ||
|
||
it { should set_skip_sidebar_to nil } | ||
end | ||
|
||
describe '#skip_sidebar!' do | ||
before do | ||
ActiveAdmin.register Post do | ||
before_filter :skip_sidebar! | ||
end | ||
end | ||
|
||
subject { find_before_filter controller, :skip_sidebar! } | ||
|
||
it { should set_skip_sidebar_to true } | ||
end | ||
|
||
def find_before_filter(controller, filter) | ||
#raise controller._process_action_callbacks.map(&:filter).inspect | ||
controller._process_action_callbacks.detect { |f| f.raw_filter == filter.to_sym } | ||
end | ||
|
||
RSpec::Matchers.define :set_skip_sidebar_to do |expected| | ||
match do |filter| | ||
klass = filter && filter.klass || controller | ||
object = klass.new | ||
object.send filter.raw_filter if filter | ||
@actual = object.instance_variable_get(:@skip_sidebar) | ||
@actual == expected | ||
end | ||
|
||
failure_message_for_should do |filter| | ||
message = "expected before_filter to set @skip_sidebar to '#{expected}', but was '#{@actual}'" | ||
end | ||
end | ||
end |