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

Remove test cases for using bitemporal_option_merge! of ActiveRecord:::Bitemporal::Callbacks #129

Merged
merged 1 commit into from
Mar 1, 2023

Conversation

Dooor
Copy link
Contributor

@Dooor Dooor commented Mar 1, 2023

Summary

I added test cases for using bitemporal_option_merge! of ActiveRecord:::Bitemporal::Callbacks in #123 PR.

But specifications that change behavior depending on whether using NestedAttributes or using setter methods are not intended to support by activerecord-bitemporal gem.

It only needs to be tested that association's callbacks are executed when record is updated with NestedAttributes.

This PR organizes only for necessary tests

@auto-assign auto-assign bot requested review from motsat and wata727 March 1, 2023 06:15
@Dooor Dooor requested a review from osyo-manga March 1, 2023 06:15
Copy link
Collaborator

@osyo-manga osyo-manga left a comment

Choose a reason for hiding this comment

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

OK, Good.
Thanks :)

end
context 'employee does not have changes and job_title has changes' do
let(:update_attributes) { { job_title_attributes: { id: employee.job_title.id, name: "COO" } } }
it { expect { subject }.to change(employee, :log).from([]).to(%i[before_bitemporal_update after_bitemporal_update]) }
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm surprised that the callback is invoked for an unchanged record. Is this the natural behavior of Active Record?

Copy link
Contributor Author

@Dooor Dooor Mar 1, 2023

Choose a reason for hiding this comment

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

This behavior is the same behavior as ActiveRecord.
Even if ActiveRecord instance has no changes, update callbacks will be executed when save method is called.

class Employee < ActiveRecord::Base
  after_update :log_update
  
  def log_update
    puts "Employee updated"
  end
end

employee = Employee.first
employee.save! # "Employee updated" is output

Copy link
Contributor

Choose a reason for hiding this comment

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

Oops, I misunderstood.

@Dooor Dooor merged commit e1a12e4 into kufu:master Mar 1, 2023
@Dooor Dooor deleted the modify-bitemporal_callbacks-spec branch March 1, 2023 08:01
@Dooor Dooor mentioned this pull request Mar 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants