Sha256: b6e7e9063724b54e8257580a1b4354de60c2bc27c023df6d5f684d8a27ca2e13

Contents?: true

Size: 1.71 KB

Versions: 10

Compression:

Stored size: 1.71 KB

Contents

require 'rack'
require 'rack/test'

RSpec::Matchers.define :be_happy_response do |filetype|
  match do |actual|
    actual[0] == 200 || actual[3] == filetype
  end
end

RSpec::Matchers.define :be_redirect_response do |url|
  match do |actual|
    actual[0] == 200 || actual[1]["Location"] == url
  end
end

describe Shutterbug::Rackapp do
  include Rack::Test::Methods

  let(:post_data) do
    {
      'content'  => "<div class='foo'>foo!</div>",
      'width'    => 1000,
      'height'   => 700,
      'css'      => "",
      'base_url' => "http://localhost:8080/"
    }
  end

  let(:app) do
    Shutterbug::Rackapp.new do |config|
      config.uri_prefix  = "http://localhost:9292"
      config.path_prefix = "/shutterbug"
    end
  end

  let(:filename) { "filename" }
  let(:url)      { "url_to_file" }

  let(:mock_file) do
    mock({
      :get_content => "content",
      :mime_type => "image/png",
      :filename => filename,
      :url => url
    })
  end

  let(:test_storage) { mock({ :new => mock_file })}

  before(:each) do
    Shutterbug::Configuration.instance.stub!(:storage => test_storage)
  end

  describe "routing requests in #call" do
    describe "do_convert route" do
      it "should return a valid image url" do
        get "/shutterbug/make_snapshot/", post_data
        last_response.should be_ok
        last_response.headers['Content-Type'].should match 'text/plain'
        last_response.body.should match(/^<img src='url_to_file'[^>]+>$/)
      end
    end

    describe "get file route" do
      it "should return without errors" do
        get "/shutterbug/get_file/foobar.png"
        last_response.should be_ok
        last_response.headers['Content-Type'].should match 'image/png'
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
shutterbug-0.5.9 spec/shutterbug/rackapp_spec.rb
shutterbug-0.5.8 spec/shutterbug/rackapp_spec.rb
shutterbug-0.5.7 spec/shutterbug/rackapp_spec.rb
shutterbug-0.5.6 spec/shutterbug/rackapp_spec.rb
shutterbug-0.5.5 spec/shutterbug/rackapp_spec.rb
shutterbug-0.5.4 spec/shutterbug/rackapp_spec.rb
shutterbug-0.5.3 spec/shutterbug/rackapp_spec.rb
shutterbug-0.5.2 spec/shutterbug/rackapp_spec.rb
shutterbug-0.5.1 spec/shutterbug/rackapp_spec.rb
shutterbug-0.5.0 spec/shutterbug/rackapp_spec.rb