Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Add test for `AR::Base#to_param` #10416

Merged
merged 1 commit into from

2 participants

@take

According to the doc of AR::Base#to_param(
https://github.com/rails/rails/blob/04cda1848cb847c2bdad0bfc12160dc8d5547775/activerecord/lib/active_record/integration.rb#L18 ), it returns
nil if the record is not persisted.

activerecord/test/cases/integration_test.rb
@@ -11,7 +11,12 @@ def test_to_param_should_return_string
assert_kind_of String, Client.first.to_param
end
- def test_to_param_returns_id_even_if_not_persisted
+ def test_to_param_returns_nil_if_not_persisted
+ client = Client.new
+ assert_equal nil, client.to_param
+ end
+
+ def test_to_param_returns_id_even_if_not_persisted_and_id_set

Wdyt: test_to_param_returns_id_if_not_persisted_but_id_is_set

@take
take added a note

aha :smile: that sounds better! will update :dancer:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@take take Add test for `AR::Base#to_param`
According to the doc of `AR::Base#to_param`(
https://github.com/rails/rails/blob/04cda1848cb847c2bdad0bfc12160dc8d554
7775/activerecord/lib/active_record/integration.rb#L18 ), it returns
`nil` if the record is not persisted.
ec0566c
@carlosantoniodasilva

Great, thanks!

@carlosantoniodasilva carlosantoniodasilva merged commit ca2bc30 into rails:master
@take take deleted the take:add-test-for-AR--Base#to_param branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 2, 2013
  1. @take

    Add test for `AR::Base#to_param`

    take authored
    According to the doc of `AR::Base#to_param`(
    https://github.com/rails/rails/blob/04cda1848cb847c2bdad0bfc12160dc8d554
    7775/activerecord/lib/active_record/integration.rb#L18 ), it returns
    `nil` if the record is not persisted.
This page is out of date. Refresh to see the latest.
Showing with 6 additions and 1 deletion.
  1. +6 −1 activerecord/test/cases/integration_test.rb
View
7 activerecord/test/cases/integration_test.rb
@@ -11,7 +11,12 @@ def test_to_param_should_return_string
assert_kind_of String, Client.first.to_param
end
- def test_to_param_returns_id_even_if_not_persisted
+ def test_to_param_returns_nil_if_not_persisted
+ client = Client.new
+ assert_equal nil, client.to_param
+ end
+
+ def test_to_param_returns_id_if_not_persisted_but_id_is_set
client = Client.new
client.id = 1
assert_equal '1', client.to_param
Something went wrong with that request. Please try again.