Sha256: 83b018ba4238abd1685669500adf44ee0b2effbba7836611ce6272037e3ffb64

Contents?: true

Size: 1.71 KB

Versions: 2

Compression:

Stored size: 1.71 KB

Contents

require 'spec_helper'

describe ApiClient::Base do
  describe "#initialize" do
    context "with a hash {:a => 'a', :b => 'b'}" do
      before :each do
        @user = User.new({:a => "a", :b => "b"})
      end

      it "should set #a" do
        @user.a.should == "a"
      end

      it "should set #b" do
        @user.b.should == "b"
      end
    end
  end

  describe "#remote_object" do
    context "on a class without remote object specification" do
      it "should return the class name" do
        User.remote_object.should == "user"
      end
    end

    context "on a class with remote object specification" do
      it "should return the class name" do
        Admin.remote_object.should == "user"
      end
    end
  end

  describe "#remote_object=" do
    it "should set the remote object name" do
      Admin.remote_object.should == "user"
    end
  end

  describe "#persisted?" do
    it "should return false" do
      User.new.should_not be_persisted
    end
  end

  describe "#errors" do
    context "when @errors is not nil" do
      before :each do
        @user = User.new(:errors => {:a => :bc})
      end

      it "should return the errors" do
        @user.errors.should == {:a => :bc}
      end
    end

    context "when @errors is nil" do
      before :each do
        @user = User.new
      end

      it "should instantiate a new instance of ApiClient::Errors" do
        @user.errors.should be_an_instance_of(ApiClient::Errors)
      end
    end
  end

  describe "#errors=" do
    before :each do
      @user = User.new(:errors => { "a" => "message", "b" => "message" })
    end

    it "should set @errors with symbolic keys" do
      @user.errors.should == { :a => "message", :b => "message" }
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
api-client-1.5.2 spec/api-client/base_spec.rb
api-client-1.5.1 spec/api-client/base_spec.rb