merb-helpers 0.9.8
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/LICENSE +20 -0
- data/README +180 -0
- data/Rakefile +77 -0
- data/TODO +5 -0
- data/lib/merb-helpers.rb +38 -0
- data/lib/merb-helpers/core_ext.rb +57 -0
- data/lib/merb-helpers/core_ext/numeric.rb +388 -0
- data/lib/merb-helpers/date_time_formatting.rb +127 -0
- data/lib/merb-helpers/date_time_helpers.rb +190 -0
- data/lib/merb-helpers/form/builder.rb +410 -0
- data/lib/merb-helpers/form/helpers.rb +448 -0
- data/lib/merb-helpers/form_helpers.rb +24 -0
- data/lib/merb-helpers/tag_helpers.rb +61 -0
- data/lib/merb-helpers/text_helpers.rb +61 -0
- data/lib/merb-helpers/time_dsl.rb +59 -0
- data/spec/core_ext_spec.rb +19 -0
- data/spec/fixture/app/controllers/application.rb +4 -0
- data/spec/fixture/app/controllers/bound_check_box.rb +2 -0
- data/spec/fixture/app/controllers/bound_file_field.rb +2 -0
- data/spec/fixture/app/controllers/bound_hidden_field.rb +2 -0
- data/spec/fixture/app/controllers/bound_option_tag.rb +2 -0
- data/spec/fixture/app/controllers/bound_password_field.rb +2 -0
- data/spec/fixture/app/controllers/bound_radio_button.rb +2 -0
- data/spec/fixture/app/controllers/bound_radio_group.rb +2 -0
- data/spec/fixture/app/controllers/bound_select.rb +2 -0
- data/spec/fixture/app/controllers/bound_text_area.rb +2 -0
- data/spec/fixture/app/controllers/bound_text_field.rb +2 -0
- data/spec/fixture/app/controllers/button.rb +2 -0
- data/spec/fixture/app/controllers/check_box.rb +2 -0
- data/spec/fixture/app/controllers/custom_builder.rb +2 -0
- data/spec/fixture/app/controllers/delete_button.rb +2 -0
- data/spec/fixture/app/controllers/exceptions.rb +25 -0
- data/spec/fixture/app/controllers/field_set.rb +2 -0
- data/spec/fixture/app/controllers/fields_for.rb +3 -0
- data/spec/fixture/app/controllers/file_field.rb +2 -0
- data/spec/fixture/app/controllers/foo.rb +23 -0
- data/spec/fixture/app/controllers/form.rb +2 -0
- data/spec/fixture/app/controllers/form_for.rb +2 -0
- data/spec/fixture/app/controllers/hidden_field.rb +2 -0
- data/spec/fixture/app/controllers/label.rb +3 -0
- data/spec/fixture/app/controllers/numeric_ext.rb +3 -0
- data/spec/fixture/app/controllers/option_tag.rb +2 -0
- data/spec/fixture/app/controllers/password_field.rb +2 -0
- data/spec/fixture/app/controllers/radio_button.rb +2 -0
- data/spec/fixture/app/controllers/radio_group.rb +2 -0
- data/spec/fixture/app/controllers/select.rb +2 -0
- data/spec/fixture/app/controllers/specs_controller.rb +11 -0
- data/spec/fixture/app/controllers/submit.rb +2 -0
- data/spec/fixture/app/controllers/tag_helper.rb +21 -0
- data/spec/fixture/app/controllers/text_area.rb +2 -0
- data/spec/fixture/app/controllers/text_field.rb +3 -0
- data/spec/fixture/app/helpers/global_helpers.rb +8 -0
- data/spec/fixture/app/models/fake_dm_model.rb +25 -0
- data/spec/fixture/app/models/first_generic_fake_model.rb +57 -0
- data/spec/fixture/app/models/second_generic_fake_model.rb +18 -0
- data/spec/fixture/app/models/third_generic_fake_model.rb +3 -0
- data/spec/fixture/app/views/bound_check_box_specs/basic.html.erb +4 -0
- data/spec/fixture/app/views/bound_check_box_specs/checked.html.erb +4 -0
- data/spec/fixture/app/views/bound_check_box_specs/errors.html.erb +4 -0
- data/spec/fixture/app/views/bound_check_box_specs/label.html.erb +3 -0
- data/spec/fixture/app/views/bound_check_box_specs/on_and_off.html.erb +3 -0
- data/spec/fixture/app/views/bound_check_box_specs/raise_value_error.html.erb +3 -0
- data/spec/fixture/app/views/bound_file_field_specs/additional_attributes.html.erb +3 -0
- data/spec/fixture/app/views/bound_file_field_specs/takes_string.html.erb +3 -0
- data/spec/fixture/app/views/bound_file_field_specs/with_label.html.erb +3 -0
- data/spec/fixture/app/views/bound_hidden_field_specs/basic.html.erb +3 -0
- data/spec/fixture/app/views/bound_hidden_field_specs/errors.html.erb +3 -0
- data/spec/fixture/app/views/bound_hidden_field_specs/hidden_error.html.erb +3 -0
- data/spec/fixture/app/views/bound_hidden_field_specs/label.html.erb +3 -0
- data/spec/fixture/app/views/bound_option_tag_specs/grouped.html.erb +3 -0
- data/spec/fixture/app/views/bound_option_tag_specs/nested.html.erb +3 -0
- data/spec/fixture/app/views/bound_option_tag_specs/text_and_value.html.erb +4 -0
- data/spec/fixture/app/views/bound_password_field_specs/attributes.html.erb +3 -0
- data/spec/fixture/app/views/bound_password_field_specs/basic.html.erb +3 -0
- data/spec/fixture/app/views/bound_password_field_specs/label.html.erb +3 -0
- data/spec/fixture/app/views/bound_radio_button_specs/basic.html.erb +3 -0
- data/spec/fixture/app/views/bound_radio_group_specs/basic.html.erb +3 -0
- data/spec/fixture/app/views/bound_radio_group_specs/hashes.html.erb +3 -0
- data/spec/fixture/app/views/bound_radio_group_specs/mixed.html.erb +4 -0
- data/spec/fixture/app/views/bound_radio_group_specs/override_id.html.erb +3 -0
- data/spec/fixture/app/views/bound_select_specs/basic.html.erb +3 -0
- data/spec/fixture/app/views/bound_select_specs/blank.html.erb +3 -0
- data/spec/fixture/app/views/bound_select_specs/multiple.html.erb +3 -0
- data/spec/fixture/app/views/bound_select_specs/prompt.html.erb +3 -0
- data/spec/fixture/app/views/bound_select_specs/with_options.html.erb +3 -0
- data/spec/fixture/app/views/bound_select_specs/with_options_with_blank.html.erb +3 -0
- data/spec/fixture/app/views/bound_text_area_specs/basic.html.erb +3 -0
- data/spec/fixture/app/views/bound_text_field_specs/basic.html.erb +3 -0
- data/spec/fixture/app/views/button_specs/button_with_label.html.erb +1 -0
- data/spec/fixture/app/views/button_specs/button_with_values.html.erb +1 -0
- data/spec/fixture/app/views/button_specs/disabled_button.html.erb +1 -0
- data/spec/fixture/app/views/check_box_specs/basic.html.erb +1 -0
- data/spec/fixture/app/views/check_box_specs/boolean.html.erb +1 -0
- data/spec/fixture/app/views/check_box_specs/disabled.html.erb +1 -0
- data/spec/fixture/app/views/check_box_specs/label.html.erb +1 -0
- data/spec/fixture/app/views/check_box_specs/on_off_is_boolean.html.erb +1 -0
- data/spec/fixture/app/views/check_box_specs/raise_unless_both_on_and_off.html.erb +2 -0
- data/spec/fixture/app/views/check_box_specs/raises_error_if_not_boolean.html.erb +1 -0
- data/spec/fixture/app/views/check_box_specs/raises_error_if_on_off_and_boolean_false.html.erb +1 -0
- data/spec/fixture/app/views/check_box_specs/simple.html.erb +1 -0
- data/spec/fixture/app/views/check_box_specs/to_string.html.erb +8 -0
- data/spec/fixture/app/views/check_box_specs/unchecked.html.erb +2 -0
- data/spec/fixture/app/views/custom_builder_specs/everything.html.erb +10 -0
- data/spec/fixture/app/views/delete_button_specs/delete_with_explicit_url.html.erb +1 -0
- data/spec/fixture/app/views/delete_button_specs/delete_with_extra_params.html.erb +1 -0
- data/spec/fixture/app/views/delete_button_specs/delete_with_label.html.erb +1 -0
- data/spec/fixture/app/views/delete_button_specs/simple_delete.html.erb +1 -0
- data/spec/fixture/app/views/exeptions/client_error.html.erb +37 -0
- data/spec/fixture/app/views/exeptions/internal_server_error.html.erb +216 -0
- data/spec/fixture/app/views/exeptions/not_acceptable.html.erb +38 -0
- data/spec/fixture/app/views/exeptions/not_found.html.erb +40 -0
- data/spec/fixture/app/views/fields_for_specs/basic.html.erb +3 -0
- data/spec/fixture/app/views/fields_for_specs/midstream.html.erb +7 -0
- data/spec/fixture/app/views/fields_for_specs/nil.html.erb +3 -0
- data/spec/fixture/app/views/fieldset_specs/legend.html.erb +3 -0
- data/spec/fixture/app/views/file_field_specs/disabled.html.erb +1 -0
- data/spec/fixture/app/views/file_field_specs/makes_multipart.html.erb +3 -0
- data/spec/fixture/app/views/file_field_specs/with_label.html.erb +1 -0
- data/spec/fixture/app/views/file_field_specs/with_values.html.erb +1 -0
- data/spec/fixture/app/views/foo/bar.html.erb +0 -0
- data/spec/fixture/app/views/form_for_specs/basic.html.erb +3 -0
- data/spec/fixture/app/views/form_specs/create_a_form.html.erb +3 -0
- data/spec/fixture/app/views/form_specs/create_a_multipart_form.html.erb +3 -0
- data/spec/fixture/app/views/form_specs/fake_delete_if_set.html.erb +3 -0
- data/spec/fixture/app/views/form_specs/fake_put_if_set.html.erb +3 -0
- data/spec/fixture/app/views/form_specs/get_if_set.html.erb +3 -0
- data/spec/fixture/app/views/form_specs/post_by_default.html.erb +3 -0
- data/spec/fixture/app/views/form_specs/resourceful_form.html.erb +3 -0
- data/spec/fixture/app/views/hidden_field_specs/basic.html.erb +1 -0
- data/spec/fixture/app/views/hidden_field_specs/disabled.html.erb +1 -0
- data/spec/fixture/app/views/hidden_field_specs/label.html.erb +1 -0
- data/spec/fixture/app/views/label_specs/basic.html.erb +1 -0
- data/spec/fixture/app/views/layout/application.html.erb +11 -0
- data/spec/fixture/app/views/numeric_ext_specs/minutes_to_hours.html.erb +1 -0
- data/spec/fixture/app/views/numeric_ext_specs/to_concurrency_default.html.erb +1 -0
- data/spec/fixture/app/views/numeric_ext_specs/two_digits.html.erb +1 -0
- data/spec/fixture/app/views/option_tag_specs/array.html.erb +1 -0
- data/spec/fixture/app/views/option_tag_specs/clean.html.erb +1 -0
- data/spec/fixture/app/views/option_tag_specs/collection.html.erb +1 -0
- data/spec/fixture/app/views/option_tag_specs/multiple_selects.html.erb +1 -0
- data/spec/fixture/app/views/option_tag_specs/no_extra_attributes.html.erb +1 -0
- data/spec/fixture/app/views/option_tag_specs/optgroups.html.erb +1 -0
- data/spec/fixture/app/views/option_tag_specs/selected.html.erb +1 -0
- data/spec/fixture/app/views/option_tag_specs/with_blank.html.erb +1 -0
- data/spec/fixture/app/views/option_tag_specs/with_prompt.html.erb +1 -0
- data/spec/fixture/app/views/password_field_specs/basic.html.erb +1 -0
- data/spec/fixture/app/views/password_field_specs/disabled.html.erb +1 -0
- data/spec/fixture/app/views/radio_button_specs/basic.html.erb +1 -0
- data/spec/fixture/app/views/radio_button_specs/disabled.html.erb +1 -0
- data/spec/fixture/app/views/radio_button_specs/label.html.erb +1 -0
- data/spec/fixture/app/views/radio_group_specs/attributes.html.erb +1 -0
- data/spec/fixture/app/views/radio_group_specs/basic.html.erb +1 -0
- data/spec/fixture/app/views/radio_group_specs/hash.html.erb +1 -0
- data/spec/fixture/app/views/radio_group_specs/specific_attributes.html.erb +1 -0
- data/spec/fixture/app/views/select_specs/blank.html.erb +1 -0
- data/spec/fixture/app/views/select_specs/multiple.html.erb +1 -0
- data/spec/fixture/app/views/submit_specs/disabled_submit.html.erb +1 -0
- data/spec/fixture/app/views/submit_specs/submit_with_label.html.erb +1 -0
- data/spec/fixture/app/views/submit_specs/submit_with_values.html.erb +1 -0
- data/spec/fixture/app/views/tag_helper/nested_tags.html.erb +5 -0
- data/spec/fixture/app/views/tag_helper/tag_with_attributes.html.erb +1 -0
- data/spec/fixture/app/views/tag_helper/tag_with_content.html.erb +1 -0
- data/spec/fixture/app/views/tag_helper/tag_with_content_in_the_block.html.erb +3 -0
- data/spec/fixture/app/views/text_area_specs/basic.html.erb +1 -0
- data/spec/fixture/app/views/text_area_specs/disabled.html.erb +1 -0
- data/spec/fixture/app/views/text_area_specs/label.html.erb +1 -0
- data/spec/fixture/app/views/text_area_specs/nil.html.erb +1 -0
- data/spec/fixture/app/views/text_field_specs/basic.html.erb +1 -0
- data/spec/fixture/app/views/text_field_specs/class.html.erb +1 -0
- data/spec/fixture/app/views/text_field_specs/disabled.html.erb +1 -0
- data/spec/fixture/app/views/text_field_specs/label.html.erb +1 -0
- data/spec/fixture/config/environments/development.rb +6 -0
- data/spec/fixture/config/environments/production.rb +5 -0
- data/spec/fixture/config/environments/test.rb +6 -0
- data/spec/fixture/config/init.rb +46 -0
- data/spec/fixture/config/rack.rb +11 -0
- data/spec/fixture/config/router.rb +36 -0
- data/spec/fixture/log/merb.main.pid +1 -0
- data/spec/fixture/log/merb_test.log +624 -0
- data/spec/fixture/public/images/merb.jpg +0 -0
- data/spec/fixture/public/merb.fcgi +4 -0
- data/spec/fixture/public/stylesheets/master.css +119 -0
- data/spec/merb_helpers_config_spec.rb +82 -0
- data/spec/merb_helpers_date_time_spec.rb +257 -0
- data/spec/merb_helpers_form_spec.rb +1266 -0
- data/spec/merb_helpers_tag_helper_spec.rb +46 -0
- data/spec/merb_helpers_text_spec.rb +67 -0
- data/spec/numeric_extlib_spec.rb +135 -0
- data/spec/ordinalize_spec.rb +51 -0
- data/spec/spec_helper.rb +149 -0
- data/spec/time_dsl_spec.rb +43 -0
- metadata +303 -0
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
module Merb
|
|
2
|
+
module Helpers
|
|
3
|
+
module Tag
|
|
4
|
+
# Creates a generic HTML tag. You can invoke it a variety of ways.
|
|
5
|
+
#
|
|
6
|
+
# tag :div
|
|
7
|
+
# # <div></div>
|
|
8
|
+
#
|
|
9
|
+
# tag :div, 'content'
|
|
10
|
+
# # <div>content</div>
|
|
11
|
+
#
|
|
12
|
+
# tag :div, :class => 'class'
|
|
13
|
+
# # <div class="class"></div>
|
|
14
|
+
#
|
|
15
|
+
# tag :div, 'content', :class => 'class'
|
|
16
|
+
# # <div class="class">content</div>
|
|
17
|
+
#
|
|
18
|
+
# tag :div do
|
|
19
|
+
# 'content'
|
|
20
|
+
# end
|
|
21
|
+
# # <div>content</div>
|
|
22
|
+
#
|
|
23
|
+
# tag :div, :class => 'class' do
|
|
24
|
+
# 'content'
|
|
25
|
+
# end
|
|
26
|
+
# # <div class="class">content</div>
|
|
27
|
+
#
|
|
28
|
+
def tag(name, contents = nil, attrs = {}, &block)
|
|
29
|
+
attrs, contents = contents, nil if contents.is_a?(Hash)
|
|
30
|
+
contents = capture(&block) if block_given?
|
|
31
|
+
open_tag(name, attrs) + contents.to_s + close_tag(name)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
# Creates the opening tag with attributes for the provided +name+
|
|
35
|
+
# attrs is a hash where all members will be mapped to key="value"
|
|
36
|
+
#
|
|
37
|
+
# Note: This tag will need to be closed
|
|
38
|
+
def open_tag(name, attrs = nil)
|
|
39
|
+
"<#{name}#{' ' + attrs.to_html_attributes unless attrs.blank?}>"
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# Creates a closing tag
|
|
43
|
+
def close_tag(name)
|
|
44
|
+
"</#{name}>"
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
# Creates a self closing tag. Like <br/> or <img src="..."/>
|
|
48
|
+
#
|
|
49
|
+
# +name+ : the name of the tag to create
|
|
50
|
+
# +attrs+ : a hash where all members will be mapped to key="value"
|
|
51
|
+
def self_closing_tag(name, attrs = nil)
|
|
52
|
+
"<#{name}#{' ' + attrs.to_html_attributes if attrs && !attrs.empty?}/>"
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
class Merb::Controller
|
|
60
|
+
include Merb::Helpers::Tag
|
|
61
|
+
end
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
module Merb::Helpers::Text
|
|
2
|
+
# Allows you to cycle through elements in an array
|
|
3
|
+
#
|
|
4
|
+
# ==== Parameters
|
|
5
|
+
# values<Array>:: Array of objects to cycle through
|
|
6
|
+
# values<Hash>:: Last element of array can be a hash with the key of
|
|
7
|
+
# :name to specify the name of the cycle
|
|
8
|
+
#
|
|
9
|
+
# ==== Returns
|
|
10
|
+
# String
|
|
11
|
+
#
|
|
12
|
+
# ==== Notes
|
|
13
|
+
# * Default name is :default
|
|
14
|
+
#
|
|
15
|
+
# ==== Example
|
|
16
|
+
# <%= 5.times { cycle("odd! ","even! "} %>
|
|
17
|
+
#
|
|
18
|
+
# Generates:
|
|
19
|
+
#
|
|
20
|
+
# odd! even! odd! even! odd!
|
|
21
|
+
def cycle(*values)
|
|
22
|
+
options = extract_options_from_args!(values) || {}
|
|
23
|
+
key = (options[:name] || :default).to_sym
|
|
24
|
+
(@cycle_positions ||= {})[key] ||= {:position => -1, :values => values}
|
|
25
|
+
unless values == @cycle_positions[key][:values]
|
|
26
|
+
@cycle_positions[key] = {:position => -1, :values => values}
|
|
27
|
+
end
|
|
28
|
+
current = @cycle_positions[key][:position]
|
|
29
|
+
@cycle_positions[key][:position] = current + 1
|
|
30
|
+
values.at( (current + 1) % values.length).to_s
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# Allows you to reset a cycle
|
|
34
|
+
#
|
|
35
|
+
# ==== Parameters
|
|
36
|
+
# name<Symbol|String>:: Name of the cycle
|
|
37
|
+
#
|
|
38
|
+
# ==== Returns
|
|
39
|
+
# True if successful, otherwise nil
|
|
40
|
+
#
|
|
41
|
+
# ==== Notes
|
|
42
|
+
# * Default name is :default
|
|
43
|
+
#
|
|
44
|
+
# ==== Example
|
|
45
|
+
# <%= cycle("odd! ","even! ","what comes after even?") %>
|
|
46
|
+
# <%= cycle("odd! ","even! ","what comes after even?") %>
|
|
47
|
+
# <% reset_cycle %>
|
|
48
|
+
# <%= cycle("odd! ","even! ","what comes after even?") %>
|
|
49
|
+
#
|
|
50
|
+
# Generates:
|
|
51
|
+
#
|
|
52
|
+
# odd! even! odd!
|
|
53
|
+
def reset_cycle(name = :default)
|
|
54
|
+
(@cycle_positions[name.to_sym] = nil) &&
|
|
55
|
+
true if @cycle_positions && @cycle_positions[name.to_sym]
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
class Merb::Controller
|
|
60
|
+
include Merb::Helpers::Text
|
|
61
|
+
end
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# Provides a a simple way of calling time units and to see the elapsed time between 2 moments
|
|
2
|
+
# ==== Examples
|
|
3
|
+
# 142.minutes => returns a value in seconds
|
|
4
|
+
# 7.days => returns a value in seconds
|
|
5
|
+
# 1.week => returns a value in seconds
|
|
6
|
+
# 2.weeks.ago => returns a date
|
|
7
|
+
# 1.year.since(time) => returns a date
|
|
8
|
+
# 5.months.since(2.weeks.from_now) => returns a date
|
|
9
|
+
module TimeDSL
|
|
10
|
+
|
|
11
|
+
def second
|
|
12
|
+
self * 1
|
|
13
|
+
end
|
|
14
|
+
alias_method :seconds, :second
|
|
15
|
+
|
|
16
|
+
def minute
|
|
17
|
+
self * 60
|
|
18
|
+
end
|
|
19
|
+
alias_method :minutes, :minute
|
|
20
|
+
|
|
21
|
+
def hour
|
|
22
|
+
self * 3600
|
|
23
|
+
end
|
|
24
|
+
alias_method :hours, :hour
|
|
25
|
+
|
|
26
|
+
def day
|
|
27
|
+
self * 86400
|
|
28
|
+
end
|
|
29
|
+
alias_method :days, :day
|
|
30
|
+
|
|
31
|
+
def week
|
|
32
|
+
self * 604800
|
|
33
|
+
end
|
|
34
|
+
alias_method :weeks, :week
|
|
35
|
+
|
|
36
|
+
def month
|
|
37
|
+
self * 2592000
|
|
38
|
+
end
|
|
39
|
+
alias_method :months, :month
|
|
40
|
+
|
|
41
|
+
def year
|
|
42
|
+
self * 31471200
|
|
43
|
+
end
|
|
44
|
+
alias_method :years, :year
|
|
45
|
+
|
|
46
|
+
# Reads best without arguments: 10.minutes.ago
|
|
47
|
+
def ago(time = ::Time.now)
|
|
48
|
+
time - self
|
|
49
|
+
end
|
|
50
|
+
alias :until :ago
|
|
51
|
+
|
|
52
|
+
# Reads best with argument: 10.minutes.since(time)
|
|
53
|
+
def since(time = ::Time.now)
|
|
54
|
+
time + self
|
|
55
|
+
end
|
|
56
|
+
alias :from_now :since
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
Numeric.send :include, TimeDSL
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
|
2
|
+
|
|
3
|
+
describe "String" do
|
|
4
|
+
before :each do
|
|
5
|
+
@str = "This is a fairly long string to test with!"
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
it "should default to appending ..." do
|
|
9
|
+
@str.truncate(5).should == "Th..."
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
it "should default to a length of 30" do
|
|
13
|
+
@str.truncate().should == "This is a fairly long strin..."
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
it "should truncate to a given length with a given suffix" do
|
|
17
|
+
@str.truncate(15, "--more").should == "This is a--more"
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
class Exceptions < Application
|
|
2
|
+
|
|
3
|
+
attr_reader :handler
|
|
4
|
+
|
|
5
|
+
# handle NotFound exceptions (404)
|
|
6
|
+
|
|
7
|
+
def not_found
|
|
8
|
+
@handler = :not_found
|
|
9
|
+
render :format => :html
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
# handle NotAcceptable exceptions (406)
|
|
13
|
+
|
|
14
|
+
def not_acceptable
|
|
15
|
+
@handler = :not_acceptable
|
|
16
|
+
render "Handled by: not_acceptable"
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
# # Any client error (400 series)
|
|
20
|
+
def client_error
|
|
21
|
+
@handler = :client_error
|
|
22
|
+
render "Handled by: client_error"
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
class Foo < Application
|
|
2
|
+
|
|
3
|
+
def index
|
|
4
|
+
"index"
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
def bar
|
|
8
|
+
render
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def renders_tag
|
|
12
|
+
render
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def raise_conflict
|
|
16
|
+
raise Conflict
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def raise_not_acceptable
|
|
20
|
+
raise NotAcceptable
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
end
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# Helpers are tested going through the full stack.
|
|
2
|
+
# to keep things isolated each helper has its own controller subclass
|
|
3
|
+
# if you are working on a new helper, please consider creating
|
|
4
|
+
# a new spec controller subclass
|
|
5
|
+
#
|
|
6
|
+
# Remember that your helper spec views
|
|
7
|
+
# will be located in a folder named after the controller you use
|
|
8
|
+
|
|
9
|
+
class SpecController < Merb::Controller
|
|
10
|
+
layout nil
|
|
11
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
class TagHelper < Merb::Controller
|
|
2
|
+
def tag_with_content
|
|
3
|
+
@content = "Astral Projection ~ Dancing Galaxy"
|
|
4
|
+
|
|
5
|
+
render
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def tag_with_content_in_the_block
|
|
9
|
+
render
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def nested_tags
|
|
13
|
+
@content = "Astral Projection ~ In the Mix"
|
|
14
|
+
|
|
15
|
+
render
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def tag_with_attributes
|
|
19
|
+
render
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
class FakeDMModel
|
|
2
|
+
def self.properties
|
|
3
|
+
[FakeColumn.new(:baz, TrueClass),
|
|
4
|
+
FakeColumn.new(:bat, TrueClass)
|
|
5
|
+
]
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def new_record?
|
|
9
|
+
false
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def errors
|
|
13
|
+
FakeErrors.new(self)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def baz?
|
|
17
|
+
true
|
|
18
|
+
end
|
|
19
|
+
alias baz baz?
|
|
20
|
+
|
|
21
|
+
def bat?
|
|
22
|
+
false
|
|
23
|
+
end
|
|
24
|
+
alias bat bat?
|
|
25
|
+
end
|