Permalink
Browse files

cleanup

  • Loading branch information...
1 parent 2ee4531 commit 5501e1e7a6a4209d693546b70c0ddc1c0d1a8fe4 Sven Fuchs committed Sep 5, 2010
Showing with 25 additions and 25 deletions.
  1. +0 −1 rack-cache-tags.gemspec
  2. +20 −0 test/test_helper.rb
  3. +0 −4 test/test_store.rb
  4. +5 −20 test/test_tags.rb
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
View
@@ -29,11 +29,31 @@
DatabaseCleaner.strategy = :truncation
class Test::Unit::TestCase
+ include Rack::Cache::Tags::Store
+
def setup
DatabaseCleaner.start
end
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
View
@@ -1,4 +0,0 @@
-require File.expand_path('../test_helper', __FILE__)
-
-class StoreTest < Test::Unit::TestCase
-end
View
@@ -4,38 +4,23 @@ 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
create_tags('http://example.com/foo', %w(foo-1 foo-2))
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

0 comments on commit 5501e1e

Please sign in to comment.