spec/request_spec.rb in relax-0.0.3 vs spec/request_spec.rb in relax-0.0.4
- old
+ new
@@ -1,13 +1,19 @@
require File.dirname(__FILE__) + '/spec_helper'
require 'relax/request'
+class Amount < Relax::Request
+ parameter :amount
+ parameter :currency
+end
+
class TestRequest < Relax::Request
parameter :action
parameter :token_id
parameter :user_id
+ parameter :amount, :type => Amount
end
class ChildRequest < TestRequest
parameter :child_id
end
@@ -28,16 +34,18 @@
it 'should include its parameters in the query' do
@query[:action].should eql('Search')
@query[:token_id].should eql('123')
@query[:user_id].should be_nil
+ @query[:amount].should be_nil
end
it 'should only include parameters in the query if they are set' do
@query.key?(:action).should be_true
@query.key?(:token_id).should be_true
@query.key?(:user_id).should be_false
+ @query.key?(:amount).should be_false
end
end
describe 'a normal request' do
it_should_behave_like 'a request that converts to a query'
@@ -47,10 +55,11 @@
describe 'a template request' do
it_should_behave_like 'a request that converts to a query'
it_should_behave_like 'an option initialized request'
before(:each) do
+ # this syntax may need to go away unless we can find a way to make it work
TestRequest[:api_key] = '123456'
TestRequest[:secret] = 'shhh!'
end
it 'should always have the template values in its query' do
@@ -80,7 +89,20 @@
parent = TestRequest.new
parent.api_key.should eql('123456')
parent.secret.should eql('shhh!')
parent.respond_to?(:query).should be_false
+ end
+end
+
+describe 'a request with a custom type' do
+ before(:each) do
+ request = TestRequest.new(:action => 'Pay', :token_id => 123)
+ request.amount = Amount.new(:amount => 3.50, :currency => 'USD')
+ @query = request.to_query
+ end
+
+ it 'should add the type parameters to the query' do
+ @query.key?(:"amount.amount").should be_true
+ @query.key?(:"amount.currency").should be_true
end
end