diff options
6 files changed, 32 insertions, 6 deletions
diff --git a/actionpack/lib/action_view/helpers/form_options_helper.rb b/actionpack/lib/action_view/helpers/form_options_helper.rb index 3ee0d8ebc5..0dd4b19573 100644 --- a/actionpack/lib/action_view/helpers/form_options_helper.rb +++ b/actionpack/lib/action_view/helpers/form_options_helper.rb @@ -578,6 +578,7 @@ module ActionView def to_select_tag(choices, options, html_options) selected_value = options.has_key?(:selected) ? options[:selected] : value(object) + choices = choices.to_a if choices.is_a?(Range) # Grouped choices look like this: # diff --git a/actionpack/test/template/form_options_helper_test.rb b/actionpack/test/template/form_options_helper_test.rb index 4a889beadd..62ab208c2e 100644 --- a/actionpack/test/template/form_options_helper_test.rb +++ b/actionpack/test/template/form_options_helper_test.rb @@ -159,6 +159,13 @@ class FormOptionsHelperTest < ActionView::TestCase ) end + def test_range_options_for_select + assert_dom_equal( + "<option value=\"1\">1</option>\n<option value=\"2\">2</option>\n<option value=\"3\">3</option>", + options_for_select(1..3) + ) + end + def test_hash_options_for_select assert_dom_equal( "<option value=\"<Kroner>\"><DKR></option>\n<option value=\"Dollar\">$</option>", @@ -671,6 +678,15 @@ class FormOptionsHelperTest < ActionView::TestCase ) end + def test_select_with_range + @post = Post.new + @post.category = 0 + assert_dom_equal( + "<select id=\"post_category\" name=\"post[category]\"><option value=\"1\">1</option>\n<option value=\"2\">2</option>\n<option value=\"3\">3</option></select>", + select("post", "category", 1..3) + ) + end + def test_collection_select @post = Post.new @post.author_name = "Babe" diff --git a/activesupport/lib/active_support/base64.rb b/activesupport/lib/active_support/base64.rb index bb4c955eea..61a4af1a87 100644 --- a/activesupport/lib/active_support/base64.rb +++ b/activesupport/lib/active_support/base64.rb @@ -40,7 +40,7 @@ module ActiveSupport def self.decode64(value) ActiveSupport::Deprecation.warn "ActiveSupport::Base64.decode64 " \ "is deprecated. Use Base64.decode64 instead", caller - ::Base64.encode64(value) + ::Base64.decode64(value) end def self.encode64s(value) diff --git a/activesupport/test/core_ext/base64_ext_test.rb b/activesupport/test/core_ext/base64_ext_test.rb index 544c990b3c..07052a366a 100644 --- a/activesupport/test/core_ext/base64_ext_test.rb +++ b/activesupport/test/core_ext/base64_ext_test.rb @@ -7,4 +7,13 @@ class Base64Test < Test::Unit::TestCase assert_no_match(/\n/, ActiveSupport::Base64.encode64s("oneverylongstringthatwouldnormallybesplitupbynewlinesbytheregularbase64")) end end + + def test_encode_and_decode + ActiveSupport::Deprecation.silence do + string = "foobar" + encoded_string = ActiveSupport::Base64.encode64(string) + assert_equal "Zm9vYmFy\n", encoded_string + assert_equal string, ActiveSupport::Base64.decode64(encoded_string) + end + end end diff --git a/railties/lib/rails/generators/generated_attribute.rb b/railties/lib/rails/generators/generated_attribute.rb index cfd58527ef..8d307ca536 100644 --- a/railties/lib/rails/generators/generated_attribute.rb +++ b/railties/lib/rails/generators/generated_attribute.rb @@ -29,8 +29,8 @@ module Rails case type when /(string|text|binary|integer)\{(\d+)\}/ return $1, :limit => $2.to_i - when /decimal\{(\d+),(\d+)\}/ - return :decimal, :precision => $1.to_i, :scale => $2.to_i + when /decimal\{(\d+)(,|\.|\-)(\d+)\}/ + return :decimal, :precision => $1.to_i, :scale => $3.to_i else return type, {} end diff --git a/railties/test/generators/migration_generator_test.rb b/railties/test/generators/migration_generator_test.rb index cdac014965..3f4e160988 100644 --- a/railties/test/generators/migration_generator_test.rb +++ b/railties/test/generators/migration_generator_test.rb @@ -105,18 +105,18 @@ class MigrationGeneratorTest < Rails::Generators::TestCase def test_add_migration_with_attributes_index_declaration_and_attribute_options migration = "add_title_and_content_to_books" - run_generator [migration, "title:string{40}:index", "content:string{255}", "price:decimal{5,2}:index", "discount:decimal{3,2}:uniq"] + run_generator [migration, "title:string{40}:index", "content:string{255}", "price:decimal{1,2}:index", "discount:decimal{3.4}:uniq"] assert_migration "db/migrate/#{migration}.rb" do |content| assert_method :change, content do |up| assert_match(/add_column :books, :title, :string, :limit => 40/, up) assert_match(/add_column :books, :content, :string, :limit => 255/, up) assert_match(/add_column :books, :price, :decimal,/, up) - assert_match(/, :precision => 5/, up) + assert_match(/, :precision => 1/, up) assert_match(/, :scale => 2/, up) assert_match(/add_column :books, :discount, :decimal,/, up) assert_match(/, :precision => 3/, up) - assert_match(/, :scale => 2/, up) + assert_match(/, :scale => 4/, up) end assert_match(/add_index :books, :title/, content) assert_match(/add_index :books, :price/, content) |