When I am checking the value of an integer model attribute with assert_equal, the value returned is a string.
I am running an integration test where I update a model instance and then check the model instance to insure the values has been changed.
database table:
create_table :launches do |t|
...
t.integer :result
...
t.timestamps
end
model:
validates :result, presence: true, numericality: { only_integer: true, greater_than: 0 }
Here is the test:
@launch.reload
assert_equal 2, @launch.result
and it produces this error:
test_edit_a_launch#LaunchesNewAndEditTest (0.99s)
Expected: 2
Actual: "2"
test/integration/launches_new_and_edit_test.rb:57:in `block in <class:LaunchesNewAndEditTest>'
The values is getting returned as a string and the comparison to an integer fails. If I change the test to:
@launch.reload
assert_equal 2, @launch.result.to_i
it works. But this does not make any sense and it should be comparing an integer value in the model to the integer expected result. When I manipulate the object in rails console, the value is an integer.