Sha256: 5dae30bbd11967c01ae79fd31b9c3afc11865df2e71f6f8b4d47c9c6f84fc373

Contents?: true

Size: 888 Bytes

Versions: 36

Compression:

Stored size: 888 Bytes

Contents

require 'spec_helper'
require 'roqua/responders/api_errors_responder'
class AEResponder < ActionController::Responder
  include Roqua::Responders::ApiErrorsResponder
end

class ApplicationController < ActionController::Base
  respond_to :json
end

class SomeModel
  include ActiveModel::Model

  attr_accessor :name
end

describe Roqua::Responders::ApiErrorsResponder, type: :controller do
  context 'with an invalid model' do
    controller(ApplicationController) do
      self.responder  = AEResponder
      def index
        sm = SomeModel.new name: 'foo'
        sm.errors.add :name, "That is not a real name"
        respond_with sm
      end
    end
    subject { post :index, format: :json }

    it 'returns the errors scoped on the object name' do
      subject
      expect(response.body).to eq '{"errors":{"some_model":{"name":["That is not a real name"]}}}'
    end
  end
end

Version data entries

36 entries across 36 versions & 1 rubygems

Version Path
roqua-support-0.1.25 spec/roqua/responders/api_errors_responder_spec.rb
roqua-support-0.1.24 spec/roqua/responders/api_errors_responder_spec.rb
roqua-support-0.1.23 spec/roqua/responders/api_errors_responder_spec.rb
roqua-support-0.1.22 spec/roqua/responders/api_errors_responder_spec.rb
roqua-support-0.1.21 spec/roqua/responders/api_errors_responder_spec.rb
roqua-support-0.1.20 spec/roqua/responders/api_errors_responder_spec.rb
roqua-support-0.1.19 spec/roqua/responders/api_errors_responder_spec.rb
roqua-support-0.1.18 spec/roqua/responders/api_errors_responder_spec.rb
roqua-support-0.1.17 spec/roqua/responders/api_errors_responder_spec.rb
roqua-support-0.1.16 spec/roqua/responders/api_errors_responder_spec.rb
roqua-support-0.1.15 spec/roqua/responders/api_errors_responder_spec.rb
roqua-support-0.1.14 spec/roqua/responders/api_errors_responder_spec.rb
roqua-support-0.1.13 spec/roqua/responders/api_errors_responder_spec.rb
roqua-support-0.1.12 spec/roqua/responders/api_errors_responder_spec.rb
roqua-support-0.1.11 spec/roqua/responders/api_errors_responder_spec.rb
roqua-support-0.1.10 spec/roqua/responders/api_errors_responder_spec.rb