Skip to content
This repository has been archived by the owner on Dec 19, 2018. It is now read-only.

Commit

Permalink
Remove module incusion/extension
Browse files Browse the repository at this point in the history
Now there's no weird meta and we're just dealing with methods in classes
we can stop with the modules and just wrap some stuff in `class << self`
  • Loading branch information
eightbitraptor committed Jun 19, 2014
1 parent d6388fa commit f01e076
Showing 1 changed file with 38 additions and 43 deletions.
81 changes: 38 additions & 43 deletions lib/http_redirect_test/http_redirect_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class HTTPRedirectTest < MiniTest::Test

def default_test; end # placeholder to stop Test::Unit from complaining

module ClassMethods
class << self
attr_reader :domain
attr_accessor :permanent

Expand All @@ -17,59 +17,54 @@ def permanent?
end
end

module InstanceMethods
def should_not_redirect(path)
assert_equal false, check_for(path).redirected?, "#{path} is redirecting"
assert_equal true, check_for(path).success?, "#{path} is not a success response"
end
def should_not_redirect(path)
assert_equal false, check_for(path).redirected?, "#{path} is redirecting"
assert_equal true, check_for(path).success?, "#{path} is not a success response"
end

def should_redirect(source, options)
source_path = ResourcePath.new(source, :param => 'subdir').to_s
destination_path = ResourcePath.new(options[:to], :param => 'subdir').to_s
def should_redirect(source, options)
source_path = ResourcePath.new(source, :param => 'subdir').to_s
destination_path = ResourcePath.new(options[:to], :param => 'subdir').to_s

redirection = check_for(source_path, destination_path)
assert_equal true, redirection.redirected?, "'#{source_path}' is not redirecting"
assert_equal destination_path, redirection.redirected_path,
"'#{source_path}' is not redirecting to '#{destination_path}'"
redirection = check_for(source_path, destination_path)
assert_equal true, redirection.redirected?, "'#{source_path}' is not redirecting"
assert_equal destination_path, redirection.redirected_path,
"'#{source_path}' is not redirecting to '#{destination_path}'"

if permanent? || options[:permanent]
assert_equal true, redirection.permanent_redirect?,
"The redirection from '#{source_path}' to '#{destination_path}' doesn't appear to be a permanent redirect"
end
if permanent? || options[:permanent]
assert_equal true, redirection.permanent_redirect?,
"The redirection from '#{source_path}' to '#{destination_path}' doesn't appear to be a permanent redirect"
end
end

def should_be_gone(path)
assert check_for(path).gone?
end
def should_be_gone(path)
assert check_for(path).gone?
end

def should_not_be_found(path)
assert check_for(path).not_found?
end
def should_not_be_found(path)
assert check_for(path).not_found?
end

def should_have_header(path, header, options)
value = options[:with_value]
assert_equal value, check_for(path).header(header)
end
def should_have_header(path, header, options)
value = options[:with_value]
assert_equal value, check_for(path).header(header)
end

private
private

def check_for(path, destination=nil)
RedirectCheck.new(self.class.domain, path, destination)
end
def check_for(path, destination=nil)
RedirectCheck.new(self.class.domain, path, destination)
end

def permanent?
!!self.class.permanent
end
def permanent?
!!self.class.permanent
end

def name_for(path)
if path.empty?
'root'
else
path.strip.gsub(/\W+/, '_')
end
def name_for(path)
if path.empty?
'root'
else
path.strip.gsub(/\W+/, '_')
end
end

extend ClassMethods
include InstanceMethods
end

0 comments on commit f01e076

Please sign in to comment.