/
hidden_input_spec.rb
61 lines (46 loc) · 2.03 KB
/
hidden_input_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# coding: utf-8
require File.dirname(__FILE__) + '/../spec_helper'
describe 'hidden input' do
include FormtasticSpecHelper
before do
@output_buffer = ''
mock_everything
semantic_form_for(@new_post) do |builder|
concat(builder.input(:secret, :as => :hidden))
concat(builder.input(:author_id, :as => :hidden, :value => 99))
concat(builder.input(:published, :as => :hidden, :input_html => {:value => true}))
end
end
it_should_have_input_wrapper_with_class("hidden")
it_should_have_input_wrapper_with_id("post_secret_input")
it_should_not_have_a_label
it "should generate a input field" do
output_buffer.should have_tag("form li input#post_secret")
output_buffer.should have_tag("form li input#post_secret[@type=\"hidden\"]")
output_buffer.should have_tag("form li input#post_secret[@name=\"post[secret]\"]")
end
it "should pass any explicitly specified value - using :value" do
output_buffer.should have_tag("form li input#post_author_id[@type=\"hidden\"][@value=\"99\"]")
end
# Handle Formtastic :input_html options for consistency.
it "should pass any explicitly specified value - using :input_html options" do
output_buffer.should have_tag("form li input#post_published[@type=\"hidden\"][@value=\"true\"]")
end
it "should not render inline errors" do
@errors = mock('errors')
@errors.stub!(:[]).with(:secret).and_return(["foo", "bah"])
@new_post.stub!(:errors).and_return(@errors)
semantic_form_for(@new_post) do |builder|
concat(builder.input(:secret, :as => :hidden))
end
output_buffer.should_not have_tag("form li p.inline-errors")
output_buffer.should_not have_tag("form li ul.errors")
end
it "should not render inline hints" do
semantic_form_for(@new_post) do |builder|
concat(builder.input(:secret, :as => :hidden, :hint => "all your base are belong to use"))
end
output_buffer.should_not have_tag("form li p.inline-hints")
output_buffer.should_not have_tag("form li ul.hints")
end
end