Sha256: 8915311af4f555b9774f5a56eb7d60d697c0a62e1fb93617730e3665918575b5

Contents?: true

Size: 1.1 KB

Versions: 25

Compression:

Stored size: 1.1 KB

Contents

module Gris
  module RspecExtensions
    module ResponseHelpers
      def response_code
        last_response.status
      end

      def response_body
        last_response.body
      end

      def parsed_response_body
        Hashie::Mash.new JSON.parse(response_body)
      end

      def result
        parsed_response_body
      end

      def embedded_results(klass)
        parsed_response_body[:_embedded][klass.name.tableize.to_sym]
      end

      def embedded_results_count(klass)
        embedded_results(klass).count
      end

      def expect_embedded_results_count_of(count, klass)
        expect(embedded_results_count(klass)).to eq(count)
      end

      def first_embedded_result(klass)
        embedded_results(klass).first
      end

      def embedded_result_with_id(id, klass)
        embedded_results(klass).detect { |r| r.id == id }
      end

      def links
        parsed_response_body['_links']
      end

      def link_to_self
        links['self']
      end

      def link_to_next
        links['next']
      end

      def link_to_previous
        links['prev']
      end
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
gris-0.4.6 lib/gris/rspec_extensions/response_helpers.rb
gris-0.4.5 lib/gris/rspec_extensions/response_helpers.rb
gris-0.4.4 lib/gris/rspec_extensions/response_helpers.rb
gris-0.4.3 lib/gris/rspec_extensions/response_helpers.rb
gris-0.4.2 lib/gris/rspec_extensions/response_helpers.rb