Skip to content

Commit

Permalink
Merge pull request #3 from bkeepers/array
Browse files Browse the repository at this point in the history
Accept an array of records
  • Loading branch information
jeremy committed May 6, 2013
2 parents d7b62c2 + 77e0d06 commit 0a6c1e3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/etagger.rb
Expand Up @@ -22,7 +22,8 @@ def fresh_when(record_or_options, additional_options = {})
private
def revise_etag(options, additional_options = nil)
if !options.is_a?(Hash)
revise_etag({ etag: options, last_modified: options.try(:updated_at) }.merge(additional_options))
last_modified = options.respond_to?(:updated_at) ? options.updated_at : nil
revise_etag({ etag: options, last_modified: last_modified }.merge(additional_options))
elsif etag = options[:etag]
etags = etaggers.map { |etagger| instance_exec &etagger }.compact
options.merge etag: [etag, *etags]
Expand Down
4 changes: 4 additions & 0 deletions test/etagger_test.rb
Expand Up @@ -29,4 +29,8 @@ def setup
def test_revises_etag
assert_equal ['123', 'ab', :cde, [:f]], @controller.fresh_when(etag: '123')
end

def test_updated_at_with_array
assert_equal [%w(1 2), 'ab', :cde, [:f]], @controller.fresh_when(%w(1 2))
end
end

0 comments on commit 0a6c1e3

Please sign in to comment.