|
1 | 1 | require 'spec_helper'
|
2 | 2 |
|
3 | 3 | describe ActiveAdmin::ViewHelpers::FormHelper do
|
| 4 | + |
| 5 | + describe '.active_admin_form_for' do |
| 6 | + let(:view) { action_view } |
| 7 | + let(:resource) { stub('resource') } |
| 8 | + let(:default_options) { { builder: ActiveAdmin::FormBuilder } } |
| 9 | + |
| 10 | + it 'calls semantic_form_for with the ActiveAdmin form builder' do |
| 11 | + view.should_receive(:semantic_form_for).with(resource, builder: ActiveAdmin::FormBuilder) |
| 12 | + view.active_admin_form_for(resource) |
| 13 | + end |
| 14 | + |
| 15 | + it 'allows the form builder to be customized' do |
| 16 | + # We can't use a stub here because options gets marshalled, and a new |
| 17 | + # instance built. Any constant will work. |
| 18 | + custom_builder = Object |
| 19 | + view.should_receive(:semantic_form_for).with(resource, builder: custom_builder) |
| 20 | + view.active_admin_form_for(resource, builder: custom_builder) |
| 21 | + end |
| 22 | + |
| 23 | + context 'with a decorated resource' do |
| 24 | + let(:decorated) { stub('decorated_resource', model: resource) } |
| 25 | + |
| 26 | + it 'can disable automatic decoration' do |
| 27 | + view.should_receive(:semantic_form_for).with(resource, default_options.merge(decorate: false)) |
| 28 | + view.active_admin_form_for(decorated, decorate: false) |
| 29 | + end |
| 30 | + |
| 31 | + it 'can enable automatic decoration' do |
| 32 | + view.should_receive(:semantic_form_for).with(decorated, default_options.merge(decorate: true)) |
| 33 | + view.active_admin_form_for(decorated, decorate: true) |
| 34 | + end |
| 35 | + end |
| 36 | + end |
| 37 | + |
4 | 38 | describe ".hidden_field_tags_for" do
|
5 | 39 | let(:view) { action_view }
|
6 | 40 |
|
7 | 41 | it "should render hidden field tags for params" do
|
8 |
| - view.hidden_field_tags_for(:scope => "All", :filter => "None").should == |
| 42 | + view.hidden_field_tags_for(:scope => "All", :filter => "None").should == |
9 | 43 | %{<input id="hidden_active_admin_scope" name="scope" type="hidden" value="All" />\n<input id="hidden_active_admin_filter" name="filter" type="hidden" value="None" />}
|
10 | 44 | end
|
11 | 45 |
|
|
14 | 48 | end
|
15 | 49 |
|
16 | 50 | it "should filter out the field passed via the option :except" do
|
17 |
| - view.hidden_field_tags_for({:scope => "All", :filter => "None"}, :except => :filter).should == |
| 51 | + view.hidden_field_tags_for({:scope => "All", :filter => "None"}, :except => :filter).should == |
18 | 52 | %{<input id="hidden_active_admin_scope" name="scope" type="hidden" value="All" />}
|
19 | 53 | end
|
20 | 54 | end
|
|
0 commit comments