Commit bb22be30 by Prem Sichanugrist

Use Net::HTTP instead of curl

There was some problem with command line parsing with a special character.
parent 88a8af95
...@@ -161,3 +161,17 @@ end ...@@ -161,3 +161,17 @@ end
def fixture_file(filename) def fixture_file(filename)
File.join(File.dirname(__FILE__), 'fixtures', filename) File.join(File.dirname(__FILE__), 'fixtures', filename)
end end
def assert_success_response(url)
Net::HTTP.get_response(URI.parse(url)) do |response|
assert_equal "200", response.code,
"Expected HTTP response code 200, got #{response.code}"
end
end
def assert_not_found_response(url)
Net::HTTP.get_response(URI.parse(url)) do |response|
assert_equal "404", response.code,
"Expected HTTP response code 404, got #{response.code}"
end
end
...@@ -91,13 +91,13 @@ unless ENV["S3_BUCKET"].blank? ...@@ -91,13 +91,13 @@ unless ENV["S3_BUCKET"].blank?
end end
should "be accessible" do should "be accessible" do
assert_match /200 OK/, `curl -I #{@dummy.avatar.url}` assert_success_response @dummy.avatar.url
end end
should "be destoryable" do should "be destoryable" do
url = @dummy.avatar.url url = @dummy.avatar.url
@dummy.destroy @dummy.destroy
assert_match /404 Not Found/, `curl -I #{url}` assert_not_found_response url
end end
end end
...@@ -125,17 +125,17 @@ unless ENV["S3_BUCKET"].blank? ...@@ -125,17 +125,17 @@ unless ENV["S3_BUCKET"].blank?
end end
should "be accessible" do should "be accessible" do
assert_match /200 OK/, `curl -I "#{@dummy.avatar.url}"` assert_success_response @dummy.avatar.url
end end
should "be accessible with an expiring url" do should "be accessible with an expiring url" do
assert_match /200 OK/, `curl -I "#{@dummy.avatar.expiring_url}"` assert_success_response @dummy.avatar.expiring_url
end end
should "be destroyable" do should "be destroyable" do
url = @dummy.avatar.url url = @dummy.avatar.url
@dummy.destroy @dummy.destroy
assert_match /404 Not Found/, `curl -I "#{url}"` assert_not_found_response url
end end
end end
end end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment