lrd_view_tools 0.1.1 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +28 -18
- data/lib/app/helpers/lrd_form_helper.rb +32 -16
- data/spec/labelled_input_spec.rb +242 -9
- data/spec/spec_helper.rb +4 -0
- data/spec/unlabeled_submit_spec.rb +44 -0
- metadata +6 -8
- data/spec/helpers/lrd_view_helper_spec.rb +0 -43
- data/spec/spec_helper_naked.rb +0 -11
- data/spec/spec_helper_plugin.rb +0 -10
data/README.rdoc
CHANGED
@@ -1,48 +1,58 @@
|
|
1
|
-
=LRD
|
1
|
+
=LRD::ViewTools
|
2
2
|
|
3
3
|
Standard view helpers and stylesheet defaults for Logical Reality Design
|
4
4
|
Projects.
|
5
5
|
|
6
6
|
== Installing
|
7
7
|
|
8
|
-
Add to Gemfile:
|
8
|
+
Add to Gemfile:
|
9
9
|
gem 'lrd_view_tools'
|
10
10
|
|
11
11
|
and run 'bundle install'.
|
12
12
|
|
13
|
-
Also, 'rails generate lrd_view_tools:install' will copy in default images,
|
14
|
-
stylesheets, and helper partials to the rails app.
|
15
|
-
|
16
13
|
== Simple labeled inputs for forms:
|
17
14
|
|
18
|
-
labeled_input(
|
15
|
+
form.labeled_input(field)
|
19
16
|
|
20
17
|
Produces a <label> <input> pair for a text field in a standard form helper.
|
21
|
-
The
|
22
|
-
float to the left of the input
|
18
|
+
The default LRD stylesheet (forms.sass) in all LRD projects will format the
|
19
|
+
label as an 8-em wide float to the left of the input (or may have been modified
|
20
|
+
on a per-project basis).
|
23
21
|
|
24
22
|
Usage example:
|
25
|
-
form_for(@user) do |
|
26
|
-
= labeled_input(
|
27
|
-
= labeled_input(
|
28
|
-
= labeled_input(
|
23
|
+
form_for(@user) do |f|
|
24
|
+
= f.labeled_input(:name)
|
25
|
+
= f.labeled_input(:email)
|
26
|
+
= f.labeled_input(:country) do
|
27
|
+
= f.select(:country, [ 'option 1', 'option 2'])
|
28
|
+
= f.unlabeled_submit
|
29
29
|
end
|
30
30
|
|
31
31
|
Options:
|
32
32
|
The output defaults to <input type="text" name="#{field}"> for the
|
33
33
|
but can be overridden in a number of ways:
|
34
34
|
|
35
|
-
#Override the
|
36
|
-
labeled_input(
|
35
|
+
#Override the input element by passing a block:
|
36
|
+
f.labeled_input(:boolean_field) do
|
37
|
+
f.checkbox(:boolean_field))
|
38
|
+
|
39
|
+
#Alter label text:
|
40
|
+
f.labeled_input(:fieldname, :text => "Other Text")
|
37
41
|
|
38
42
|
#Force a blank label:
|
39
|
-
labeled_input(
|
43
|
+
f.labeled_input(:fieldname, :text => '' )
|
40
44
|
|
41
|
-
#
|
42
|
-
labeled_input(
|
45
|
+
#Set to required - appends class 'required' to both the div and the input:
|
46
|
+
f.labeled_input(:fieldname, :required => 'true' )
|
43
47
|
|
44
48
|
#Add a comment after the input:
|
45
|
-
labeled_input(
|
49
|
+
f.labeled_input(:password_confirmation, :comment => "Re-enter password")
|
50
|
+
|
51
|
+
#Change the input type to a textarea:
|
52
|
+
f.labeled_input(:description, :input_type => :text_area) # or :textarea, both work
|
53
|
+
|
54
|
+
#Create a telephone input:
|
55
|
+
f.labeled_input(:description, :input_type => :tel) # or :telephone, both work
|
46
56
|
|
47
57
|
== Pass a block to partial:
|
48
58
|
|
@@ -3,7 +3,6 @@ module LRD
|
|
3
3
|
module FormHelper
|
4
4
|
|
5
5
|
def self.included(arg)
|
6
|
-
p "LRD::FormHelper included in #{arg}"
|
7
6
|
ActionView::Helpers::FormBuilder.send(:include, LRD::FormBuilder)
|
8
7
|
end
|
9
8
|
|
@@ -11,11 +10,11 @@ module LRD
|
|
11
10
|
# block, pre-styled in LRD style.
|
12
11
|
#
|
13
12
|
# pass :label => false to suppress the label text. (A label tag is still emitted.)
|
14
|
-
# pass :required => true to dispay as a required field
|
13
|
+
# pass :required => true to dispay as a required field (class required set on both the div and the input)
|
15
14
|
# pass :text => "foo" to override the label text
|
16
|
-
# pass :
|
15
|
+
# pass :divclass => 'foo' to add 'foo' to the CSS class of the <div>
|
17
16
|
# pass :comment => "text" to append a span.comment with text after the input
|
18
|
-
# pass :
|
17
|
+
# pass :type => 'password' } to use a password_field instead of a text_field
|
19
18
|
# (also supported: text, passsword, hidden, file, text_area, search, telephone, url
|
20
19
|
# email, range, submit)
|
21
20
|
#
|
@@ -27,23 +26,24 @@ module LRD
|
|
27
26
|
# # => <input type='text' name='user[login]' id='user_login' value="#{@user.login}" />
|
28
27
|
# # => </div>
|
29
28
|
def labeled_input(object_name, method, options = {}, &block)
|
30
|
-
divclass =
|
29
|
+
divclass = options.delete(:divclass)
|
30
|
+
div_final_class = labeled_input_div_class(options, divclass)
|
31
31
|
comment = comment_for_labeled_input(options.delete(:comment))
|
32
|
+
label_text = options.delete(:text)
|
32
33
|
if block_given?
|
33
34
|
input = capture(&block)
|
34
35
|
else
|
35
36
|
input = input_for_labeled_input(object_name, method, options)
|
36
37
|
end
|
37
38
|
|
38
|
-
|
39
39
|
if object_name.blank? or method.blank?
|
40
40
|
label = "<label> </label>".html_safe
|
41
|
-
elsif
|
42
|
-
label = label(object_name, method,
|
41
|
+
elsif label_text =
|
42
|
+
label = label(object_name, method, label_text, options)
|
43
43
|
else
|
44
44
|
label = label(object_name, method, options)
|
45
45
|
end
|
46
|
-
content_tag(:div, (label + input + comment), { :class =>
|
46
|
+
content_tag(:div, (label + input + comment), { :class => div_final_class })
|
47
47
|
end
|
48
48
|
|
49
49
|
def comment_for_labeled_input(text)
|
@@ -55,15 +55,20 @@ module LRD
|
|
55
55
|
end
|
56
56
|
|
57
57
|
|
58
|
-
def
|
58
|
+
def labeled_input_div_class(options, divclass = nil)
|
59
59
|
cssclass = "labeled_input"
|
60
60
|
cssclass += " required" if options[:required]
|
61
|
-
cssclass += " #{
|
61
|
+
cssclass += " #{divclass}" if divclass
|
62
62
|
cssclass
|
63
63
|
end
|
64
64
|
|
65
65
|
def input_for_labeled_input(object_name, method, options)
|
66
|
-
|
66
|
+
if required = options.delete(:required)
|
67
|
+
options[:class] = (options[:class] or '') + " required"
|
68
|
+
end
|
69
|
+
submit_text = options.delete(:submit_text)
|
70
|
+
|
71
|
+
case input_type = options.delete(:type).to_s
|
67
72
|
when "text", ""
|
68
73
|
input = text_field( object_name, method, options)
|
69
74
|
when "password"
|
@@ -72,11 +77,11 @@ module LRD
|
|
72
77
|
input = hidden_field( object_name, method, options)
|
73
78
|
when "file"
|
74
79
|
input = file_field( object_name, method, options)
|
75
|
-
when "text_area"
|
80
|
+
when "text_area", "textarea"
|
76
81
|
input = text_area( object_name, method, options)
|
77
82
|
when "search"
|
78
83
|
input = search_field( object_name, method, options)
|
79
|
-
when "telephone"
|
84
|
+
when "telephone", 'tel'
|
80
85
|
input = telephone_field(object_name, method, options)
|
81
86
|
when "url"
|
82
87
|
input = url_field( object_name, method, options)
|
@@ -87,20 +92,31 @@ module LRD
|
|
87
92
|
when "range"
|
88
93
|
input = range_field( object_name, method, options)
|
89
94
|
when "submit"
|
90
|
-
input = submit_tag(
|
95
|
+
input = submit_tag( submit_text, options)
|
91
96
|
else
|
92
97
|
raise "labeled_input input_type #{input_type} is not a valid type!"
|
93
98
|
end
|
94
99
|
input
|
95
100
|
end
|
96
101
|
|
102
|
+
# Shortcut for a version of labeled_input that suppresses the
|
103
|
+
# label text. Just calls labeled_input with :label => false.
|
97
104
|
def unlabeled_input(object_name, method, options)
|
98
105
|
labeled_input(object_name, method, options.merge!(:label => false))
|
99
106
|
end
|
100
107
|
|
101
108
|
# creates a submit button that lines up with a bunch of labeled_input fields
|
109
|
+
# Pass a single argument to override the default text of the submit button.
|
110
|
+
#
|
111
|
+
# ==== Examples (in HAML):
|
112
|
+
# - form_for(@user) do
|
113
|
+
# = f.unlabeled_submit("Click Me")
|
114
|
+
# # => <div class='labeled_input'>
|
115
|
+
# # => <label> </label>
|
116
|
+
# # => <input type='submit' name='[]' value='Click Me' />
|
117
|
+
# # => </div>
|
102
118
|
def unlabeled_submit(text = nil)
|
103
|
-
labeled_input(nil, nil, :
|
119
|
+
labeled_input(nil, nil, :type => :submit, :submit_text => text)
|
104
120
|
end
|
105
121
|
end
|
106
122
|
end
|
data/spec/labelled_input_spec.rb
CHANGED
@@ -10,17 +10,250 @@ describe "form_for().labelled_input", :type => :view do
|
|
10
10
|
|
11
11
|
let :user do
|
12
12
|
view.stub!(:user_path => "#")
|
13
|
-
mock_model("User", :login => "Username")
|
13
|
+
mock_model("User", :login => "Username", :bio => "This is my story", :phone => "626-111-2222")
|
14
14
|
end
|
15
15
|
|
16
|
-
it "should render a labeled_input successfully" do
|
17
|
-
render(:inline => <<-EOTEMPLATE, :locals => { :user => user })
|
18
|
-
<%= form_for(user) do |f| %>
|
19
|
-
<%= f.labeled_input(:login) %>
|
20
|
-
<%- end -%>
|
21
|
-
EOTEMPLATE
|
22
|
-
p "Rendered is: ", rendered
|
23
|
-
rendered.should_not be_nil
|
24
16
|
|
17
|
+
describe "with default type" do
|
18
|
+
let :template do
|
19
|
+
<<-EOTEMPLATE
|
20
|
+
<%= form_for(user) do |f| %>
|
21
|
+
<%= f.labeled_input(:login) %>
|
22
|
+
<%- end -%>
|
23
|
+
EOTEMPLATE
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should render successfully" do
|
27
|
+
render(:inline => template, :locals => { :user => user })
|
28
|
+
rendered.should_not be_nil
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should have a label" do
|
32
|
+
render(:inline => template, :locals => { :user => user })
|
33
|
+
rendered.should have_xpath('//label')
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should have a text input" do
|
37
|
+
render(:inline => template, :locals => { :user => user })
|
38
|
+
rendered.should have_xpath('//input')
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should have a div with class labeled_input" do
|
42
|
+
render(:inline => template, :locals => { :user => user })
|
43
|
+
rendered.should have_xpath('//div[@class="labeled_input"]')
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe "with block passed" do
|
48
|
+
let :template do
|
49
|
+
<<-EOTEMPLATE
|
50
|
+
<%= form_for(user) do |f| %>
|
51
|
+
<%= f.labeled_input(:login) do %>
|
52
|
+
<select name='foo'>
|
53
|
+
<option value='bar'>Bar</option>
|
54
|
+
<option value='baz'>Baz</option>
|
55
|
+
<option value='bletch'>Bletch</option>
|
56
|
+
</select>
|
57
|
+
<%- end -%>
|
58
|
+
<%- end -%>
|
59
|
+
EOTEMPLATE
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should not generate the default input" do
|
63
|
+
render(:inline => template, :locals => { :user => user })
|
64
|
+
rendered.should_not have_xpath("//div[@class='labeled_input']/input")
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should insert the block's elements" do
|
68
|
+
render(:inline => template, :locals => { :user => user })
|
69
|
+
rendered.should have_xpath(
|
70
|
+
"//div[@class='labeled_input']/select[@name='foo'][count(option)=3]"
|
71
|
+
)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
describe "with :required => true" do
|
76
|
+
let :template do
|
77
|
+
<<-EOTEMPLATE
|
78
|
+
<%= form_for(user) do |f| %>
|
79
|
+
<%= f.labeled_input(:login, :required => true) %>
|
80
|
+
<%- end -%>
|
81
|
+
EOTEMPLATE
|
82
|
+
end
|
83
|
+
|
84
|
+
it "should set the div class to required" do
|
85
|
+
render(:inline => template, :locals => { :user => user })
|
86
|
+
rendered.should have_xpath("//div[contains(@class,'required')][contains(@class, 'labeled_input')]")
|
87
|
+
end
|
88
|
+
|
89
|
+
it "should set the input class to required" do
|
90
|
+
render(:inline => template, :locals => { :user => user })
|
91
|
+
rendered.should have_xpath("//div[contains(@class,'required')]/input[contains(@class, 'required')]")
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
95
|
+
|
96
|
+
|
97
|
+
describe "with label text specified" do
|
98
|
+
let :template do
|
99
|
+
<<-EOTEMPLATE
|
100
|
+
<%= form_for(user) do |f| %>
|
101
|
+
<%= f.labeled_input(:login, :text => 'Label text') %>
|
102
|
+
<%- end -%>
|
103
|
+
EOTEMPLATE
|
104
|
+
end
|
105
|
+
|
106
|
+
it "should set the content of the label" do
|
107
|
+
render(:inline => template, :locals => { :user => user })
|
108
|
+
rendered.should have_xpath("//label[.='Label text']")
|
109
|
+
end
|
110
|
+
|
111
|
+
it "should not apply a 'text' attribute to the other elements" do
|
112
|
+
render(:inline => template, :locals => { :user => user })
|
113
|
+
rendered.should_not have_xpath("//label[@text]")
|
114
|
+
rendered.should_not have_xpath("//input[@text]")
|
115
|
+
rendered.should_not have_xpath("//div[@text]")
|
116
|
+
end
|
117
|
+
|
118
|
+
it "should not apply a class 'text' to the other elements" do
|
119
|
+
render(:inline => template, :locals => { :user => user })
|
120
|
+
rendered.should_not have_xpath("//label[contains(@class, 'text')]")
|
121
|
+
rendered.should_not have_xpath("//input[contains(@class, 'text')]")
|
122
|
+
rendered.should_not have_xpath("//div[contains(@class, 'text')]")
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
describe "with a comment specified" do
|
127
|
+
let :template do
|
128
|
+
<<-EOTEMPLATE
|
129
|
+
<%= form_for(user) do |f| %>
|
130
|
+
<%= f.labeled_input(:login, :comment => 'Reminder text') %>
|
131
|
+
<%- end -%>
|
132
|
+
EOTEMPLATE
|
133
|
+
end
|
134
|
+
|
135
|
+
it "should add a span for the comment" do
|
136
|
+
render(:inline => template, :locals => { :user => user })
|
137
|
+
rendered.should have_xpath("//div/span[contains(@class, 'comment')][.='Reminder text']")
|
138
|
+
end
|
139
|
+
|
140
|
+
it "should not apply a comment attribute to the other elements" do
|
141
|
+
render(:inline => template, :locals => { :user => user })
|
142
|
+
rendered.should_not have_xpath("//label[@comment]")
|
143
|
+
rendered.should_not have_xpath("//input[@comment]")
|
144
|
+
rendered.should_not have_xpath("//div[@comment]")
|
145
|
+
end
|
146
|
+
|
147
|
+
it "should not apply a class 'comment' to the other elements" do
|
148
|
+
render(:inline => template, :locals => { :user => user })
|
149
|
+
rendered.should_not have_xpath("//label[contains(@class, 'comment')]")
|
150
|
+
rendered.should_not have_xpath("//input[contains(@class, 'comment')]")
|
151
|
+
rendered.should_not have_xpath("//div[contains(@class, 'comment')]")
|
152
|
+
end
|
25
153
|
end
|
154
|
+
|
155
|
+
describe "with a divclass specified" do
|
156
|
+
let :template do
|
157
|
+
<<-EOTEMPLATE
|
158
|
+
<%= form_for(user) do |f| %>
|
159
|
+
<%= f.labeled_input(:login, :divclass => 'foobar') %>
|
160
|
+
<%- end -%>
|
161
|
+
EOTEMPLATE
|
162
|
+
end
|
163
|
+
|
164
|
+
it "should apply the appropriate class to the div" do
|
165
|
+
render(:inline => template, :locals => { :user => user })
|
166
|
+
rendered.should have_xpath("//div[contains(@class, 'foobar')]")
|
167
|
+
end
|
168
|
+
|
169
|
+
it "should not apply the divclass to the input or label" do
|
170
|
+
render(:inline => template, :locals => { :user => user })
|
171
|
+
rendered.should_not have_xpath("//label[contains(@class, 'foobar')]")
|
172
|
+
rendered.should_not have_xpath("//input[contains(@class, 'foobar')]")
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
describe "with type :submit" do
|
177
|
+
let :template do
|
178
|
+
<<-EOTEMPLATE
|
179
|
+
<%= form_for(user) do |f| %>
|
180
|
+
<%= f.labeled_input(:bio, :type => :submit) %>
|
181
|
+
<%- end -%>
|
182
|
+
EOTEMPLATE
|
183
|
+
end
|
184
|
+
|
185
|
+
it "should have a submit button" do
|
186
|
+
render(:inline => template, :locals => { :user => user })
|
187
|
+
rendered.should have_xpath("//div[@class='labeled_input']/input[@type='submit']")
|
188
|
+
end
|
189
|
+
|
190
|
+
describe "and submit text" do
|
191
|
+
let :template do
|
192
|
+
<<-EOTEMPLATE
|
193
|
+
<%= form_for(user) do |f| %>
|
194
|
+
<%= f.labeled_input(:bio, :type => :submit, :submit_text => 'Click Me') %>
|
195
|
+
<%- end -%>
|
196
|
+
EOTEMPLATE
|
197
|
+
end
|
198
|
+
|
199
|
+
it "should have a submit button with text" do
|
200
|
+
render(:inline => template, :locals => { :user => user })
|
201
|
+
rendered.should have_xpath("//div[@class='labeled_input']/input[@type='submit'][@value='Click Me']")
|
202
|
+
end
|
203
|
+
|
204
|
+
it "should not put a 'submit_text' attribute in the other tags" do
|
205
|
+
render(:inline => template, :locals => { :user => user })
|
206
|
+
rendered.should_not have_xpath("//*[@submit_text]")
|
207
|
+
end
|
208
|
+
end
|
209
|
+
end
|
210
|
+
|
211
|
+
|
212
|
+
describe "with type :text_area" do
|
213
|
+
let :template do
|
214
|
+
<<-EOTEMPLATE
|
215
|
+
<%= form_for(user) do |f| %>
|
216
|
+
<%= f.labeled_input(:bio, :type => 'text_area') %>
|
217
|
+
<%- end -%>
|
218
|
+
EOTEMPLATE
|
219
|
+
end
|
220
|
+
|
221
|
+
it "should have a text area" do
|
222
|
+
render(:inline => template, :locals => { :user => user })
|
223
|
+
rendered.should have_xpath('//textarea')
|
224
|
+
end
|
225
|
+
end
|
226
|
+
|
227
|
+
|
228
|
+
describe "with type :textarea" do
|
229
|
+
let :template do
|
230
|
+
<<-EOTEMPLATE
|
231
|
+
<%= form_for(user) do |f| %>
|
232
|
+
<%= f.labeled_input(:bio, :type => :textarea) %>
|
233
|
+
<%- end -%>
|
234
|
+
EOTEMPLATE
|
235
|
+
end
|
236
|
+
|
237
|
+
it "should have a text area" do
|
238
|
+
render(:inline => template, :locals => { :user => user })
|
239
|
+
rendered.should have_xpath('//textarea')
|
240
|
+
end
|
241
|
+
end
|
242
|
+
|
243
|
+
describe "with type :telephane" do
|
244
|
+
let :template do
|
245
|
+
<<-EOTEMPLATE
|
246
|
+
<%= form_for(user) do |f| %>
|
247
|
+
<%= f.labeled_input(:phone, :type => :telephone) %>
|
248
|
+
<%- end -%>
|
249
|
+
EOTEMPLATE
|
250
|
+
end
|
251
|
+
it "should have a telephone input" do
|
252
|
+
render(:inline => template, :locals => { :user=> user })
|
253
|
+
rendered.should have_xpath('//input[@type="tel"]')
|
254
|
+
end
|
255
|
+
|
256
|
+
end
|
257
|
+
|
258
|
+
|
26
259
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -7,6 +7,9 @@ require 'rspec/rails/matchers/render_template'
|
|
7
7
|
require 'rspec/rails/browser_simulators'
|
8
8
|
require 'rspec/rails/example/view_example_group'
|
9
9
|
require 'rspec/rails/mocks'
|
10
|
+
require 'webrat'
|
11
|
+
require "webrat/integrations/rspec-rails"
|
12
|
+
require 'webrat/core/matchers'
|
10
13
|
|
11
14
|
plugin_spec_dir = File.dirname(__FILE__)
|
12
15
|
#ActiveRecord::Base.logger = Logger.new(plugin_spec_dir + "/debug.log")
|
@@ -16,3 +19,4 @@ RSpec::configure do |c|
|
|
16
19
|
:file_path => 'spec/views'
|
17
20
|
}
|
18
21
|
end
|
22
|
+
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'spec/spec_helper'
|
2
|
+
require File.join(File.dirname(__FILE__), '..', 'lib','app', 'helpers', 'lrd_form_helper')
|
3
|
+
ActionView::Helpers::FormHelper.send(:include, LRD::FormHelper)
|
4
|
+
|
5
|
+
describe "form_for().unlabeled_submit", :type => :view do
|
6
|
+
let :user do
|
7
|
+
view.stub!(:user_path => "#")
|
8
|
+
mock_model("User", :login => "Username", :bio => "This is my story", :phone => "626-111-2222")
|
9
|
+
end
|
10
|
+
|
11
|
+
|
12
|
+
let :template do
|
13
|
+
<<-EOTEMPLATE
|
14
|
+
<%= form_for(user) do |f| %>
|
15
|
+
<%= f.unlabeled_submit %>
|
16
|
+
<%- end -%>
|
17
|
+
EOTEMPLATE
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should have a submit button" do
|
21
|
+
render(:inline => template, :locals => { :user => user })
|
22
|
+
rendered.should have_xpath("//div[@class='labeled_input']/input[@type='submit']")
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "and submit text" do
|
26
|
+
let :template do
|
27
|
+
<<-EOTEMPLATE
|
28
|
+
<%= form_for(user) do |f| %>
|
29
|
+
<%= f.unlabeled_submit('Click Me') %>
|
30
|
+
<%- end -%>
|
31
|
+
EOTEMPLATE
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should have a submit button with text" do
|
35
|
+
render(:inline => template, :locals => { :user => user })
|
36
|
+
rendered.should have_xpath("//div[@class='labeled_input']/input[@type='submit'][@value='Click Me']")
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should not put a 'submit_text' attribute in the other tags" do
|
40
|
+
render(:inline => template, :locals => { :user => user })
|
41
|
+
rendered.should_not have_xpath("//*[@submit_text]")
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lrd_view_tools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 29
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 3
|
10
|
+
version: 0.1.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Evan Dorn
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-05-02 00:00:00 -07:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|
@@ -35,13 +35,11 @@ files:
|
|
35
35
|
- lib/app/helpers/lrd_form_helper.rb
|
36
36
|
- lib/app/helpers/lrd_view_helper.rb
|
37
37
|
- lib/lrd_view_tools.rb
|
38
|
-
- spec/helpers/lrd_view_helper_spec.rb
|
39
38
|
- spec/labelled_input_spec.rb
|
40
39
|
- spec/lrd_view_tools_spec.rb
|
41
40
|
- spec/spec.opts
|
42
41
|
- spec/spec_helper.rb
|
43
|
-
- spec/
|
44
|
-
- spec/spec_helper_plugin.rb
|
42
|
+
- spec/unlabeled_submit_spec.rb
|
45
43
|
has_rdoc: true
|
46
44
|
homepage: http://LRDesign.com
|
47
45
|
licenses:
|
@@ -72,7 +70,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
72
70
|
requirements: []
|
73
71
|
|
74
72
|
rubyforge_project:
|
75
|
-
rubygems_version: 1.
|
73
|
+
rubygems_version: 1.4.2
|
76
74
|
signing_key:
|
77
75
|
specification_version: 3
|
78
76
|
summary: View helpers and defaults for LRD projects.
|
@@ -1,43 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
-
require 'lrd_view_helper'
|
3
|
-
|
4
|
-
describe LRD::ViewHelper do
|
5
|
-
|
6
|
-
describe "bool_checked" do
|
7
|
-
describe "with true" do
|
8
|
-
it "should return an image tag for the checkmark" do
|
9
|
-
helper.bool_checked(true).should =~ /images\/check.png/
|
10
|
-
end
|
11
|
-
end
|
12
|
-
describe "with false" do
|
13
|
-
it "should return an image tag for a spacer" do
|
14
|
-
helper.bool_checked(false).should =~ /images\/blank.gif/
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
describe "labeled_input" do
|
20
|
-
before(:each) do
|
21
|
-
@form = mock(ActionView::Helpers::FormHelper)
|
22
|
-
@form.stub!(:text_field).and_return("<input name='field' />")
|
23
|
-
@form.stub!(:label).and_return("<label for='field'>")
|
24
|
-
|
25
|
-
@labeled_input = helper.labeled_input(@form, :field)
|
26
|
-
end
|
27
|
-
|
28
|
-
it "should return a string" do
|
29
|
-
@labeled_input.is_a?(String).should be_true
|
30
|
-
end
|
31
|
-
it "should contain the input tag" do
|
32
|
-
@labeled_input.should match(/<input/)
|
33
|
-
@labeled_input.should match(/name='field'/)
|
34
|
-
end
|
35
|
-
it "should contain the label tag field" do
|
36
|
-
@labeled_input.should match(/<label/)
|
37
|
-
@labeled_input.should match(/for='field'/)
|
38
|
-
end
|
39
|
-
|
40
|
-
end
|
41
|
-
|
42
|
-
|
43
|
-
end
|
data/spec/spec_helper_naked.rb
DELETED
@@ -1,11 +0,0 @@
|
|
1
|
-
begin
|
2
|
-
require File.dirname(__FILE__) + '/../../../../spec/spec_helper'
|
3
|
-
rescue LoadError
|
4
|
-
# puts "You need to install rspec in your base app"
|
5
|
-
# exit
|
6
|
-
end
|
7
|
-
|
8
|
-
require 'rspec/rails/example/view_example_group'
|
9
|
-
|
10
|
-
plugin_spec_dir = File.dirname(__FILE__)
|
11
|
-
#ActiveRecord::Base.logger = Logger.new(plugin_spec_dir + "/debug.log")
|
data/spec/spec_helper_plugin.rb
DELETED
@@ -1,10 +0,0 @@
|
|
1
|
-
begin
|
2
|
-
require File.dirname(__FILE__) + '/../../../../spec/spec_helper'
|
3
|
-
rescue LoadError
|
4
|
-
puts "You need to install rspec in your base app"
|
5
|
-
exit
|
6
|
-
end
|
7
|
-
|
8
|
-
plugin_spec_dir = File.dirname(__FILE__)
|
9
|
-
ActiveRecord::Base.logger = Logger.new(plugin_spec_dir + "/debug.log")
|
10
|
-
|