spec/grape/dsl/inside_route_spec.rb in grape-0.9.0 vs spec/grape/dsl/inside_route_spec.rb in grape-0.10.0

- old
+ new

@@ -4,16 +4,16 @@ module DSL module InsideRouteSpec class Dummy include Grape::DSL::InsideRoute - attr_reader :env, :request, :settings + attr_reader :env, :request, :new_settings def initialize @env = {} @header = {} - @settings = Grape::Util::HashStack.new + @new_settings = { namespace_inheritable: {}, namespace_stackable: {} } end end end describe Endpoint do @@ -44,11 +44,11 @@ end end describe 'default_error_status' do before do - subject.settings[:default_error_status] = 500 + subject.namespace_inheritable(:default_error_status, 500) catch(:error) { subject.error! 'Unknown' } end it 'sets status to default_error_status' do expect(subject.status).to eq 500 end @@ -87,11 +87,11 @@ end end end describe '#status' do - ['GET', 'PUT', 'DELETE', 'OPTIONS'].each do |method| + %w(GET PUT DELETE OPTIONS).each do |method| it 'defaults to 200 on GET' do request = Grape::Request.new(Rack::MockRequest.env_for('/', method: method)) expect(subject).to receive(:request).and_return(request) expect(subject.status).to eq 200 end @@ -158,10 +158,21 @@ it 'returns value' do expect(subject.body).to eq 'body' end end + describe 'false' do + before do + subject.body false + end + + it 'sets status to 204' do + expect(subject.body).to eq '' + expect(subject.status).to eq 204 + end + end + it 'returns default' do expect(subject.body).to be nil end end @@ -202,9 +213,37 @@ subject.present 'dummy', with: entity_mock end it 'presents dummy object' do expect(subject.body).to eq 'dummy' + end + end + end + end + + describe 'with' do + describe 'multiple entities' do + let(:entity_mock1) do + entity_mock1 = Object.new + allow(entity_mock1).to receive(:represent).and_return(dummy1: 'dummy1') + entity_mock1 + end + + let(:entity_mock2) do + entity_mock2 = Object.new + allow(entity_mock2).to receive(:represent).and_return(dummy2: 'dummy2') + entity_mock2 + end + + describe 'instance' do + before do + subject.present 'dummy1', with: entity_mock1 + subject.present 'dummy2', with: entity_mock2 + end + + it 'presents both dummy objects' do + expect(subject.body[:dummy1]).to eq 'dummy1' + expect(subject.body[:dummy2]).to eq 'dummy2' end end end end end