-
Notifications
You must be signed in to change notification settings - Fork 48
Localize patch for AR::Relation#primary_key in Rails 8.0+ #243
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
Merged
+197
−11
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require 'spec_helper' | ||
|
|
||
| RSpec.describe ActiveRecord::Bitemporal::Relation do | ||
| describe "#exists?" do | ||
| def create_employees_with_history | ||
| Employee | ||
| .create!([{ name: "Jane" }, { name: "Tom" } ]) | ||
| .each { |e| e.update!(updated_at: Time.current) } | ||
| end | ||
|
|
||
| # Assuming that the number of records will not reach the maximum value in tests. | ||
| # employees.bitemporal_id is a 4-byte signed integer. | ||
| MAX_BITEMPORAL_ID = 1 << 31 - 1 | ||
|
|
||
| context "on BTDM" do | ||
| let(:employees) { create_employees_with_history } | ||
|
|
||
| it "finds existing bitemporal IDs" do | ||
| first_employee, second_employee = *employees | ||
|
|
||
| expect(Employee.exists?(first_employee.bitemporal_id)).to eq true | ||
| expect(Employee.exists?(second_employee.bitemporal_id)).to eq true | ||
| expect(Employee.exists?(MAX_BITEMPORAL_ID)).to eq false | ||
| end | ||
| end | ||
|
|
||
| context "on relation" do | ||
| let(:employees) { create_employees_with_history } | ||
|
|
||
| it "finds existing bitemporal IDs" do | ||
| first_employee, second_employee = *employees | ||
|
|
||
| expect(Employee.all.exists?(first_employee.bitemporal_id)).to eq true | ||
| expect(Employee.all.exists?(second_employee.bitemporal_id)).to eq true | ||
| expect(Employee.all.exists?(MAX_BITEMPORAL_ID)).to eq false | ||
| end | ||
| end | ||
|
|
||
| context "on loaded relation" do | ||
| let(:employees) { create_employees_with_history } | ||
|
|
||
| it "finds existing bitemporal IDs" do | ||
| first_employee, second_employee = *employees | ||
|
|
||
| expect(Employee.all.load.exists?(first_employee.bitemporal_id)).to eq true | ||
| expect(Employee.all.load.exists?(second_employee.bitemporal_id)).to eq true | ||
| expect(Employee.all.load.exists?(MAX_BITEMPORAL_ID)).to eq false | ||
| end | ||
| end | ||
|
|
||
| context "with eager loading by includes" do | ||
| let(:company) { | ||
| Company | ||
| .create!(name: "Company") | ||
| .tap { |c| c.employees << create_employees_with_history } | ||
| } | ||
|
|
||
| it "finds existing bitemporal IDs" do | ||
| first_employee, second_employee = *company.employees | ||
|
|
||
| expect(Employee.includes(:company).exists?(first_employee.bitemporal_id)).to eq true | ||
| expect(Employee.includes(:company).exists?(second_employee.bitemporal_id)).to eq true | ||
| expect(Employee.includes(:company).exists?(MAX_BITEMPORAL_ID)).to eq false | ||
| end | ||
| end | ||
|
|
||
| context "on association" do | ||
| let(:company) { | ||
| Company | ||
| .create!(name: "Company") | ||
| .tap { |c| c.employees << create_employees_with_history } | ||
| } | ||
|
|
||
| it "finds existing bitemporal IDs" do | ||
| first_employee, second_employee = *company.employees | ||
|
|
||
| expect(company.employees.reset.exists?(first_employee.bitemporal_id)).to eq true | ||
| expect(company.employees.reset.exists?(second_employee.bitemporal_id)).to eq true | ||
| expect(company.employees.reset.exists?(MAX_BITEMPORAL_ID)).to eq false | ||
| end | ||
| end | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require 'spec_helper' | ||
|
|
||
| RSpec.describe ActiveRecord::Bitemporal::Relation do | ||
| describe "#ids" do | ||
| def create_employees_with_history | ||
| Employee | ||
| .create!([{ name: "Jane" }, { name: "Tom" } ]) | ||
| .each { |e| e.update!(updated_at: Time.current) } | ||
| end | ||
|
|
||
| context "on BTDM" do | ||
| let(:employees) { create_employees_with_history } | ||
|
|
||
| it "returns all bitemporal IDs" do | ||
| expected = [employees[0].bitemporal_id, employees[1].bitemporal_id] | ||
| expect(Employee.ids).to match_array expected | ||
| end | ||
| end | ||
|
|
||
| context "on relation" do | ||
| let(:employees) { create_employees_with_history } | ||
|
|
||
| it "returns all bitemporal IDs" do | ||
| expected = [employees[0].bitemporal_id, employees[1].bitemporal_id] | ||
| expect(Employee.all.ids).to match_array expected | ||
| end | ||
| end | ||
|
|
||
| context "on loaded relation" do | ||
| let(:employees) { create_employees_with_history } | ||
|
|
||
| it "returns all bitemporal IDs" do | ||
| expected = [employees[0].bitemporal_id, employees[1].bitemporal_id] | ||
| expect(Employee.all.load.ids).to match_array expected | ||
| end | ||
| end | ||
|
|
||
| context "with eager loading by includes" do | ||
| let(:company) { | ||
| Company | ||
| .create!(name: "Company") | ||
| .tap { |c| c.employees << create_employees_with_history } | ||
| } | ||
|
|
||
| it "returns bitemporal IDs" do | ||
| expected = [company.employees[0].bitemporal_id, company.employees[1].bitemporal_id] | ||
| expect(Employee.includes(:company).ids).to match_array expected | ||
| end | ||
| end | ||
|
|
||
| context "on association" do | ||
| let(:company) { | ||
| Company | ||
| .create!(name: "Company") | ||
| .tap { |c| c.employees << create_employees_with_history } | ||
| } | ||
|
|
||
| it "returns bitemporal IDs" do | ||
| expected = [company.employees[0].bitemporal_id, company.employees[1].bitemporal_id] | ||
| expect(company.employees.reset.ids).to match_array expected | ||
| end | ||
| end | ||
| end | ||
| end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.