diff options
-rw-r--r-- | actionview/CHANGELOG.md | 4 | ||||
-rw-r--r-- | actionview/lib/action_view/tasks/dependencies.rake | 16 | ||||
-rw-r--r-- | activemodel/lib/active_model/validator.rb | 16 | ||||
-rw-r--r-- | activemodel/test/cases/validations_test.rb | 21 | ||||
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/column.rb | 8 | ||||
-rw-r--r-- | activerecord/lib/active_record/core.rb | 1 | ||||
-rw-r--r-- | activerecord/lib/active_record/type/serialized.rb | 11 | ||||
-rw-r--r-- | activerecord/test/cases/yaml_serialization_test.rb | 15 |
8 files changed, 46 insertions, 46 deletions
diff --git a/actionview/CHANGELOG.md b/actionview/CHANGELOG.md index 147e5b47db..aaa9322c4e 100644 --- a/actionview/CHANGELOG.md +++ b/actionview/CHANGELOG.md @@ -1,3 +1,7 @@ +* Bring `cache_digest` rake tasks up-to-date with the latest API changes + + *Jiri Pospisil* + * Allow custom `:host` option to be passed to `asset_url` helper that overwrites `config.action_controller.asset_host` for particular asset. diff --git a/actionview/lib/action_view/tasks/dependencies.rake b/actionview/lib/action_view/tasks/dependencies.rake index 1b9426c0e5..b39f7d583b 100644 --- a/actionview/lib/action_view/tasks/dependencies.rake +++ b/actionview/lib/action_view/tasks/dependencies.rake @@ -2,16 +2,20 @@ namespace :cache_digests do desc 'Lookup nested dependencies for TEMPLATE (like messages/show or comments/_comment.html)' task :nested_dependencies => :environment do abort 'You must provide TEMPLATE for the task to run' unless ENV['TEMPLATE'].present? - template, format = ENV['TEMPLATE'].split(".") - format ||= :html - puts JSON.pretty_generate ActionView::Digestor.new(template, format, ApplicationController.new.lookup_context).nested_dependencies + puts JSON.pretty_generate ActionView::Digestor.new(name: template_name, finder: finder).nested_dependencies end desc 'Lookup first-level dependencies for TEMPLATE (like messages/show or comments/_comment.html)' task :dependencies => :environment do abort 'You must provide TEMPLATE for the task to run' unless ENV['TEMPLATE'].present? - template, format = ENV['TEMPLATE'].split(".") - format ||= :html - puts JSON.pretty_generate ActionView::Digestor.new(template, format, ApplicationController.new.lookup_context).dependencies + puts JSON.pretty_generate ActionView::Digestor.new(name: template_name, finder: finder).dependencies + end + + def template_name + ENV['TEMPLATE'].split('.', 2).first + end + + def finder + ApplicationController.new.lookup_context end end diff --git a/activemodel/lib/active_model/validator.rb b/activemodel/lib/active_model/validator.rb index bddacc8c45..65cb1e5a88 100644 --- a/activemodel/lib/active_model/validator.rb +++ b/activemodel/lib/active_model/validator.rb @@ -106,7 +106,6 @@ module ActiveModel # Accepts options that will be made available through the +options+ reader. def initialize(options = {}) @options = options.except(:class).freeze - deprecated_setup(options) end # Returns the kind for this validator. @@ -122,21 +121,6 @@ module ActiveModel def validate(record) raise NotImplementedError, "Subclasses must implement a validate(record) method." end - - private - def deprecated_setup(options) # TODO: remove me in 4.2. - return unless respond_to?(:setup) - ActiveSupport::Deprecation.warn "The `Validator#setup` instance method is deprecated and will be removed on Rails 4.2. Do your setup in the constructor instead: - -class MyValidator < ActiveModel::Validator - def initialize(options={}) - super - options[:class].send :attr_accessor, :custom_attribute - end -end -" - setup(options[:class]) - end end # +EachValidator+ is a validator which iterates through the attributes given diff --git a/activemodel/test/cases/validations_test.rb b/activemodel/test/cases/validations_test.rb index 6a74ee353d..4fee704ef5 100644 --- a/activemodel/test/cases/validations_test.rb +++ b/activemodel/test/cases/validations_test.rb @@ -378,25 +378,4 @@ class ValidationsTest < ActiveModel::TestCase assert topic.invalid? assert duped.valid? end - - # validator test: - def test_setup_is_deprecated_but_still_receives_klass # TODO: remove me in 4.2. - validator_class = Class.new(ActiveModel::Validator) do - def setup(klass) - @old_klass = klass - end - - def validate(*) - @old_klass == Topic or raise "#setup didn't work" - end - end - - assert_deprecated do - Topic.validates_with validator_class - end - - t = Topic.new - t.valid? - end - end diff --git a/activerecord/lib/active_record/connection_adapters/column.rb b/activerecord/lib/active_record/connection_adapters/column.rb index 72c6990ba5..21273364b9 100644 --- a/activerecord/lib/active_record/connection_adapters/column.rb +++ b/activerecord/lib/active_record/connection_adapters/column.rb @@ -13,7 +13,7 @@ module ActiveRecord ISO_DATETIME = /\A(\d{4})-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)(\.\d+)?\z/ end - attr_reader :name, :cast_type, :null, :sql_type, :default_function + attr_reader :name, :cast_type, :sql_type, :default_function delegate :type, :precision, :scale, :limit, :klass, :accessor, :text?, :number?, :binary?, :serialized?, :changed?, @@ -34,7 +34,7 @@ module ActiveRecord @name = name @cast_type = cast_type @sql_type = sql_type - @null = null + @nullable = null @original_default = default @default_function = nil end @@ -61,6 +61,10 @@ module ActiveRecord clone.instance_variable_set('@cast_type', type) end end + + def null + @nullable + end end class NullColumn < Column diff --git a/activerecord/lib/active_record/core.rb b/activerecord/lib/active_record/core.rb index 79388f53b5..7edaf256c7 100644 --- a/activerecord/lib/active_record/core.rb +++ b/activerecord/lib/active_record/core.rb @@ -356,6 +356,7 @@ module ActiveRecord def encode_with(coder) coder['raw_attributes'] = @raw_attributes coder['attributes'] = @attributes + coder['column_types'] = @column_types_override coder['new_record'] = new_record? end diff --git a/activerecord/lib/active_record/type/serialized.rb b/activerecord/lib/active_record/type/serialized.rb index 9144028576..e6d84eadc0 100644 --- a/activerecord/lib/active_record/type/serialized.rb +++ b/activerecord/lib/active_record/type/serialized.rb @@ -36,6 +36,17 @@ module ActiveRecord ActiveRecord::Store::IndifferentHashAccessor end + def init_with(coder) + @subtype = coder['subtype'] + @coder = coder['coder'] + __setobj__(@subtype) + end + + def encode_with(coder) + coder['subtype'] = @subtype + coder['coder'] = @coder + end + private def is_default_value?(value) diff --git a/activerecord/test/cases/yaml_serialization_test.rb b/activerecord/test/cases/yaml_serialization_test.rb index d4f8ef5b4d..9f1d110ddb 100644 --- a/activerecord/test/cases/yaml_serialization_test.rb +++ b/activerecord/test/cases/yaml_serialization_test.rb @@ -1,8 +1,10 @@ require 'cases/helper' require 'models/topic' +require 'models/post' +require 'models/author' class YamlSerializationTest < ActiveRecord::TestCase - fixtures :topics + fixtures :topics, :authors, :posts def test_to_yaml_with_time_with_zone_should_not_raise_exception with_timezone_config aware_attributes: true, zone: "Pacific Time (US & Canada)" do @@ -69,4 +71,15 @@ class YamlSerializationTest < ActiveRecord::TestCase assert_not topic.new_record?, "Loaded records without ID are not new" assert_not YAML.load(YAML.dump(topic)).new_record?, "Record should not be new after deserialization" end + + def test_types_of_virtual_columns_are_not_changed_on_round_trip + author = Author.select('authors.*, count(posts.id) as posts_count') + .joins(:posts) + .group('authors.id') + .first + dumped = YAML.load(YAML.dump(author)) + + assert_equal 5, author.posts_count + assert_equal 5, dumped.posts_count + end end |