batasrki-calendar_date_select 1.13 → 1.13.1

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.
@@ -0,0 +1,14 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe CalendarDateSelect do
4
+ it "should detect presence of time in a string" do
5
+ CalendarDateSelect.has_time?("January 7, 2007").should == false
6
+ CalendarDateSelect.has_time?("January 7, 2007 5:50pm").should == true
7
+ CalendarDateSelect.has_time?("January 7, 2007 5:50 pm").should == true
8
+ CalendarDateSelect.has_time?("January 7, 2007 16:30 pm").should == true
9
+
10
+ CalendarDateSelect.has_time?(Date.parse("January 7, 2007 3:00 pm")).should == false
11
+ CalendarDateSelect.has_time?(Time.parse("January 7, 2007 3:00 pm")).should == true
12
+ CalendarDateSelect.has_time?(DateTime.parse("January 7, 2007 3:00 pm")).should == true
13
+ end
14
+ end
@@ -0,0 +1,161 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe CalendarDateSelect::FormHelpers do
4
+ include ActionView::Helpers::FormHelper
5
+ include ActionView::Helpers::JavaScriptHelper
6
+ include ActionView::Helpers::AssetTagHelper
7
+ include ActionView::Helpers::TagHelper
8
+ include ActionView::Helpers::FormTagHelper
9
+
10
+ include CalendarDateSelect::FormHelpers
11
+
12
+ before(:each) do
13
+ @controller = ActionController::Base.new
14
+ @request = OpenStruct.new
15
+ @controller.request = @request
16
+
17
+ @model = OpenStruct.new
18
+ end
19
+
20
+ describe "mixed mode" do
21
+ it "should not output a time when the value is a Date" do
22
+ @model.start_datetime = Date.parse("January 2, 2007")
23
+ output = calendar_date_select(:model, :start_datetime, :time => "mixed")
24
+ output.should_not match(/12:00 AM/)
25
+ end
26
+
27
+ it "should output a time when the value is a Time" do
28
+ @model.start_datetime = Time.parse("January 2, 2007 12:00 AM")
29
+ output = calendar_date_select(:model, :start_datetime, :time => "mixed")
30
+ output.should match(/12:00 AM/)
31
+ end
32
+ end
33
+
34
+ it "should render a time when time is passed as 'true'" do
35
+ @model.start_datetime = Date.parse("January 2, 2007")
36
+ output = calendar_date_select(:model, :start_datetime, :time => "true")
37
+ output.should match(/12:00 AM/)
38
+ end
39
+
40
+ it "should time_false__model_returns_time__should_render_without_time" do
41
+ @model.start_datetime = Time.parse("January 2, 2007 12:00 AM")
42
+ output = calendar_date_select(:model, :start_datetime)
43
+ output.should_not match(/12:00 AM/)
44
+ end
45
+
46
+ it "should _nil_model__shouldnt_populate_value" do
47
+ @model = nil
48
+ output = calendar_date_select(:model, :start_datetime)
49
+
50
+ output.should_not match(/value/)
51
+ end
52
+
53
+ it "should _vdc__should_auto_format_function" do
54
+ @model.start_datetime = Time.parse("January 2, 2007 12:00 AM")
55
+ output = calendar_date_select(:model,
56
+ :start_datetime,
57
+ :valid_date_check => "date < new Date()"
58
+ )
59
+ output.should include("valid_date_check:function(date) { return(date &lt; new Date()) }")
60
+
61
+ output = calendar_date_select(:model,
62
+ :start_datetime,
63
+ :valid_date_check => "return(date < new Date())"
64
+ )
65
+ output.should include("valid_date_check:function(date) { return(date &lt; new Date()) }")
66
+ output = calendar_date_select(:model,
67
+ :start_datetime,
68
+ :valid_date_check => "function(p) { return(date < new Date()) }"
69
+ )
70
+ output.should include("valid_date_check:function(p) { return(date &lt; new Date()) }")
71
+ end
72
+
73
+ it "should raise an error if the valid_date_check function is missing a return statement" do
74
+ message = ":valid_date_check function is missing a 'return' statement. Try something like: :valid_date_check => 'if (date > new(Date)) return true; else return false;'"
75
+ lambda {
76
+ output = calendar_date_select(:model,
77
+ :start_datetime,
78
+ :valid_date_check => "date = 5; date < new Date());"
79
+ )
80
+ }.should raise_error(ArgumentError, message)
81
+
82
+ lambda {
83
+ output = calendar_date_select(:model,
84
+ :start_datetime,
85
+ :valid_date_check => "function(p) { date = 5; date < new Date()); }"
86
+ )
87
+ }.should raise_error(ArgumentError, message)
88
+ end
89
+
90
+ it "should render the year_range argument correctly" do
91
+ output = calendar_date_select(:model, :start_datetime)
92
+ output.should include("year_range:10")
93
+ output = calendar_date_select(:model, :start_datetime, :year_range => 2000..2010)
94
+ output.should include("year_range:[2000, 2010]")
95
+ output = calendar_date_select(:model, :start_datetime, :year_range => (15.years.ago..5.years.ago))
96
+ output.should include("year_range:[#{15.years.ago.year}, #{5.years.ago.year}]")
97
+ end
98
+
99
+ it "should disregard the :object parameter when nil" do
100
+ @model.start_datetime = Time.parse("January 2, 2007 12:00 AM")
101
+ output = calendar_date_select(:model, :start_datetime, :time => true, :object => nil)
102
+ output.should include(CalendarDateSelect.format_date(@model.start_datetime))
103
+ end
104
+
105
+ it "should regard :object parameter" do
106
+ @model.start_datetime = Time.parse("January 2, 2007 12:00 AM")
107
+ output = calendar_date_select(:lame_o, :start_datetime, :time => true, :object => @model)
108
+ output.should include(CalendarDateSelect.format_date(@model.start_datetime))
109
+ end
110
+
111
+ it "should respect parameters provided in default_options" do
112
+ new_options = CalendarDateSelect.default_options.merge(:popup => "force")
113
+ CalendarDateSelect.stub!(:default_options).and_return(new_options)
114
+ calendar_date_select_tag(:name, "").should include("popup:'force'")
115
+ end
116
+
117
+ it "should respect the :image option" do
118
+ output = calendar_date_select_tag(:name, "Some String", :image => "boogy.png")
119
+ output.should include("boogy.png")
120
+ end
121
+
122
+ it "should not pass the :image option as a javascript option" do
123
+ output = calendar_date_select_tag(:name, "Some String", :image => "boogy.png")
124
+ output.should_not include("image:")
125
+ end
126
+
127
+ it "should use the CSS class calendar_date_select_tag for popup selector icon" do
128
+ output = calendar_date_select_tag(:name, "Some String", :image => "boogy.png")
129
+ output.should include("calendar_date_select_popup_icon")
130
+ end
131
+
132
+ describe "calendar_date_select_tag" do
133
+ it "should use the string verbatim when provided" do
134
+ output = calendar_date_select_tag(:name, "Some String")
135
+
136
+ output.should include("Some String")
137
+ end
138
+
139
+ it "should not render the time when time is false (or nil)" do
140
+ time = Time.parse("January 2, 2007 12:01:23 AM")
141
+ output = calendar_date_select_tag(:name, time, :time => false)
142
+
143
+ output.should_not match(/12:01 AM/)
144
+ output.should include(CalendarDateSelect.format_date(time.to_date))
145
+ end
146
+
147
+ it "should render the time when :time => true" do
148
+ time = Time.parse("January 2, 2007 12:01:23 AM")
149
+ output = calendar_date_select_tag(:name, time, :time => true)
150
+
151
+ output.should include(CalendarDateSelect.format_date(time))
152
+ end
153
+
154
+ it "should render the time when :time => 'mixed'" do
155
+ time = Time.parse("January 2, 2007 12:01:23 AM")
156
+ output = calendar_date_select_tag(:name, time, :time => 'mixed')
157
+
158
+ output.should include(CalendarDateSelect.format_date(time))
159
+ end
160
+ end
161
+ end
@@ -0,0 +1,46 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe CalendarDateSelect::IncludesHelper do
4
+ include ActionView::Helpers::TagHelper
5
+ include ActionView::Helpers::AssetTagHelper
6
+ include CalendarDateSelect::IncludesHelper
7
+
8
+ describe "calendar_date_select_includes" do
9
+ it "should include the specified locale" do
10
+ calendar_date_select_includes(:locale => "fr").should include("calendar_date_select/locale/fr.js")
11
+ end
12
+
13
+ it "should include the specified style" do
14
+ calendar_date_select_includes(:style => "blue").should include("calendar_date_select/blue.css")
15
+ end
16
+
17
+ it "should complain if you provide an illegitimate argument" do
18
+ lambda { calendar_date_select_includes(:language => "fr") }.should raise_error(ArgumentError)
19
+ end
20
+ end
21
+
22
+ describe "calendar_date_select_javascripts" do
23
+ it "should return an array of javascripts" do
24
+ calendar_date_select_javascripts.should == ["calendar_date_select/calendar_date_select"]
25
+ end
26
+
27
+ it "should return the :javascript_include of the specified format, if the specified format expects it" do
28
+ CalendarDateSelect.stub!(:format).and_return(CalendarDateSelect::FORMATS[:hyphen_ampm])
29
+ calendar_date_select_javascripts.should == ["calendar_date_select/calendar_date_select", "calendar_date_select/format_hyphen_ampm"]
30
+ end
31
+
32
+ it "should blow up if an illegitimate argument is passed" do
33
+ lambda { calendar_date_select_javascripts(:language => "fr") }.should raise_error(ArgumentError)
34
+ end
35
+ end
36
+
37
+ describe "calendar_date_select_stylesheets" do
38
+ it "should return an array of stylesheet" do
39
+ calendar_date_select_javascripts.should == ["calendar_date_select/calendar_date_select"]
40
+ end
41
+
42
+ it "should blow up if an illegitimate argument is passed" do
43
+ lambda { calendar_date_select_stylesheets(:css_version => "blue") }.should raise_error(ArgumentError)
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,26 @@
1
+ require "rubygems"
2
+
3
+ require 'spec'
4
+
5
+ gem 'activesupport', ">= 2.2.0"
6
+ gem 'actionpack', ">= 2.2.0"
7
+
8
+ require 'active_support'
9
+ require 'action_pack'
10
+ require 'action_controller'
11
+ require 'action_view'
12
+
13
+ require 'ostruct'
14
+
15
+ ActionView::Helpers::InstanceTag.class_eval do
16
+ class << self; alias new_with_backwards_compatibility new; end
17
+ end
18
+
19
+ $: << (File.dirname(__FILE__) + "/../lib")
20
+ require "calendar_date_select"
21
+
22
+ class String
23
+ def to_regexp
24
+ is_a?(Regexp) ? self : Regexp.new(Regexp.escape(self.to_s))
25
+ end
26
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: batasrki-calendar_date_select
3
3
  version: !ruby/object:Gem::Version
4
- version: "1.13"
4
+ version: 1.13.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Srdjan Pejic
@@ -42,6 +42,7 @@ files:
42
42
  - js_test/unittest.js
43
43
  - lib/calendar_date_select/calendar_date_select.rb
44
44
  - lib/calendar_date_select/includes_helper.rb
45
+ - lib/calendar_date_select/forms_helper.rb
45
46
  - lib/calendar_date_select.rb
46
47
  - Manifest.txt
47
48
  - MIT-LICENSE
@@ -72,6 +73,10 @@ files:
72
73
  - test/functional/calendar_date_select_test.rb
73
74
  - test/functional/helper_methods_test.rb
74
75
  - test/test_helper.rb
76
+ - spec/spec_helper.rb
77
+ - spec/calendar_date_select/calendar_date_select_spec.rb
78
+ - spec/calendar_date_select/form_helpers_spec.rb
79
+ - spec/calendar_date_select/includes_helper_spec.rb
75
80
  has_rdoc: true
76
81
  homepage: http://code.google.com/p/calendardateselect/
77
82
  post_install_message: