aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
authorAkira Matsuda <ronnie@dio.jp>2019-08-01 16:41:26 +0900
committerAkira Matsuda <ronnie@dio.jp>2019-08-01 17:58:00 +0900
commitaf2129b4c74732c88ffce76e5c55c805cb9431f6 (patch)
treec74d8c85f81ea6b3a5e4209be247c9d83666bd4d /activesupport
parentdbf3e4882f9da95e34ed9086f182cf424aaac224 (diff)
downloadrails-af2129b4c74732c88ffce76e5c55c805cb9431f6.tar.gz
rails-af2129b4c74732c88ffce76e5c55c805cb9431f6.tar.bz2
rails-af2129b4c74732c88ffce76e5c55c805cb9431f6.zip
Use `try` only when we're unsure if the receiver would respond_to the method
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/test/current_attributes_test.rb10
1 files changed, 5 insertions, 5 deletions
diff --git a/activesupport/test/current_attributes_test.rb b/activesupport/test/current_attributes_test.rb
index adbdc646bc..4cbf462da0 100644
--- a/activesupport/test/current_attributes_test.rb
+++ b/activesupport/test/current_attributes_test.rb
@@ -9,7 +9,7 @@ class CurrentAttributesTest < ActiveSupport::TestCase
attribute :world, :account, :person, :request
delegate :time_zone, to: :person
- before_reset { Session.previous = person.try(:id) }
+ before_reset { Session.previous = person&.id }
resets do
Time.zone = "UTC"
@@ -18,13 +18,13 @@ class CurrentAttributesTest < ActiveSupport::TestCase
def account=(account)
super
- self.person = "#{account}'s person"
+ self.person = Person.new(1, "#{account}'s person")
end
def person=(person)
super
- Time.zone = person.try(:time_zone)
- Session.current = person.try(:id)
+ Time.zone = person&.time_zone
+ Session.current = person&.id
end
def request
@@ -63,7 +63,7 @@ class CurrentAttributesTest < ActiveSupport::TestCase
test "set attribute via overwritten method" do
Current.account = "account/1"
assert_equal "account/1", Current.account
- assert_equal "account/1's person", Current.person
+ assert_equal "account/1's person", Current.person.name
end
test "set auxiliary class via overwritten method" do