Skip to content

Commit

Permalink
Fix various warnings in the test suite
Browse files Browse the repository at this point in the history
  • Loading branch information
byroot committed Apr 10, 2024
1 parent 14f465c commit 7d3b011
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 25 deletions.
3 changes: 2 additions & 1 deletion lib/active_model/serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,8 @@ def initialize(object, options={})
@context = options[:context]
@namespace = options[:namespace]
end
attr_accessor :object, :scope, :root, :meta_key, :meta, :key_format, :context, :polymorphic
attr_accessor :object, :scope, :root, :meta_key, :meta, :context, :polymorphic
attr_writer :key_format

def json_key
key = if root == true || root.nil?
Expand Down
2 changes: 2 additions & 0 deletions lib/active_model/serializer/association.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ class Serializer
class Association
def initialize(name, options={})
if options.has_key?(:include)
puts '-' * 40
puts caller
ActiveSupport::Deprecation.warn <<-WARN
** Notice: include was renamed to embed_in_root. **
WARN
Expand Down
7 changes: 4 additions & 3 deletions test/fixtures/poro.rb
Original file line number Diff line number Diff line change
Expand Up @@ -144,14 +144,14 @@ class TypeSerializer < ActiveModel::Serializer

class SelfReferencingUserParentSerializer < ActiveModel::Serializer
attributes :name
has_one :type, serializer: TypeSerializer, embed: :ids, include: true
has_one :type, serializer: TypeSerializer, embed: :ids, embed_in_root: true
end

class SelfReferencingUserSerializer < ActiveModel::Serializer
attributes :name

has_one :type, serializer: TypeSerializer, embed: :ids, include: true
has_one :parent, serializer: SelfReferencingUserSerializer, embed: :ids, include: true
has_one :type, serializer: TypeSerializer, embed: :ids, embed_in_root: true
has_one :parent, serializer: SelfReferencingUserSerializer, embed: :ids, embed_in_root: true
end

class UserInfoSerializer < ActiveModel::Serializer
Expand All @@ -176,6 +176,7 @@ class CategorySerializer < ActiveModel::Serializer
class PostSerializer < ActiveModel::Serializer
attributes :title, :body

alias_method :title, :title # silence method redefinition warning
def title
keyword = serialization_options[:highlight_keyword]
title = object.read_attribute_for_serialization(:title)
Expand Down
40 changes: 20 additions & 20 deletions test/integration/generators/scaffold_controller_generator_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,44 +17,44 @@ def test_generated_controller

assert_file 'app/controllers/accounts_controller.rb' do |content|
assert_instance_method :index, content do |m|
assert_match /@accounts = Account\.all/, m
assert_match /format.html/, m
assert_match /format.json \{ render json: @accounts \}/, m
assert_match(/@accounts = Account\.all/, m)
assert_match(/format.html/, m)
assert_match(/format.json \{ render json: @accounts \}/, m)
end

assert_instance_method :show, content do |m|
assert_match /format.html/, m
assert_match /format.json \{ render json: @account \}/, m
assert_match(/format.html/, m)
assert_match(/format.json \{ render json: @account \}/, m)
end

assert_instance_method :new, content do |m|
assert_match /@account = Account\.new/, m
assert_match(/@account = Account\.new/, m)
end

assert_instance_method :edit, content do |m|
assert m.blank?
assert_predicate m, :blank?
end

assert_instance_method :create, content do |m|
assert_match /@account = Account\.new\(account_params\)/, m
assert_match /@account\.save/, m
assert_match /format\.html \{ redirect_to @account, notice: 'Account was successfully created\.' \}/, m
assert_match /format\.json \{ render json: @account, status: :created \}/, m
assert_match /format\.html \{ render action: 'new' \}/, m
assert_match /format\.json \{ render json: @account\.errors, status: :unprocessable_entity \}/, m
assert_match(/@account = Account\.new\(account_params\)/, m)
assert_match(/@account\.save/, m)
assert_match(/format\.html \{ redirect_to @account, notice: 'Account was successfully created\.' \}/, m)
assert_match(/format\.json \{ render json: @account, status: :created \}/, m)
assert_match(/format\.html \{ render action: 'new' \}/, m)
assert_match(/format\.json \{ render json: @account\.errors, status: :unprocessable_entity \}/, m)
end

assert_instance_method :update, content do |m|
assert_match /format\.html \{ redirect_to @account, notice: 'Account was successfully updated\.' \}/, m
assert_match /format\.json \{ head :no_content \}/, m
assert_match /format\.html \{ render action: 'edit' \}/, m
assert_match /format\.json \{ render json: @account.errors, status: :unprocessable_entity \}/, m
assert_match(/format\.html \{ redirect_to @account, notice: 'Account was successfully updated\.' \}/, m)
assert_match(/format\.json \{ head :no_content \}/, m)
assert_match(/format\.html \{ render action: 'edit' \}/, m)
assert_match(/format\.json \{ render json: @account.errors, status: :unprocessable_entity \}/, m)
end

assert_instance_method :destroy, content do |m|
assert_match /@account\.destroy/, m
assert_match /format\.html { redirect_to accounts_url \}/, m
assert_match /format\.json \{ head :no_content \}/, m
assert_match(/@account\.destroy/, m)
assert_match(/format\.html { redirect_to accounts_url \}/, m)
assert_match(/format\.json \{ head :no_content \}/, m)
end

assert_match(/def account_params/, content)
Expand Down
2 changes: 2 additions & 0 deletions test/test_app.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
class TestApp < Rails::Application
config.load_defaults("#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}")

if Rails.version.to_s.first >= '4'
config.eager_load = false
config.secret_key_base = 'abc123'
Expand Down
2 changes: 1 addition & 1 deletion test/unit/active_model/default_serializer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module ActiveModel
class DefaultSerializer
class Test < Minitest::Test
def test_serialize_objects
assert_equal(nil, DefaultSerializer.new(nil).serializable_object)
assert_nil(DefaultSerializer.new(nil).serializable_object)
assert_equal(1, DefaultSerializer.new(1).serializable_object)
assert_equal('hi', DefaultSerializer.new('hi').serializable_object)
end
Expand Down
1 change: 1 addition & 0 deletions test/unit/active_model/serializer/url_helpers_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def test_url_helpers_are_available
serializer = Class.new(ActiveModel::Serializer) do
attributes :url

alias_method :url, :url # silence redefinition warning
def url
profile_url(id: object.object_id)
end
Expand Down

0 comments on commit 7d3b011

Please sign in to comment.