Skip to content

Commit

Permalink
Bugfix: implement #macro in IronTrail::Reflection (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrepiske authored Dec 30, 2024
1 parent 449b3ac commit d597cc1
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
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

0 comments on commit d597cc1

Please sign in to comment.