Sha256: e68f18e5b7fac2c9846b82de24c4859492af1a42044aeef153b7bce687f6c995

Contents?: true

Size: 1.23 KB

Versions: 1

Compression:

Stored size: 1.23 KB

Contents

require File.dirname(__FILE__) + '/spec_helper'

require 'relax/query'

describe 'a query' do
  before(:each) do
    @uri = URI::parse('http://example.com/?action=search&query=keyword')
    @query = Relax::Query.new
  end

  it 'should convert to a query string' do
    @query[:action] = 'Search'
    @query[:query] = 'strings'
    @query.to_s.should eql('action=Search&query=strings')
  end

  it 'should convert its values to strings' do
    date = Date.today
    @query[:date] = date
    @query.to_s.should eql("date=#{date.to_s}")
  end

  it 'should escape its values using "+" instead of "%20"' do
    Relax::Query.send(:escape_value, 'two words').should == 'two+words'
  end

  it 'should sort its parameters' do
    @query[:charlie] = 3
    @query[:alpha] = 1
    @query[:bravo] = 2
    @query.to_s.should eql('alpha=1&bravo=2&charlie=3')
  end

  it 'should encode its parameter values' do
    @query[:spaces] = 'two words'
    @query[:url] = 'http://example.com/'
    @query.to_s.should eql('spaces=two+words&url=http%3A%2F%2Fexample.com%2F')
  end

  it 'should be able to parse query strings' do
    parsed_query = Relax::Query.parse(@uri)
    parsed_query[:action].should eql('search')
    parsed_query[:query].should eql('keyword')
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
relax-0.0.4 spec/query_spec.rb