merb-helpers 0.9.8
Sign up to get free protection for your applications and to get access to all the features.
- 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
Binary file
|
@@ -0,0 +1,119 @@
|
|
1
|
+
body {
|
2
|
+
font-family: Arial, Verdana, sans-serif;
|
3
|
+
font-size: 12px;
|
4
|
+
background-color: #fff;
|
5
|
+
}
|
6
|
+
* {
|
7
|
+
margin: 0px;
|
8
|
+
padding: 0px;
|
9
|
+
text-decoration: none;
|
10
|
+
}
|
11
|
+
html {
|
12
|
+
height: 100%;
|
13
|
+
margin-bottom: 1px;
|
14
|
+
}
|
15
|
+
#container {
|
16
|
+
width: 80%;
|
17
|
+
text-align: left;
|
18
|
+
background-color: #fff;
|
19
|
+
margin-right: auto;
|
20
|
+
margin-left: auto;
|
21
|
+
}
|
22
|
+
#header-container {
|
23
|
+
width: 100%;
|
24
|
+
padding-top: 15px;
|
25
|
+
}
|
26
|
+
#header-container h1, #header-container h2 {
|
27
|
+
margin-left: 6px;
|
28
|
+
margin-bottom: 6px;
|
29
|
+
}
|
30
|
+
.spacer {
|
31
|
+
width: 100%;
|
32
|
+
height: 15px;
|
33
|
+
}
|
34
|
+
hr {
|
35
|
+
border: 0px;
|
36
|
+
color: #ccc;
|
37
|
+
background-color: #cdcdcd;
|
38
|
+
height: 1px;
|
39
|
+
width: 100%;
|
40
|
+
text-align: left;
|
41
|
+
}
|
42
|
+
h1 {
|
43
|
+
font-size: 28px;
|
44
|
+
color: #c55;
|
45
|
+
background-color: #fff;
|
46
|
+
font-family: Arial, Verdana, sans-serif;
|
47
|
+
font-weight: 300;
|
48
|
+
}
|
49
|
+
h2 {
|
50
|
+
font-size: 15px;
|
51
|
+
color: #999;
|
52
|
+
font-family: Arial, Verdana, sans-serif;
|
53
|
+
font-weight: 300;
|
54
|
+
background-color: #fff;
|
55
|
+
}
|
56
|
+
h3 {
|
57
|
+
color: #4d9b12;
|
58
|
+
font-size: 15px;
|
59
|
+
text-align: left;
|
60
|
+
font-weight: 300;
|
61
|
+
padding: 5px;
|
62
|
+
margin-top: 5px;
|
63
|
+
}
|
64
|
+
|
65
|
+
#left-container {
|
66
|
+
float: left;
|
67
|
+
width: 250px;
|
68
|
+
background-color: #FFFFFF;
|
69
|
+
color: black;
|
70
|
+
}
|
71
|
+
|
72
|
+
#left-container h3 {
|
73
|
+
color: #c55;
|
74
|
+
}
|
75
|
+
|
76
|
+
#main-container {
|
77
|
+
margin: 5px 5px 5px 260px;
|
78
|
+
padding: 15px;
|
79
|
+
border-left: 1px solid silver;
|
80
|
+
min-height: 400px;
|
81
|
+
}
|
82
|
+
p {
|
83
|
+
color: #000;
|
84
|
+
background-color: #fff;
|
85
|
+
line-height: 20px;
|
86
|
+
padding: 5px;
|
87
|
+
}
|
88
|
+
a {
|
89
|
+
color: #4d9b12;
|
90
|
+
background-color: #fff;
|
91
|
+
text-decoration: none;
|
92
|
+
}
|
93
|
+
a:hover {
|
94
|
+
color: #4d9b12;
|
95
|
+
background-color: #fff;
|
96
|
+
text-decoration: underline;
|
97
|
+
}
|
98
|
+
#footer-container {
|
99
|
+
clear: both;
|
100
|
+
font-size: 12px;
|
101
|
+
font-family: Verdana, Arial, sans-serif;
|
102
|
+
}
|
103
|
+
.right {
|
104
|
+
float: right;
|
105
|
+
font-size: 100%;
|
106
|
+
margin-top: 5px;
|
107
|
+
color: #999;
|
108
|
+
background-color: #fff;
|
109
|
+
}
|
110
|
+
.left {
|
111
|
+
float: left;
|
112
|
+
font-size: 100%;
|
113
|
+
margin-top: 5px;
|
114
|
+
color: #999;
|
115
|
+
background-color: #fff;
|
116
|
+
}
|
117
|
+
#main-container ul {
|
118
|
+
margin-left: 3.0em;
|
119
|
+
}
|
@@ -0,0 +1,82 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
FIXTURES_DIR = File.dirname(__FILE__) + '/fixtures'
|
3
|
+
MERB_HELPERS_ROOT = File.dirname(__FILE__) + "/.."
|
4
|
+
|
5
|
+
describe "loading configuration" do
|
6
|
+
|
7
|
+
before :each do
|
8
|
+
unload_merb_helpers
|
9
|
+
end
|
10
|
+
|
11
|
+
after :all do
|
12
|
+
reload_merb_helpers
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should not have any helper available now" do
|
16
|
+
unload_merb_helpers
|
17
|
+
defined?(Merb::Helpers).should be_nil
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should load reload_merb_helpers" do
|
21
|
+
unload_merb_helpers
|
22
|
+
reload_merb_helpers
|
23
|
+
defined?(Merb::Helpers).should_not be_nil
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should load all helpers by default" do
|
27
|
+
reload_merb_helpers
|
28
|
+
defined?(Merb::Helpers).should_not be_nil
|
29
|
+
defined?(Merb::Helpers::Form).should_not be_nil
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should load all helpers by default" do
|
33
|
+
Merb::Plugins.should_receive(:config).any_number_of_times.and_return({})
|
34
|
+
reload_merb_helpers
|
35
|
+
defined?(Merb::Helpers).should_not be_nil
|
36
|
+
defined?(Merb::Helpers::DateAndTime).should_not be_nil
|
37
|
+
defined?(Merb::Helpers::Form)
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should only load the helpers specified in the config hash (if defined)" do
|
41
|
+
unload_merb_helpers
|
42
|
+
defined?(Merb::Helpers).should be_nil
|
43
|
+
defined?(Merb::Helpers::DateAndTime).should be_nil
|
44
|
+
Merb::Plugins.stub!(:config).and_return(:merb_helpers => {:include => "form_helpers"})
|
45
|
+
reload_merb_helpers
|
46
|
+
defined?(Merb::Helpers).should_not be_nil
|
47
|
+
defined?(Merb::Helpers::Form).should_not be_nil
|
48
|
+
defined?(Merb::Helpers::DateAndTime).should be_nil
|
49
|
+
|
50
|
+
unload_merb_helpers
|
51
|
+
defined?(Merb::Helpers).should be_nil
|
52
|
+
defined?(Merb::Helpers::DateAndTime).should be_nil
|
53
|
+
Merb::Plugins.stub!(:config).and_return(:merb_helpers => {:include => ["form_helpers", "date_time_helpers"]})
|
54
|
+
reload_merb_helpers
|
55
|
+
defined?(Merb::Helpers).should_not be_nil
|
56
|
+
defined?(Merb::Helpers::Form).should_not be_nil
|
57
|
+
defined?(Merb::Helpers::DateAndTime).should_not be_nil
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should load all helpers if the include hash is empty" do
|
61
|
+
unload_merb_helpers
|
62
|
+
defined?(Merb::Helpers).should be_nil
|
63
|
+
defined?(Merb::Helpers::DateAndTime).should be_nil
|
64
|
+
Merb::Plugins.stub!(:config).and_return(:merb_helpers => {:include => ""})
|
65
|
+
reload_merb_helpers
|
66
|
+
defined?(Merb::Helpers).should_not be_nil
|
67
|
+
defined?(Merb::Helpers::Form).should_not be_nil
|
68
|
+
defined?(Merb::Helpers::DateAndTime).should_not be_nil
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should load helpers if the plugin conf is defined but the include pair is missing" do
|
72
|
+
unload_merb_helpers
|
73
|
+
defined?(Merb::Helpers).should be_nil
|
74
|
+
defined?(Merb::Helpers::DateAndTime).should be_nil
|
75
|
+
Merb::Plugins.stub!(:config).and_return(:merb_helpers => {})
|
76
|
+
reload_merb_helpers
|
77
|
+
defined?(Merb::Helpers).should_not be_nil
|
78
|
+
defined?(Merb::Helpers::Form).should_not be_nil
|
79
|
+
defined?(Merb::Helpers::DateAndTime).should_not be_nil
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
@@ -0,0 +1,257 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe "relative_date" do
|
4
|
+
include Merb::Helpers::DateAndTime
|
5
|
+
|
6
|
+
before :each do
|
7
|
+
Time.stub!(:now).and_return(Time.utc(2007, 6, 1, 11))
|
8
|
+
end
|
9
|
+
|
10
|
+
it "Should show today" do
|
11
|
+
relative_date(Time.now.utc).should == "today"
|
12
|
+
end
|
13
|
+
|
14
|
+
it "Should show yesterday" do
|
15
|
+
relative_date(1.day.ago.utc).should == 'yesterday'
|
16
|
+
end
|
17
|
+
|
18
|
+
it "Should show tomorrow" do
|
19
|
+
relative_date(1.day.from_now.utc).should == 'tomorrow'
|
20
|
+
end
|
21
|
+
|
22
|
+
it "Should show date with year" do
|
23
|
+
relative_date(Time.utc(2005, 11, 15)).should == 'Nov 15th, 2005'
|
24
|
+
end
|
25
|
+
|
26
|
+
it "Should show date" do
|
27
|
+
relative_date(Time.utc(2007, 11, 15)).should == 'Nov 15th'
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "relative_date_span" do
|
32
|
+
include Merb::Helpers::DateAndTime
|
33
|
+
|
34
|
+
before :each do
|
35
|
+
Time.stub!(:now).and_return(Time.utc(2007, 6, 1, 11))
|
36
|
+
end
|
37
|
+
|
38
|
+
it "Should show date span on the same day" do
|
39
|
+
relative_date_span([Time.utc(2007, 11, 15), Time.utc(2007, 11, 15)]).should == 'Nov 15th'
|
40
|
+
end
|
41
|
+
|
42
|
+
it "Should show date span on the same day on different year" do
|
43
|
+
relative_date_span([Time.utc(2006, 11, 15), Time.utc(2006, 11, 15)]).should == 'Nov 15th, 2006'
|
44
|
+
end
|
45
|
+
|
46
|
+
it "Should show date span on the same month" do
|
47
|
+
relative_date_span([Time.utc(2007, 11, 15), Time.utc(2007, 11, 16)]).should == 'Nov 15th - 16th'
|
48
|
+
relative_date_span([Time.utc(2007, 11, 16), Time.utc(2007, 11, 15)]).should == 'Nov 15th - 16th'
|
49
|
+
end
|
50
|
+
|
51
|
+
it "Should show date span on the same month on different year" do
|
52
|
+
relative_date_span([Time.utc(2006, 11, 15), Time.utc(2006, 11, 16)]).should == 'Nov 15th - 16th, 2006'
|
53
|
+
relative_date_span([Time.utc(2006, 11, 16), Time.utc(2006, 11, 15)]).should == 'Nov 15th - 16th, 2006'
|
54
|
+
end
|
55
|
+
|
56
|
+
it "Should show date span on the different month" do
|
57
|
+
relative_date_span([Time.utc(2007, 11, 15), Time.utc(2007, 12, 16)]).should == 'Nov 15th - Dec 16th'
|
58
|
+
relative_date_span([Time.utc(2007, 12, 16), Time.utc(2007, 11, 15)]).should == 'Nov 15th - Dec 16th'
|
59
|
+
end
|
60
|
+
|
61
|
+
it "Should show date span on the different month on different year" do
|
62
|
+
relative_date_span([Time.utc(2006, 11, 15), Time.utc(2006, 12, 16)]).should == 'Nov 15th - Dec 16th, 2006'
|
63
|
+
relative_date_span([Time.utc(2006, 12, 16), Time.utc(2006, 11, 15)]).should == 'Nov 15th - Dec 16th, 2006'
|
64
|
+
end
|
65
|
+
|
66
|
+
it "Should show date span on the different year" do
|
67
|
+
relative_date_span([Time.utc(2006, 11, 15), Time.utc(2007, 12, 16)]).should == 'Nov 15th, 2006 - Dec 16th, 2007'
|
68
|
+
relative_date_span([Time.utc(2007, 12, 16), Time.utc(2006, 11, 15)]).should == 'Nov 15th, 2006 - Dec 16th, 2007'
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
describe "relative_time_span" do
|
73
|
+
include Merb::Helpers::DateAndTime
|
74
|
+
|
75
|
+
before :each do
|
76
|
+
Time.stub!(:now).and_return(Time.utc(2007, 6, 1, 11))
|
77
|
+
end
|
78
|
+
|
79
|
+
# Time, Single Date
|
80
|
+
it "Should show time span on the same day with same time" do
|
81
|
+
relative_time_span([Time.utc(2007, 11, 15, 17, 00, 00)]).should == '5:00 PM Nov 15th'
|
82
|
+
end
|
83
|
+
|
84
|
+
it "Should show time span on the same day with same time on different year" do
|
85
|
+
relative_time_span([Time.utc(2006, 11, 15, 17, 0), Time.utc(2006, 11, 15, 17, 0)]).should == '5:00 PM Nov 15th, 2006'
|
86
|
+
end
|
87
|
+
|
88
|
+
it "Should show time span on the same day with different times in same half of day" do
|
89
|
+
relative_time_span([Time.utc(2007, 11, 15, 10), Time.utc(2007, 11, 15, 11, 0)]).should == '10:00 - 11:00 AM Nov 15th'
|
90
|
+
end
|
91
|
+
|
92
|
+
it "Should show time span on the same day with different times in different half of day" do
|
93
|
+
relative_time_span([Time.utc(2007, 11, 15, 10, 0), Time.utc(2007, 11, 15, 14, 0)]).should == '10:00 AM - 2:00 PM Nov 15th'
|
94
|
+
end
|
95
|
+
|
96
|
+
it "Should show time span on the same day with different times in different half of day in different year" do
|
97
|
+
relative_time_span([Time.utc(2006, 11, 15, 10, 0), Time.utc(2006, 11, 15, 14, 0)]).should == '10:00 AM - 2:00 PM Nov 15th, 2006'
|
98
|
+
end
|
99
|
+
|
100
|
+
it "Should show time span on different days in same year" do
|
101
|
+
relative_time_span([Time.utc(2006, 11, 15, 10, 0), Time.utc(2006, 12, 16, 14, 0)]).should == '10:00 AM Nov 15th - 2:00 PM Dec 16th, 2006'
|
102
|
+
end
|
103
|
+
|
104
|
+
it "Should show time span on different days in different years" do
|
105
|
+
relative_time_span([Time.utc(2006, 11, 15, 10, 0), Time.utc(2007, 12, 16, 14, 0)]).should == '10:00 AM Nov 15th, 2006 - 2:00 PM Dec 16th, 2007'
|
106
|
+
end
|
107
|
+
|
108
|
+
it "Should show time span on different days in current year" do
|
109
|
+
relative_time_span([Time.utc(2007, 11, 15, 10, 0), Time.utc(2007, 12, 16, 14, 0)]).should == '10:00 AM Nov 15th - 2:00 PM Dec 16th'
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
describe "time_lost_in_words" do
|
114
|
+
include Merb::Helpers::DateAndTime
|
115
|
+
|
116
|
+
it "Should show seconds" do
|
117
|
+
time_lost_in_words(Time.now, Time.now, true).should == "less than 5 seconds"
|
118
|
+
end
|
119
|
+
|
120
|
+
it "Should not show seconds" do
|
121
|
+
time_lost_in_words(Time.now).should == "less than a minute"
|
122
|
+
end
|
123
|
+
|
124
|
+
it "Should do minutes" do
|
125
|
+
time_lost_in_words(2.minutes.ago).should == "2 minutes"
|
126
|
+
end
|
127
|
+
|
128
|
+
it "Should do hour" do
|
129
|
+
time_lost_in_words(50.minutes.ago).should == "about 1 hour"
|
130
|
+
end
|
131
|
+
|
132
|
+
it "Should do hours" do
|
133
|
+
time_lost_in_words(2.hours.ago).should == "about 2 hours"
|
134
|
+
end
|
135
|
+
|
136
|
+
it "Should do day" do
|
137
|
+
time_lost_in_words(1.day.ago).should == "1 day"
|
138
|
+
end
|
139
|
+
|
140
|
+
it "Should do days" do
|
141
|
+
time_lost_in_words(5.days.ago).should == "5 days"
|
142
|
+
end
|
143
|
+
|
144
|
+
it "Should do month" do
|
145
|
+
time_lost_in_words(1.month.ago).should == "about 1 month"
|
146
|
+
end
|
147
|
+
|
148
|
+
it "Should do months" do
|
149
|
+
time_lost_in_words(5.months.ago).should == "5 months"
|
150
|
+
end
|
151
|
+
|
152
|
+
it "Should do year" do
|
153
|
+
time_lost_in_words(1.2.years.ago).should == "about 1 year"
|
154
|
+
end
|
155
|
+
|
156
|
+
it "Should do years" do
|
157
|
+
time_lost_in_words(5.5.years.ago).should == "over 5 years"
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
describe "prettier_time" do
|
162
|
+
include Merb::Helpers::DateAndTime
|
163
|
+
|
164
|
+
# prettier time"
|
165
|
+
it "Should not show leading zero in hour" do
|
166
|
+
prettier_time(Time.utc(2007, 11, 15, 14, 0)).should == '2:00 PM'
|
167
|
+
end
|
168
|
+
|
169
|
+
it "Should convert to 12 hour time" do
|
170
|
+
prettier_time(Time.utc(2007, 11, 15, 2, 0)).should == '2:00 AM'
|
171
|
+
end
|
172
|
+
|
173
|
+
it "Should handle midnight correctly" do
|
174
|
+
prettier_time(Time.utc(2007, 11, 15, 0, 0)).should == '12:00 AM'
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
shared_examples_for "Date, DateTime, Time formatting" do
|
179
|
+
|
180
|
+
before(:each) do
|
181
|
+
Date.reset_formats
|
182
|
+
end
|
183
|
+
|
184
|
+
it "should list the available formats" do
|
185
|
+
Date.formats.should be_an_instance_of(Hash)
|
186
|
+
Date.formats.keys.length.should > 1
|
187
|
+
end
|
188
|
+
|
189
|
+
it "should support to be db formatted" do
|
190
|
+
@date.formatted(:db).should =~ /^2007-11-02 \d{2}:\d{2}:\d{2}$/
|
191
|
+
end
|
192
|
+
|
193
|
+
it "should support to be time formatted" do
|
194
|
+
@date.formatted(:time).should == "00:00"
|
195
|
+
end
|
196
|
+
|
197
|
+
it "should support to be short formatted" do
|
198
|
+
@date.formatted(:short).should == "02 Nov 00:00"
|
199
|
+
end
|
200
|
+
|
201
|
+
it "should support to be date formatted" do
|
202
|
+
@date.formatted(:date).should == "2007-11-02"
|
203
|
+
end
|
204
|
+
|
205
|
+
it "should support to be long formatted" do
|
206
|
+
@date.formatted(:long).should == "November 02, 2007 00:00"
|
207
|
+
end
|
208
|
+
|
209
|
+
it "should support a new date format" do
|
210
|
+
@date.formatted(:matt).should == @date.to_s
|
211
|
+
Date.add_format(:matt, "%H:%M:%S %Y-%m-%d")
|
212
|
+
@date.formatted(:matt).should == "00:00:00 2007-11-02"
|
213
|
+
end
|
214
|
+
|
215
|
+
end
|
216
|
+
|
217
|
+
|
218
|
+
describe "Date" do
|
219
|
+
before :each do
|
220
|
+
@date = Date.new(2007, 11, 02)
|
221
|
+
end
|
222
|
+
|
223
|
+
it "Should do to_time conversion and return a Time class" do
|
224
|
+
@date.is_a?(Date)
|
225
|
+
@date.to_time.is_a?(Time)
|
226
|
+
end
|
227
|
+
|
228
|
+
it "Should do to_time conversion to utc by default" do
|
229
|
+
@date.to_time.to_s.should == 'Fri Nov 02 00:00:00 UTC 2007'
|
230
|
+
end
|
231
|
+
|
232
|
+
it "Should do to_time conversion to utc when param :utc is given" do
|
233
|
+
@date.to_time(:utc).to_s.should == 'Fri Nov 02 00:00:00 UTC 2007'
|
234
|
+
end
|
235
|
+
|
236
|
+
it "Should do to_time conversion to local time when param :local is given" do
|
237
|
+
pending("Needs to have the call to figure out the local time stubbed so this test will work no matter what your local TZ is.")
|
238
|
+
@date.to_time(:local).to_s.should == 'Fri Nov 02 00:00:00 -0500 2007'
|
239
|
+
end
|
240
|
+
|
241
|
+
it "Should return itself when to_date is called" do
|
242
|
+
@date.to_date.should == @date
|
243
|
+
end
|
244
|
+
|
245
|
+
it_should_behave_like "Date, DateTime, Time formatting"
|
246
|
+
|
247
|
+
end
|
248
|
+
|
249
|
+
describe "DateTime" do
|
250
|
+
|
251
|
+
before(:each) do
|
252
|
+
@date = DateTime.new(2007, 11, 02)
|
253
|
+
end
|
254
|
+
|
255
|
+
it_should_behave_like "Date, DateTime, Time formatting"
|
256
|
+
|
257
|
+
end
|