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

Bugfix: implement #macro in IronTrail::Reflection #14

Merged
merged 1 commit into from
Dec 30, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Fixed

- `ActiveRecord::Reflection#reflect_on_all_associations` would not work for models having IronTrail enabled

### Added

- Now able to travel back in time with `model.iron_trails.travel_to(some_timestamp)`
Expand Down
2 changes: 2 additions & 0 deletions lib/iron_trail/reflection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ module IronTrail
class Reflection < ::ActiveRecord::Reflection::AssociationReflection
def collection?; true; end

def macro; :has_iron_trails; end

def association_class
::IronTrail::Association
end
Expand Down
19 changes: 19 additions & 0 deletions spec/services/people_manager_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,26 @@
record_new = JSON.parse(results.first['rec_new'])
expect(record_new).to eq(person.as_json)
end
end

describe 'rails model reflection' do
it 'lists the IronTrail reflection in a model' do
all_reflections = Person.reflect_on_all_associations
only_irontrail = all_reflections.select { |refl| IronTrail::Reflection === refl }

expect(all_reflections.length).to eq(3)
expect(only_irontrail.length).to eq(1)
end

it 'is able to list specific reflections' do
belongs_to_reflections = Person.reflect_on_all_associations(:belongs_to)
expect(belongs_to_reflections.length).to eq(1)
end

it 'is able to list only IronTrail reflections' do
irontrail_reflections = Person.reflect_on_all_associations(:has_iron_trails)
expect(irontrail_reflections.length).to eq(1)
end
end

describe '#employ_classic_guitars' do
Expand Down
Loading