jakewendt-simply_helpful 2.2.14
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +28 -0
- data/generators/simply_helpful/USAGE +0 -0
- data/generators/simply_helpful/simply_helpful_generator.rb +92 -0
- data/generators/simply_helpful/templates/autotest_simply_helpful.rb +2 -0
- data/generators/simply_helpful/templates/javascripts/simply_helpful.js +72 -0
- data/generators/simply_helpful/templates/simply_helpful.rake +6 -0
- data/generators/simply_helpful/templates/stylesheets/simply_helpful.css +48 -0
- data/lib/jakewendt-simply_helpful.rb +1 -0
- data/lib/simply_helpful.rb +6 -0
- data/lib/simply_helpful/autotest.rb +26 -0
- data/lib/simply_helpful/form_helper.rb +254 -0
- data/lib/simply_helpful/rails_helpers.rb +123 -0
- data/lib/simply_helpful/tasks.rb +1 -0
- data/lib/simply_helpful/test_tasks.rb +62 -0
- data/lib/tasks/database.rake +52 -0
- data/lib/tasks/rcov.rake +52 -0
- data/rails/init.rb +1 -0
- data/test/app/controllers/application_controller.rb +16 -0
- data/test/app/controllers/home_controller.rb +10 -0
- data/test/config/routes.rb +6 -0
- data/test/unit/helpful/form_helper_test.rb +192 -0
- data/test/unit/helpful/rails_helpers_test.rb +121 -0
- metadata +119 -0
data/README.rdoc
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
= Simply Helpful
|
2
|
+
|
3
|
+
|
4
|
+
== ToDo
|
5
|
+
|
6
|
+
== Installation / Usage
|
7
|
+
|
8
|
+
config.gem 'jakewendt-simply_helpful',
|
9
|
+
:source => 'http://rubygems.org'
|
10
|
+
|
11
|
+
script/generate simply_helpful
|
12
|
+
|
13
|
+
== Gemified with Jeweler
|
14
|
+
|
15
|
+
vi Rakefile
|
16
|
+
rake version:write
|
17
|
+
|
18
|
+
rake version:bump:patch
|
19
|
+
rake version:bump:minor
|
20
|
+
rake version:bump:major
|
21
|
+
|
22
|
+
rake gemspec
|
23
|
+
|
24
|
+
rake install
|
25
|
+
rake release
|
26
|
+
|
27
|
+
|
28
|
+
Copyright (c) 2010 [George 'Jake' Wendt], released under the MIT license
|
File without changes
|
@@ -0,0 +1,92 @@
|
|
1
|
+
class SimplyHelpfulGenerator < Rails::Generator::Base
|
2
|
+
|
3
|
+
def manifest
|
4
|
+
# See Rails::Generator::Commands::Create
|
5
|
+
# rails-2.3.10/lib/rails_generator/commands.rb
|
6
|
+
# for code methods for record (Manifest)
|
7
|
+
record do |m|
|
8
|
+
m.directory('config/autotest')
|
9
|
+
m.file('autotest_simply_helpful.rb', 'config/autotest/simply_helpful.rb')
|
10
|
+
m.directory('lib/tasks')
|
11
|
+
m.file('simply_helpful.rake', 'lib/tasks/simply_helpful.rake')
|
12
|
+
|
13
|
+
# File.open('Rakefile','a'){|f|
|
14
|
+
# f.puts <<-EOF
|
15
|
+
## From `script/generate simply_helpful` ...
|
16
|
+
#require 'simply_helpful/test_tasks'
|
17
|
+
# EOF
|
18
|
+
# }
|
19
|
+
#
|
20
|
+
# File.open('.autotest','a'){|f|
|
21
|
+
# f.puts <<-EOF
|
22
|
+
## From `script/generate simply_helpful` ...
|
23
|
+
#require 'simply_helpful/autotest'
|
24
|
+
# EOF
|
25
|
+
# }
|
26
|
+
|
27
|
+
# %w( ).each do |migration|
|
28
|
+
# m.migration_template "migrations/#{migration}.rb",
|
29
|
+
# 'db/migrate', :migration_file_name => migration
|
30
|
+
# end
|
31
|
+
dot = File.dirname(__FILE__)
|
32
|
+
m.directory('public/javascripts')
|
33
|
+
Dir["#{dot}/templates/javascripts/*js"].each{|file|
|
34
|
+
f = file.split('/').slice(-2,2).join('/')
|
35
|
+
m.file(f, "public/javascripts/#{File.basename(file)}")
|
36
|
+
}
|
37
|
+
m.directory('public/stylesheets')
|
38
|
+
Dir["#{dot}/templates/stylesheets/*css"].each{|file|
|
39
|
+
f = file.split('/').slice(-2,2).join('/')
|
40
|
+
m.file(f, "public/stylesheets/#{File.basename(file)}")
|
41
|
+
}
|
42
|
+
|
43
|
+
# m.directory('public/images')
|
44
|
+
# %w( full large medium original small ).each do |style|
|
45
|
+
# m.directory("public/images/#{style}")
|
46
|
+
# m.file("images/#{style}/missing.png",
|
47
|
+
# "public/images/#{style}/missing.png")
|
48
|
+
# end
|
49
|
+
|
50
|
+
# m.directory('test/functional/helpful')
|
51
|
+
# Dir["#{dot}/templates/functional/*rb"].each{|file|
|
52
|
+
# f = file.split('/').slice(-2,2).join('/')
|
53
|
+
# m.file(f, "test/functional/helpful/#{File.basename(file)}")
|
54
|
+
# }
|
55
|
+
# m.directory('test/unit/helpful')
|
56
|
+
# Dir["#{dot}/templates/unit/*rb"].each{|file|
|
57
|
+
# f = file.split('/').slice(-2,2).join('/')
|
58
|
+
# m.file(f, "test/unit/helpful/#{File.basename(file)}")
|
59
|
+
# }
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
module Rails::Generator::Commands
|
65
|
+
class Create
|
66
|
+
def migration_template(relative_source,
|
67
|
+
relative_destination, template_options = {})
|
68
|
+
migration_directory relative_destination
|
69
|
+
migration_file_name = template_options[
|
70
|
+
:migration_file_name] || file_name
|
71
|
+
if migration_exists?(migration_file_name)
|
72
|
+
puts "Another migration is already named #{migration_file_name}: #{existing_migrations(migration_file_name).first}: Skipping"
|
73
|
+
else
|
74
|
+
template(relative_source, "#{relative_destination}/#{next_migration_string}_#{migration_file_name}.rb", template_options)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end # Create
|
78
|
+
class Base
|
79
|
+
protected
|
80
|
+
# the loop through migrations happens so fast
|
81
|
+
# that they all have the same timestamp which
|
82
|
+
# won't work when you actually try to migrate.
|
83
|
+
# All the timestamps MUST be unique.
|
84
|
+
def next_migration_string(padding = 3)
|
85
|
+
@s = (!@s.nil?)? @s.to_i + 1 : if ActiveRecord::Base.timestamped_migrations
|
86
|
+
Time.now.utc.strftime("%Y%m%d%H%M%S")
|
87
|
+
else
|
88
|
+
"%.#{padding}d" % next_migration_number
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end # Base
|
92
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
jQuery(function(){
|
2
|
+
|
3
|
+
/*
|
4
|
+
'clicking' a submit button apparently skips the 'submit' method
|
5
|
+
which then skips the destroy confirmation, so we need to explicitly
|
6
|
+
catch the click and manually submit to trigger the confirmation.
|
7
|
+
*/
|
8
|
+
jQuery('form.destroy_link_to input[type=submit]').click(function(){
|
9
|
+
jQuery(this).parents('form').submit();
|
10
|
+
return false;
|
11
|
+
});
|
12
|
+
|
13
|
+
jQuery('form.destroy_link_to').submit(function(){
|
14
|
+
var message = "Destroy? Seriously?"
|
15
|
+
if( this.confirm && this.confirm.value ) {
|
16
|
+
message = this.confirm.value
|
17
|
+
}
|
18
|
+
if( !confirm(message) ){
|
19
|
+
return false;
|
20
|
+
}
|
21
|
+
});
|
22
|
+
|
23
|
+
jQuery('p.flash').click(function(){$(this).remove();});
|
24
|
+
|
25
|
+
if( typeof jQuery('.datepicker').datepicker == 'function' ){
|
26
|
+
jQuery('.datepicker').datepicker();
|
27
|
+
}
|
28
|
+
|
29
|
+
jQuery('form a.submit.button').siblings('input[type=submit]').hide();
|
30
|
+
|
31
|
+
jQuery('form a.submit.button').click(function(){
|
32
|
+
if( jQuery(this).next('input[type=submit]').length > 0 ){
|
33
|
+
jQuery(this).next().click();
|
34
|
+
} else {
|
35
|
+
jQuery(this).parents('form').submit();
|
36
|
+
}
|
37
|
+
return false;
|
38
|
+
});
|
39
|
+
|
40
|
+
});
|
41
|
+
|
42
|
+
|
43
|
+
jQuery(window).resize(function(){
|
44
|
+
resize_text_areas()
|
45
|
+
});
|
46
|
+
|
47
|
+
jQuery(window).load(function(){
|
48
|
+
/*
|
49
|
+
This MUST be in window/load, not the normal document/ready,
|
50
|
+
for Google Chrome to get correct values
|
51
|
+
*/
|
52
|
+
resize_text_areas()
|
53
|
+
});
|
54
|
+
|
55
|
+
function resize_text_areas() {
|
56
|
+
/*
|
57
|
+
jQuery('textarea.autosize').each(function(){
|
58
|
+
*/
|
59
|
+
jQuery('.autosize').each(function(){
|
60
|
+
new_width = $(this).parent().innerWidth() +
|
61
|
+
$(this).parent().position().left -
|
62
|
+
$(this).position().left -
|
63
|
+
parseInt($(this).css('margin-left')) -
|
64
|
+
parseInt($(this).css('margin-right')) -
|
65
|
+
parseInt($(this).css('padding-left')) -
|
66
|
+
parseInt($(this).css('padding-right')) -
|
67
|
+
parseInt($(this).css('border-left-width')) -
|
68
|
+
parseInt($(this).css('border-right-width') )
|
69
|
+
$(this).css('width',new_width-10) /* take 10 more for good measure */
|
70
|
+
})
|
71
|
+
}
|
72
|
+
|
@@ -0,0 +1,48 @@
|
|
1
|
+
.flash {
|
2
|
+
/* http://css-radius.heroku.com */
|
3
|
+
-webkit-border-radius: 8px;
|
4
|
+
-moz-border-radius: 8px;
|
5
|
+
border-radius: 8px;
|
6
|
+
padding: 0.7em;
|
7
|
+
text-align: center;
|
8
|
+
font-weight: bold;
|
9
|
+
font-size: 12pt;
|
10
|
+
}
|
11
|
+
.flash.error,
|
12
|
+
.flash#error {
|
13
|
+
border: 2px solid #F44;
|
14
|
+
background-color: #FCC;
|
15
|
+
}
|
16
|
+
.flash.warn,
|
17
|
+
.flash#warn {
|
18
|
+
border: 2px solid #FF6600;
|
19
|
+
background-color: #FFCC99;
|
20
|
+
}
|
21
|
+
.flash.notice,
|
22
|
+
.flash#notice {
|
23
|
+
border: 2px solid #4F4;
|
24
|
+
background-color: #CFC;
|
25
|
+
}
|
26
|
+
.flash.noscript,
|
27
|
+
.flash#noscript {
|
28
|
+
border: 2px solid #FF8C00;
|
29
|
+
background-color: #FFC5AF;
|
30
|
+
}
|
31
|
+
|
32
|
+
|
33
|
+
a.button {
|
34
|
+
/* http://css-radius.heroku.com */
|
35
|
+
-webkit-border-radius: 10px;
|
36
|
+
-moz-border-radius: 10px;
|
37
|
+
border-radius: 10px;
|
38
|
+
border: 1px solid gray;
|
39
|
+
text-decoration:none;
|
40
|
+
padding: 1px 8px;
|
41
|
+
color:black;
|
42
|
+
|
43
|
+
/* for webkit browsers */
|
44
|
+
background: -webkit-gradient(linear, left top, left bottom, from(#EEEEEE), to(#CCCCCC));
|
45
|
+
/* for firefox 3.6+ */
|
46
|
+
background: -moz-linear-gradient(top, #EEEEEE, #CCCCCC);
|
47
|
+
}
|
48
|
+
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'simply_helpful'
|
@@ -0,0 +1,26 @@
|
|
1
|
+
class Autotest::Rails
|
2
|
+
|
3
|
+
#
|
4
|
+
# Need both the mapping and the extra files
|
5
|
+
#
|
6
|
+
def run_with_simply_helpful
|
7
|
+
add_exception %r%config/%
|
8
|
+
add_exception %r%versions/%
|
9
|
+
add_exception %r%\.git/%
|
10
|
+
self.extra_files << File.expand_path(File.join(
|
11
|
+
File.dirname(__FILE__),'/../../test/unit/helpful/'))
|
12
|
+
|
13
|
+
self.extra_files << File.expand_path(File.join(
|
14
|
+
File.dirname(__FILE__),'/../../test/functional/helpful/'))
|
15
|
+
|
16
|
+
add_mapping(
|
17
|
+
%r{^#{File.expand_path(File.join(File.dirname(__FILE__),'/../../test/'))}/(unit|functional)/helpful/.*_test\.rb$}
|
18
|
+
) do |filename, _|
|
19
|
+
filename
|
20
|
+
end
|
21
|
+
run_without_simply_helpful
|
22
|
+
end
|
23
|
+
alias_method_chain :run, :simply_helpful
|
24
|
+
|
25
|
+
|
26
|
+
end
|
@@ -0,0 +1,254 @@
|
|
1
|
+
module SimplyHelpful::FormHelper
|
2
|
+
|
3
|
+
def mdy(date)
|
4
|
+
( date.nil? ) ? ' ' : date.strftime("%m/%d/%Y")
|
5
|
+
end
|
6
|
+
|
7
|
+
def time_mdy(time)
|
8
|
+
( time.nil? ) ? ' ' : time.strftime("%I:%M %p %m/%d/%Y")
|
9
|
+
end
|
10
|
+
|
11
|
+
def y_n_dk(value)
|
12
|
+
case value
|
13
|
+
when 1 then 'Yes'
|
14
|
+
when 2 then 'No'
|
15
|
+
when 999 then "Don't Know"
|
16
|
+
else ' '
|
17
|
+
end
|
18
|
+
end
|
19
|
+
alias_method :yndk, :y_n_dk
|
20
|
+
|
21
|
+
def field_wrapper(method,options={},&block)
|
22
|
+
classes = [method,options[:class]].compact.join(' ')
|
23
|
+
s = "<div class='#{classes} field_wrapper'>\n"
|
24
|
+
s << yield
|
25
|
+
s << "\n</div><!-- class='#{classes}' -->"
|
26
|
+
end
|
27
|
+
|
28
|
+
# This is NOT a form field
|
29
|
+
def _wrapped_spans(object_name,method,options={})
|
30
|
+
s = "<span class='label'>#{options[:label_text]||method}</span>\n"
|
31
|
+
value = if options[:value]
|
32
|
+
options[:value]
|
33
|
+
else
|
34
|
+
object = instance_variable_get("@#{object_name}")
|
35
|
+
value = object.send(method)
|
36
|
+
value = (value.to_s.blank?)?' ':value
|
37
|
+
end
|
38
|
+
s << "<span class='value'>#{value}</span>"
|
39
|
+
end
|
40
|
+
|
41
|
+
def _wrapped_y_n_dk_spans(object_name,method,options={})
|
42
|
+
object = instance_variable_get("@#{object_name}")
|
43
|
+
_wrapped_spans(object_name,method,options.update(
|
44
|
+
:value => y_n_dk(object.send(method)) ) )
|
45
|
+
end
|
46
|
+
alias_method :_wrapped_yndk_spans, :_wrapped_y_n_dk_spans
|
47
|
+
|
48
|
+
def _wrapped_date_spans(object_name,method,options={})
|
49
|
+
object = instance_variable_get("@#{object_name}")
|
50
|
+
_wrapped_spans(object_name,method,options.update(
|
51
|
+
:value => mdy(object.send(method)) ) )
|
52
|
+
end
|
53
|
+
|
54
|
+
def sex_select(object_name, method,
|
55
|
+
options={}, html_options={})
|
56
|
+
select(object_name, method,
|
57
|
+
[['male','M'],['female','F']],
|
58
|
+
options, html_options)
|
59
|
+
end
|
60
|
+
alias_method :gender_select, :sex_select
|
61
|
+
|
62
|
+
def date_text_field(object_name,method,options={})
|
63
|
+
format = options.delete(:format) || '%m/%d/%Y'
|
64
|
+
tmp_value = if options[:value].blank? #and !options[:object].nil?
|
65
|
+
object = options[:object]
|
66
|
+
tmp = object.send("#{method}") ||
|
67
|
+
object.send("#{method}_before_type_cast")
|
68
|
+
else
|
69
|
+
options[:value]
|
70
|
+
end
|
71
|
+
begin
|
72
|
+
options[:value] = tmp_value.to_date.try(:strftime,format)
|
73
|
+
rescue NoMethodError, ArgumentError
|
74
|
+
options[:value] = tmp_value
|
75
|
+
end
|
76
|
+
options.update(:class => [options[:class],'datepicker'].compact.join(' '))
|
77
|
+
text_field( object_name, method, options )
|
78
|
+
end
|
79
|
+
|
80
|
+
# This is NOT a form field
|
81
|
+
def _wrapped_yes_or_no_spans(object_name,method,options={})
|
82
|
+
object = instance_variable_get("@#{object_name}")
|
83
|
+
s = "<span class='label'>#{options[:label_text]||method}</span>\n"
|
84
|
+
value = (object.send("#{method}?"))?'Yes':'No'
|
85
|
+
s << "<span class='value'>#{value}</span>"
|
86
|
+
end
|
87
|
+
|
88
|
+
def y_n_dk_select(object_name, method,
|
89
|
+
options={}, html_options={})
|
90
|
+
select(object_name, method,
|
91
|
+
[['Yes',1],['No',2],["Don't Know",999]],
|
92
|
+
{:include_blank => true}.merge(options), html_options)
|
93
|
+
end
|
94
|
+
alias_method :yndk_select, :y_n_dk_select
|
95
|
+
|
96
|
+
def hour_select(object_name, method,
|
97
|
+
options={}, html_options={})
|
98
|
+
select(object_name, method,
|
99
|
+
(1..12),
|
100
|
+
{:include_blank => 'Hour'}.merge(options), html_options)
|
101
|
+
end
|
102
|
+
|
103
|
+
def minute_select(object_name, method,
|
104
|
+
options={}, html_options={})
|
105
|
+
minutes = (0..59).to_a.collect{|m|[sprintf("%02d",m),m]}
|
106
|
+
select(object_name, method,
|
107
|
+
minutes,
|
108
|
+
{:include_blank => 'Minute'}.merge(options), html_options)
|
109
|
+
end
|
110
|
+
|
111
|
+
def meridiem_select(object_name, method,
|
112
|
+
options={}, html_options={})
|
113
|
+
select(object_name, method,
|
114
|
+
['AM','PM'],
|
115
|
+
{:include_blank => 'Meridiem'}.merge(options), html_options)
|
116
|
+
end
|
117
|
+
|
118
|
+
def self.included(base)
|
119
|
+
base.class_eval do
|
120
|
+
alias_method_chain( :method_missing, :wrapping
|
121
|
+
) unless base.respond_to?(:method_missing_without_wrapping)
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
def method_missing_with_wrapping(symb,*args, &block)
|
126
|
+
method_name = symb.to_s
|
127
|
+
if method_name =~ /^wrapped_(.+)$/
|
128
|
+
unwrapped_method_name = $1
|
129
|
+
#
|
130
|
+
# It'd be nice to be able to genericize all of the
|
131
|
+
# wrapped_* methods since they are all basically
|
132
|
+
# the same.
|
133
|
+
# Strip of the "wrapped_"
|
134
|
+
# Label
|
135
|
+
# Call "unwrapped" method
|
136
|
+
#
|
137
|
+
|
138
|
+
object_name = args[0]
|
139
|
+
method = args[1]
|
140
|
+
|
141
|
+
content = field_wrapper(method,:class => unwrapped_method_name) do
|
142
|
+
s = if respond_to?(unwrapped_method_name)
|
143
|
+
options = args.detect{|i| i.is_a?(Hash) }
|
144
|
+
label_text = options.delete(:label_text) unless options.nil?
|
145
|
+
if unwrapped_method_name == 'check_box'
|
146
|
+
send("#{unwrapped_method_name}",*args,&block) <<
|
147
|
+
label( object_name, method, label_text )
|
148
|
+
else
|
149
|
+
label( object_name, method, label_text ) <<
|
150
|
+
send("#{unwrapped_method_name}",*args,&block)
|
151
|
+
end
|
152
|
+
else
|
153
|
+
send("_#{method_name}",*args,&block)
|
154
|
+
end
|
155
|
+
|
156
|
+
s << (( block_given? )? capture(&block) : '')
|
157
|
+
# send("_#{method_name}",*args) <<
|
158
|
+
# (( block_given? )? capture(&block) : '')
|
159
|
+
end
|
160
|
+
if block_called_from_erb?(block)
|
161
|
+
concat(content)
|
162
|
+
else
|
163
|
+
content
|
164
|
+
end
|
165
|
+
else
|
166
|
+
method_missing_without_wrapping(symb,*args, &block)
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
end
|
171
|
+
ActionView::Base.send(:include, SimplyHelpful::FormHelper)
|
172
|
+
|
173
|
+
|
174
|
+
|
175
|
+
ActionView::Helpers::FormBuilder.class_eval do
|
176
|
+
|
177
|
+
def submit_link_to(value=nil,options={})
|
178
|
+
# submit_link_to will remove :value, which is intended for submit
|
179
|
+
# so it MUST be executed first. Unfortunately, my javascript
|
180
|
+
# expects it to be AFTER the a tag.
|
181
|
+
# s = submit(value,options.reverse_merge(
|
182
|
+
# :id => "#{object_name}_submit_#{value.try(:downcase).try(:gsub,/\s+/,'_')}"
|
183
|
+
# ) ) << @template.submit_link_to(value,nil,options)
|
184
|
+
s1 = submit(value,options.reverse_merge(
|
185
|
+
:id => "#{object_name}_submit_#{value.try(:downcase).try(
|
186
|
+
:gsub,/\s+/,'_').try(
|
187
|
+
:gsub,/(&|'|\/)/,'').try(
|
188
|
+
:gsub,/_+/,'_')}"
|
189
|
+
) )
|
190
|
+
s2 = @template.submit_link_to(value,nil,options)
|
191
|
+
s2 << s1
|
192
|
+
end
|
193
|
+
|
194
|
+
def hour_select(method,options={},html_options={})
|
195
|
+
@template.hour_select(
|
196
|
+
@object_name, method,
|
197
|
+
objectify_options(options),
|
198
|
+
html_options)
|
199
|
+
end
|
200
|
+
|
201
|
+
def minute_select(method,options={},html_options={})
|
202
|
+
@template.minute_select(
|
203
|
+
@object_name, method,
|
204
|
+
objectify_options(options),
|
205
|
+
html_options)
|
206
|
+
end
|
207
|
+
|
208
|
+
def meridiem_select(method,options={},html_options={})
|
209
|
+
@template.meridiem_select(
|
210
|
+
@object_name, method,
|
211
|
+
objectify_options(options),
|
212
|
+
html_options)
|
213
|
+
end
|
214
|
+
|
215
|
+
def sex_select(method,options={},html_options={})
|
216
|
+
@template.sex_select(
|
217
|
+
@object_name, method,
|
218
|
+
objectify_options(options),
|
219
|
+
html_options)
|
220
|
+
end
|
221
|
+
alias_method :gender_select, :sex_select
|
222
|
+
|
223
|
+
def date_text_field(method, options = {})
|
224
|
+
@template.date_text_field(
|
225
|
+
@object_name, method, objectify_options(options))
|
226
|
+
end
|
227
|
+
|
228
|
+
def y_n_dk_select(method,options={},html_options={})
|
229
|
+
@template.y_n_dk_select(
|
230
|
+
@object_name, method,
|
231
|
+
objectify_options(options),
|
232
|
+
html_options)
|
233
|
+
end
|
234
|
+
alias_method :yndk_select, :y_n_dk_select
|
235
|
+
|
236
|
+
def method_missing_with_wrapping(symb,*args, &block)
|
237
|
+
method_name = symb.to_s
|
238
|
+
if method_name =~ /^wrapped_(.+)$/
|
239
|
+
i = args.find_index{|i| i.is_a?(Hash) }
|
240
|
+
if i.nil?
|
241
|
+
args.push(objectify_options({}))
|
242
|
+
else
|
243
|
+
args[i] = objectify_options(args[i])
|
244
|
+
end
|
245
|
+
@template.send(method_name,@object_name,*args,&block)
|
246
|
+
else
|
247
|
+
method_missing_without_wrapping(symb,*args, &block)
|
248
|
+
end
|
249
|
+
end
|
250
|
+
|
251
|
+
alias_method_chain( :method_missing, :wrapping
|
252
|
+
) unless respond_to?(:method_missing_without_wrapping)
|
253
|
+
|
254
|
+
end
|
@@ -0,0 +1,123 @@
|
|
1
|
+
module SimplyHelpful::RailsHelpers
|
2
|
+
|
3
|
+
# Just add the classes 'submit' and 'button'
|
4
|
+
# for styling and function
|
5
|
+
def submit_link_to(*args,&block)
|
6
|
+
html_options = if block_given?
|
7
|
+
args[1] ||= {}
|
8
|
+
else
|
9
|
+
args[2] ||= {}
|
10
|
+
end
|
11
|
+
html_options.delete(:value) # possible key meant for submit button
|
12
|
+
html_options.delete('value') # possible key meant for submit button
|
13
|
+
( html_options[:class] ||= '' ) << ' submit button'
|
14
|
+
link_to( *args, &block )
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
def form_link_to( title, url, options={}, &block )
|
19
|
+
# "action='#{url}' " <<
|
20
|
+
extra_tags = extra_tags_for_form(options)
|
21
|
+
s = "\n" <<
|
22
|
+
"<form " <<
|
23
|
+
"class='#{options.delete(:class)||'form_link_to'}' " <<
|
24
|
+
"action='#{url_for(url)}' " <<
|
25
|
+
"method='#{options.delete('method')}'>\n" <<
|
26
|
+
extra_tags << "\n"
|
27
|
+
s << (( block_given? )? capture(&block) : '')
|
28
|
+
s << submit_tag(title, :name => nil ) << "\n" <<
|
29
|
+
"</form>\n"
|
30
|
+
if block_called_from_erb?(block)
|
31
|
+
concat(s)
|
32
|
+
else
|
33
|
+
s
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def destroy_link_to( title, url, options={}, &block )
|
38
|
+
s = form_link_to( title, url, options.merge(
|
39
|
+
'method' => 'delete',
|
40
|
+
:class => 'destroy_link_to'
|
41
|
+
),&block )
|
42
|
+
end
|
43
|
+
|
44
|
+
def aws_image_tag(image,options={})
|
45
|
+
# in console @controller is nil
|
46
|
+
protocol = @controller.try(:request).try(:protocol) || 'http://'
|
47
|
+
host = 's3.amazonaws.com/'
|
48
|
+
bucket = ( defined?(RAILS_APP_NAME) && RAILS_APP_NAME ) || 'ccls'
|
49
|
+
src = "#{protocol}#{host}#{bucket}/images/#{image}"
|
50
|
+
alt = options.delete(:alt) || options.delete('alt') || image
|
51
|
+
tag('img',options.merge({:src => src, :alt => alt}))
|
52
|
+
end
|
53
|
+
|
54
|
+
# This style somehow for some reason actually submits the request TWICE?
|
55
|
+
# In many cases, this is no big deal, but when using it to send
|
56
|
+
# emails or something, the controller/action is called twice
|
57
|
+
# resulting in 2 emails (if that's what your action does)
|
58
|
+
# I'd really like to understand why.
|
59
|
+
def button_link_to( title, url, options={} )
|
60
|
+
classes = ['link']
|
61
|
+
classes << options[:class]
|
62
|
+
s = "<a href='#{url_for(url)}' style='text-decoration:none;'>"
|
63
|
+
s << "<button type='button'>"
|
64
|
+
s << title
|
65
|
+
s << "</button></a>\n"
|
66
|
+
end
|
67
|
+
|
68
|
+
# This creates a button that looks like a submit button
|
69
|
+
# but is just a javascript controlled link.
|
70
|
+
# I don't like it.
|
71
|
+
def old_button_link_to( title, url, options={} )
|
72
|
+
# id = "id='#{options[:id]}'" unless options[:id].blank?
|
73
|
+
# klass = if options[:class].blank?
|
74
|
+
# "class='link'"
|
75
|
+
# else
|
76
|
+
# "class='#{options[:class]}'"
|
77
|
+
# end
|
78
|
+
# s = "<button #{id} #{klass} type='button'>"
|
79
|
+
classes = ['link']
|
80
|
+
classes << options[:class]
|
81
|
+
s = "<button class='#{classes.flatten.join(' ')}' type='button'>"
|
82
|
+
s << "<span class='href' style='display:none;'>"
|
83
|
+
s << url_for(url)
|
84
|
+
s << "</span>"
|
85
|
+
s << title
|
86
|
+
s << "</button>"
|
87
|
+
s
|
88
|
+
end
|
89
|
+
|
90
|
+
def flasher
|
91
|
+
s = ''
|
92
|
+
flash.each do |key, msg|
|
93
|
+
s << content_tag( :p, msg, :id => key, :class => 'flash' )
|
94
|
+
s << "\n"
|
95
|
+
end
|
96
|
+
s << "<noscript><p id='noscript' class='flash'>\n"
|
97
|
+
s << "Javascript is required for this site to be fully functional.\n"
|
98
|
+
s << "</p></noscript>\n"
|
99
|
+
end
|
100
|
+
|
101
|
+
# Created to stop multiple entries of same stylesheet
|
102
|
+
def stylesheets(*args)
|
103
|
+
@stylesheets ||= []
|
104
|
+
args.each do |stylesheet|
|
105
|
+
unless @stylesheets.include?(stylesheet.to_s)
|
106
|
+
@stylesheets.push(stylesheet.to_s)
|
107
|
+
content_for(:head,stylesheet_link_tag(stylesheet.to_s))
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
def javascripts(*args)
|
113
|
+
@javascripts ||= []
|
114
|
+
args.each do |javascript|
|
115
|
+
unless @javascripts.include?(javascript.to_s)
|
116
|
+
@javascripts.push(javascript.to_s)
|
117
|
+
content_for(:head,javascript_include_tag(javascript).to_s)
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
end
|
123
|
+
ActionView::Base.send(:include, SimplyHelpful::RailsHelpers)
|
@@ -0,0 +1 @@
|
|
1
|
+
Dir["#{File.dirname(__FILE__)}/../tasks/**/*.rake"].sort.each { |ext| load ext }
|
@@ -0,0 +1,62 @@
|
|
1
|
+
module SimplyHelpful;end
|
2
|
+
namespace :test do
|
3
|
+
namespace :units do
|
4
|
+
Rake::TestTask.new(:simply_helpful => "db:test:prepare") do |t|
|
5
|
+
t.pattern = File.expand_path(File.join(
|
6
|
+
File.dirname(__FILE__),'/../../test/unit/helpful/*_test.rb'))
|
7
|
+
t.libs << "test"
|
8
|
+
t.verbose = true
|
9
|
+
end
|
10
|
+
end
|
11
|
+
namespace :functionals do
|
12
|
+
Rake::TestTask.new(:simply_helpful => "db:test:prepare") do |t|
|
13
|
+
t.pattern = File.expand_path(File.join(
|
14
|
+
File.dirname(__FILE__),'/../../test/functional/helpful/*_test.rb'))
|
15
|
+
t.libs << "test"
|
16
|
+
t.verbose = true
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
Rake::Task['test:functionals'].prerequisites.unshift(
|
21
|
+
"test:functionals:simply_helpful" )
|
22
|
+
Rake::Task['test:units'].prerequisites.unshift(
|
23
|
+
"test:units:simply_helpful" )
|
24
|
+
|
25
|
+
# I thought of possibly just including this file
|
26
|
+
# but that would make __FILE__ different.
|
27
|
+
# Hmmm
|
28
|
+
|
29
|
+
#
|
30
|
+
# used in simply_helpful's rake test:coverage to run gem's
|
31
|
+
# tests in the context of the application
|
32
|
+
#
|
33
|
+
@gem_test_dirs ||= []
|
34
|
+
#@gem_test_dirs << File.expand_path(File.join(File.dirname(__FILE__),
|
35
|
+
# '/../../test/unit/helpful/'))
|
36
|
+
|
37
|
+
|
38
|
+
#
|
39
|
+
# No functional tests so...
|
40
|
+
#
|
41
|
+
#/Library/Ruby/Gems/1.8/gems/rcov-0.9.9/bin/rcov:516:in `load': no such file to load -- /Library/Ruby/Gems/1.8/gems/jakewendt-simply_helpful-2.2.12/test/functional/helpful/*_test.rb (LoadError)
|
42
|
+
# from /Library/Ruby/Gems/1.8/gems/rcov-0.9.9/bin/rcov:516
|
43
|
+
# from /usr/bin/rcov:19:in `load'
|
44
|
+
# from /usr/bin/rcov:19
|
45
|
+
#
|
46
|
+
# Actually, I think the error is because the directory isn't there
|
47
|
+
# because there aren't any files in the gem in that directory.
|
48
|
+
# Perhaps I could try to force it. Until then, comment this line out.
|
49
|
+
#
|
50
|
+
#@gem_test_dirs << File.expand_path(File.join(File.dirname(__FILE__),
|
51
|
+
# '/../../test/functional/helpful/'))
|
52
|
+
|
53
|
+
#
|
54
|
+
# More flexible. Find all test files, pick out their dir, uniq 'em and add.
|
55
|
+
#
|
56
|
+
Dir.glob( File.expand_path(File.join(File.dirname(__FILE__),
|
57
|
+
'/../../test/*/helpful/*_test.rb'))
|
58
|
+
).collect{|f|
|
59
|
+
File.dirname(f)
|
60
|
+
}.uniq.each{ |dir|
|
61
|
+
@gem_test_dirs << dir
|
62
|
+
}
|
@@ -0,0 +1,52 @@
|
|
1
|
+
namespace :db do
|
2
|
+
|
3
|
+
desc "Create yml fixtures for given model in database\n" <<
|
4
|
+
"rake db:extract_fixtures_from pages"
|
5
|
+
task :extract_fixtures_from => :environment do
|
6
|
+
me = $*.shift
|
7
|
+
while( table_name = $*.shift )
|
8
|
+
File.open("#{RAILS_ROOT}/db/#{table_name}.yml", 'w') do |file|
|
9
|
+
data = table_name.singularize.capitalize.constantize.find(
|
10
|
+
:all).collect(&:attributes)
|
11
|
+
file.write data.inject({}) { |hash, record|
|
12
|
+
record.delete('created_at')
|
13
|
+
record.delete('updated_at')
|
14
|
+
hash["#{table_name}_#{record['id']}"] = record
|
15
|
+
hash
|
16
|
+
}.to_yaml
|
17
|
+
end
|
18
|
+
end
|
19
|
+
exit
|
20
|
+
end
|
21
|
+
|
22
|
+
desc "Dump MYSQL table descriptions."
|
23
|
+
task :describe => :environment do
|
24
|
+
puts
|
25
|
+
puts "FYI: This task ONLY works on MYSQL databases."
|
26
|
+
puts
|
27
|
+
config = ActiveRecord::Base.connection.instance_variable_get(:@config)
|
28
|
+
#=> {:adapter=>"mysql", :host=>"localhost", :password=>nil, :username=>"root", :database=>"my_development", :encoding=>"utf8"}
|
29
|
+
|
30
|
+
tables = ActiveRecord::Base.connection.execute('show tables;')
|
31
|
+
while( table = tables.fetch_row ) do
|
32
|
+
puts "Table: #{table}"
|
33
|
+
|
34
|
+
# may have to include host and port
|
35
|
+
system("mysql --table=true " <<
|
36
|
+
"--user=#{config[:username]} " <<
|
37
|
+
"--password='#{config[:password]}' " <<
|
38
|
+
"--execute='describe #{table}' " <<
|
39
|
+
config[:database]);
|
40
|
+
|
41
|
+
#
|
42
|
+
# mysql formats the table well so doing it by hand is something that
|
43
|
+
# will have to wait until I feel like wasting my time
|
44
|
+
#
|
45
|
+
# columns = ActiveRecord::Base.connection.execute("describe #{table};")
|
46
|
+
# while( column = columns.fetch_hash ) do
|
47
|
+
# puts column.keys Extra Default Null Type Field Key
|
48
|
+
# end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
data/lib/tasks/rcov.rake
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
#
|
2
|
+
# This is from Advanced Rails Recipes, page 277
|
3
|
+
#
|
4
|
+
namespace :test do
|
5
|
+
|
6
|
+
desc 'Tracks test coverage with rcov'
|
7
|
+
task :coverage do
|
8
|
+
rm_f "coverage"
|
9
|
+
rm_f "coverage.data"
|
10
|
+
|
11
|
+
unless PLATFORM['i386-mswin32']
|
12
|
+
rcov = "rcov --sort coverage --rails --aggregate coverage.data " <<
|
13
|
+
"--text-summary -Ilib:test -T "
|
14
|
+
# exclusions are ...
|
15
|
+
# -x, --exclude PATTERNS Don't generate info for files matching a
|
16
|
+
# pattern (comma-separated regexp list)
|
17
|
+
exclusions = ['gems/','db/.*schema.rb','db/migrate']
|
18
|
+
exclusions += RCOV_EXCLUDES if defined?(RCOV_EXCLUDES)
|
19
|
+
puts "Excluding : #{exclusions.join(',')}"
|
20
|
+
rcov << "-x #{exclusions.join(',')}"
|
21
|
+
# "-x gems/*,db/migrate/*,jrails/*/*"
|
22
|
+
# ',\(eval\),\(recognize_optimized\),\(erb\)' << # needed in jruby
|
23
|
+
# ",yaml,yaml/*,lib/tmail/parser.y,jruby.jar!/*" << # needed in jruby
|
24
|
+
# ",db/*schema.rb"
|
25
|
+
# ",html_test/*/*" <<
|
26
|
+
# ",html_test_extension/*/*"
|
27
|
+
else
|
28
|
+
rcov = "rcov.cmd --sort coverage --rails --aggregate " <<
|
29
|
+
"coverage.data --text-summary -Ilib -T"
|
30
|
+
end
|
31
|
+
|
32
|
+
dirs = Dir.glob("test/**/*_test.rb").collect{|f|File.dirname(f)}.uniq
|
33
|
+
if defined?(@gem_test_dirs) && @gem_test_dirs.is_a?(Array)
|
34
|
+
dirs += @gem_test_dirs
|
35
|
+
end
|
36
|
+
lastdir = dirs.pop
|
37
|
+
dirs.each do |dir|
|
38
|
+
system("#{rcov} --no-html #{dir}/*_test.rb")
|
39
|
+
end
|
40
|
+
system("#{rcov} --html #{lastdir}/*_test.rb") unless lastdir.nil?
|
41
|
+
|
42
|
+
unless PLATFORM['i386-mswin32']
|
43
|
+
# jruby-1.5.0.RC1 > PLATFORM
|
44
|
+
# => "java"
|
45
|
+
# system("open coverage/index.html") if PLATFORM['darwin']
|
46
|
+
system("open coverage/index.html")
|
47
|
+
else
|
48
|
+
system("\"C:/Program Files/Mozilla Firefox/firefox.exe\" " +
|
49
|
+
"coverage/index.html")
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
data/rails/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'jakewendt-simply_helpful'
|
@@ -0,0 +1,16 @@
|
|
1
|
+
class ApplicationController < ActionController::Base
|
2
|
+
|
3
|
+
helper :all # include all helpers, all the time
|
4
|
+
|
5
|
+
# See ActionController::RequestForgeryProtection for details
|
6
|
+
protect_from_forgery
|
7
|
+
|
8
|
+
def redirections
|
9
|
+
@redirections ||= HashWithIndifferentAccess.new({
|
10
|
+
:not_be_user => {
|
11
|
+
:redirect_to => user_path(current_user)
|
12
|
+
}
|
13
|
+
})
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
@@ -0,0 +1,192 @@
|
|
1
|
+
#require File.dirname(__FILE__) + '/../../test_helper'
|
2
|
+
require 'test_helper'
|
3
|
+
|
4
|
+
class SimplyHelpful::User
|
5
|
+
attr_accessor :yes_or_no, :yndk, :dob, :sex, :name, :dob_before_type_cast
|
6
|
+
def initialize(*args,&block)
|
7
|
+
yield self if block_given?
|
8
|
+
end
|
9
|
+
def yes_or_no?
|
10
|
+
!!yes_or_no
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
class SimplyHelpful::FormHelperTest < ActionView::TestCase
|
15
|
+
|
16
|
+
test "field_wrapper" do
|
17
|
+
response = HTML::Document.new(
|
18
|
+
field_wrapper('mymethod') do
|
19
|
+
'Yield'
|
20
|
+
end).root
|
21
|
+
#<div class="mymethod field_wrapper">
|
22
|
+
#Yield
|
23
|
+
#</div><!-- class='mymethod' -->
|
24
|
+
assert_select response, 'div.mymethod.field_wrapper'
|
25
|
+
end
|
26
|
+
|
27
|
+
test "wrapped_spans without options" do
|
28
|
+
@user = SimplyHelpful::User.new
|
29
|
+
response = HTML::Document.new(
|
30
|
+
wrapped_spans(:user, :name)).root
|
31
|
+
#<div class="name field_wrapper">
|
32
|
+
#<span class="label">name</span>
|
33
|
+
#<span class="value"> </span>
|
34
|
+
#</div><!-- class='name' -->
|
35
|
+
assert_select response, 'div.name.field_wrapper', 1 do
|
36
|
+
assert_select 'span.label', 1
|
37
|
+
assert_select 'span.value', 1
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
test "wrapped_yes_or_no_spans blank" do
|
42
|
+
@user = SimplyHelpful::User.new
|
43
|
+
response = HTML::Document.new(
|
44
|
+
wrapped_yes_or_no_spans(:user, :yes_or_no)).root
|
45
|
+
#<div class="yes_or_no field_wrapper">
|
46
|
+
#<span class="label">yes_or_no</span>
|
47
|
+
#<span class="value">no</span>
|
48
|
+
#</div><!-- class='yes_or_no' -->
|
49
|
+
assert_select response, 'div.yes_or_no.field_wrapper' do
|
50
|
+
assert_select 'span.label','yes_or_no',1
|
51
|
+
assert_select 'span.value','No',1
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
test "wrapped_yes_or_no_spans true" do
|
56
|
+
@user = SimplyHelpful::User.new{|u| u.yes_or_no = true }
|
57
|
+
response = HTML::Document.new(
|
58
|
+
wrapped_yes_or_no_spans(:user, :yes_or_no)).root
|
59
|
+
#<div class="yes_or_no field_wrapper">
|
60
|
+
#<span class="label">yes_or_no</span>
|
61
|
+
#<span class="value">yes</span>
|
62
|
+
#</div><!-- class='yes_or_no' -->
|
63
|
+
assert_select response, 'div.yes_or_no.field_wrapper' do
|
64
|
+
assert_select 'span.label','yes_or_no',1
|
65
|
+
assert_select 'span.value','Yes',1
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
test "wrapped_yes_or_no_spans false" do
|
70
|
+
@user = SimplyHelpful::User.new(:yes_or_no => false)
|
71
|
+
response = HTML::Document.new(
|
72
|
+
wrapped_yes_or_no_spans(:user, :yes_or_no)).root
|
73
|
+
#<div class="yes_or_no field_wrapper">
|
74
|
+
#<span class="label">yes_or_no</span>
|
75
|
+
#<span class="value">no</span>
|
76
|
+
#</div><!-- class='yes_or_no' -->
|
77
|
+
assert_select response, 'div.yes_or_no.field_wrapper' do
|
78
|
+
assert_select 'span.label','yes_or_no',1
|
79
|
+
assert_select 'span.value','No',1
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
test "wrapped_sex_select" do
|
84
|
+
@user = SimplyHelpful::User.new
|
85
|
+
response = HTML::Document.new(
|
86
|
+
wrapped_sex_select(:user, :sex)).root
|
87
|
+
#<div class="sex field_wrapper">
|
88
|
+
#<label for="user_sex">Sex</label><select id="user_sex" name="user[sex]"><option value="M">male</option>
|
89
|
+
#<option value="F">female</option></select>
|
90
|
+
#</div><!-- class='sex' -->
|
91
|
+
assert_select response, 'div.sex.field_wrapper', 1 do
|
92
|
+
assert_select 'label[for=user_sex]','Sex',1
|
93
|
+
assert_select "select#user_sex[name='user[sex]']" do
|
94
|
+
assert_select 'option[value=M]', 'male'
|
95
|
+
assert_select 'option[value=F]', 'female'
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
test "wrapped_gender_select" do
|
101
|
+
@user = SimplyHelpful::User.new
|
102
|
+
response = HTML::Document.new(
|
103
|
+
wrapped_gender_select(:user, :sex)).root
|
104
|
+
#<div class="sex field_wrapper">
|
105
|
+
#<label for="user_sex">Sex</label><select id="user_sex" name="user[sex]"><option value="M">male</option>
|
106
|
+
#<option value="F">female</option></select>
|
107
|
+
#</div><!-- class='sex' -->
|
108
|
+
assert_select response, 'div.sex.field_wrapper', 1 do
|
109
|
+
assert_select 'label[for=user_sex]','Sex',1
|
110
|
+
assert_select "select#user_sex[name='user[sex]']" do
|
111
|
+
assert_select 'option[value=M]', 'male'
|
112
|
+
assert_select 'option[value=F]', 'female'
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
test "wrapped_date_text_field" do
|
118
|
+
@user = SimplyHelpful::User.new
|
119
|
+
response = HTML::Document.new(
|
120
|
+
wrapped_date_text_field(:user,:dob, :object => @user)).root
|
121
|
+
#<div class="dob field_wrapper">
|
122
|
+
#<label for="user_dob">Dob</label><input id="user_dob" name="user[dob]" size="30" type="text" />
|
123
|
+
#</div><!-- class='dob' -->
|
124
|
+
assert_select response, 'div.dob.field_wrapper', 1 do
|
125
|
+
assert_select 'label[for=user_dob]','Dob', 1
|
126
|
+
assert_select "input#user_dob[name='user[dob]']"
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
test "wrapped_date_text_field with invalid dob" do
|
131
|
+
@user = SimplyHelpful::User.new
|
132
|
+
@user.dob = "07181989"
|
133
|
+
# will raise ...
|
134
|
+
#ArgumentError: invalid date
|
135
|
+
# /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/date.rb:752:in `new'
|
136
|
+
# lib/simply_helpful/form_helper.rb:67:in `date_text_field'
|
137
|
+
# lib/simply_helpful/form_helper.rb:123:in `send'
|
138
|
+
# lib/simply_helpful/form_helper.rb:123:in `method_missing'
|
139
|
+
# lib/simply_helpful/form_helper.rb:19:in `field_wrapper'
|
140
|
+
# lib/simply_helpful/form_helper.rb:114:in `method_missing'
|
141
|
+
# /test/unit/helpful/form_helper_test.rb:134:in `test_wrapped_date_text_field_with_invalid_dob'
|
142
|
+
#
|
143
|
+
response = HTML::Document.new(
|
144
|
+
wrapped_date_text_field(:user,:dob, :object => @user)).root
|
145
|
+
#<div class="dob field_wrapper">
|
146
|
+
#<label for="user_dob">Dob</label><input id="user_dob" name="user[dob]" size="30" type="text" />
|
147
|
+
#</div><!-- class='dob' -->
|
148
|
+
assert_select response, 'div.dob.field_wrapper', 1 do
|
149
|
+
assert_select 'label[for=user_dob]','Dob', 1
|
150
|
+
assert_select "input#user_dob[name='user[dob]']"
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
test "wrapped_y_n_dk_select" do
|
155
|
+
@user = SimplyHelpful::User.new
|
156
|
+
response = HTML::Document.new(
|
157
|
+
wrapped_y_n_dk_select(:user, :yndk)).root
|
158
|
+
#<div class="yndk field_wrapper">
|
159
|
+
#<label for="user_yndk">Yndk</label><select id="user_yndk" name="user[yndk]"><option value="1">Yes</option>
|
160
|
+
#<option value="2">No</option>
|
161
|
+
#<option value="999">Don't Know</option></select>
|
162
|
+
#</div><!-- class='yndk' -->
|
163
|
+
assert_select response, 'div.yndk.field_wrapper', 1 do
|
164
|
+
assert_select 'label[for=user_yndk]','Yndk',1
|
165
|
+
assert_select "select#user_yndk[name='user[yndk]']" do
|
166
|
+
assert_select 'option[value=1]', 'Yes'
|
167
|
+
assert_select 'option[value=2]', 'No'
|
168
|
+
assert_select 'option[value=999]', "Don't Know"
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
test "wrapped_yndk_select" do
|
174
|
+
@user = SimplyHelpful::User.new
|
175
|
+
response = HTML::Document.new(
|
176
|
+
wrapped_yndk_select(:user, :yndk)).root
|
177
|
+
#<div class="yndk field_wrapper">
|
178
|
+
#<label for="user_yndk">Yndk</label><select id="user_yndk" name="user[yndk]"><option value="1">Yes</option>
|
179
|
+
#<option value="2">No</option>
|
180
|
+
#<option value="999">Don't Know</option></select>
|
181
|
+
#</div><!-- class='yndk' -->
|
182
|
+
assert_select response, 'div.yndk.field_wrapper', 1 do
|
183
|
+
assert_select 'label[for=user_yndk]','Yndk',1
|
184
|
+
assert_select "select#user_yndk[name='user[yndk]']" do
|
185
|
+
assert_select 'option[value=1]', 'Yes'
|
186
|
+
assert_select 'option[value=2]', 'No'
|
187
|
+
assert_select 'option[value=999]', "Don't Know"
|
188
|
+
end
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
end
|
@@ -0,0 +1,121 @@
|
|
1
|
+
#require File.dirname(__FILE__) + '/../../test_helper'
|
2
|
+
require 'test_helper'
|
3
|
+
|
4
|
+
class SimplyHelpful::RailsHelpersTest < ActionView::TestCase
|
5
|
+
|
6
|
+
def flash
|
7
|
+
{:notice => "Hello There"}
|
8
|
+
end
|
9
|
+
# delegate :flash, :to => :controller
|
10
|
+
|
11
|
+
test "form_link_to with block" do
|
12
|
+
response = HTML::Document.new(
|
13
|
+
form_link_to('mytitle','/myurl') do
|
14
|
+
hidden_field_tag('apple','orange')
|
15
|
+
end).root
|
16
|
+
#<form class='form_link_to' action='/myurl' method='post'>
|
17
|
+
#<input id="apple" name="apple" type="hidden" value="orange" />
|
18
|
+
#<input type="submit" value="mytitle" />
|
19
|
+
#</form>
|
20
|
+
assert_select response, 'form.form_link_to[action=/myurl]', 1 do
|
21
|
+
assert_select 'input', 2
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
test "form_link_to without block" do
|
26
|
+
response = HTML::Document.new(form_link_to('mytitle','/myurl')).root
|
27
|
+
assert_select response, 'form.form_link_to[action=/myurl]', 1 do
|
28
|
+
assert_select 'input', 1
|
29
|
+
end
|
30
|
+
#<form class="form_link_to" action="/myurl" method="post">
|
31
|
+
#<input type="submit" value="mytitle" />
|
32
|
+
#</form>
|
33
|
+
end
|
34
|
+
|
35
|
+
test "destroy_link_to with block" do
|
36
|
+
response = HTML::Document.new(
|
37
|
+
destroy_link_to('mytitle','/myurl') do
|
38
|
+
hidden_field_tag('apple','orange')
|
39
|
+
end).root
|
40
|
+
#<form class="destroy_link_to" action="/myurl" method="post">
|
41
|
+
#<div style="margin:0;padding:0;display:inline"><input name="_method" type="hidden" value="delete" /></div>
|
42
|
+
#<input id="apple" name="apple" type="hidden" value="orange" /><input type="submit" value="mytitle" />
|
43
|
+
#</form>
|
44
|
+
assert_select response, 'form.destroy_link_to[action=/myurl]', 1 do
|
45
|
+
assert_select 'div', 1 do
|
46
|
+
assert_select 'input[name=_method][value=delete]',1
|
47
|
+
end
|
48
|
+
assert_select 'input', 3
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
test "destroy_link_to without block" do
|
53
|
+
response = HTML::Document.new(destroy_link_to('mytitle','/myurl')).root
|
54
|
+
#<form class="destroy_link_to" action="/myurl" method="post">
|
55
|
+
#<div style="margin:0;padding:0;display:inline"><input name="_method" type="hidden" value="delete" /></div>
|
56
|
+
#<input type="submit" value="mytitle" />
|
57
|
+
#</form>
|
58
|
+
assert_select response, 'form.destroy_link_to[action=/myurl]', 1 do
|
59
|
+
assert_select 'div', 1 do
|
60
|
+
assert_select 'input[name=_method][value=delete]',1
|
61
|
+
end
|
62
|
+
assert_select 'input', 2
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
test "button_link_to without block" do
|
67
|
+
response = HTML::Document.new(button_link_to('mytitle','/myurl')).root
|
68
|
+
assert_select response, 'a[href=/myurl]', 1 do
|
69
|
+
assert_select 'button[type=button]', 1
|
70
|
+
end
|
71
|
+
#<a href="/myurl" style="text-decoration:none;"><button type="button">mytitle</button></a>
|
72
|
+
end
|
73
|
+
|
74
|
+
test "aws_image_tag" do
|
75
|
+
response = HTML::Document.new(
|
76
|
+
aws_image_tag('myimage')
|
77
|
+
).root
|
78
|
+
bucket = ( defined?(RAILS_APP_NAME) && RAILS_APP_NAME ) || 'ccls'
|
79
|
+
#<img alt="myimage" src="http://s3.amazonaws.com/ccls/images/myimage" />
|
80
|
+
assert_select response, "img[src=http://s3.amazonaws.com/#{bucket}/images/myimage]", 1
|
81
|
+
end
|
82
|
+
|
83
|
+
test "flasher" do
|
84
|
+
response = HTML::Document.new(
|
85
|
+
flasher
|
86
|
+
).root
|
87
|
+
#<p class="flash" id="notice">Hello There</p>
|
88
|
+
#<noscript>
|
89
|
+
#<p id="noscript" class="flash">Javascript is required for this site to be fully functional.</p>
|
90
|
+
#</noscript>
|
91
|
+
assert_select response, 'p#notice.flash'
|
92
|
+
assert_select response, 'noscript' do
|
93
|
+
assert_select 'p#noscript.flash'
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
test "javascripts" do
|
98
|
+
assert_nil @javascripts
|
99
|
+
javascripts('myjavascript')
|
100
|
+
assert @javascripts.include?('myjavascript')
|
101
|
+
assert_equal 1, @javascripts.length
|
102
|
+
javascripts('myjavascript')
|
103
|
+
assert_equal 1, @javascripts.length
|
104
|
+
#<script src="/javascripts/myjavascript.js" type="text/javascript"></script>
|
105
|
+
response = HTML::Document.new( @content_for_head).root
|
106
|
+
assert_select response, 'script[src=/javascripts/myjavascript.js]'
|
107
|
+
end
|
108
|
+
|
109
|
+
test "stylesheets" do
|
110
|
+
assert_nil @stylesheets
|
111
|
+
stylesheets('mystylesheet')
|
112
|
+
assert @stylesheets.include?('mystylesheet')
|
113
|
+
assert_equal 1, @stylesheets.length
|
114
|
+
stylesheets('mystylesheet')
|
115
|
+
assert_equal 1, @stylesheets.length
|
116
|
+
#<link href="/stylesheets/mystylesheet.css" media="screen" rel="stylesheet" type="text/css" />
|
117
|
+
response = HTML::Document.new( @content_for_head).root
|
118
|
+
assert_select response, 'link[href=/stylesheets/mystylesheet.css]'
|
119
|
+
end
|
120
|
+
|
121
|
+
end
|
metadata
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jakewendt-simply_helpful
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 2
|
8
|
+
- 2
|
9
|
+
- 14
|
10
|
+
version: 2.2.14
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- George 'Jake' Wendt
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-08-10 00:00:00 -07:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: rails
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 7
|
30
|
+
segments:
|
31
|
+
- 2
|
32
|
+
version: "2"
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: jakewendt-rails_extension
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
hash: 3
|
44
|
+
segments:
|
45
|
+
- 0
|
46
|
+
version: "0"
|
47
|
+
type: :runtime
|
48
|
+
version_requirements: *id002
|
49
|
+
description: longer description of your gem
|
50
|
+
email: github@jake.otherinbox.com
|
51
|
+
executables: []
|
52
|
+
|
53
|
+
extensions: []
|
54
|
+
|
55
|
+
extra_rdoc_files:
|
56
|
+
- README.rdoc
|
57
|
+
files:
|
58
|
+
- generators/simply_helpful/USAGE
|
59
|
+
- generators/simply_helpful/simply_helpful_generator.rb
|
60
|
+
- generators/simply_helpful/templates/autotest_simply_helpful.rb
|
61
|
+
- generators/simply_helpful/templates/javascripts/simply_helpful.js
|
62
|
+
- generators/simply_helpful/templates/simply_helpful.rake
|
63
|
+
- generators/simply_helpful/templates/stylesheets/simply_helpful.css
|
64
|
+
- lib/jakewendt-simply_helpful.rb
|
65
|
+
- lib/simply_helpful.rb
|
66
|
+
- lib/simply_helpful/autotest.rb
|
67
|
+
- lib/simply_helpful/form_helper.rb
|
68
|
+
- lib/simply_helpful/rails_helpers.rb
|
69
|
+
- lib/simply_helpful/tasks.rb
|
70
|
+
- lib/simply_helpful/test_tasks.rb
|
71
|
+
- lib/tasks/database.rake
|
72
|
+
- lib/tasks/rcov.rake
|
73
|
+
- rails/init.rb
|
74
|
+
- README.rdoc
|
75
|
+
- test/app/controllers/application_controller.rb
|
76
|
+
- test/app/controllers/home_controller.rb
|
77
|
+
- test/config/routes.rb
|
78
|
+
- test/unit/helpful/form_helper_test.rb
|
79
|
+
- test/unit/helpful/rails_helpers_test.rb
|
80
|
+
has_rdoc: true
|
81
|
+
homepage: http://github.com/jakewendt/simply_helpful
|
82
|
+
licenses: []
|
83
|
+
|
84
|
+
post_install_message:
|
85
|
+
rdoc_options: []
|
86
|
+
|
87
|
+
require_paths:
|
88
|
+
- lib
|
89
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
90
|
+
none: false
|
91
|
+
requirements:
|
92
|
+
- - ">="
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
hash: 3
|
95
|
+
segments:
|
96
|
+
- 0
|
97
|
+
version: "0"
|
98
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
99
|
+
none: false
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
hash: 3
|
104
|
+
segments:
|
105
|
+
- 0
|
106
|
+
version: "0"
|
107
|
+
requirements: []
|
108
|
+
|
109
|
+
rubyforge_project:
|
110
|
+
rubygems_version: 1.6.2
|
111
|
+
signing_key:
|
112
|
+
specification_version: 3
|
113
|
+
summary: one-line summary of your gem
|
114
|
+
test_files:
|
115
|
+
- test/app/controllers/application_controller.rb
|
116
|
+
- test/app/controllers/home_controller.rb
|
117
|
+
- test/config/routes.rb
|
118
|
+
- test/unit/helpful/form_helper_test.rb
|
119
|
+
- test/unit/helpful/rails_helpers_test.rb
|