Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

cleanup

  • Loading branch information...
commit 5501e1e7a6a4209d693546b70c0ddc1c0d1a8fe4 1 parent 2ee4531
Sven Fuchs authored
1  rack-cache-tags.gemspec
View
@@ -16,5 +16,4 @@ Gem::Specification.new do |s|
s.platform = Gem::Platform::RUBY
s.require_path = 'lib'
s.rubyforge_project = '[none]'
- s.required_rubygems_version = '>= 1.3.6'
end
20 test/test_helper.rb
View
@@ -29,6 +29,8 @@
DatabaseCleaner.strategy = :truncation
class Test::Unit::TestCase
+ include Rack::Cache::Tags::Store
+
def setup
DatabaseCleaner.start
end
@@ -36,4 +38,22 @@ def setup
def teardown
DatabaseCleaner.clean
end
+
+ attr_reader :app
+
+ def create_tags(url, tags)
+ tags.each { |tag| ActiveRecord::Tagging.create!(:url => url, :tag => tag) }
+ end
+
+ def respond_with(status, headers, body)
+ @app = Rack::Cache::Tags.new(lambda { |env| [200, headers, ''] })
+ end
+
+ def get(url)
+ app.call(env_for(url))
+ end
+
+ def env_for(*args)
+ Rack::MockRequest.env_for(*args)
+ end
end
4 test/test_store.rb
View
@@ -1,4 +0,0 @@
-require File.expand_path('../test_helper', __FILE__)
-
-class StoreTest < Test::Unit::TestCase
-end
25 test/test_tags.rb
View
@@ -4,13 +4,11 @@ class TagsTest < Test::Unit::TestCase
include Rack::Cache::Tags::Store
test 'stores tags for the current url' do
- url = 'http://example.com/foo'
- headers = { Rack::Cache::Tags::TAGS_HEADER => %w(foo-1 bar-2) }
- tags = Rack::Cache::Tags.new(lambda { |env| [200, headers, ''] })
+ respond_with 200, { Rack::Cache::Tags::TAGS_HEADER => %w(foo-1 bar-2) }, ''
- tags.call(env_for(url))
+ get('http://example.com/')
actual = ActiveRecord::Tagging.all.map { |tagging| [tagging.url, tagging.tag] }
- assert_equal [%W(#{url} foo-1), %W(#{url} bar-2)], actual
+ assert_equal [%W(http://example.com/ foo-1), %W(http://example.com/ bar-2)], actual
end
test 'expands tags to urls for purge headers and deletes the tagging' do
@@ -18,24 +16,11 @@ class TagsTest < Test::Unit::TestCase
create_tags('http://example.com/bar', %w(foo-1))
create_tags('http://example.com/baz', %w(baz-1))
- headers = { Rack::Cache::Tags::PURGE_TAGS_HEADER => %w(foo-1) }
- tags = Rack::Cache::Tags.new(lambda { |env| [200, headers, ''] })
-
- status, headers, body = tags.call(env_for('http://example.com'))
+ respond_with 200, { Rack::Cache::Tags::PURGE_TAGS_HEADER => %w(foo-1) }, ''
+ status, headers, body = get('http://example.com')
actual = ActiveRecord::Tagging.all.map { |tagging| [tagging.url, tagging.tag] }
assert_equal [%w(http://example.com/baz baz-1)], actual
-
assert_equal %w(http://example.com/foo http://example.com/bar), headers[Rack::Cache::Tags::PURGE_HEADER]
end
-
- protected
-
- def create_tags(url, tags)
- tags.each { |tag| ActiveRecord::Tagging.create!(:url => url, :tag => tag) }
- end
-
- def env_for(*args)
- Rack::MockRequest.env_for(*args)
- end
end
Please sign in to comment.
Something went wrong with that request. Please try again.