Navigation Menu

Skip to content

Commit

Permalink
Fixed to recognize AR cached queries as reads.
Browse files Browse the repository at this point in the history
Bumping version due to the fix being important.
  • Loading branch information
Dmitry Ratnikov committed Apr 19, 2012
1 parent b58a403 commit c952579
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 39 deletions.
74 changes: 37 additions & 37 deletions Gemfile.lock
@@ -1,76 +1,76 @@
PATH
remote: .
specs:
strict-forgery-protection (0.0.2)
strict-forgery-protection (0.0.3)
rails (~> 3.1)

GEM
remote: http://rubygems.org/
specs:
actionmailer (3.2.1)
actionpack (= 3.2.1)
mail (~> 2.4.0)
actionpack (3.2.1)
activemodel (= 3.2.1)
activesupport (= 3.2.1)
actionmailer (3.2.3)
actionpack (= 3.2.3)
mail (~> 2.4.4)
actionpack (3.2.3)
activemodel (= 3.2.3)
activesupport (= 3.2.3)
builder (~> 3.0.0)
erubis (~> 2.7.0)
journey (~> 1.0.1)
rack (~> 1.4.0)
rack-cache (~> 1.1)
rack-cache (~> 1.2)
rack-test (~> 0.6.1)
sprockets (~> 2.1.2)
activemodel (3.2.1)
activesupport (= 3.2.1)
activemodel (3.2.3)
activesupport (= 3.2.3)
builder (~> 3.0.0)
activerecord (3.2.1)
activemodel (= 3.2.1)
activesupport (= 3.2.1)
arel (~> 3.0.0)
activerecord (3.2.3)
activemodel (= 3.2.3)
activesupport (= 3.2.3)
arel (~> 3.0.2)
tzinfo (~> 0.3.29)
activerecord-jdbc-adapter (1.2.2)
activerecord-jdbcsqlite3-adapter (1.2.2)
activerecord-jdbc-adapter (~> 1.2.2)
jdbc-sqlite3 (~> 3.7.2)
activeresource (3.2.1)
activemodel (= 3.2.1)
activesupport (= 3.2.1)
activesupport (3.2.1)
activeresource (3.2.3)
activemodel (= 3.2.3)
activesupport (= 3.2.3)
activesupport (3.2.3)
i18n (~> 0.6)
multi_json (~> 1.0)
arel (3.0.0)
arel (3.0.2)
builder (3.0.0)
erubis (2.7.0)
hike (1.2.1)
i18n (0.6.0)
jdbc-sqlite3 (3.7.2)
journey (1.0.1)
json (1.6.5-java)
mail (2.4.1)
journey (1.0.3)
json (1.6.6-java)
mail (2.4.4)
i18n (>= 0.4.0)
mime-types (~> 1.16)
treetop (~> 1.4.8)
mime-types (1.17.2)
multi_json (1.0.4)
mime-types (1.18)
multi_json (1.2.0)
polyglot (0.3.3)
rack (1.4.1)
rack-cache (1.1)
rack-cache (1.2)
rack (>= 0.4)
rack-ssl (1.3.2)
rack
rack-test (0.6.1)
rack (>= 1.0)
rails (3.2.1)
actionmailer (= 3.2.1)
actionpack (= 3.2.1)
activerecord (= 3.2.1)
activeresource (= 3.2.1)
activesupport (= 3.2.1)
rails (3.2.3)
actionmailer (= 3.2.3)
actionpack (= 3.2.3)
activerecord (= 3.2.3)
activeresource (= 3.2.3)
activesupport (= 3.2.3)
bundler (~> 1.0)
railties (= 3.2.1)
railties (3.2.1)
actionpack (= 3.2.1)
activesupport (= 3.2.1)
railties (= 3.2.3)
railties (3.2.3)
actionpack (= 3.2.3)
activesupport (= 3.2.3)
rack-ssl (~> 1.3.2)
rake (>= 0.8.7)
rdoc (~> 3.4)
Expand All @@ -81,13 +81,13 @@ GEM
sprockets (2.1.2)
hike (~> 1.2)
rack (~> 1.0)
tilt (!= 1.3.0, ~> 1.1)
tilt (~> 1.1, != 1.3.0)
thor (0.14.6)
tilt (1.3.3)
treetop (1.4.10)
polyglot
polyglot (>= 0.3.1)
tzinfo (0.3.31)
tzinfo (0.3.33)

PLATFORMS
java
Expand Down
6 changes: 5 additions & 1 deletion lib/forgery_protection/sql_event.rb
Expand Up @@ -3,13 +3,17 @@
module ForgeryProtection
class SqlEvent < ActiveSupport::Notifications::Event
def read?
result.respond_to?(:each)
cache? || result.respond_to?(:each)
end

def write?
!read?
end

def cache?
payload[:name] == 'CACHE'
end

private

def result
Expand Down
2 changes: 1 addition & 1 deletion lib/forgery_protection/version.rb
@@ -1,3 +1,3 @@
module ForgeryProtection
VERSION = '0.0.3'.freeze
VERSION = '0.0.4'.freeze
end
6 changes: 6 additions & 0 deletions test/db_events_test.rb
Expand Up @@ -34,6 +34,12 @@ def test_raw_writes
end
end

def test_cache
assert_reads do
Post.connection.cache { 2.times { Post.all } }
end
end

private

def assert_reads
Expand Down

0 comments on commit c952579

Please sign in to comment.