diff options
-rw-r--r-- | .gitignore | 48 | ||||
-rw-r--r-- | actionpack/CHANGELOG | 2 | ||||
-rw-r--r-- | actionpack/lib/action_controller/metal/responder.rb | 22 | ||||
-rw-r--r-- | actionpack/lib/action_view/helpers/form_options_helper.rb | 7 | ||||
-rw-r--r-- | actionpack/test/controller/mime_responds_test.rb | 20 | ||||
-rw-r--r-- | actionpack/test/template/form_options_helper_test.rb | 9 | ||||
-rw-r--r-- | activerecord/lib/active_record/railties/databases.rake | 2 | ||||
-rw-r--r-- | activerecord/lib/active_record/store.rb | 1 | ||||
-rw-r--r-- | activerecord/test/cases/store_test.rb | 5 | ||||
-rw-r--r-- | activesupport/lib/active_support/cache/file_store.rb | 21 | ||||
-rw-r--r-- | activesupport/test/buffered_logger_test.rb | 2 | ||||
-rw-r--r-- | activesupport/test/caching_test.rb | 34 | ||||
-rw-r--r-- | railties/CHANGELOG | 2 | ||||
-rw-r--r-- | railties/guides/source/caching_with_rails.textile | 6 | ||||
-rw-r--r-- | railties/lib/rails/generators/rails/scaffold_controller/templates/controller.rb | 4 | ||||
-rw-r--r-- | railties/test/application/rack/logger_test.rb | 2 | ||||
-rw-r--r-- | railties/test/generators/app_generator_test.rb | 10 |
17 files changed, 78 insertions, 119 deletions
diff --git a/.gitignore b/.gitignore index 437a1067f8..aa14cee911 100644 --- a/.gitignore +++ b/.gitignore @@ -1,27 +1,23 @@ -pkg -.bundle -Gemfile.lock +# Don't put *.swp, *.bak, etc here; those belong in a global ~/.gitignore. +# Check out http://help.github.com/ignore-files/ for how to set that up. + debug.log -doc/rdoc -activemodel/doc -activeresource/doc -activerecord/doc -activerecord/sqlnet.log -actionpack/doc -actionmailer/doc -activesupport/doc -activesupport/test/tmp -activemodel/test/fixtures/fixture_database.sqlite3 -actionpack/test/tmp -activesupport/test/fixtures/isolation_test -dist -railties/test/500.html -railties/test/fixtures/tmp -railties/test/initializer/root/log -railties/doc -railties/guides/output -railties/tmp -.rvmrc -.rbenv-version -RDOC_MAIN.rdoc -.rbx +/.bundle +/.rbenv-version +/.rvmrc +/Gemfile.lock +/pkg +/dist +/doc/rdoc +/*/doc +/*/test/tmp +/activerecord/sqlnet.log +/activemodel/test/fixtures/fixture_database.sqlite3 +/activesupport/test/fixtures/isolation_test +/railties/test/500.html +/railties/test/fixtures/tmp +/railties/test/initializer/root/log +/railties/doc +/railties/guides/output +/railties/tmp +/RDOC_MAIN.rdoc diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG index e7886facb9..a7a47bf930 100644 --- a/actionpack/CHANGELOG +++ b/actionpack/CHANGELOG @@ -1,5 +1,7 @@ *Rails 3.2.0 (unreleased)* +* Responders now return 204 No Content for API requests without a response body (as in the new scaffold) [José Valim] + * Added ActionDispatch::RequestId middleware that'll make a unique X-Request-Id header available to the response and enables the ActionDispatch::Request#uuid method. This makes it easy to trace requests from end-to-end in the stack and to identify individual requests in mixed logs like Syslog [DHH] * Limit the number of options for select_year to 1000. diff --git a/actionpack/lib/action_controller/metal/responder.rb b/actionpack/lib/action_controller/metal/responder.rb index c7827309dd..b932302a60 100644 --- a/actionpack/lib/action_controller/metal/responder.rb +++ b/actionpack/lib/action_controller/metal/responder.rb @@ -202,10 +202,8 @@ module ActionController #:nodoc: display resource elsif post? display resource, :status => :created, :location => api_location - elsif has_empty_resource_definition? - display empty_resource, :status => :ok else - head :ok + head :no_content end end @@ -269,24 +267,6 @@ module ActionController #:nodoc: @action ||= ACTIONS_FOR_VERBS[request.request_method_symbol] end - # Check whether resource needs a specific definition of empty resource to be valid - # - def has_empty_resource_definition? - respond_to?("empty_#{format}_resource") - end - - # Delegate to proper empty resource method - # - def empty_resource - send("empty_#{format}_resource") - end - - # Return a valid empty JSON resource - # - def empty_json_resource - "{}" - end - def resource_errors respond_to?("#{format}_resource_errors") ? send("#{format}_resource_errors") : resource.errors end diff --git a/actionpack/lib/action_view/helpers/form_options_helper.rb b/actionpack/lib/action_view/helpers/form_options_helper.rb index d636702111..1a6c3b9740 100644 --- a/actionpack/lib/action_view/helpers/form_options_helper.rb +++ b/actionpack/lib/action_view/helpers/form_options_helper.rb @@ -579,7 +579,12 @@ module ActionView def to_select_tag(choices, options, html_options) selected_value = options.has_key?(:selected) ? options[:selected] : value(object) - if !choices.empty? && Array === choices.first + # Grouped choices look like this: + # + # [nil, []] + # { nil => [] } + # + if !choices.empty? && choices.first.last.respond_to?(:each) option_tags = grouped_options_for_select(choices, :selected => selected_value, :disabled => options[:disabled]) else option_tags = options_for_select(choices, :selected => selected_value, :disabled => options[:disabled]) diff --git a/actionpack/test/controller/mime_responds_test.rb b/actionpack/test/controller/mime_responds_test.rb index e91e11a8a7..76a8c89e60 100644 --- a/actionpack/test/controller/mime_responds_test.rb +++ b/actionpack/test/controller/mime_responds_test.rb @@ -796,21 +796,21 @@ class RespondWithControllerTest < ActionController::TestCase end end - def test_using_resource_for_put_with_xml_yields_ok_on_success + def test_using_resource_for_put_with_xml_yields_no_content_on_success @request.accept = "application/xml" put :using_resource assert_equal "application/xml", @response.content_type - assert_equal 200, @response.status + assert_equal 204, @response.status assert_equal " ", @response.body end - def test_using_resource_for_put_with_json_yields_ok_on_success + def test_using_resource_for_put_with_json_yields_no_content_on_success Customer.any_instance.stubs(:to_json).returns('{"name": "David"}') @request.accept = "application/json" put :using_resource assert_equal "application/json", @response.content_type - assert_equal 200, @response.status - assert_equal "{}", @response.body + assert_equal 204, @response.status + assert_equal " ", @response.body end def test_using_resource_for_put_with_xml_yields_unprocessable_entity_on_failure @@ -846,23 +846,23 @@ class RespondWithControllerTest < ActionController::TestCase end end - def test_using_resource_for_delete_with_xml_yields_ok_on_success + def test_using_resource_for_delete_with_xml_yields_no_content_on_success Customer.any_instance.stubs(:destroyed?).returns(true) @request.accept = "application/xml" delete :using_resource assert_equal "application/xml", @response.content_type - assert_equal 200, @response.status + assert_equal 204, @response.status assert_equal " ", @response.body end - def test_using_resource_for_delete_with_json_yields_ok_on_success + def test_using_resource_for_delete_with_json_yields_no_content_on_success Customer.any_instance.stubs(:to_json).returns('{"name": "David"}') Customer.any_instance.stubs(:destroyed?).returns(true) @request.accept = "application/json" delete :using_resource assert_equal "application/json", @response.content_type - assert_equal 200, @response.status - assert_equal "{}", @response.body + assert_equal 204, @response.status + assert_equal " ", @response.body end def test_using_resource_for_delete_with_html_redirects_on_failure diff --git a/actionpack/test/template/form_options_helper_test.rb b/actionpack/test/template/form_options_helper_test.rb index d3e0cc41a9..469718e1bd 100644 --- a/actionpack/test/template/form_options_helper_test.rb +++ b/actionpack/test/template/form_options_helper_test.rb @@ -596,6 +596,15 @@ class FormOptionsHelperTest < ActionView::TestCase ) end + def test_list_of_lists + @post = Post.new + @post.category = "" + assert_dom_equal( + "<select id=\"post_category\" name=\"post[category]\"><option value=\"\">Please select</option>\n<option value=\"\"></option>\n<option value=\"number\">Number</option>\n<option value=\"text\">Text</option>\n<option value=\"boolean\">Yes/No</option></select>", + select("post", "category", [["Number", "number"], ["Text", "text"], ["Yes/No", "boolean"]], :prompt => true, :include_blank => true) + ) + end + def test_select_with_selected_value @post = Post.new @post.category = "<mus>" diff --git a/activerecord/lib/active_record/railties/databases.rake b/activerecord/lib/active_record/railties/databases.rake index f8fa65ea87..44848b3391 100644 --- a/activerecord/lib/active_record/railties/databases.rake +++ b/activerecord/lib/active_record/railties/databases.rake @@ -550,7 +550,7 @@ end def configs_for_environment environments = [Rails.env] environments << 'test' if Rails.env.development? - ActiveRecord::Base.configurations.values_at(*environments) + ActiveRecord::Base.configurations.values_at(*environments).compact.reject { |config| config['database'].blank? } end def session_table_name diff --git a/activerecord/lib/active_record/store.rb b/activerecord/lib/active_record/store.rb index d5910df891..8cc84f81d0 100644 --- a/activerecord/lib/active_record/store.rb +++ b/activerecord/lib/active_record/store.rb @@ -37,6 +37,7 @@ module ActiveRecord Array(keys).flatten.each do |key| define_method("#{key}=") do |value| send(store_attribute)[key] = value + send("#{store_attribute}_will_change!") end define_method(key) do diff --git a/activerecord/test/cases/store_test.rb b/activerecord/test/cases/store_test.rb index fb77220875..074fd39e65 100644 --- a/activerecord/test/cases/store_test.rb +++ b/activerecord/test/cases/store_test.rb @@ -26,4 +26,9 @@ class StoreTest < ActiveRecord::TestCase assert 'graeters', @john.reload.settings[:icecream] end + + test "updating the store will mark it as changed" do + @john.color = 'red' + assert @john.settings_changed? + end end diff --git a/activesupport/lib/active_support/cache/file_store.rb b/activesupport/lib/active_support/cache/file_store.rb index bc5d94b5a7..b431041b76 100644 --- a/activesupport/lib/active_support/cache/file_store.rb +++ b/activesupport/lib/active_support/cache/file_store.rb @@ -26,26 +26,11 @@ module ActiveSupport FileUtils.rm_r(root_dirs.collect{|f| File.join(cache_path, f)}) end - # Cleanup the cache by removing old entries. By default this will delete entries - # that haven't been accessed in one day. You can change this behavior by passing - # in a +not_accessed_in+ option. Any entry not accessed in that number of seconds - # in the past will be deleted. Alternatively, you can pass in +:expired_only+ with - # +true+ to only delete expired entries. def cleanup(options = nil) options = merged_options(options) - expired_only = options[:expired_only] - timestamp = Time.now - (options[:not_accessed_in] || 1.day.to_i) - search_dir(cache_path) do |fname| - if expired_only - key = file_path_key(fname) - entry = read_entry(key, options) - delete_entry(key, options) if entry && entry.expired? - else - if File.atime(fname) <= timestamp - key = file_path_key(fname) - delete_entry(key, options) - end - end + each_key(options) do |key| + entry = read_entry(key, options) + delete_entry(key, options) if entry && entry.expired? end end diff --git a/activesupport/test/buffered_logger_test.rb b/activesupport/test/buffered_logger_test.rb index 8699862d9e..386006677b 100644 --- a/activesupport/test/buffered_logger_test.rb +++ b/activesupport/test/buffered_logger_test.rb @@ -233,7 +233,7 @@ class BufferedLoggerTest < Test::Unit::TestCase end keep_running = true - b = Thread.new do + Thread.new do @logger.info("b") while keep_running sleep(0.001) diff --git a/activesupport/test/caching_test.rb b/activesupport/test/caching_test.rb index 1b2f6d061c..cb5362525f 100644 --- a/activesupport/test/caching_test.rb +++ b/activesupport/test/caching_test.rb @@ -557,29 +557,6 @@ class FileStoreTest < ActiveSupport::TestCase key = @cache_with_pathname.send(:key_file_path, "views/index?id=1") assert_equal "views/index?id=1", @cache_with_pathname.send(:file_path_key, key) end - - def test_cleanup_with_not_accessed_in - @cache.write(1, "aaaaaaaaaa") - @cache.write(2, "bbbbbbbbbb") - @cache.write(3, "cccccccccc") - sleep(2) - @cache.read(2) - @cache.cleanup(:not_accessed_in => 1) - assert_equal false, @cache.exist?(1) - assert_equal true, @cache.exist?(2) - assert_equal false, @cache.exist?(3) - end - - def test_cleanup_with_expired_only - @cache.write(1, "aaaaaaaaaa", :expires_in => 0.001) - @cache.write(2, "bbbbbbbbbb") - @cache.write(3, "cccccccccc", :expires_in => 0.001) - sleep(0.002) - @cache.cleanup(:expired_only => 0.001) - assert_equal false, @cache.exist?(1) - assert_equal true, @cache.exist?(2) - assert_equal false, @cache.exist?(3) - end # Because file systems have a maximum filename size, filenames > max size should be split in to directories # If filename is 'AAAAB', where max size is 4, the returned path should be AAAA/B @@ -669,17 +646,6 @@ class MemoryStoreTest < ActiveSupport::TestCase assert_equal true, @cache.exist?(2) assert_equal false, @cache.exist?(1) end - - def test_cleanup_removes_expired_entries - @cache.write(1, "aaaaaaaaaa", :expires_in => 0.001) - @cache.write(2, "bbbbbbbbbb") - @cache.write(3, "cccccccccc", :expires_in => 0.001) - sleep(0.002) - @cache.cleanup - assert_equal false, @cache.exist?(1) - assert_equal true, @cache.exist?(2) - assert_equal false, @cache.exist?(3) - end end uses_memcached 'memcached backed store' do diff --git a/railties/CHANGELOG b/railties/CHANGELOG index 7f7b24804d..404bc73b0b 100644 --- a/railties/CHANGELOG +++ b/railties/CHANGELOG @@ -1,5 +1,7 @@ *Rails 3.2.0 (unreleased)* +* Scaffold returns 204 No Content for API requests without content. This makes scaffold work with jQuery out of the box. [José Valim] + * Updated Rails::Rack::Logger middleware to apply any tags set in config.log_tags to the newly ActiveSupport::TaggedLogging Rails.logger. This makes it easy to tag log lines with debug information like subdomain and request id -- both very helpful in debugging multi-user production applications [DHH] * Default options to `rails new` can be set in ~/.railsrc [Guillermo Iguaran] diff --git a/railties/guides/source/caching_with_rails.textile b/railties/guides/source/caching_with_rails.textile index 721c791a33..4273d0dd64 100644 --- a/railties/guides/source/caching_with_rails.textile +++ b/railties/guides/source/caching_with_rails.textile @@ -289,11 +289,7 @@ ActionController::Base.cache_store = :file_store, "/path/to/cache/directory" With this cache store, multiple server processes on the same host can share a cache. Servers processes running on different hosts could share a cache by using a shared file system, but that set up would not be ideal and is not recommended. The cache store is appropriate for low to medium traffic sites that are served off one or two hosts. -Note that the cache will grow until the disk is full unless you periodically clear out old entries. You can call +ActiveSupport::Cache::FileStore#cleanup+ to remove entries older than a specified time. - -<ruby> -Rails.cache.cleanup(:not_accessed_in => 2.days) -</ruby> +Note that the cache will grow until the disk is full unless you periodically clear out old entries. h4. ActiveSupport::Cache::MemCacheStore 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 32b961d9fc..4ff15fd288 100644 --- a/railties/lib/rails/generators/rails/scaffold_controller/templates/controller.rb +++ b/railties/lib/rails/generators/rails/scaffold_controller/templates/controller.rb @@ -62,7 +62,7 @@ class <%= controller_class_name %>Controller < ApplicationController respond_to do |format| if @<%= orm_instance.update_attributes("params[:#{singular_table_name}]") %> format.html { redirect_to @<%= singular_table_name %>, <%= key_value :notice, "'#{human_name} was successfully updated.'" %> } - format.json { head :ok } + format.json { head :no_content } else format.html { render <%= key_value :action, '"edit"' %> } format.json { render <%= key_value :json, "@#{orm_instance.errors}" %>, <%= key_value :status, ':unprocessable_entity' %> } @@ -78,7 +78,7 @@ class <%= controller_class_name %>Controller < ApplicationController respond_to do |format| format.html { redirect_to <%= index_helper %>_url } - format.json { head :ok } + format.json { head :no_content } end end end diff --git a/railties/test/application/rack/logger_test.rb b/railties/test/application/rack/logger_test.rb index 8b2b2f1802..387eb25525 100644 --- a/railties/test/application/rack/logger_test.rb +++ b/railties/test/application/rack/logger_test.rb @@ -12,6 +12,8 @@ module ApplicationTests build_app require "#{app_path}/config/environment" super + @logger = MockLogger.new + Rails.stubs(:logger).returns(@logger) end def teardown diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index 4b74bd6a4b..955ed09361 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -143,6 +143,16 @@ class AppGeneratorTest < Rails::Generators::TestCase end end + def test_config_postgresql_database + run_generator([destination_root, "-d", "postgresql"]) + assert_file "config/database.yml", /postgresql/ + unless defined?(JRUBY_VERSION) + assert_file "Gemfile", /^gem\s+["']pg["']$/ + else + assert_file "Gemfile", /^gem\s+["']activerecord-jdbcpostgresql-adapter["']$/ + end + end + def test_config_jdbcmysql_database run_generator([destination_root, "-d", "jdbcmysql"]) assert_file "config/database.yml", /mysql/ |