-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rename columns, start developing model integration
- Loading branch information
1 parent
6cda976
commit e62ad99
Showing
18 changed files
with
133 additions
and
23 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
PATH | ||
remote: .. | ||
specs: | ||
iron_trail (0.1.2) | ||
iron_trail (0.1.3) | ||
rails (>= 7.1) | ||
request_store (~> 1.5) | ||
|
||
|
This file contains 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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
PATH | ||
remote: .. | ||
specs: | ||
iron_trail (0.1.2) | ||
iron_trail (0.1.3) | ||
rails (>= 7.1) | ||
request_store (~> 1.5) | ||
|
||
|
This file contains 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 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 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 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 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,33 @@ | ||
# frozen_string_literal: true | ||
|
||
module IronTrail | ||
module ChangeModelConcern | ||
extend ::ActiveSupport::Concern | ||
|
||
module ClassMethods | ||
def where_object_changes_to(args = {}) | ||
scope = all | ||
|
||
args.each do |col_name, value| | ||
scope.where!( | ||
::Arel::Nodes::SqlLiteral.new("rec_delta->#{connection.quote col_name}->>1").eq( | ||
::Arel::Nodes::BindParam.new(value) | ||
) | ||
) | ||
end | ||
|
||
scope | ||
# where_object_changes(0, args) | ||
end | ||
|
||
def where_object_changes_from(args = {}) | ||
where_object_changes(0, args) | ||
end | ||
|
||
private | ||
|
||
def where_object_changes(ary_index, args) | ||
end | ||
end | ||
end | ||
end |
This file contains 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 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 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
Empty file.
This file contains 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 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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# frozen_literal_string: true | ||
|
||
module IronTrail | ||
VERSION = '0.1.2' | ||
VERSION = '0.1.3' | ||
end |
This file contains 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 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 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 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,65 @@ | ||
# frozen_string_literal: true | ||
|
||
RSpec.describe IrontrailChange do | ||
let(:person) { Person.create!(first_name: 'Arthur', last_name: 'Klarkey') } | ||
|
||
before do | ||
# let's have other people to ensure tests are picking up the right person | ||
@other_people = 3.times do |index| | ||
Person.create!(first_name: "Joey#{index}", last_name: "Doe#{index}").tap do |t| | ||
t.update!(first_name: "Ashley#{index}") | ||
t.update!(last_name: "X#{index}") | ||
end.reload | ||
end | ||
end | ||
|
||
describe 'IronTrail::ChangeModelConcern' do | ||
it 'tests the test' do | ||
# just ensure other people have been created | ||
expect(Person.count).to be >= 3 | ||
expect(IrontrailChange.count).to be >= 9 | ||
end | ||
|
||
describe 'where_object_changes_to' do | ||
before do | ||
person.update!(first_name: 'Michael') | ||
person.update!(first_name: 'Johnny', last_name: 'Tod') | ||
person.update!(first_name: 'Michael', favorite_planet: 'Saturn') | ||
person.update!(last_name: 'Cash') | ||
end | ||
|
||
it 'finds the expected records' do | ||
scope = person.iron_trails.where_object_changes_to(last_name: 'Cash') | ||
expect(scope.count).to eq(1) | ||
|
||
expect(scope.first.rec_old).to include('first_name' => 'Michael', 'last_name' => 'Tod') | ||
expect(scope.first.rec_new).to include('first_name' => 'Michael', 'last_name' => 'Cash') | ||
expect(scope.first.rec_delta).to eq({ 'last_name' => ['Tod', 'Cash'] }) | ||
|
||
scope = person.iron_trails.where_object_changes_to(first_name: 'Michael') | ||
.order({ | ||
described_class.arel_table[:created_at] => :asc, | ||
described_class.arel_table[:id] => :asc | ||
}) | ||
|
||
expect(scope.first.rec_old).to include('first_name' => 'Arthur', 'last_name' => 'Klarkey') | ||
expect(scope.first.rec_new).to include('first_name' => 'Michael', 'last_name' => 'Klarkey') | ||
expect(scope.first.rec_delta).to eq({ 'first_name' => ['Arthur', 'Michael'] }) | ||
|
||
expect(scope.last.rec_old).to include('first_name' => 'Johnny', 'last_name' => 'Tod', 'favorite_planet' => nil) | ||
expect(scope.last.rec_new).to include('first_name' => 'Michael', 'last_name' => 'Tod', 'favorite_planet' => 'Saturn') | ||
expect(scope.last.rec_delta).to eq({ | ||
'first_name' => ['Johnny', 'Michael'], | ||
'favorite_planet' => [nil, 'Saturn'] | ||
}) | ||
|
||
planet_changed_record = scope.last.clone | ||
|
||
scope = person.iron_trails.where_object_changes_to(favorite_planet: 'Saturn') | ||
expect(scope.count).to eq(1) | ||
|
||
expect(scope.first.id).to eq(planet_changed_record.id) | ||
end | ||
end | ||
end | ||
end |
This file contains 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