Skip to content

Commit

Permalink
Merge pull request #298 from ifad/bugfix/297-match-rails-signature-an…
Browse files Browse the repository at this point in the history
…d-return-type

Change `load` method to match AR implementation
  • Loading branch information
tagliala authored Jun 2, 2024
2 parents 0addc9c + 8b9933e commit d598760
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/chrono_model/patches/relation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ def empty_scope?
@values == klass.unscoped.as_of(as_of_time).values
end

def load
return super unless @_as_of_time && !loaded?
def load(&block)
return super unless @_as_of_time && (!loaded? || scheduled?)

super.each { |record| record.as_of_time!(@_as_of_time) }

self
end

def merge(*)
Expand Down
6 changes: 6 additions & 0 deletions spec/chrono_model/time_machine/as_of_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -181,5 +181,11 @@
it { expect($t.baz.as_of($t.bar.ts[2]).bar.foo.name).to eq 'new foo' }
it { expect($t.baz.as_of($t.bar.ts[3]).bar.foo.name).to eq 'new foo' }
end

describe '#load' do
it 'returns a relation' do
expect(Foo.as_of(Time.now).load).to be_an(ActiveRecord::Relation)
end
end
end
end

0 comments on commit d598760

Please sign in to comment.