diff options
-rw-r--r-- | .travis.yml | 3 | ||||
-rw-r--r-- | Gemfile | 3 | ||||
-rw-r--r-- | actionmailer/CHANGELOG.md | 5 | ||||
-rw-r--r-- | actionpack/CHANGELOG.md | 4 | ||||
-rw-r--r-- | actionpack/lib/action_dispatch/middleware/params_parser.rb | 4 | ||||
-rw-r--r-- | actionpack/lib/action_view/helpers/form_helper.rb | 2 | ||||
-rw-r--r-- | actionpack/test/dispatch/request/json_params_parsing_test.rb | 7 | ||||
-rw-r--r-- | actionpack/test/template/form_helper_test.rb | 23 | ||||
-rw-r--r-- | activemodel/test/cases/errors_test.rb | 53 | ||||
-rw-r--r-- | activerecord/lib/active_record/associations/preloader/association.rb | 2 | ||||
-rw-r--r-- | activerecord/test/cases/associations/eager_test.rb | 14 | ||||
-rw-r--r-- | activesupport/lib/active_support/core_ext/array/access.rb | 8 | ||||
-rw-r--r-- | railties/lib/rails/generators/rails/app/templates/Gemfile | 2 | ||||
-rw-r--r-- | railties/lib/rails/generators/rails/scaffold/scaffold_generator.rb | 2 | ||||
-rw-r--r-- | railties/lib/rails/generators/rails/scaffold_controller/templates/controller.rb | 4 | ||||
-rw-r--r-- | railties/test/generators/scaffold_controller_generator_test.rb | 2 |
16 files changed, 114 insertions, 24 deletions
diff --git a/.travis.yml b/.travis.yml index 18b0100c62..ba5526c009 100644 --- a/.travis.yml +++ b/.travis.yml @@ -24,6 +24,3 @@ notifications: rooms: - secure: "YA1alef1ESHWGFNVwvmVGCkMe4cUy4j+UcNvMUESraceiAfVyRMAovlQBGs6\n9kBRm7DHYBUXYC2ABQoJbQRLDr/1B5JPf/M8+Qd7BKu8tcDC03U01SMHFLpO\naOs/HLXcDxtnnpL07tGVsm0zhMc5N8tq4/L3SHxK7Vi+TacwQzI=" bundler_args: --path vendor/bundle -matrix: - allow_failures: - - rvm: 2.0.0 @@ -12,7 +12,8 @@ gem 'jquery-rails', '~> 2.1.4', github: 'rails/jquery-rails' gem 'turbolinks' gem 'coffee-rails', github: 'rails/coffee-rails' -gem 'thread_safe', '~> 0.1' +# TODO: Release thor +gem 'thor', github: 'wycats/thor', branch: 'master' gem 'activerecord-deprecated_finders', github: 'rails/activerecord-deprecated_finders', branch: 'master' diff --git a/actionmailer/CHANGELOG.md b/actionmailer/CHANGELOG.md index 9feca324a3..43bfa536c1 100644 --- a/actionmailer/CHANGELOG.md +++ b/actionmailer/CHANGELOG.md @@ -1,5 +1,10 @@ ## Rails 4.0.0 (unreleased) ## +* Eager loading made to use relation's in_clause_length instead of host's one. + Fix #8474 + + *Boris Staal* + * Explicit multipart messages no longer set the order of the MIME parts. *Nate Berkopec* diff --git a/actionpack/CHANGELOG.md b/actionpack/CHANGELOG.md index 7dea0e7fa5..2cb7af05e5 100644 --- a/actionpack/CHANGELOG.md +++ b/actionpack/CHANGELOG.md @@ -1,5 +1,9 @@ ## Rails 4.0.0 (unreleased) ## +* Fixed json params parsing regression for non-object JSON content. + + *Dylan Smith* + * Extract `ActionDispatch::PerformanceTest` into https://github.com/rails/rails-perftest You can add the gem to your Gemfile to keep using performance tests. diff --git a/actionpack/lib/action_dispatch/middleware/params_parser.rb b/actionpack/lib/action_dispatch/middleware/params_parser.rb index a3291bb7ad..0898ad82dd 100644 --- a/actionpack/lib/action_dispatch/middleware/params_parser.rb +++ b/actionpack/lib/action_dispatch/middleware/params_parser.rb @@ -50,9 +50,9 @@ module ActionDispatch data = request.deep_munge(Hash.from_xml(request.body.read) || {}) data.with_indifferent_access when :json - data = request.deep_munge ActiveSupport::JSON.decode(request.body) + data = ActiveSupport::JSON.decode(request.body) data = {:_json => data} unless data.is_a?(Hash) - data.with_indifferent_access + request.deep_munge(data).with_indifferent_access else false end diff --git a/actionpack/lib/action_view/helpers/form_helper.rb b/actionpack/lib/action_view/helpers/form_helper.rb index 50f1eff4ec..4a31de715d 100644 --- a/actionpack/lib/action_view/helpers/form_helper.rb +++ b/actionpack/lib/action_view/helpers/form_helper.rb @@ -1800,7 +1800,7 @@ module ActionView association = convert_to_model(association) if association.respond_to?(:persisted?) - association = [association] if @object.send(association_name).is_a?(Array) + association = [association] if @object.send(association_name).respond_to?(:to_ary) elsif !association.respond_to?(:to_ary) association = @object.send(association_name) end diff --git a/actionpack/test/dispatch/request/json_params_parsing_test.rb b/actionpack/test/dispatch/request/json_params_parsing_test.rb index 2c4a6c2147..7d3fc84089 100644 --- a/actionpack/test/dispatch/request/json_params_parsing_test.rb +++ b/actionpack/test/dispatch/request/json_params_parsing_test.rb @@ -122,6 +122,13 @@ class RootLessJSONParamsParsingTest < ActionDispatch::IntegrationTest ) end + test "parses json with non-object JSON content" do + assert_parses( + {"user" => {"_json" => "string content" }, "_json" => "string content" }, + "\"string content\"", { 'CONTENT_TYPE' => 'application/json' } + ) + end + private def assert_parses(expected, actual, headers = {}) with_test_routing(UsersController) do diff --git a/actionpack/test/template/form_helper_test.rb b/actionpack/test/template/form_helper_test.rb index 5e47e4db23..247068de4e 100644 --- a/actionpack/test/template/form_helper_test.rb +++ b/actionpack/test/template/form_helper_test.rb @@ -2163,6 +2163,29 @@ class FormHelperTest < ActionView::TestCase assert_dom_equal expected, output_buffer end + class FakeAssociatonProxy + def to_ary + [1, 2, 3] + end + end + + def test_nested_fields_for_with_child_index_option_override_on_a_nested_attributes_collection_association_with_proxy + @post.comments = FakeAssociatonProxy.new + + form_for(@post) do |f| + concat f.fields_for(:comments, Comment.new(321), :child_index => 'abc') { |cf| + concat cf.text_field(:name) + } + end + + expected = whole_form('/posts/123', 'edit_post_123', 'edit_post', :method => 'patch') do + '<input id="post_comments_attributes_abc_name" name="post[comments_attributes][abc][name]" type="text" value="comment #321" />' + + '<input id="post_comments_attributes_abc_id" name="post[comments_attributes][abc][id]" type="hidden" value="321" />' + end + + assert_dom_equal expected, output_buffer + end + def test_nested_fields_for_index_method_with_existing_records_on_a_nested_attributes_collection_association @post.comments = Array.new(2) { |id| Comment.new(id + 1) } diff --git a/activemodel/test/cases/errors_test.rb b/activemodel/test/cases/errors_test.rb index 1ffce1ae47..cc0c3f16d2 100644 --- a/activemodel/test/cases/errors_test.rb +++ b/activemodel/test/cases/errors_test.rb @@ -54,6 +54,59 @@ class ErrorsTest < ActiveModel::TestCase assert errors.has_key?(:foo), 'errors should have key :foo' end + test "should be able to clear the errors" do + person = Person.new + person.validate! + + assert_equal 1, person.errors.count + person.errors.clear + assert person.errors.empty? + end + + test "get returns the error by the provided key" do + errors = ActiveModel::Errors.new(self) + errors[:foo] = "omg" + + assert_equal ["omg"], errors.get(:foo) + end + + test "sets the error with the provided key" do + errors = ActiveModel::Errors.new(self) + errors.set(:foo, "omg") + + assert_equal({ foo: "omg" }, errors.messages) + end + + test "values returns an array of messages" do + errors = ActiveModel::Errors.new(self) + errors.set(:foo, "omg") + errors.set(:baz, "zomg") + + assert_equal ["omg", "zomg"], errors.values + end + + test "keys returns the error keys" do + errors = ActiveModel::Errors.new(self) + errors.set(:foo, "omg") + errors.set(:baz, "zomg") + + assert_equal [:foo, :baz], errors.keys + end + + test "as_json returns a json formatted representation of the errors hash" do + person = Person.new + person.validate! + + assert_equal({ name: ["can not be nil"] }, person.errors.as_json) + end + + test "as_json with :full_messages option" do + person = Person.new + person.validate! + + assert_equal({ name: ["name can not be nil"] }, person.errors.as_json(full_messages: true)) + end + test "should return true if no errors" do person = Person.new person.errors[:foo] diff --git a/activerecord/lib/active_record/associations/preloader/association.rb b/activerecord/lib/active_record/associations/preloader/association.rb index cbf5e734ea..82588905c6 100644 --- a/activerecord/lib/active_record/associations/preloader/association.rb +++ b/activerecord/lib/active_record/associations/preloader/association.rb @@ -76,7 +76,7 @@ module ActiveRecord else # Some databases impose a limit on the number of ids in a list (in Oracle it's 1000) # Make several smaller queries if necessary or make one query if the adapter supports it - sliced = owner_keys.each_slice(model.connection.in_clause_length || owner_keys.size) + sliced = owner_keys.each_slice(klass.connection.in_clause_length || owner_keys.size) records = sliced.map { |slice| records_for(slice).to_a }.flatten end diff --git a/activerecord/test/cases/associations/eager_test.rb b/activerecord/test/cases/associations/eager_test.rb index ce1da53859..be2d30641e 100644 --- a/activerecord/test/cases/associations/eager_test.rb +++ b/activerecord/test/cases/associations/eager_test.rb @@ -93,31 +93,31 @@ class EagerAssociationTest < ActiveRecord::TestCase end def test_preloading_has_many_in_multiple_queries_with_more_ids_than_database_can_handle - Post.connection.expects(:in_clause_length).at_least_once.returns(5) + Comment.connection.expects(:in_clause_length).at_least_once.returns(5) posts = Post.all.merge!(:includes=>:comments).to_a assert_equal 11, posts.size end def test_preloading_has_many_in_one_queries_when_database_has_no_limit_on_ids_it_can_handle - Post.connection.expects(:in_clause_length).at_least_once.returns(nil) + Comment.connection.expects(:in_clause_length).at_least_once.returns(nil) posts = Post.all.merge!(:includes=>:comments).to_a assert_equal 11, posts.size end def test_preloading_habtm_in_multiple_queries_with_more_ids_than_database_can_handle - Post.connection.expects(:in_clause_length).at_least_once.returns(5) + Comment.connection.expects(:in_clause_length).at_least_once.returns(5) posts = Post.all.merge!(:includes=>:categories).to_a assert_equal 11, posts.size end def test_preloading_habtm_in_one_queries_when_database_has_no_limit_on_ids_it_can_handle - Post.connection.expects(:in_clause_length).at_least_once.returns(nil) + Comment.connection.expects(:in_clause_length).at_least_once.returns(nil) posts = Post.all.merge!(:includes=>:categories).to_a assert_equal 11, posts.size end def test_load_associated_records_in_one_query_when_adapter_has_no_limit - Post.connection.expects(:in_clause_length).at_least_once.returns(nil) + Comment.connection.expects(:in_clause_length).at_least_once.returns(nil) post = posts(:welcome) assert_queries(2) do @@ -126,7 +126,7 @@ class EagerAssociationTest < ActiveRecord::TestCase end def test_load_associated_records_in_several_queries_when_many_ids_passed - Post.connection.expects(:in_clause_length).at_least_once.returns(1) + Comment.connection.expects(:in_clause_length).at_least_once.returns(1) post1, post2 = posts(:welcome), posts(:thinking) assert_queries(3) do @@ -135,7 +135,7 @@ class EagerAssociationTest < ActiveRecord::TestCase end def test_load_associated_records_in_one_query_when_a_few_ids_passed - Post.connection.expects(:in_clause_length).at_least_once.returns(3) + Comment.connection.expects(:in_clause_length).at_least_once.returns(3) post = posts(:welcome) assert_queries(2) do diff --git a/activesupport/lib/active_support/core_ext/array/access.rb b/activesupport/lib/active_support/core_ext/array/access.rb index a8f9dddae5..4f1e432b61 100644 --- a/activesupport/lib/active_support/core_ext/array/access.rb +++ b/activesupport/lib/active_support/core_ext/array/access.rb @@ -21,28 +21,28 @@ class Array # Equal to <tt>self[1]</tt>. # - # %w( a b c d e).second # => "b" + # %w( a b c d e ).second # => "b" def second self[1] end # Equal to <tt>self[2]</tt>. # - # %w( a b c d e).third # => "c" + # %w( a b c d e ).third # => "c" def third self[2] end # Equal to <tt>self[3]</tt>. # - # %w( a b c d e).fourth # => "d" + # %w( a b c d e ).fourth # => "d" def fourth self[3] end # Equal to <tt>self[4]</tt>. # - # %w( a b c d e).fifth # => "e" + # %w( a b c d e ).fifth # => "e" def fifth self[4] end diff --git a/railties/lib/rails/generators/rails/app/templates/Gemfile b/railties/lib/rails/generators/rails/app/templates/Gemfile index 2b80896c27..b5db3d2187 100644 --- a/railties/lib/rails/generators/rails/app/templates/Gemfile +++ b/railties/lib/rails/generators/rails/app/templates/Gemfile @@ -10,7 +10,7 @@ source 'https://rubygems.org' <%= javascript_gemfile_entry -%> # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder -gem 'jbuilder' +gem 'jbuilder', '~> 1.0.1' # To use ActiveModel has_secure_password # gem 'bcrypt-ruby', '~> 3.0.0' diff --git a/railties/lib/rails/generators/rails/scaffold/scaffold_generator.rb b/railties/lib/rails/generators/rails/scaffold/scaffold_generator.rb index 9a7ea1f657..36589d65e2 100644 --- a/railties/lib/rails/generators/rails/scaffold/scaffold_generator.rb +++ b/railties/lib/rails/generators/rails/scaffold/scaffold_generator.rb @@ -10,7 +10,7 @@ module Rails class_option :stylesheet_engine, desc: "Engine for Stylesheets" def handle_skip - @options = @options.merge(stylesheet_engine: false) if !options[:stylesheets] + @options = @options.merge(stylesheet_engine: false) unless options[:stylesheets] end hook_for :scaffold_controller, required: true diff --git a/railties/lib/rails/generators/rails/scaffold_controller/templates/controller.rb b/railties/lib/rails/generators/rails/scaffold_controller/templates/controller.rb index 6f7eb07229..e813437d75 100644 --- a/railties/lib/rails/generators/rails/scaffold_controller/templates/controller.rb +++ b/railties/lib/rails/generators/rails/scaffold_controller/templates/controller.rb @@ -31,7 +31,7 @@ class <%= controller_class_name %>Controller < ApplicationController if @<%= orm_instance.save %> redirect_to @<%= singular_table_name %>, notice: <%= "'#{human_name} was successfully created.'" %> else - render action: "new" + render action: 'new' end end @@ -40,7 +40,7 @@ class <%= controller_class_name %>Controller < ApplicationController if @<%= orm_instance.update("#{singular_table_name}_params") %> redirect_to @<%= singular_table_name %>, notice: <%= "'#{human_name} was successfully updated.'" %> else - render action: "edit" + render action: 'edit' end end diff --git a/railties/test/generators/scaffold_controller_generator_test.rb b/railties/test/generators/scaffold_controller_generator_test.rb index bd99e78644..c34ce285e3 100644 --- a/railties/test/generators/scaffold_controller_generator_test.rb +++ b/railties/test/generators/scaffold_controller_generator_test.rb @@ -162,7 +162,7 @@ class ScaffoldControllerGeneratorTest < Rails::Generators::TestCase def test_new_hash_style run_generator assert_file "app/controllers/users_controller.rb" do |content| - assert_match(/render action: "new"/, content) + assert_match(/render action: 'new'/, content) end end end |