Sha256: 279bbb2bd2a6102aa2d795bdced093e18beea258ef115db5e16db91685919aa7

Contents?: true

Size: 1.55 KB

Versions: 5

Compression:

Stored size: 1.55 KB

Contents

require 'spec_helper'

describe CatalogController do

  describe "when logged in" do
    let(:user) { FactoryGirl.create(:user) }
    let!(:work1) { FactoryGirl.create(:generic_work, user: user) }
    let!(:work2) { FactoryGirl.create(:generic_work) }
    before do
      sign_in user
    end
    context "Searching all works" do
      it "should return all the works" do
        get 'index', 'f' => {'generic_type_sim' => 'Work'}
        response.should be_successful
        assigns(:document_list).map(&:id).should == [work1.id, work2.id]
      end
    end

    context "searching just my works" do
      it "should return just my works" do
        get 'index', works: 'mine'
        response.should be_successful
        assigns(:document_list).map(&:id).should == [work1.id]
      end
    end

    context "index page" do
      let!(:collection) { FactoryGirl.create(:collection, user: user) }

      it "assigns options for adding items to collection" do
        get 'index'
        assigns(:collection_options).should == [collection]
      end
    end

    context "when json is requested for autosuggest of related works" do
      let!(:work) { FactoryGirl.create(:generic_work, user: user, title:"All my #{srand}") }
      it "should return json" do
        xhr :get, :index, format: :json, q: work.title
        json = JSON.parse(response.body)
        # Grab the doc corresponding to work and inspect the json
        work_json = json["docs"].first
        work_json.should == {"pid"=>work.pid, "title"=> "#{work.title} (#{work.human_readable_type})"}
      end
    end

  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
curate-0.6.5 spec/controllers/catalog_controller_spec.rb
curate-0.6.4 spec/controllers/catalog_controller_spec.rb
curate-0.6.3 spec/controllers/catalog_controller_spec.rb
curate-0.6.1 spec/controllers/catalog_controller_spec.rb
curate-0.6.0 spec/controllers/catalog_controller_spec.rb