Sha256: b489485704fd27cc9f89fc2c593c30572dbc373cb1dccb9086489ebed61449dd

Contents?: true

Size: 1.51 KB

Versions: 3

Compression:

Stored size: 1.51 KB

Contents

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

describe ActsAsApi::Base do

  describe "calling a closure in the api template", :orm => :active_record do

    before(:each) do
      setup_models
    end

    after(:each) do
      clean_up
    end

    describe "i.e. a proc (the record is passed as only parameter)" do

      before(:each) do
        @response = @luke.as_api_response(:calling_a_proc)
      end

      it "returns a hash" do
        @response.should be_kind_of(Hash)
      end

      it "returns the correct number of fields" do
        @response.should have(2).keys
      end

      it "returns all specified fields" do
        @response.keys.sort_by(&:to_s).should eql([:all_caps_name, :without_param])
      end

      it "returns the correct values for the specified fields" do
        @response.values.sort.should eql(["LUKE SKYWALKER", "Time"])
      end
    end

    describe "i.e. a lambda (the record is passed as only parameter)" do

      before(:each) do
        @response = @luke.as_api_response(:calling_a_lambda)
      end

      it "returns a hash" do
        @response.should be_kind_of(Hash)
      end

      it "returns the correct number of fields" do
        @response.should have(2).keys
      end

      it "returns all specified fields" do
        @response.keys.sort_by(&:to_s).should eql([:all_caps_name, :without_param])
      end

      it "returns the correct values for the specified fields" do
        @response.values.sort.should eql(["LUKE SKYWALKER", "Time"])
      end

    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
acts_as_api-0.3.5 spec/models/base/closures_spec.rb
acts_as_api-0.3.4 spec/models/base/closures_spec.rb
acts_as_api-0.3.3 spec/models/base/closures_spec.rb