Skip to content

Commit

Permalink
[ISSUE-57] Male rails/activeresource 4.x compatibl (#60)
Browse files Browse the repository at this point in the history
  • Loading branch information
jlurena authored Jan 15, 2024
1 parent eb4b5a8 commit ef78bc5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ CachedResource is designed to be framework agnostic, but will hook into Rails fo
| πŸ’Ž 3.1 | | | | βœ… | βœ… | βœ… |
| πŸ’Ž 3.2 | | | | βœ… | βœ… | βœ… |

## Limitations

The following are limitations for ActiveResource/Rails versions

| ActiveSupport Version | Limitation |
|---------------------- | ----------------------------------------------------------------------- |
| πŸ›€οΈ 4.X | You cannot chain calls. Ie `Thing.where(fn: 'foo').where(ln: 'bar')`. <br> However, you can still access `original_params` and the `resource_class` and replicate it with <br>`call1 = Thing.where(fn: 'foo')`<br>`call1.resource_class.where(call1.original_params.merge(ln: 'bar'))` |

## Configuration

Expand Down
11 changes: 9 additions & 2 deletions spec/cached_resource/caching_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -234,14 +234,21 @@ class CustomCollection < ActiveResource::Collection; end
cached = read_from_cache('thing/all/{:params=>{:name=>"ada"}}')
cached.should be_instance_of(CustomCollection)
cached.original_params.should == { 'name' => 'ada' }
cached.resource_class.should == Thing
cached.map(&:id).should == @thing_collection.map { |h| h[:id]}

non_cached = cached.where(major: 'CS')
if ActiveResource::VERSION::MAJOR < 5
non_cached = cached.resource_class.where(cached.original_params.merge(major: 'CS'))
else
non_cached = cached.where(major: 'CS')
end

non_cached.original_params.should == { 'name' => 'ada', 'major' => 'CS' }
non_cached.resource_class.should == Thing
non_cached.map(&:id).should == @thing_collection2.map { |h| h[:id]}

cached = read_from_cache('thing/all/{:params=>{"name"=>"ada",:major=>"cs"}}')
cached.original_params.should == { 'name' => 'ada', 'major' => 'CS' }
cached.resource_class.should == Thing
cached.map(&:id).should == @thing_collection2.map { |h| h[:id]}
end
else
Expand Down

0 comments on commit ef78bc5

Please sign in to comment.