require 'spec_helper' require 'rspec_api_documentation' require 'rspec_api_documentation/dsl' require 'securerandom' resource 'Content Folder', :api => true do get '/content_folder' do context 'has a content folder' do example 'returns the content folder' do folder_id = 'folder id' folder = ContentFolder.new(:folder_id => folder_id, :label => 'folder label', :document_ids => %w(id1 id2)) ContentFolder.stub(:last).and_return(folder) do_request expect(status).to eq(200) result = JSON.parse(response_body) expect(result).not_to be_nil expect(result['folder_id']).to eq(folder_id) end example 'returns 404 when the folder does not exist' do ContentFolder.stub(:last).and_return(nil) do_request expect(status).to eq(404) end end end post '/content_folder' do parameter :folder_id, 'folder id', :require => true, :scope => 'content_folder' parameter :label, 'folder label', :require => true, :scope => 'content_folder' parameter :document_ids, 'array of document ids associated with folder', :require => true, :scope => 'content_folder' parameter :child_folders, 'array of child folder hashes', :require => true, :scope => 'content_folder' context 'successful' do folder_id = 'folder id' label = 'label' document_ids = %w(id1 id2) child_folders = nil let(:folder_id) { folder_id } let(:label) { label } let(:document_ids) { document_ids } let(:child_folders) { [{:folder_id => 'child folder id', :label => 'child label', :document_ids => document_ids}] } example 'stores the content folder and returns the content folder instance' do do_request expect(status).to eq(201) result = JSON.parse(response_body) expect(result).not_to be_nil end end context 'missing required values' do folder_id = 'folder id' label = 'label' document_ids = nil child_folders = nil let(:folder_id) { folder_id } let(:label) { label } let(:document_ids) { document_ids } let(:child_folders) { child_folders } example 'returns status 422 when missing document id and child_folders' do do_request expect(status).to eq(422) end end end end