Sha256: b2c9b41d762aed3585486dd452f314efca60c6a5b211a10903eafe0cbc2a7d81

Contents?: true

Size: 1.23 KB

Versions: 2

Compression:

Stored size: 1.23 KB

Contents

shared_examples_for 'calling a closure in the api template' do
  describe 'i.e. a proc (the record is passed as only parameter)' do
    subject(:response) { @luke.as_api_response(:calling_a_proc) }

    it 'returns a hash' do
      expect(response).to be_kind_of(Hash)
    end

    it 'returns the correct number of fields' do
      expect(response).to have(2).keys
    end

    it 'returns all specified fields' do
      expect(response.keys.sort_by(&:to_s)).to eql([:all_caps_name, :without_param])
    end

    it 'returns the correct values for the specified fields' do
      expect(response.values.sort).to eql(['LUKE SKYWALKER', 'Time'])
    end
  end

  describe 'i.e. a lambda (the record is passed as only parameter)' do
    subject(:response) { @luke.as_api_response(:calling_a_lambda) }

    it 'returns a hash' do
      expect(response).to be_kind_of(Hash)
    end

    it 'returns the correct number of fields' do
      expect(response).to have(2).keys
    end

    it 'returns all specified fields' do
      expect(response.keys.sort_by(&:to_s)).to eql([:all_caps_name, :without_param])
    end

    it 'returns the correct values for the specified fields' do
      expect(response.values.sort).to eql(['LUKE SKYWALKER', 'Time'])
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
acts_as_api-1.0.1 spec/support/model_examples/closures.rb
acts_as_api-1.0.0 spec/support/model_examples/closures.rb