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.4.4 spec/roqua/responders/api_errors_responder_spec.rb
roqua-support-0.4.3 spec/roqua/responders/api_errors_responder_spec.rb
roqua-support-0.4.2 spec/roqua/responders/api_errors_responder_spec.rb
roqua-support-0.4.1 spec/roqua/responders/api_errors_responder_spec.rb
roqua-support-0.4.0 spec/roqua/responders/api_errors_responder_spec.rb
roqua-support-0.3.5 spec/roqua/responders/api_errors_responder_spec.rb
roqua-support-0.3.4 spec/roqua/responders/api_errors_responder_spec.rb
roqua-support-0.3.3 spec/roqua/responders/api_errors_responder_spec.rb
roqua-support-0.3.2 spec/roqua/responders/api_errors_responder_spec.rb
roqua-support-0.3.1 spec/roqua/responders/api_errors_responder_spec.rb
roqua-support-0.3.0 spec/roqua/responders/api_errors_responder_spec.rb
roqua-support-0.1.34 spec/roqua/responders/api_errors_responder_spec.rb
roqua-support-0.1.33 spec/roqua/responders/api_errors_responder_spec.rb
roqua-support-0.1.32 spec/roqua/responders/api_errors_responder_spec.rb
roqua-support-0.1.31 spec/roqua/responders/api_errors_responder_spec.rb
roqua-support-0.1.30 spec/roqua/responders/api_errors_responder_spec.rb
roqua-support-0.1.29 spec/roqua/responders/api_errors_responder_spec.rb
roqua-support-0.1.28 spec/roqua/responders/api_errors_responder_spec.rb
roqua-support-0.1.27 spec/roqua/responders/api_errors_responder_spec.rb
roqua-support-0.1.26 spec/roqua/responders/api_errors_responder_spec.rb