diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2005-04-13 05:15:41 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2005-04-13 05:15:41 +0000 |
commit | c29db9f210c81a757e035ee6c8e1a055f6b676b3 (patch) | |
tree | b0304a1908769172bb0aae4680493a28673a05bd /actionpack | |
parent | e0a2dab8166d67c556ab9abc13fb673d2eee1e20 (diff) | |
download | rails-c29db9f210c81a757e035ee6c8e1a055f6b676b3.tar.gz rails-c29db9f210c81a757e035ee6c8e1a055f6b676b3.tar.bz2 rails-c29db9f210c81a757e035ee6c8e1a055f6b676b3.zip |
Added minute_step as an option to select_minute (and the helpers that use it) to jump in larger increments than just 1 minute. At 15, it would return 0, 15, 30, 45 options #1085 [ordwaye@evergreen.edu]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1154 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack')
-rw-r--r-- | actionpack/CHANGELOG | 2 | ||||
-rwxr-xr-x | actionpack/lib/action_view/helpers/date_helper.rb | 3 | ||||
-rwxr-xr-x | actionpack/test/template/date_helper_test.rb | 16 |
3 files changed, 20 insertions, 1 deletions
diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG index 9abf436390..591fe91b4e 100644 --- a/actionpack/CHANGELOG +++ b/actionpack/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Added minute_step as an option to select_minute (and the helpers that use it) to jump in larger increments than just 1 minute. At 15, it would return 0, 15, 30, 45 options #1085 [ordwaye@evergreen.edu] + * Fixed that an exception would be thrown when an empty form was submitted #1090 [jan@ulbrich-boerwang.de] * Moved TextHelper#human_size to NumberHelper#number_to_human_size, but kept an deprecated alias to the old method name diff --git a/actionpack/lib/action_view/helpers/date_helper.rb b/actionpack/lib/action_view/helpers/date_helper.rb index 9ffafe70b4..6f9545983c 100755 --- a/actionpack/lib/action_view/helpers/date_helper.rb +++ b/actionpack/lib/action_view/helpers/date_helper.rb @@ -114,11 +114,12 @@ module ActionView end # Returns a select tag with options for each of the minutes 0 through 59 with the current minute selected. + # Also can return a select tag with options by <tt>minute_step</tt> from 0 through 59 with the 00 minute selected # The <tt>minute</tt> can also be substituted for a minute number. def select_minute(datetime, options = {}) minute_options = [] - 0.upto(59) do |minute| + 0.step(59, options[:minute_step] || 1) do |minute| minute_options << ((datetime && (datetime.kind_of?(Fixnum) ? datetime : datetime.min) == minute) ? "<option selected=\"selected\">#{leading_zero_on_single_digits(minute)}</option>\n" : "<option>#{leading_zero_on_single_digits(minute)}</option>\n" diff --git a/actionpack/test/template/date_helper_test.rb b/actionpack/test/template/date_helper_test.rb index fa51ef8253..ab5cfc1c7a 100755 --- a/actionpack/test/template/date_helper_test.rb +++ b/actionpack/test/template/date_helper_test.rb @@ -164,6 +164,14 @@ class DateHelperTest < Test::Unit::TestCase assert_equal expected, select_minute(Time.mktime(2003, 8, 16, 8, 4, 18), :include_blank => true) end + def test_select_minute_with_blank_and_step + expected = %(<select name="date[minute]">\n) + expected << %(<option></option>\n<option>00</option>\n<option>15</option>\n<option>30</option>\n<option>45</option>\n) + expected << "</select>\n" + + assert_equal expected, select_minute(Time.mktime(2003, 8, 16, 8, 4, 18), { :include_blank => true , :minute_step => 15 }) + end + def test_select_minute_nil_with_blank expected = %(<select name="date[minute]">\n) expected << %(<option></option>\n<option>00</option>\n<option>01</option>\n<option>02</option>\n<option>03</option>\n<option>04</option>\n<option>05</option>\n<option>06</option>\n<option>07</option>\n<option>08</option>\n<option>09</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<option>32</option>\n<option>33</option>\n<option>34</option>\n<option>35</option>\n<option>36</option>\n<option>37</option>\n<option>38</option>\n<option>39</option>\n<option>40</option>\n<option>41</option>\n<option>42</option>\n<option>43</option>\n<option>44</option>\n<option>45</option>\n<option>46</option>\n<option>47</option>\n<option>48</option>\n<option>49</option>\n<option>50</option>\n<option>51</option>\n<option>52</option>\n<option>53</option>\n<option>54</option>\n<option>55</option>\n<option>56</option>\n<option>57</option>\n<option>58</option>\n<option>59</option>\n) @@ -172,6 +180,14 @@ class DateHelperTest < Test::Unit::TestCase assert_equal expected, select_minute(nil, :include_blank => true) end + def test_select_minute_nil_with_blank_and_step + expected = %(<select name="date[minute]">\n) + expected << %(<option></option>\n<option>00</option>\n<option>15</option>\n<option>30</option>\n<option>45</option>\n) + expected << "</select>\n" + + assert_equal expected, select_minute(nil, { :include_blank => true , :minute_step => 15 }) + end + def test_select_second expected = %(<select name="date[second]">\n) expected << %(<option>00</option>\n<option>01</option>\n<option>02</option>\n<option>03</option>\n<option>04</option>\n<option>05</option>\n<option>06</option>\n<option>07</option>\n<option>08</option>\n<option>09</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 selected="selected">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<option>32</option>\n<option>33</option>\n<option>34</option>\n<option>35</option>\n<option>36</option>\n<option>37</option>\n<option>38</option>\n<option>39</option>\n<option>40</option>\n<option>41</option>\n<option>42</option>\n<option>43</option>\n<option>44</option>\n<option>45</option>\n<option>46</option>\n<option>47</option>\n<option>48</option>\n<option>49</option>\n<option>50</option>\n<option>51</option>\n<option>52</option>\n<option>53</option>\n<option>54</option>\n<option>55</option>\n<option>56</option>\n<option>57</option>\n<option>58</option>\n<option>59</option>\n) |