Sha256: ad829aaf1dc22766835fa3abe6245c08ca5e2cf13abca4fc9aef8ddb0110e3a4

Contents?: true

Size: 1.94 KB

Versions: 6

Compression:

Stored size: 1.94 KB

Contents

require File.join(File.dirname(__FILE__), '..', 'spec_helper')

describe Weary::Resource do
  before do
    @test = Weary::Resource.new("test")
  end
  
  it 'defaults to a GET request' do
    @test.via.should == :get
  end
  
  it 'should add requirements to the "with" array' do
    @test.requires = [:foo, :bar]
    @test.with.should == [:foo, :bar]
  end
  
  it 'with paramaters could be comma delimited strings' do
    @test.with = "foo", "bar"
    @test.with.should == [:foo, :bar]
  end
  
  it 'with params could be a hash' do
    @test.with = {:foo => "Foo", :bar => "Bar"}
    @test.with.should == {:foo => "Foo", :bar => "Bar"}
    @test.requires = [:id, :user]
    @test.with.should == {:bar=>"Bar", :user => nil, :foo => "Foo", :id => nil}
    @test.with = [:foo, :bar]
    @test.with.should == [:foo, :bar, :id, :user]
  end
  
  it 'authenticates? should be boolean' do
    @test.authenticates = "foobar"
    @test.authenticates?.should == true
    @test.authenticates = false
    @test.authenticates?.should == false
  end
  
  it 'follows_redirects? should be boolean' do
    @test.follows = "false"
    @test.follows_redirects?.should == true
    @test.follows = false
    @test.follows_redirects?.should == false
  end
  
  it 'should be intelligent about crafting names' do
    @test.name = "foo bar \n"
    @test.name.should == "foo_bar"
  end
  
  it 'should only allow specified http methods' do
    @test.via = "Post"
    @test.via.should == :post
    lambda { @test.via = :foobar }.should raise_error
  end

  it 'format should be a symbol' do
    @test.format = "xml"
    @test.format.class.should == Symbol
  end
  
  it 'format should be an allowed format' do
    @test.format = 'text/json'
    @test.format.should == :json
    lambda { @test.format = :foobar }.should raise_error
  end
  
  it 'should be able to set Headers' do
    @test.headers = {'Content-Type' => 'text/html'}
    @test.headers.should == {'Content-Type' => 'text/html'}
  end
  
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
mwunsch-weary-0.4.0 spec/weary/resource_spec.rb
mwunsch-weary-0.4.1 spec/weary/resource_spec.rb
mwunsch-weary-0.4.3 spec/weary/resource_spec.rb
weary-0.4.0 spec/weary/resource_spec.rb
weary-0.4.1 spec/weary/resource_spec.rb
weary-0.4.3 spec/weary/resource_spec.rb