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

Still touch associations when theres no timestamp #14390

Merged
merged 1 commit into from Mar 25, 2014
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions activerecord/lib/active_record/persistence.rb
Expand Up @@ -452,6 +452,8 @@ def touch(name = nil)
changed_attributes.except!(*changes.keys)
primary_key = self.class.primary_key
self.class.unscoped.where(primary_key => self[primary_key]).update_all(changes) == 1
else
true
Copy link
Member

Choose a reason for hiding this comment

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

Returning true seems wrong to me. We are telling the touch operation was successful even if it was not. I'm think this is more an usage problem than a Rails bug.

end
end

Expand Down
Expand Up @@ -340,6 +340,17 @@ def test_belongs_to_with_touch_option_on_touch
assert_queries(1) { line_item.touch }
end

def test_belongs_to_with_touch_option_on_touch_without_updated_at_attributes
assert !LineItem.column_names.include?("updated_at")
Copy link
Member

Choose a reason for hiding this comment

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

Could you use assert_not?


line_item = LineItem.create!
invoice = Invoice.create!(line_items: [line_item])
initial = invoice.updated_at
line_item.touch

refute_equal initial, invoice.reload.updated_at
Copy link
Member

Choose a reason for hiding this comment

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

Could you use assert_not_equal?

end

def test_belongs_to_with_touch_option_on_touch_and_removed_parent
line_item = LineItem.create!
Invoice.create!(line_items: [line_item])
Expand Down