Sha256: 7671dfed6d68b17ac2ef0226e69c69a4a97bc53c9cf6dac9fc58e703dbf9034b

Contents?: true

Size: 1.61 KB

Versions: 13

Compression:

Stored size: 1.61 KB

Contents

require 'spec_helper'

module Cellect::Server
  describe API do
    include_context 'API'

    { 'Ungrouped' => nil, 'Grouped' => 'grouped' }.each_pair do |grouping_type, grouping|
      SET_TYPES.shuffle.each do |set_type|
        context "#{ grouping_type } #{ set_type }" do
          let(:workflow_type){ [grouping, set_type].compact.join '_' }
          let(:workflow){ Workflow[workflow_type] }
          let(:user){ workflow.user 123 }
          before(:each){ pass_until_state_of workflow, is: :ready }

          it 'should sample without a user, limit, or group' do
            expect(workflow).to receive(:sample).with(limit: 5, user_id: nil, group_id: nil).and_call_original
            get "/workflows/#{ workflow_type }"
            expect(last_response.status).to eq 200
            expect(json).to be_a Array
          end

          shoulda = grouping ? 'limit, group, and user' : 'limit and user'
          it "should sample with a #{ shoulda }" do
            group_id = grouping ? 1 : nil
            expect(workflow).to receive(:sample).with(limit: 3, user_id: 123, group_id: group_id).and_call_original
            get "/workflows/#{ workflow_type }?limit=3&user_id=123#{ grouping ? '&group_id=1' : '' }"
            expect(last_response.status).to eq 200
            expect(json).to be_a Array
          end
        end
      end
    end

    it 'should handle missing workflows' do
      allow(Workflow).to receive(:[]).with('missing').and_return nil
      get '/workflows/missing', limit: 3, user_id: 123
      expect(last_response.status).to eql 404
      expect(last_response.body).to match /Not Found/
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
cellect-server-3.0.2 spec/cellect/server/api/sample_spec.rb
cellect-server-3.0.1 spec/cellect/server/api/sample_spec.rb
cellect-server-3.0.0 spec/cellect/server/api/sample_spec.rb
cellect-server-2.1.1 spec/cellect/server/api/sample_spec.rb
cellect-server-2.1.0 spec/cellect/server/api/sample_spec.rb
cellect-server-2.0.1 spec/cellect/server/api/sample_spec.rb
cellect-server-2.0.0 spec/cellect/server/api/sample_spec.rb
cellect-server-2.0.0.beta4 spec/cellect/server/api/sample_spec.rb
cellect-server-2.0.0.beta3 spec/cellect/server/api/sample_spec.rb
cellect-server-2.0.0.beta2 spec/cellect/server/api/sample_spec.rb
cellect-server-2.0.0.beta1 spec/cellect/server/api/sample_spec.rb
cellect-server-1.3.3 spec/server/api/sample_spec.rb
cellect-server-1.3.2 spec/server/api/sample_spec.rb