Skip to content

Commit 7d3b011

Browse files
committed
Fix various warnings in the test suite
1 parent 14f465c commit 7d3b011

File tree

7 files changed

+32
-25
lines changed

7 files changed

+32
-25
lines changed

lib/active_model/serializer.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,8 @@ def initialize(object, options={})
167167
@context = options[:context]
168168
@namespace = options[:namespace]
169169
end
170-
attr_accessor :object, :scope, :root, :meta_key, :meta, :key_format, :context, :polymorphic
170+
attr_accessor :object, :scope, :root, :meta_key, :meta, :context, :polymorphic
171+
attr_writer :key_format
171172

172173
def json_key
173174
key = if root == true || root.nil?

lib/active_model/serializer/association.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ class Serializer
99
class Association
1010
def initialize(name, options={})
1111
if options.has_key?(:include)
12+
puts '-' * 40
13+
puts caller
1214
ActiveSupport::Deprecation.warn <<-WARN
1315
** Notice: include was renamed to embed_in_root. **
1416
WARN

test/fixtures/poro.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,14 +144,14 @@ class TypeSerializer < ActiveModel::Serializer
144144

145145
class SelfReferencingUserParentSerializer < ActiveModel::Serializer
146146
attributes :name
147-
has_one :type, serializer: TypeSerializer, embed: :ids, include: true
147+
has_one :type, serializer: TypeSerializer, embed: :ids, embed_in_root: true
148148
end
149149

150150
class SelfReferencingUserSerializer < ActiveModel::Serializer
151151
attributes :name
152152

153-
has_one :type, serializer: TypeSerializer, embed: :ids, include: true
154-
has_one :parent, serializer: SelfReferencingUserSerializer, embed: :ids, include: true
153+
has_one :type, serializer: TypeSerializer, embed: :ids, embed_in_root: true
154+
has_one :parent, serializer: SelfReferencingUserSerializer, embed: :ids, embed_in_root: true
155155
end
156156

157157
class UserInfoSerializer < ActiveModel::Serializer
@@ -176,6 +176,7 @@ class CategorySerializer < ActiveModel::Serializer
176176
class PostSerializer < ActiveModel::Serializer
177177
attributes :title, :body
178178

179+
alias_method :title, :title # silence method redefinition warning
179180
def title
180181
keyword = serialization_options[:highlight_keyword]
181182
title = object.read_attribute_for_serialization(:title)

test/integration/generators/scaffold_controller_generator_test.rb

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,44 +17,44 @@ def test_generated_controller
1717

1818
assert_file 'app/controllers/accounts_controller.rb' do |content|
1919
assert_instance_method :index, content do |m|
20-
assert_match /@accounts = Account\.all/, m
21-
assert_match /format.html/, m
22-
assert_match /format.json \{ render json: @accounts \}/, m
20+
assert_match(/@accounts = Account\.all/, m)
21+
assert_match(/format.html/, m)
22+
assert_match(/format.json \{ render json: @accounts \}/, m)
2323
end
2424

2525
assert_instance_method :show, content do |m|
26-
assert_match /format.html/, m
27-
assert_match /format.json \{ render json: @account \}/, m
26+
assert_match(/format.html/, m)
27+
assert_match(/format.json \{ render json: @account \}/, m)
2828
end
2929

3030
assert_instance_method :new, content do |m|
31-
assert_match /@account = Account\.new/, m
31+
assert_match(/@account = Account\.new/, m)
3232
end
3333

3434
assert_instance_method :edit, content do |m|
35-
assert m.blank?
35+
assert_predicate m, :blank?
3636
end
3737

3838
assert_instance_method :create, content do |m|
39-
assert_match /@account = Account\.new\(account_params\)/, m
40-
assert_match /@account\.save/, m
41-
assert_match /format\.html \{ redirect_to @account, notice: 'Account was successfully created\.' \}/, m
42-
assert_match /format\.json \{ render json: @account, status: :created \}/, m
43-
assert_match /format\.html \{ render action: 'new' \}/, m
44-
assert_match /format\.json \{ render json: @account\.errors, status: :unprocessable_entity \}/, m
39+
assert_match(/@account = Account\.new\(account_params\)/, m)
40+
assert_match(/@account\.save/, m)
41+
assert_match(/format\.html \{ redirect_to @account, notice: 'Account was successfully created\.' \}/, m)
42+
assert_match(/format\.json \{ render json: @account, status: :created \}/, m)
43+
assert_match(/format\.html \{ render action: 'new' \}/, m)
44+
assert_match(/format\.json \{ render json: @account\.errors, status: :unprocessable_entity \}/, m)
4545
end
4646

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

5454
assert_instance_method :destroy, content do |m|
55-
assert_match /@account\.destroy/, m
56-
assert_match /format\.html { redirect_to accounts_url \}/, m
57-
assert_match /format\.json \{ head :no_content \}/, m
55+
assert_match(/@account\.destroy/, m)
56+
assert_match(/format\.html { redirect_to accounts_url \}/, m)
57+
assert_match(/format\.json \{ head :no_content \}/, m)
5858
end
5959

6060
assert_match(/def account_params/, content)

test/test_app.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
class TestApp < Rails::Application
2+
config.load_defaults("#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}")
3+
24
if Rails.version.to_s.first >= '4'
35
config.eager_load = false
46
config.secret_key_base = 'abc123'

test/unit/active_model/default_serializer_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module ActiveModel
44
class DefaultSerializer
55
class Test < Minitest::Test
66
def test_serialize_objects
7-
assert_equal(nil, DefaultSerializer.new(nil).serializable_object)
7+
assert_nil(DefaultSerializer.new(nil).serializable_object)
88
assert_equal(1, DefaultSerializer.new(1).serializable_object)
99
assert_equal('hi', DefaultSerializer.new('hi').serializable_object)
1010
end

test/unit/active_model/serializer/url_helpers_test.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ def test_url_helpers_are_available
2121
serializer = Class.new(ActiveModel::Serializer) do
2222
attributes :url
2323

24+
alias_method :url, :url # silence redefinition warning
2425
def url
2526
profile_url(id: object.object_id)
2627
end

0 commit comments

Comments
 (0)