Sha256: 85591295c71e4f8bf9f2aa943a41adeada91568adfcb890193a8d094d58a91e4

Contents?: true

Size: 1.92 KB

Versions: 1

Compression:

Stored size: 1.92 KB

Contents

require 'remote/spec_helper'

describe "Remote Basic" do
  with_environment
  with_remote_spec
  
  it "basic" do
    class BasicSpec
      inherit Rad::Remote
      
      def call
        {result: 'some result'}
      end
    end
    
    workspace = rcall BasicSpec, :call, format: 'json'
    
    workspace.delete(:remote_object).should be_a(BasicSpec)
    expected_result = {      
      params: {format: 'json'},
      
      class: BasicSpec,   
      method_name: :call, 
      
      remote_result: {result: "some result"},
      content: %({"result":"some result"})
    }
    workspace.to_h(true).subset(expected_result.keys).should == expected_result
  end
  
  describe "error handling should behave different in :production, :development and :test modes" do
    it "error in :development mode" do    
      class JsonErrorSpec
        inherit Rad::Remote
      
        def call_with_error
          raise 'some error'
        end
      end
    
      config.environment = :development
      silence_logger!
    
      workspace = rcall JsonErrorSpec, 'call_with_error', format: 'json'
    
      workspace.delete(:remote_object).should be_a(JsonErrorSpec)
      workspace.include?(:remote_result).should be_false
      expected_result = {
        params: {format: 'json'},
      
        class: JsonErrorSpec,   
        method_name: "call_with_error", 
      
        content: %({"error":"some error"})
      }
      workspace.to_h.subset(expected_result.keys).should == expected_result
    end
  end
  
  it "should be able to protect methods from GET request"
  
  it "should not allow unregistered object types be used as return value" do
    class UnregisteredReturnValueSpec
      inherit Rad::Remote
      
      def call
        Object.new
      end
    end
   
    lambda{
      rcall UnregisteredReturnValueSpec, 'call', format: 'json'
    }.should raise_error(/You can't use object of type 'Object' as Remote's return value!/)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rad_core-0.0.13 spec/remote/remote_spec.rb