33describe ActiveAdmin ::ResourceController ::Decorators do
44 let ( :controller_class ) do
55 Class . new do
6- include ActiveAdmin ::ResourceController ::Decorators
7-
86 def self . name
97 "Test Controller using Decorators"
108 end
119
10+ def self . helper_method ( method )
11+ # STUB
12+ end
13+
14+ include ActiveAdmin ::ResourceController ::Decorators
15+
1216 public :apply_decorator , :apply_collection_decorator
1317 end
1418 end
1519
1620 let ( :controller ) { controller_class . new }
17- before { controller . stub ( active_admin_config : double ( decorator_class : decorator_class ) ) }
21+ let ( :active_admin_config ) { double ( decorator_class : decorator_class ) }
22+ before { controller . stub ( active_admin_config : active_admin_config ) }
23+ before { controller . stub ( action_name : action ) }
1824
1925
2026 describe '#apply_decorator' do
27+ let ( :action ) { 'show' }
2128 let ( :resource ) { Post . new }
2229 subject ( :applied ) { controller . apply_decorator ( resource ) }
2330
@@ -34,6 +41,7 @@ def self.name
3441
3542 describe '#apply_collection_decorator' do
3643 before { Post . create! }
44+ let ( :action ) { 'index' }
3745 let ( :collection ) { Post . scoped }
3846 subject ( :applied ) { controller . apply_collection_decorator ( collection ) }
3947
@@ -54,4 +62,25 @@ def self.name
5462 end
5563 end
5664 end
65+
66+ describe 'form actions' do
67+ let ( :action ) { 'edit' }
68+ let ( :resource ) { Post . new }
69+ let ( :form_presenter ) { double options : { decorate : decorate_form } }
70+ let ( :decorator_class ) { PostDecorator }
71+ before { active_admin_config . stub ( :get_page_presenter ) . with ( :form ) . and_return form_presenter }
72+
73+ subject ( :applied ) { controller . apply_decorator ( resource ) }
74+
75+ context 'when the form is not configured to decorate' do
76+ let ( :decorate_form ) { false }
77+ it { should be_kind_of ( Post ) }
78+ end
79+
80+ context 'when the form is configured to decorate' do
81+ let ( :decorate_form ) { true }
82+ it { should be_kind_of ( PostDecorator ) }
83+ end
84+
85+ end
5786end
0 commit comments