Sha256: c754ab22958dccf388901c905c9deb44de373ab41c1fc67c4528219a4ea53013

Contents?: true

Size: 1.32 KB

Versions: 16

Compression:

Stored size: 1.32 KB

Contents

require 'spec_helper'

module Landable::Api
  describe DirectoriesController, json: true do
    routes { Landable::Engine.routes }

    describe '#index' do
      include_examples 'Authenticated API controller', :make_request

      def make_request(ids = nil)
        get :index, ids: ids
      end

      def dirs
        last_json['directories']
      end

      def dir(path)
        dirs.find { |dir| dir['id'] == path }
      end

      def subdirs(path)
        dir(path)['subdirectory_ids']
      end

      def pages(path)
        dir(path)['page_ids']
      end

      it 'defaults to the root path' do
        pages = ['/a', '/b/c', '/b/d'].map { |path| create :page, path: path }
        make_request
        response.status.should == 200

        dirs.length.should == 1
        dirs.first['id'].should == '/'

        subdirs('/').length.should == 1
        pages('/').length.should == 1
      end

      it 'returns multiple directory listings' do
        pages = ['/a', '/b/c', '/b/d', '/c/e', '/c/f/g'].map { |path| create :page, path: path }
        make_request ['/b', '/c']
        response.status.should == 200
        dirs.length.should == 2

        pages('/b').length.should == 2
        pages('/c').length.should == 1

        subdirs('/b').length.should == 0
        subdirs('/c').length.should == 1
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
landable-1.13.1 spec/controllers/landable/api/directories_controller_spec.rb
landable-1.12.3 spec/controllers/landable/api/directories_controller_spec.rb
landable-1.12.2 spec/controllers/landable/api/directories_controller_spec.rb
landable-1.12.1 spec/controllers/landable/api/directories_controller_spec.rb
landable-1.11.1 spec/controllers/landable/api/directories_controller_spec.rb
landable-1.11.0 spec/controllers/landable/api/directories_controller_spec.rb
landable-1.10.0.rc2 spec/controllers/landable/api/directories_controller_spec.rb
landable-1.10.0.rc1 spec/controllers/landable/api/directories_controller_spec.rb
landable-1.9.2 spec/controllers/landable/api/directories_controller_spec.rb
landable-1.9.1 spec/controllers/landable/api/directories_controller_spec.rb
landable-1.9.0 spec/controllers/landable/api/directories_controller_spec.rb
landable-1.9.0.rc2 spec/controllers/landable/api/directories_controller_spec.rb
landable-1.9.0.rc1 spec/controllers/landable/api/directories_controller_spec.rb
landable-1.8.0 spec/controllers/landable/api/directories_controller_spec.rb
landable-1.7.1.rc1 spec/controllers/landable/api/directories_controller_spec.rb
landable-1.7.0 spec/controllers/landable/api/directories_controller_spec.rb