Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[0.9 stable] Fix various warnings in the test suite #2469

Merged
merged 1 commit into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤦 forgotten debug, sorry.

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
4 changes: 4 additions & 0 deletions test/test_app.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
class TestApp < Rails::Application
if config.respond_to?(:load_defaults)
config.load_defaults("#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}")
end

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
Loading