enhanced_date_select 0.3.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.rbenv-version ADDED
@@ -0,0 +1 @@
1
+ 1.9.3-p392
data/.rvmrc CHANGED
@@ -1 +1,3 @@
1
- rvm use ruby-1.9.2-p290@enhanced_date_select --create
1
+ #!/usr/bin/env bash
2
+ export rvm_trust_rvmrcs_flag=1
3
+ rvm use 'ruby-1.9.3-p392@enhanced_date_select' --create
data/README.rdoc CHANGED
@@ -1,90 +1,90 @@
1
- = enhanced_date_select
2
-
3
- = Overview
4
-
5
-
6
- An enhanced date select form helper that allows you to use the full {HTML spec}[http://www.w3.org/TR/html5] for date_select helper methods from rails. This is more than what you get with the
7
- default Rails date select helper because it can allow values to persist in dropdowns even if you submit a invalid value.
8
-
9
- = Features
10
-
11
- * Fully customizable HTML5 attributes for date_select .
12
-
13
- = Requirements
14
-
15
- 1. {Ruby 1.9.x}[http://www.ruby-lang.org]
16
- 2. {Ruby on Rails}[http://rubyonrails.org].
17
-
18
- = Setup
19
-
20
- Type the following from the command line to install:
21
-
22
- gem install enhanced_date_select
23
-
24
- Add the following to your Gemfile:
25
-
26
- gem "enhanced_date_select"
27
-
28
- = Usage
29
-
30
- Use the +enhanced_date_select+ instead of +date_select+ helper
31
- methods in your views. Example:
32
-
33
- <%= form_for @post do |form| %>
34
- <div >
35
- <%= form.enhanced_date_select :birthday, { :prompt => {
36
- :day => "please select one",
37
- :month => "please select one",
38
- :year => "please select one" },
39
- :value => {:year => @year, :month => @month, :day => @day},
40
- :order => [:day, :month, :year],
41
- :start_year => Time.now.year,
42
- :end_year => 1940 }, { :class => "input_3cols" } %>
43
- </div>
44
- <% end %>
45
-
46
- ...or alternatively:
47
-
48
- <%= form_for @post do |form| %>
49
- <div >
50
- <%= form.date_select :birthday, { :prompt => {
51
- :day => "please select one",
52
- :month => "please select one",
53
- :year => "please select one" },
54
- :value => Date.new(2011,02,01),
55
- :order => [:day, :month, :year],
56
- :start_year => Time.now.year,
57
- :end_year => 1940 }, { :class => "input_3cols" } %>
58
- </div>
59
- <% end %>
60
-
61
- The +enhanced_date_select+ takes all the standard options as the default Rails date_select
62
- method. The only difference is that it expects an hash with values for year, month and day instead of an date object.
63
-
64
- = Testing
65
-
66
- To test, do the following:
67
-
68
- 1. cd to the gem root.
69
- 2. bundle install
70
- 3. bundle exec rspec spec
71
-
72
- = Contributions
73
-
74
- Please log all feedback/issues via {GitHub Issues}[http://github.com/bogdanRada/enhanced_date_select/issues]. Thanks.
75
-
76
-
77
- == Contributing to enhanced_date_select
78
-
79
- * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
80
- * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
81
- * Fork the project.
82
- * Start a feature/bugfix branch.
83
- * Commit and push until you are happy with your contribution.
84
- * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
85
- * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
86
-
87
- == Copyright
88
-
89
- Copyright (c) 2012 bogdanRada. See LICENSE.txt for
90
- further details.
1
+ = enhanced_date_select
2
+
3
+ = Overview
4
+
5
+
6
+ An enhanced date select form helper that allows you to use the full {HTML spec}[http://www.w3.org/TR/html5] for date_select helper methods from rails. This is more than what you get with the
7
+ default Rails date select helper because it can allow values to persist in dropdowns even if you submit a invalid value.
8
+
9
+ = Features
10
+
11
+ * Fully customizable HTML5 attributes for date_select .
12
+
13
+ = Requirements
14
+
15
+ 1. {Ruby 1.9.x}[http://www.ruby-lang.org]
16
+ 2. {Ruby on Rails}[http://rubyonrails.org].
17
+
18
+ = Setup
19
+
20
+ Type the following from the command line to install:
21
+
22
+ gem install enhanced_date_select
23
+
24
+ Add the following to your Gemfile:
25
+
26
+ gem "enhanced_date_select"
27
+
28
+ = Usage
29
+
30
+ Use the +enhanced_date_select+ instead of +date_select+ helper
31
+ methods in your views. Example:
32
+
33
+ <%= form_for @post do |form| %>
34
+ <div >
35
+ <%= form.enhanced_date_select :birthday, { :prompt => {
36
+ :day => "please select one",
37
+ :month => "please select one",
38
+ :year => "please select one" },
39
+ :value => {:year => @year, :month => @month, :day => @day},
40
+ :order => [:day, :month, :year],
41
+ :start_year => Time.now.year,
42
+ :end_year => 1940 }, { :class => "input_3cols" } %>
43
+ </div>
44
+ <% end %>
45
+
46
+ ...or alternatively:
47
+
48
+ <%= form_for @post do |form| %>
49
+ <div >
50
+ <%= form.date_select :birthday, { :prompt => {
51
+ :day => "please select one",
52
+ :month => "please select one",
53
+ :year => "please select one" },
54
+ :value => Date.new(2011,02,01),
55
+ :order => [:day, :month, :year],
56
+ :start_year => Time.now.year,
57
+ :end_year => 1940 }, { :class => "input_3cols" } %>
58
+ </div>
59
+ <% end %>
60
+
61
+ The +enhanced_date_select+ takes all the standard options as the default Rails date_select
62
+ method. The only difference is that it expects an hash with values for year, month and day instead of an date object.
63
+
64
+ = Testing
65
+
66
+ To test, do the following:
67
+
68
+ 1. cd to the gem root.
69
+ 2. bundle install
70
+ 3. bundle exec rspec spec
71
+
72
+ = Contributions
73
+
74
+ Please log all feedback/issues via {GitHub Issues}[http://github.com/bogdanRada/enhanced_date_select/issues]. Thanks.
75
+
76
+
77
+ == Contributing to enhanced_date_select
78
+
79
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
80
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
81
+ * Fork the project.
82
+ * Start a feature/bugfix branch.
83
+ * Commit and push until you are happy with your contribution.
84
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
85
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
86
+
87
+ == Copyright
88
+
89
+ Copyright (c) 2012 bogdanRada. See LICENSE.txt for
90
+ further details.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.0
1
+ 1.0.0
Binary file
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "enhanced_date_select"
8
- s.version = "0.3.0"
8
+ s.version = "1.0.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["bogdanRada"]
12
- s.date = "2012-10-16"
12
+ s.date = "2013-07-29"
13
13
  s.description = "\"Enhances ActionView with a customizable date select form helper where any valid HTML attribute can be applied.\""
14
14
  s.email = "raoul_ice@yahoo.com"
15
15
  s.extra_rdoc_files = [
@@ -17,6 +17,7 @@ Gem::Specification.new do |s|
17
17
  "README.rdoc"
18
18
  ]
19
19
  s.files = [
20
+ ".rbenv-version",
20
21
  ".rspec",
21
22
  ".rvmrc",
22
23
  "Gemfile",
@@ -33,7 +34,7 @@ Gem::Specification.new do |s|
33
34
  s.homepage = "http://github.com/bogdanRada/enhanced_date_select"
34
35
  s.licenses = ["MIT"]
35
36
  s.require_paths = ["lib"]
36
- s.rubygems_version = "1.8.24"
37
+ s.rubygems_version = "1.8.25"
37
38
  s.summary = "\"enhanced date select\""
38
39
 
39
40
  if s.respond_to? :specification_version then
@@ -1,16 +1,20 @@
1
- #EnhancedDateSelect
1
+ # #EnhancedDateSelect
2
2
  if defined?(Rails) && defined?(ActionView)
3
3
  module ActionView
4
4
  module Helpers
5
5
  module FormOptionsHelper
6
6
  def enhanced_date_select object, method, options = {}, html_options = {}
7
- InstanceTag.new(object, method, self, options.delete(:object)).to_enhanced_date_select_tag(options, html_options)
7
+ if ( Rails::VERSION::MAJOR.to_i <= 3 )
8
+ @instance_tag = InstanceTag.new(object, method, self, options.delete(:object))
9
+ else
10
+ @instance_tag = Tags::Base.new(object, method, self, options)
11
+ end
12
+ @instance_tag .to_enhanced_date_select_tag(options, html_options)
8
13
  end
9
14
  end
10
15
 
11
-
12
- class InstanceTag
13
- def to_enhanced_date_select_tag options, html_options
16
+ module EnhancedDateSelectTagHelper
17
+ def to_enhanced_date_select_tag options, html_options
14
18
  enhanced_datetime_selector(options, html_options).enhanced_select_date.html_safe
15
19
  end
16
20
 
@@ -21,33 +25,43 @@ if defined?(Rails) && defined?(ActionView)
21
25
  @auto_index ||= nil
22
26
 
23
27
  options = options.dup
24
- options[:field_name] = @method_name
25
- options[:include_position] = true
26
- options[:prefix] ||= @object_name
27
- options[:index] = @auto_index if @auto_index && !options.has_key?(:index)
28
+ options[:field_name] = @method_name
29
+ options[:include_position] = true
30
+ options[:prefix] ||= @object_name
31
+ options[:index] = @auto_index if @auto_index && !options.has_key?(:index)
28
32
 
29
33
  EnhancedDateTimeSelector.new(datetime, options, html_options)
30
34
  end
31
35
 
32
36
  end
37
+ class InstanceTag
38
+ include EnhancedDateSelectTagHelper
33
39
 
40
+ end
41
+
42
+ module Tags
43
+ class Base
44
+ include EnhancedDateSelectTagHelper
45
+
46
+ end
47
+ end
34
48
 
35
49
  class EnhancedDateTimeSelector < DateTimeSelector
36
50
 
37
51
  def enhanced_select_date
38
52
  order = date_order.dup
39
53
 
40
- @options[:discard_hour] = true
41
- @options[:discard_minute] = true
42
- @options[:discard_second] = true
54
+ @options[:discard_hour] = true
55
+ @options[:discard_minute] = true
56
+ @options[:discard_second] = true
43
57
 
44
- @options[:discard_year] ||= true unless order.include?(:year)
45
- @options[:discard_month] ||= true unless order.include?(:month)
46
- @options[:discard_day] ||= true if @options[:discard_month] || !order.include?(:day)
58
+ @options[:discard_year] ||= true unless order.include?(:year)
59
+ @options[:discard_month] ||= true unless order.include?(:month)
60
+ @options[:discard_day] ||= true if @options[:discard_month] || !order.include?(:day)
47
61
 
48
62
  # If the day is hidden and the month is visible, the day should be set to the 1st so all month choices are valid (otherwise it could be 31 and February wouldn't be a valid date)
49
63
  if @datetime && @options[:discard_day] && !@options[:discard_month]
50
- if @datetime.is_a?(Hash)
64
+ if @datetime.is_a?(Hash)
51
65
  @datetime[:day] = 1
52
66
  else
53
67
  @datetime = @datetime.change(:day => 1)
@@ -63,9 +77,9 @@ if defined?(Rails) && defined?(ActionView)
63
77
  %w( sec min hour day month year ).each do |method|
64
78
  define_method(method) do
65
79
  if @datetime
66
- if @datetime.kind_of?(Fixnum)
80
+ if @datetime.kind_of?(Fixnum)
67
81
  @datetime
68
- elsif @datetime.is_a?(Hash)
82
+ elsif @datetime.is_a?(Hash)
69
83
  @datetime[method.to_sym]
70
84
  else
71
85
  @datetime.send(method)
@@ -1,86 +1,86 @@
1
- require "spec_helper"
2
-
3
- describe "Enhanced DateSelect" do
4
- include ActionView::Helpers::FormOptionsHelper
5
- let(:student) {Object.new}
6
- let(:form_builder){ ActionView::Helpers::FormBuilder.new(:birthday, student, self, {}, nil)}
7
-
8
- let(:instance_tag) { ActionView::Helpers::InstanceTag.new(student.class, 'birthday', self, student )}
9
- let(:datetime){{:year => 2001, :month => 2, :day => 3}}
10
- let(:html_options){{}}
11
- let(:options) {{ :discard_day =>true,
12
- :value => {:year => 2001, :month => 2, :day => 3},
13
- :order => [:day, :month, :year],
14
- :start_year => Time.now.year,
15
- :end_year => 1940 }}
16
- let(:expected_result) {"<input id=\"birthday_birthday_3i\" name=\"birthday[birthday(3i)]\" type=\"hidden\" value=\"1\" />\n<select id=\"birthday_birthday_2i\" name=\"birthday[birthday(2i)]\">\n<option value=\"1\">January</option>\n<option selected=\"selected\" value=\"2\">February</option>\n<option value=\"3\">March</option>\n<option value=\"4\">April</option>\n<option value=\"5\">May</option>\n<option value=\"6\">June</option>\n<option value=\"7\">July</option>\n<option value=\"8\">August</option>\n<option value=\"9\">September</option>\n<option value=\"10\">October</option>\n<option value=\"11\">November</option>\n<option value=\"12\">December</option>\n</select>\n<select id=\"birthday_birthday_1i\" name=\"birthday[birthday(1i)]\">\n<option value=\"2012\">2012</option>\n<option value=\"2011\">2011</option>\n<option value=\"2010\">2010</option>\n<option value=\"2009\">2009</option>\n<option value=\"2008\">2008</option>\n<option value=\"2007\">2007</option>\n<option value=\"2006\">2006</option>\n<option value=\"2005\">2005</option>\n<option value=\"2004\">2004</option>\n<option value=\"2003\">2003</option>\n<option value=\"2002\">2002</option>\n<option selected=\"selected\" value=\"2001\">2001</option>\n<option value=\"2000\">2000</option>\n<option value=\"1999\">1999</option>\n<option value=\"1998\">1998</option>\n<option value=\"1997\">1997</option>\n<option value=\"1996\">1996</option>\n<option value=\"1995\">1995</option>\n<option value=\"1994\">1994</option>\n<option value=\"1993\">1993</option>\n<option value=\"1992\">1992</option>\n<option value=\"1991\">1991</option>\n<option value=\"1990\">1990</option>\n<option value=\"1989\">1989</option>\n<option value=\"1988\">1988</option>\n<option value=\"1987\">1987</option>\n<option value=\"1986\">1986</option>\n<option value=\"1985\">1985</option>\n<option value=\"1984\">1984</option>\n<option value=\"1983\">1983</option>\n<option value=\"1982\">1982</option>\n<option value=\"1981\">1981</option>\n<option value=\"1980\">1980</option>\n<option value=\"1979\">1979</option>\n<option value=\"1978\">1978</option>\n<option value=\"1977\">1977</option>\n<option value=\"1976\">1976</option>\n<option value=\"1975\">1975</option>\n<option value=\"1974\">1974</option>\n<option value=\"1973\">1973</option>\n<option value=\"1972\">1972</option>\n<option value=\"1971\">1971</option>\n<option value=\"1970\">1970</option>\n<option value=\"1969\">1969</option>\n<option value=\"1968\">1968</option>\n<option value=\"1967\">1967</option>\n<option value=\"1966\">1966</option>\n<option value=\"1965\">1965</option>\n<option value=\"1964\">1964</option>\n<option value=\"1963\">1963</option>\n<option value=\"1962\">1962</option>\n<option value=\"1961\">1961</option>\n<option value=\"1960\">1960</option>\n<option value=\"1959\">1959</option>\n<option value=\"1958\">1958</option>\n<option value=\"1957\">1957</option>\n<option value=\"1956\">1956</option>\n<option value=\"1955\">1955</option>\n<option value=\"1954\">1954</option>\n<option value=\"1953\">1953</option>\n<option value=\"1952\">1952</option>\n<option value=\"1951\">1951</option>\n<option value=\"1950\">1950</option>\n<option value=\"1949\">1949</option>\n<option value=\"1948\">1948</option>\n<option value=\"1947\">1947</option>\n<option value=\"1946\">1946</option>\n<option value=\"1945\">1945</option>\n<option value=\"1944\">1944</option>\n<option value=\"1943\">1943</option>\n<option value=\"1942\">1942</option>\n<option value=\"1941\">1941</option>\n<option value=\"1940\">1940</option>\n</select>\n"}
17
- before(:each) do
18
- @instance_tag =ActionView::Helpers::InstanceTag.new(student.class, 'birthday', self, student )
19
- @enhanced_datetime_selector = ActionView::Helpers::EnhancedDateTimeSelector.new(datetime, options, {})
20
- end
21
-
22
-
23
- describe ".enhanced_date_select" do
24
- it "constructs 3 selectboxes" do
25
- form_builder.enhanced_date_select(:birthday,{ :prompt => {
26
- :day => "please select one",
27
- :month => "please select one",
28
- :year => "please select one" },
29
- :value => {:year => 2001, :month => 2, :day => 3},
30
- :order => [:day, :month, :year],
31
- :start_year => Time.now.year,
32
- :end_year => 1940 } ).should == "<select id=\"birthday_birthday_3i\" name=\"birthday[birthday(3i)]\">\n<option value=\"\">please select one</option>\n<option value=\"1\">1</option>\n<option value=\"2\">2</option>\n<option selected=\"selected\" value=\"3\">3</option>\n<option value=\"4\">4</option>\n<option value=\"5\">5</option>\n<option value=\"6\">6</option>\n<option value=\"7\">7</option>\n<option value=\"8\">8</option>\n<option value=\"9\">9</option>\n<option value=\"10\">10</option>\n<option value=\"11\">11</option>\n<option value=\"12\">12</option>\n<option value=\"13\">13</option>\n<option value=\"14\">14</option>\n<option value=\"15\">15</option>\n<option value=\"16\">16</option>\n<option value=\"17\">17</option>\n<option value=\"18\">18</option>\n<option value=\"19\">19</option>\n<option value=\"20\">20</option>\n<option value=\"21\">21</option>\n<option value=\"22\">22</option>\n<option value=\"23\">23</option>\n<option value=\"24\">24</option>\n<option value=\"25\">25</option>\n<option value=\"26\">26</option>\n<option value=\"27\">27</option>\n<option value=\"28\">28</option>\n<option value=\"29\">29</option>\n<option value=\"30\">30</option>\n<option value=\"31\">31</option>\n</select>\n<select id=\"birthday_birthday_2i\" name=\"birthday[birthday(2i)]\">\n<option value=\"\">please select one</option>\n<option value=\"1\">January</option>\n<option selected=\"selected\" value=\"2\">February</option>\n<option value=\"3\">March</option>\n<option value=\"4\">April</option>\n<option value=\"5\">May</option>\n<option value=\"6\">June</option>\n<option value=\"7\">July</option>\n<option value=\"8\">August</option>\n<option value=\"9\">September</option>\n<option value=\"10\">October</option>\n<option value=\"11\">November</option>\n<option value=\"12\">December</option>\n</select>\n<select id=\"birthday_birthday_1i\" name=\"birthday[birthday(1i)]\">\n<option value=\"\">please select one</option>\n<option value=\"2012\">2012</option>\n<option value=\"2011\">2011</option>\n<option value=\"2010\">2010</option>\n<option value=\"2009\">2009</option>\n<option value=\"2008\">2008</option>\n<option value=\"2007\">2007</option>\n<option value=\"2006\">2006</option>\n<option value=\"2005\">2005</option>\n<option value=\"2004\">2004</option>\n<option value=\"2003\">2003</option>\n<option value=\"2002\">2002</option>\n<option selected=\"selected\" value=\"2001\">2001</option>\n<option value=\"2000\">2000</option>\n<option value=\"1999\">1999</option>\n<option value=\"1998\">1998</option>\n<option value=\"1997\">1997</option>\n<option value=\"1996\">1996</option>\n<option value=\"1995\">1995</option>\n<option value=\"1994\">1994</option>\n<option value=\"1993\">1993</option>\n<option value=\"1992\">1992</option>\n<option value=\"1991\">1991</option>\n<option value=\"1990\">1990</option>\n<option value=\"1989\">1989</option>\n<option value=\"1988\">1988</option>\n<option value=\"1987\">1987</option>\n<option value=\"1986\">1986</option>\n<option value=\"1985\">1985</option>\n<option value=\"1984\">1984</option>\n<option value=\"1983\">1983</option>\n<option value=\"1982\">1982</option>\n<option value=\"1981\">1981</option>\n<option value=\"1980\">1980</option>\n<option value=\"1979\">1979</option>\n<option value=\"1978\">1978</option>\n<option value=\"1977\">1977</option>\n<option value=\"1976\">1976</option>\n<option value=\"1975\">1975</option>\n<option value=\"1974\">1974</option>\n<option value=\"1973\">1973</option>\n<option value=\"1972\">1972</option>\n<option value=\"1971\">1971</option>\n<option value=\"1970\">1970</option>\n<option value=\"1969\">1969</option>\n<option value=\"1968\">1968</option>\n<option value=\"1967\">1967</option>\n<option value=\"1966\">1966</option>\n<option value=\"1965\">1965</option>\n<option value=\"1964\">1964</option>\n<option value=\"1963\">1963</option>\n<option value=\"1962\">1962</option>\n<option value=\"1961\">1961</option>\n<option value=\"1960\">1960</option>\n<option value=\"1959\">1959</option>\n<option value=\"1958\">1958</option>\n<option value=\"1957\">1957</option>\n<option value=\"1956\">1956</option>\n<option value=\"1955\">1955</option>\n<option value=\"1954\">1954</option>\n<option value=\"1953\">1953</option>\n<option value=\"1952\">1952</option>\n<option value=\"1951\">1951</option>\n<option value=\"1950\">1950</option>\n<option value=\"1949\">1949</option>\n<option value=\"1948\">1948</option>\n<option value=\"1947\">1947</option>\n<option value=\"1946\">1946</option>\n<option value=\"1945\">1945</option>\n<option value=\"1944\">1944</option>\n<option value=\"1943\">1943</option>\n<option value=\"1942\">1942</option>\n<option value=\"1941\">1941</option>\n<option value=\"1940\">1940</option>\n</select>\n"
33
- end
34
-
35
- it "construct withoud the day dropdown" do
36
- form_builder.enhanced_date_select(:birthday,{ :discard_day =>true,
37
- :value => {:year => 2001, :month => 2, :day => 3},
38
- :order => [:day, :month, :year],
39
- :start_year => Time.now.year,
40
- :end_year => 1940 } ).should =="<input id=\"birthday_birthday_3i\" name=\"birthday[birthday(3i)]\" type=\"hidden\" value=\"1\" />\n<select id=\"birthday_birthday_2i\" name=\"birthday[birthday(2i)]\">\n<option value=\"1\">January</option>\n<option selected=\"selected\" value=\"2\">February</option>\n<option value=\"3\">March</option>\n<option value=\"4\">April</option>\n<option value=\"5\">May</option>\n<option value=\"6\">June</option>\n<option value=\"7\">July</option>\n<option value=\"8\">August</option>\n<option value=\"9\">September</option>\n<option value=\"10\">October</option>\n<option value=\"11\">November</option>\n<option value=\"12\">December</option>\n</select>\n<select id=\"birthday_birthday_1i\" name=\"birthday[birthday(1i)]\">\n<option value=\"2012\">2012</option>\n<option value=\"2011\">2011</option>\n<option value=\"2010\">2010</option>\n<option value=\"2009\">2009</option>\n<option value=\"2008\">2008</option>\n<option value=\"2007\">2007</option>\n<option value=\"2006\">2006</option>\n<option value=\"2005\">2005</option>\n<option value=\"2004\">2004</option>\n<option value=\"2003\">2003</option>\n<option value=\"2002\">2002</option>\n<option selected=\"selected\" value=\"2001\">2001</option>\n<option value=\"2000\">2000</option>\n<option value=\"1999\">1999</option>\n<option value=\"1998\">1998</option>\n<option value=\"1997\">1997</option>\n<option value=\"1996\">1996</option>\n<option value=\"1995\">1995</option>\n<option value=\"1994\">1994</option>\n<option value=\"1993\">1993</option>\n<option value=\"1992\">1992</option>\n<option value=\"1991\">1991</option>\n<option value=\"1990\">1990</option>\n<option value=\"1989\">1989</option>\n<option value=\"1988\">1988</option>\n<option value=\"1987\">1987</option>\n<option value=\"1986\">1986</option>\n<option value=\"1985\">1985</option>\n<option value=\"1984\">1984</option>\n<option value=\"1983\">1983</option>\n<option value=\"1982\">1982</option>\n<option value=\"1981\">1981</option>\n<option value=\"1980\">1980</option>\n<option value=\"1979\">1979</option>\n<option value=\"1978\">1978</option>\n<option value=\"1977\">1977</option>\n<option value=\"1976\">1976</option>\n<option value=\"1975\">1975</option>\n<option value=\"1974\">1974</option>\n<option value=\"1973\">1973</option>\n<option value=\"1972\">1972</option>\n<option value=\"1971\">1971</option>\n<option value=\"1970\">1970</option>\n<option value=\"1969\">1969</option>\n<option value=\"1968\">1968</option>\n<option value=\"1967\">1967</option>\n<option value=\"1966\">1966</option>\n<option value=\"1965\">1965</option>\n<option value=\"1964\">1964</option>\n<option value=\"1963\">1963</option>\n<option value=\"1962\">1962</option>\n<option value=\"1961\">1961</option>\n<option value=\"1960\">1960</option>\n<option value=\"1959\">1959</option>\n<option value=\"1958\">1958</option>\n<option value=\"1957\">1957</option>\n<option value=\"1956\">1956</option>\n<option value=\"1955\">1955</option>\n<option value=\"1954\">1954</option>\n<option value=\"1953\">1953</option>\n<option value=\"1952\">1952</option>\n<option value=\"1951\">1951</option>\n<option value=\"1950\">1950</option>\n<option value=\"1949\">1949</option>\n<option value=\"1948\">1948</option>\n<option value=\"1947\">1947</option>\n<option value=\"1946\">1946</option>\n<option value=\"1945\">1945</option>\n<option value=\"1944\">1944</option>\n<option value=\"1943\">1943</option>\n<option value=\"1942\">1942</option>\n<option value=\"1941\">1941</option>\n<option value=\"1940\">1940</option>\n</select>\n"
41
- end
42
- end
43
-
44
-
45
- describe ActionView::Helpers::FormOptionsHelper do
46
-
47
-
48
- before(:each) do
49
- ActionView::Helpers::InstanceTag.stub(:new).and_return(@instance_tag)
50
- end
51
-
52
- it "should call the instance tag with argument" do
53
- ActionView::Helpers::InstanceTag.should_receive(:new).with(student, 'birthday', self, options.delete(:object)).and_return(@instance_tag)
54
- enhanced_date_select(student,'birthday',options )
55
- end
56
- it "should call the tp date_select_tag method" do
57
- @instance_tag.should_receive(:to_enhanced_date_select_tag).with(options, {})
58
- enhanced_date_select(student,'birthday',options )
59
- end
60
-
61
- end
62
-
63
-
64
- describe ActionView::Helpers::InstanceTag do
65
-
66
- before(:each) do
67
- @instance_tag.stub(:enhanced_datetime_selector).and_return(@enhanced_datetime_selector)
68
- end
69
-
70
-
71
- it "should call the datetimeselector" do
72
- @instance_tag.should_receive(:enhanced_datetime_selector).with(options, html_options).and_return(@enhanced_datetime_selector)
73
- @instance_tag.to_enhanced_date_select_tag(options, html_options)
74
- end
75
-
76
- it "should call the datetimeselector" do
77
- @enhanced_datetime_selector.should_receive(:enhanced_select_date).and_return(expected_result)
78
- @instance_tag.to_enhanced_date_select_tag(options, html_options)
79
- end
80
-
81
-
82
-
83
- end
84
-
85
-
86
- end
1
+ require "spec_helper"
2
+
3
+ describe "Enhanced DateSelect" do
4
+ include ActionView::Helpers::FormOptionsHelper
5
+ let(:student) {Object.new}
6
+ let(:form_builder){ ActionView::Helpers::FormBuilder.new(:birthday, student, self, {}, nil)}
7
+
8
+ let(:instance_tag) { ActionView::Helpers::InstanceTag.new(student.class, 'birthday', self, student )}
9
+ let(:datetime){{:year => 2001, :month => 2, :day => 3}}
10
+ let(:html_options){{}}
11
+ let(:options) {{ :discard_day =>true,
12
+ :value => {:year => 2001, :month => 2, :day => 3},
13
+ :order => [:day, :month, :year],
14
+ :start_year => Time.now.year,
15
+ :end_year => 1940 }}
16
+ let(:expected_result) {"<input id=\"birthday_birthday_3i\" name=\"birthday[birthday(3i)]\" type=\"hidden\" value=\"1\" />\n<select id=\"birthday_birthday_2i\" name=\"birthday[birthday(2i)]\">\n<option value=\"1\">January</option>\n<option selected=\"selected\" value=\"2\">February</option>\n<option value=\"3\">March</option>\n<option value=\"4\">April</option>\n<option value=\"5\">May</option>\n<option value=\"6\">June</option>\n<option value=\"7\">July</option>\n<option value=\"8\">August</option>\n<option value=\"9\">September</option>\n<option value=\"10\">October</option>\n<option value=\"11\">November</option>\n<option value=\"12\">December</option>\n</select>\n<select id=\"birthday_birthday_1i\" name=\"birthday[birthday(1i)]\">\n<option value=\"2012\">2012</option>\n<option value=\"2011\">2011</option>\n<option value=\"2010\">2010</option>\n<option value=\"2009\">2009</option>\n<option value=\"2008\">2008</option>\n<option value=\"2007\">2007</option>\n<option value=\"2006\">2006</option>\n<option value=\"2005\">2005</option>\n<option value=\"2004\">2004</option>\n<option value=\"2003\">2003</option>\n<option value=\"2002\">2002</option>\n<option selected=\"selected\" value=\"2001\">2001</option>\n<option value=\"2000\">2000</option>\n<option value=\"1999\">1999</option>\n<option value=\"1998\">1998</option>\n<option value=\"1997\">1997</option>\n<option value=\"1996\">1996</option>\n<option value=\"1995\">1995</option>\n<option value=\"1994\">1994</option>\n<option value=\"1993\">1993</option>\n<option value=\"1992\">1992</option>\n<option value=\"1991\">1991</option>\n<option value=\"1990\">1990</option>\n<option value=\"1989\">1989</option>\n<option value=\"1988\">1988</option>\n<option value=\"1987\">1987</option>\n<option value=\"1986\">1986</option>\n<option value=\"1985\">1985</option>\n<option value=\"1984\">1984</option>\n<option value=\"1983\">1983</option>\n<option value=\"1982\">1982</option>\n<option value=\"1981\">1981</option>\n<option value=\"1980\">1980</option>\n<option value=\"1979\">1979</option>\n<option value=\"1978\">1978</option>\n<option value=\"1977\">1977</option>\n<option value=\"1976\">1976</option>\n<option value=\"1975\">1975</option>\n<option value=\"1974\">1974</option>\n<option value=\"1973\">1973</option>\n<option value=\"1972\">1972</option>\n<option value=\"1971\">1971</option>\n<option value=\"1970\">1970</option>\n<option value=\"1969\">1969</option>\n<option value=\"1968\">1968</option>\n<option value=\"1967\">1967</option>\n<option value=\"1966\">1966</option>\n<option value=\"1965\">1965</option>\n<option value=\"1964\">1964</option>\n<option value=\"1963\">1963</option>\n<option value=\"1962\">1962</option>\n<option value=\"1961\">1961</option>\n<option value=\"1960\">1960</option>\n<option value=\"1959\">1959</option>\n<option value=\"1958\">1958</option>\n<option value=\"1957\">1957</option>\n<option value=\"1956\">1956</option>\n<option value=\"1955\">1955</option>\n<option value=\"1954\">1954</option>\n<option value=\"1953\">1953</option>\n<option value=\"1952\">1952</option>\n<option value=\"1951\">1951</option>\n<option value=\"1950\">1950</option>\n<option value=\"1949\">1949</option>\n<option value=\"1948\">1948</option>\n<option value=\"1947\">1947</option>\n<option value=\"1946\">1946</option>\n<option value=\"1945\">1945</option>\n<option value=\"1944\">1944</option>\n<option value=\"1943\">1943</option>\n<option value=\"1942\">1942</option>\n<option value=\"1941\">1941</option>\n<option value=\"1940\">1940</option>\n</select>\n"}
17
+ before(:each) do
18
+ @instance_tag =ActionView::Helpers::InstanceTag.new(student.class, 'birthday', self, student )
19
+ @enhanced_datetime_selector = ActionView::Helpers::EnhancedDateTimeSelector.new(datetime, options, {})
20
+ end
21
+
22
+
23
+ describe ".enhanced_date_select" do
24
+ it "constructs 3 selectboxes" do
25
+ form_builder.enhanced_date_select(:birthday,{ :prompt => {
26
+ :day => "please select one",
27
+ :month => "please select one",
28
+ :year => "please select one" },
29
+ :value => {:year => 2001, :month => 2, :day => 3},
30
+ :order => [:day, :month, :year],
31
+ :start_year => Time.now.year,
32
+ :end_year => 1940 } ).should == "<select id=\"birthday_birthday_3i\" name=\"birthday[birthday(3i)]\">\n<option value=\"\">please select one</option>\n<option value=\"1\">1</option>\n<option value=\"2\">2</option>\n<option selected=\"selected\" value=\"3\">3</option>\n<option value=\"4\">4</option>\n<option value=\"5\">5</option>\n<option value=\"6\">6</option>\n<option value=\"7\">7</option>\n<option value=\"8\">8</option>\n<option value=\"9\">9</option>\n<option value=\"10\">10</option>\n<option value=\"11\">11</option>\n<option value=\"12\">12</option>\n<option value=\"13\">13</option>\n<option value=\"14\">14</option>\n<option value=\"15\">15</option>\n<option value=\"16\">16</option>\n<option value=\"17\">17</option>\n<option value=\"18\">18</option>\n<option value=\"19\">19</option>\n<option value=\"20\">20</option>\n<option value=\"21\">21</option>\n<option value=\"22\">22</option>\n<option value=\"23\">23</option>\n<option value=\"24\">24</option>\n<option value=\"25\">25</option>\n<option value=\"26\">26</option>\n<option value=\"27\">27</option>\n<option value=\"28\">28</option>\n<option value=\"29\">29</option>\n<option value=\"30\">30</option>\n<option value=\"31\">31</option>\n</select>\n<select id=\"birthday_birthday_2i\" name=\"birthday[birthday(2i)]\">\n<option value=\"\">please select one</option>\n<option value=\"1\">January</option>\n<option selected=\"selected\" value=\"2\">February</option>\n<option value=\"3\">March</option>\n<option value=\"4\">April</option>\n<option value=\"5\">May</option>\n<option value=\"6\">June</option>\n<option value=\"7\">July</option>\n<option value=\"8\">August</option>\n<option value=\"9\">September</option>\n<option value=\"10\">October</option>\n<option value=\"11\">November</option>\n<option value=\"12\">December</option>\n</select>\n<select id=\"birthday_birthday_1i\" name=\"birthday[birthday(1i)]\">\n<option value=\"\">please select one</option>\n<option value=\"2012\">2012</option>\n<option value=\"2011\">2011</option>\n<option value=\"2010\">2010</option>\n<option value=\"2009\">2009</option>\n<option value=\"2008\">2008</option>\n<option value=\"2007\">2007</option>\n<option value=\"2006\">2006</option>\n<option value=\"2005\">2005</option>\n<option value=\"2004\">2004</option>\n<option value=\"2003\">2003</option>\n<option value=\"2002\">2002</option>\n<option selected=\"selected\" value=\"2001\">2001</option>\n<option value=\"2000\">2000</option>\n<option value=\"1999\">1999</option>\n<option value=\"1998\">1998</option>\n<option value=\"1997\">1997</option>\n<option value=\"1996\">1996</option>\n<option value=\"1995\">1995</option>\n<option value=\"1994\">1994</option>\n<option value=\"1993\">1993</option>\n<option value=\"1992\">1992</option>\n<option value=\"1991\">1991</option>\n<option value=\"1990\">1990</option>\n<option value=\"1989\">1989</option>\n<option value=\"1988\">1988</option>\n<option value=\"1987\">1987</option>\n<option value=\"1986\">1986</option>\n<option value=\"1985\">1985</option>\n<option value=\"1984\">1984</option>\n<option value=\"1983\">1983</option>\n<option value=\"1982\">1982</option>\n<option value=\"1981\">1981</option>\n<option value=\"1980\">1980</option>\n<option value=\"1979\">1979</option>\n<option value=\"1978\">1978</option>\n<option value=\"1977\">1977</option>\n<option value=\"1976\">1976</option>\n<option value=\"1975\">1975</option>\n<option value=\"1974\">1974</option>\n<option value=\"1973\">1973</option>\n<option value=\"1972\">1972</option>\n<option value=\"1971\">1971</option>\n<option value=\"1970\">1970</option>\n<option value=\"1969\">1969</option>\n<option value=\"1968\">1968</option>\n<option value=\"1967\">1967</option>\n<option value=\"1966\">1966</option>\n<option value=\"1965\">1965</option>\n<option value=\"1964\">1964</option>\n<option value=\"1963\">1963</option>\n<option value=\"1962\">1962</option>\n<option value=\"1961\">1961</option>\n<option value=\"1960\">1960</option>\n<option value=\"1959\">1959</option>\n<option value=\"1958\">1958</option>\n<option value=\"1957\">1957</option>\n<option value=\"1956\">1956</option>\n<option value=\"1955\">1955</option>\n<option value=\"1954\">1954</option>\n<option value=\"1953\">1953</option>\n<option value=\"1952\">1952</option>\n<option value=\"1951\">1951</option>\n<option value=\"1950\">1950</option>\n<option value=\"1949\">1949</option>\n<option value=\"1948\">1948</option>\n<option value=\"1947\">1947</option>\n<option value=\"1946\">1946</option>\n<option value=\"1945\">1945</option>\n<option value=\"1944\">1944</option>\n<option value=\"1943\">1943</option>\n<option value=\"1942\">1942</option>\n<option value=\"1941\">1941</option>\n<option value=\"1940\">1940</option>\n</select>\n"
33
+ end
34
+
35
+ it "construct withoud the day dropdown" do
36
+ form_builder.enhanced_date_select(:birthday,{ :discard_day =>true,
37
+ :value => {:year => 2001, :month => 2, :day => 3},
38
+ :order => [:day, :month, :year],
39
+ :start_year => Time.now.year,
40
+ :end_year => 1940 } ).should =="<input id=\"birthday_birthday_3i\" name=\"birthday[birthday(3i)]\" type=\"hidden\" value=\"1\" />\n<select id=\"birthday_birthday_2i\" name=\"birthday[birthday(2i)]\">\n<option value=\"1\">January</option>\n<option selected=\"selected\" value=\"2\">February</option>\n<option value=\"3\">March</option>\n<option value=\"4\">April</option>\n<option value=\"5\">May</option>\n<option value=\"6\">June</option>\n<option value=\"7\">July</option>\n<option value=\"8\">August</option>\n<option value=\"9\">September</option>\n<option value=\"10\">October</option>\n<option value=\"11\">November</option>\n<option value=\"12\">December</option>\n</select>\n<select id=\"birthday_birthday_1i\" name=\"birthday[birthday(1i)]\">\n<option value=\"2012\">2012</option>\n<option value=\"2011\">2011</option>\n<option value=\"2010\">2010</option>\n<option value=\"2009\">2009</option>\n<option value=\"2008\">2008</option>\n<option value=\"2007\">2007</option>\n<option value=\"2006\">2006</option>\n<option value=\"2005\">2005</option>\n<option value=\"2004\">2004</option>\n<option value=\"2003\">2003</option>\n<option value=\"2002\">2002</option>\n<option selected=\"selected\" value=\"2001\">2001</option>\n<option value=\"2000\">2000</option>\n<option value=\"1999\">1999</option>\n<option value=\"1998\">1998</option>\n<option value=\"1997\">1997</option>\n<option value=\"1996\">1996</option>\n<option value=\"1995\">1995</option>\n<option value=\"1994\">1994</option>\n<option value=\"1993\">1993</option>\n<option value=\"1992\">1992</option>\n<option value=\"1991\">1991</option>\n<option value=\"1990\">1990</option>\n<option value=\"1989\">1989</option>\n<option value=\"1988\">1988</option>\n<option value=\"1987\">1987</option>\n<option value=\"1986\">1986</option>\n<option value=\"1985\">1985</option>\n<option value=\"1984\">1984</option>\n<option value=\"1983\">1983</option>\n<option value=\"1982\">1982</option>\n<option value=\"1981\">1981</option>\n<option value=\"1980\">1980</option>\n<option value=\"1979\">1979</option>\n<option value=\"1978\">1978</option>\n<option value=\"1977\">1977</option>\n<option value=\"1976\">1976</option>\n<option value=\"1975\">1975</option>\n<option value=\"1974\">1974</option>\n<option value=\"1973\">1973</option>\n<option value=\"1972\">1972</option>\n<option value=\"1971\">1971</option>\n<option value=\"1970\">1970</option>\n<option value=\"1969\">1969</option>\n<option value=\"1968\">1968</option>\n<option value=\"1967\">1967</option>\n<option value=\"1966\">1966</option>\n<option value=\"1965\">1965</option>\n<option value=\"1964\">1964</option>\n<option value=\"1963\">1963</option>\n<option value=\"1962\">1962</option>\n<option value=\"1961\">1961</option>\n<option value=\"1960\">1960</option>\n<option value=\"1959\">1959</option>\n<option value=\"1958\">1958</option>\n<option value=\"1957\">1957</option>\n<option value=\"1956\">1956</option>\n<option value=\"1955\">1955</option>\n<option value=\"1954\">1954</option>\n<option value=\"1953\">1953</option>\n<option value=\"1952\">1952</option>\n<option value=\"1951\">1951</option>\n<option value=\"1950\">1950</option>\n<option value=\"1949\">1949</option>\n<option value=\"1948\">1948</option>\n<option value=\"1947\">1947</option>\n<option value=\"1946\">1946</option>\n<option value=\"1945\">1945</option>\n<option value=\"1944\">1944</option>\n<option value=\"1943\">1943</option>\n<option value=\"1942\">1942</option>\n<option value=\"1941\">1941</option>\n<option value=\"1940\">1940</option>\n</select>\n"
41
+ end
42
+ end
43
+
44
+
45
+ describe ActionView::Helpers::FormOptionsHelper do
46
+
47
+
48
+ before(:each) do
49
+ ActionView::Helpers::InstanceTag.stub(:new).and_return(@instance_tag)
50
+ end
51
+
52
+ it "should call the instance tag with argument" do
53
+ ActionView::Helpers::InstanceTag.should_receive(:new).with(student, 'birthday', self, options.delete(:object)).and_return(@instance_tag)
54
+ enhanced_date_select(student,'birthday',options )
55
+ end
56
+ it "should call the tp date_select_tag method" do
57
+ @instance_tag.should_receive(:to_enhanced_date_select_tag).with(options, {})
58
+ enhanced_date_select(student,'birthday',options )
59
+ end
60
+
61
+ end
62
+
63
+
64
+ describe ActionView::Helpers::InstanceTag do
65
+
66
+ before(:each) do
67
+ @instance_tag.stub(:enhanced_datetime_selector).and_return(@enhanced_datetime_selector)
68
+ end
69
+
70
+
71
+ it "should call the datetimeselector" do
72
+ @instance_tag.should_receive(:enhanced_datetime_selector).with(options, html_options).and_return(@enhanced_datetime_selector)
73
+ @instance_tag.to_enhanced_date_select_tag(options, html_options)
74
+ end
75
+
76
+ it "should call the datetimeselector" do
77
+ @enhanced_datetime_selector.should_receive(:enhanced_select_date).and_return(expected_result)
78
+ @instance_tag.to_enhanced_date_select_tag(options, html_options)
79
+ end
80
+
81
+
82
+
83
+ end
84
+
85
+
86
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: enhanced_date_select
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 1.0.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-16 00:00:00.000000000 Z
12
+ date: 2013-07-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec-rails
@@ -276,6 +276,7 @@ extra_rdoc_files:
276
276
  - LICENSE.txt
277
277
  - README.rdoc
278
278
  files:
279
+ - .rbenv-version
279
280
  - .rspec
280
281
  - .rvmrc
281
282
  - Gemfile
@@ -303,7 +304,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
303
304
  version: '0'
304
305
  segments:
305
306
  - 0
306
- hash: 136929645
307
+ hash: 110692367
307
308
  required_rubygems_version: !ruby/object:Gem::Requirement
308
309
  none: false
309
310
  requirements:
@@ -312,7 +313,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
312
313
  version: '0'
313
314
  requirements: []
314
315
  rubyforge_project:
315
- rubygems_version: 1.8.24
316
+ rubygems_version: 1.8.25
316
317
  signing_key:
317
318
  specification_version: 3
318
319
  summary: ! '"enhanced date select"'