diff options
-rw-r--r-- | Gemfile | 2 | ||||
-rw-r--r-- | activerecord/CHANGELOG.md | 11 | ||||
-rw-r--r-- | activerecord/lib/active_record/relation/calculations.rb | 4 | ||||
-rw-r--r-- | activerecord/test/cases/base_test.rb | 7 | ||||
-rw-r--r-- | activerecord/test/cases/calculations_test.rb | 6 | ||||
-rw-r--r-- | activesupport/CHANGELOG.md | 2 | ||||
-rw-r--r-- | activesupport/lib/active_support/test_case.rb | 8 | ||||
-rw-r--r-- | activesupport/lib/active_support/testing/mocha_module.rb | 22 |
8 files changed, 34 insertions, 28 deletions
@@ -4,7 +4,7 @@ gemspec gem 'arel', github: 'rails/arel', branch: 'master' -gem 'mocha', github: 'freerange/mocha', require: false +gem 'mocha', '~> 0.13.0', require: false gem 'rack-test', github: 'brynary/rack-test' gem 'rack-cache', '~> 1.2' gem 'bcrypt-ruby', '~> 3.0.0' diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md index dee398177c..580a580ba5 100644 --- a/activerecord/CHANGELOG.md +++ b/activerecord/CHANGELOG.md @@ -1,7 +1,16 @@ ## Rails 4.0.0 (unreleased) ## +* `#pluck` can be used on a relation with `select` clause + Fix #7551 + + Example: + + Topic.select([:approved, :id]).order(:id).pluck(:id) + + *Yves Senn* + * Do not create useless database transaction when building `has_one` association. - + Example: User.has_one :profile diff --git a/activerecord/lib/active_record/relation/calculations.rb b/activerecord/lib/active_record/relation/calculations.rb index a7d2f4bd24..df27318678 100644 --- a/activerecord/lib/active_record/relation/calculations.rb +++ b/activerecord/lib/active_record/relation/calculations.rb @@ -165,7 +165,9 @@ module ActiveRecord if has_include?(column_names.first) construct_relation_for_association_calculations.pluck(*column_names) else - result = klass.connection.select_all(select(column_names).arel, nil, bind_values) + relation = spawn + relation.select_values = column_names + result = klass.connection.select_all(relation.arel, nil, bind_values) columns = result.columns.map do |key| klass.column_types.fetch(key) { result.column_types.fetch(key) { diff --git a/activerecord/test/cases/base_test.rb b/activerecord/test/cases/base_test.rb index 203e44857a..c02d8f7760 100644 --- a/activerecord/test/cases/base_test.rb +++ b/activerecord/test/cases/base_test.rb @@ -1442,6 +1442,13 @@ class BasicsTest < ActiveRecord::TestCase assert_match(/\/#{dev.id}$/, dev.cache_key) end + def test_cache_key_format_is_precise_enough + dev = Developer.first + key = dev.cache_key + dev.touch + assert_not_equal key, dev.cache_key + end + def test_uniq_delegates_to_scoped scope = stub Bird.stubs(:all).returns(mock(:uniq => scope)) diff --git a/activerecord/test/cases/calculations_test.rb b/activerecord/test/cases/calculations_test.rb index abbf2a765e..65d28ea028 100644 --- a/activerecord/test/cases/calculations_test.rb +++ b/activerecord/test/cases/calculations_test.rb @@ -580,4 +580,10 @@ class CalculationsTest < ActiveRecord::TestCase assert_equal ["Over There"], Possession.pluck(:where) end + + def test_pluck_replaces_select_clause + taks_relation = Topic.select(:approved, :id).order(:id) + assert_equal [1,2,3,4], taks_relation.pluck(:id) + assert_equal [false, true, true, true], taks_relation.pluck(:approved) + end end diff --git a/activesupport/CHANGELOG.md b/activesupport/CHANGELOG.md index 24989fc244..2bbc41296f 100644 --- a/activesupport/CHANGELOG.md +++ b/activesupport/CHANGELOG.md @@ -1,5 +1,7 @@ ## Rails 4.0.0 (unreleased) ## +* Simplify mocha integration and remove monkey-patches, bumping mocha to 0.13.0. *James Mead* + * `#as_json` isolates options when encoding a hash. Fix #8182 diff --git a/activesupport/lib/active_support/test_case.rb b/activesupport/lib/active_support/test_case.rb index 8b06739b7f..c96ad17aba 100644 --- a/activesupport/lib/active_support/test_case.rb +++ b/activesupport/lib/active_support/test_case.rb @@ -5,16 +5,18 @@ require 'active_support/testing/setup_and_teardown' require 'active_support/testing/assertions' require 'active_support/testing/deprecation' require 'active_support/testing/isolation' -require 'active_support/testing/mocha_module' require 'active_support/testing/constant_lookup' require 'active_support/core_ext/kernel/reporting' require 'active_support/deprecation' +begin + silence_warnings { require 'mocha/setup' } +rescue LoadError +end + module ActiveSupport class TestCase < ::MiniTest::Spec - include ActiveSupport::Testing::MochaModule - # Use AS::TestCase for the base class when describing a model register_spec_type(self) do |desc| Class === desc && desc < ActiveRecord::Base diff --git a/activesupport/lib/active_support/testing/mocha_module.rb b/activesupport/lib/active_support/testing/mocha_module.rb deleted file mode 100644 index 833dc867f0..0000000000 --- a/activesupport/lib/active_support/testing/mocha_module.rb +++ /dev/null @@ -1,22 +0,0 @@ -module ActiveSupport - module Testing - module MochaModule - begin - require 'mocha/api' - include Mocha::API - - def before_setup - mocha_setup - super - end - - def after_teardown - super - mocha_verify - mocha_teardown - end - rescue LoadError - end - end - end -end |