spec/controllers/dashboard_controller_spec.rb in sufia-2.0.1 vs spec/controllers/dashboard_controller_spec.rb in sufia-3.0.0

- old
+ new

@@ -1,21 +1,7 @@ -# Copyright © 2012 The Pennsylvania State University -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. +require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') -require 'spec_helper' - describe DashboardController do before do GenericFile.any_instance.stub(:terms_of_service).and_return('1') User.any_instance.stub(:groups).and_return([]) controller.stub(:clear_session_user) ## Don't clear out the authenticated session @@ -61,17 +47,37 @@ User.any_instance.stub(:groups).and_return([]) end describe "#index" do before (:each) do xhr :get, :index + # Make sure there are at least 3 files owned by @user. Otherwise, the tests aren't meaningful. + if assigns(:document_list).count < 3 + files_count = assigns(:document_list).count + until files_count == 3 + gf = GenericFile.new() + gf.apply_depositor_metadata(@user.user_key) + gf.save + files_count += 1 + end + xhr :get, :index + end end it "should be a success" do response.should be_success response.should render_template('dashboard/index') end it "should return an array of documents I can edit" do - user_results = Blacklight.solr.get "select", :params=>{:fq=>["edit_access_group_ssim:public OR edit_access_person_ssim:#{@user.user_key}"]} - assigns(:document_list).count.should eql(user_results["response"]["numFound"]) + editable_docs_response = Blacklight.solr.get "select", :params=>{:fq=>["edit_access_group_ssim:public OR edit_access_person_ssim:#{@user.user_key}"]} + assigns(:result_set_size).should eql(editable_docs_response["response"]["numFound"]) + assigns(:document_list).each {|doc| doc.should be_kind_of SolrDocument} + end + context "with render views" do + render_views + it "should paginate" do + xhr :get, :index, per_page: 2 + response.should be_success + response.should render_template('dashboard/index') + end end end end describe "not logged in as a user" do describe "#index" do