mirror of https://github.com/rails/rails
Fixed DateHelper#date_select so that you can pass include_blank as an option even if you don't use start_year and end_year #59 [what-a-day]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@167 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
parent
846a1236bc
commit
db6179d12f
|
@ -1,5 +1,7 @@
|
|||
*SVN*
|
||||
|
||||
* Fixed DateHelper#date_select so that you can pass include_blank as an option even if you don't use start_year and end_year #59 [what-a-day]
|
||||
|
||||
* Added that controllers will now search for a layout in $template_root/layouts/$controller_name.r(html|xml), so PostsController will look
|
||||
for layouts/posts.rhtml or layouts/posts.rxml and automatically configure this layout if found #307 [Marcel]
|
||||
|
||||
|
|
|
@ -158,7 +158,8 @@ module ActionView
|
|||
# select_year(Date.today, :start_year => 1992, :end_year => 2007)
|
||||
def select_year(date, options = {})
|
||||
year_options = []
|
||||
unless date.kind_of?(Fixnum) then default_start_year, default_end_year = date.year - 5, date.year + 5 end
|
||||
y = date.kind_of?(Fixnum) ? (y = (date == 0) ? Date.today.year : date) : date.year
|
||||
default_start_year, default_end_year = y-5, y+5
|
||||
|
||||
(options[:start_year] || default_start_year).upto(options[:end_year] || default_end_year) do |year|
|
||||
year_options << ((date.kind_of?(Fixnum) ? date : date.year) == year ?
|
||||
|
|
|
@ -101,4 +101,148 @@ class DateHelperTest < Test::Unit::TestCase
|
|||
Time.mktime(2003, 8, 16), :start_year => 2003, :end_year => 2005, :prefix => "date[first]"
|
||||
)
|
||||
end
|
||||
|
||||
def test_select_date_with_no_start_year
|
||||
expected = %(<select name="date[first][year]">\n)
|
||||
(Date.today.year-5).upto(Date.today.year+1) do |y|
|
||||
if y == Date.today.year
|
||||
expected << %(<option selected="selected">#{y}</option>\n)
|
||||
else
|
||||
expected << %(<option>#{y}</option>\n)
|
||||
end
|
||||
end
|
||||
expected << "</select>\n"
|
||||
|
||||
expected << %(<select name="date[first][month]">\n)
|
||||
expected << %(<option value="1">January</option>\n<option 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" selected="selected">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)
|
||||
expected << "</select>\n"
|
||||
|
||||
expected << %(<select name="date[first][day]">\n)
|
||||
expected <<
|
||||
%(<option>1</option>\n<option>2</option>\n<option>3</option>\n<option>4</option>\n<option>5</option>\n<option>6</option>\n<option>7</option>\n<option>8</option>\n<option>9</option>\n<option>10</option>\n<option>11</option>\n<option>12</option>\n<option>13</option>\n<option>14</option>\n<option>15</option>\n<option selected="selected">16</option>\n<option>17</option>\n<option>18</option>\n<option>19</option>\n<option>20</option>\n<option>21</option>\n<option>22</option>\n<option>23</option>\n<option>24</option>\n<option>25</option>\n<option>26</option>\n<option>27</option>\n<option>28</option>\n<option>29</option>\n<option>30</option>\n<option>31</option>\n)
|
||||
expected << "</select>\n"
|
||||
|
||||
assert_equal expected, select_date(
|
||||
Time.mktime(Date.today.year, 8, 16), :end_year => Date.today.year+1, :prefix => "date[first]"
|
||||
)
|
||||
end
|
||||
|
||||
def test_select_date_with_no_end_year
|
||||
expected = %(<select name="date[first][year]">\n)
|
||||
2003.upto(2008) do |y|
|
||||
if y == 2003
|
||||
expected << %(<option selected="selected">#{y}</option>\n)
|
||||
else
|
||||
expected << %(<option>#{y}</option>\n)
|
||||
end
|
||||
end
|
||||
expected << "</select>\n"
|
||||
|
||||
expected << %(<select name="date[first][month]">\n)
|
||||
expected << %(<option value="1">January</option>\n<option 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" selected="selected">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)
|
||||
expected << "</select>\n"
|
||||
|
||||
expected << %(<select name="date[first][day]">\n)
|
||||
expected <<
|
||||
%(<option>1</option>\n<option>2</option>\n<option>3</option>\n<option>4</option>\n<option>5</option>\n<option>6</option>\n<option>7</option>\n<option>8</option>\n<option>9</option>\n<option>10</option>\n<option>11</option>\n<option>12</option>\n<option>13</option>\n<option>14</option>\n<option>15</option>\n<option selected="selected">16</option>\n<option>17</option>\n<option>18</option>\n<option>19</option>\n<option>20</option>\n<option>21</option>\n<option>22</option>\n<option>23</option>\n<option>24</option>\n<option>25</option>\n<option>26</option>\n<option>27</option>\n<option>28</option>\n<option>29</option>\n<option>30</option>\n<option>31</option>\n)
|
||||
expected << "</select>\n"
|
||||
|
||||
assert_equal expected, select_date(
|
||||
Time.mktime(2003, 8, 16), :start_year => 2003, :prefix => "date[first]"
|
||||
)
|
||||
end
|
||||
|
||||
def test_select_date_with_no_start_or_end_year
|
||||
expected = %(<select name="date[first][year]">\n)
|
||||
(Date.today.year-5).upto(Date.today.year+5) do |y|
|
||||
if y == Date.today.year
|
||||
expected << %(<option selected="selected">#{y}</option>\n)
|
||||
else
|
||||
expected << %(<option>#{y}</option>\n)
|
||||
end
|
||||
end
|
||||
expected << "</select>\n"
|
||||
|
||||
expected << %(<select name="date[first][month]">\n)
|
||||
expected << %(<option value="1">January</option>\n<option 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" selected="selected">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)
|
||||
expected << "</select>\n"
|
||||
|
||||
expected << %(<select name="date[first][day]">\n)
|
||||
expected <<
|
||||
%(<option>1</option>\n<option>2</option>\n<option>3</option>\n<option>4</option>\n<option>5</option>\n<option>6</option>\n<option>7</option>\n<option>8</option>\n<option>9</option>\n<option>10</option>\n<option>11</option>\n<option>12</option>\n<option>13</option>\n<option>14</option>\n<option>15</option>\n<option selected="selected">16</option>\n<option>17</option>\n<option>18</option>\n<option>19</option>\n<option>20</option>\n<option>21</option>\n<option>22</option>\n<option>23</option>\n<option>24</option>\n<option>25</option>\n<option>26</option>\n<option>27</option>\n<option>28</option>\n<option>29</option>\n<option>30</option>\n<option>31</option>\n)
|
||||
expected << "</select>\n"
|
||||
|
||||
assert_equal expected, select_date(
|
||||
Time.mktime(Date.today.year, 8, 16), :prefix => "date[first]"
|
||||
)
|
||||
end
|
||||
|
||||
def test_date_select_with_zero_value
|
||||
expected = %(<select name="date[first][year]">\n)
|
||||
expected << %(<option>2003</option>\n<option>2004</option>\n<option>2005</option>\n)
|
||||
expected << "</select>\n"
|
||||
|
||||
expected << %(<select name="date[first][month]">\n)
|
||||
expected << %(<option value="1">January</option>\n<option 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)
|
||||
expected << "</select>\n"
|
||||
|
||||
expected << %(<select name="date[first][day]">\n)
|
||||
expected <<
|
||||
%(<option>1</option>\n<option>2</option>\n<option>3</option>\n<option>4</option>\n<option>5</option>\n<option>6</option>\n<option>7</option>\n<option>8</option>\n<option>9</option>\n<option>10</option>\n<option>11</option>\n<option>12</option>\n<option>13</option>\n<option>14</option>\n<option>15</option>\n<option>16</option>\n<option>17</option>\n<option>18</option>\n<option>19</option>\n<option>20</option>\n<option>21</option>\n<option>22</option>\n<option>23</option>\n<option>24</option>\n<option>25</option>\n<option>26</option>\n<option>27</option>\n<option>28</option>\n<option>29</option>\n<option>30</option>\n<option>31</option>\n)
|
||||
expected << "</select>\n"
|
||||
|
||||
assert_equal expected, select_date(0, :start_year => 2003, :end_year => 2005, :prefix => "date[first]")
|
||||
end
|
||||
|
||||
def test_date_select_with_zero_value_and_no_start_year
|
||||
expected = %(<select name="date[first][year]">\n)
|
||||
(Date.today.year-5).upto(Date.today.year+1) { |y| expected << %(<option>#{y}</option>\n) }
|
||||
expected << "</select>\n"
|
||||
|
||||
expected << %(<select name="date[first][month]">\n)
|
||||
expected << %(<option value="1">January</option>\n<option 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)
|
||||
expected << "</select>\n"
|
||||
|
||||
expected << %(<select name="date[first][day]">\n)
|
||||
expected <<
|
||||
%(<option>1</option>\n<option>2</option>\n<option>3</option>\n<option>4</option>\n<option>5</option>\n<option>6</option>\n<option>7</option>\n<option>8</option>\n<option>9</option>\n<option>10</option>\n<option>11</option>\n<option>12</option>\n<option>13</option>\n<option>14</option>\n<option>15</option>\n<option>16</option>\n<option>17</option>\n<option>18</option>\n<option>19</option>\n<option>20</option>\n<option>21</option>\n<option>22</option>\n<option>23</option>\n<option>24</option>\n<option>25</option>\n<option>26</option>\n<option>27</option>\n<option>28</option>\n<option>29</option>\n<option>30</option>\n<option>31</option>\n)
|
||||
expected << "</select>\n"
|
||||
|
||||
assert_equal expected, select_date(0, :end_year => Date.today.year+1, :prefix => "date[first]")
|
||||
end
|
||||
|
||||
def test_date_select_with_zero_value_and_no_end_year
|
||||
expected = %(<select name="date[first][year]">\n)
|
||||
2003.upto(2009) { |y| expected << %(<option>#{y}</option>\n) }
|
||||
expected << "</select>\n"
|
||||
|
||||
expected << %(<select name="date[first][month]">\n)
|
||||
expected << %(<option value="1">January</option>\n<option 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)
|
||||
expected << "</select>\n"
|
||||
|
||||
expected << %(<select name="date[first][day]">\n)
|
||||
expected <<
|
||||
%(<option>1</option>\n<option>2</option>\n<option>3</option>\n<option>4</option>\n<option>5</option>\n<option>6</option>\n<option>7</option>\n<option>8</option>\n<option>9</option>\n<option>10</option>\n<option>11</option>\n<option>12</option>\n<option>13</option>\n<option>14</option>\n<option>15</option>\n<option>16</option>\n<option>17</option>\n<option>18</option>\n<option>19</option>\n<option>20</option>\n<option>21</option>\n<option>22</option>\n<option>23</option>\n<option>24</option>\n<option>25</option>\n<option>26</option>\n<option>27</option>\n<option>28</option>\n<option>29</option>\n<option>30</option>\n<option>31</option>\n)
|
||||
expected << "</select>\n"
|
||||
|
||||
assert_equal expected, select_date(0, :start_year => 2003, :prefix => "date[first]")
|
||||
end
|
||||
|
||||
def test_date_select_with_zero_value_and_no_start_and_end_year
|
||||
expected = %(<select name="date[first][year]">\n)
|
||||
(Date.today.year-5).upto(Date.today.year+5) { |y| expected << %(<option>#{y}</option>\n) }
|
||||
expected << "</select>\n"
|
||||
|
||||
expected << %(<select name="date[first][month]">\n)
|
||||
expected << %(<option value="1">January</option>\n<option 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)
|
||||
expected << "</select>\n"
|
||||
|
||||
expected << %(<select name="date[first][day]">\n)
|
||||
expected <<
|
||||
%(<option>1</option>\n<option>2</option>\n<option>3</option>\n<option>4</option>\n<option>5</option>\n<option>6</option>\n<option>7</option>\n<option>8</option>\n<option>9</option>\n<option>10</option>\n<option>11</option>\n<option>12</option>\n<option>13</option>\n<option>14</option>\n<option>15</option>\n<option>16</option>\n<option>17</option>\n<option>18</option>\n<option>19</option>\n<option>20</option>\n<option>21</option>\n<option>22</option>\n<option>23</option>\n<option>24</option>\n<option>25</option>\n<option>26</option>\n<option>27</option>\n<option>28</option>\n<option>29</option>\n<option>30</option>\n<option>31</option>\n)
|
||||
expected << "</select>\n"
|
||||
|
||||
assert_equal expected, select_date(0, :prefix => "date[first]")
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue