Skip to content

Commit

Permalink
Use standard rspec expectations for text
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeer committed Nov 5, 2015
1 parent af99af5 commit 3710c1c
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 74 deletions.
49 changes: 17 additions & 32 deletions spec/controllers/catalog_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,6 @@
describe CatalogController do

describe "index action" do

# In Rails 3 ActionDispatch::TestProcess#assigns() converts anything that
# descends from Hash to a HashWithIndifferentAccess. Therefore our Solr
# response object gets replaced if we call assigns(:response)
# Fixed by https://github.com/rails/rails/commit/185c3dbc6ab845edfc94e8d38ef5be11c417dd81
if ::Rails.version < "4.0"
def assigns_response
controller.instance_variable_get("@response")
end
else
def assigns_response
assigns(:response)
end
end

describe "with format :html" do
let(:user_query) { 'history' } # query that will get results

Expand All @@ -38,53 +23,53 @@ def assigns_response
# check each user manipulated parameter
it "should have docs and facets for query with results", :integration => true do
get :index, q: user_query
expect(assigns_response.docs).to_not be_empty
assert_facets_have_values(assigns_response.aggregations)
expect(assigns(:response).docs).to_not be_empty
assert_facets_have_values(assigns(:response).aggregations)
end
it "should have docs and facets for existing facet value", :integration => true do
get :index, f: {"format" => 'Book'}
expect(assigns_response.docs).to_not be_empty
assert_facets_have_values(assigns_response.aggregations)
expect(assigns(:response).docs).to_not be_empty
assert_facets_have_values(assigns(:response).aggregations)
end
it "should have docs and facets for non-default results per page", :integration => true do
num_per_page = 7
get :index, :per_page => num_per_page
expect(assigns_response.docs).to have(num_per_page).items
assert_facets_have_values(assigns_response.aggregations)
expect(assigns(:response).docs).to have(num_per_page).items
assert_facets_have_values(assigns(:response).aggregations)
end

it "should have docs and facets for second page", :integration => true do
page = 2
get :index, :page => page
expect(assigns_response.docs).to_not be_empty
expect(assigns_response.params[:start].to_i).to eq (page-1) * @controller.blacklight_config[:default_solr_params][:rows]
assert_facets_have_values(assigns_response.aggregations)
expect(assigns(:response).docs).to_not be_empty
expect(assigns(:response).params[:start].to_i).to eq (page-1) * @controller.blacklight_config[:default_solr_params][:rows]
assert_facets_have_values(assigns(:response).aggregations)
end

it "should have no docs or facet values for query without results", :integration => true do
get :index, q: 'sadfdsafasdfsadfsadfsadf' # query for no results

expect(assigns_response.docs).to be_empty
assigns_response.aggregations.each do |key, facet|
expect(assigns(:response).docs).to be_empty
assigns(:response).aggregations.each do |key, facet|
expect(facet.items).to be_empty
end
end

it "should show 0 results when the user asks for an invalid value to a custom facet query", :integration => true do
get :index, f: {example_query_facet_field: 'bogus'} # bogus custom facet value
expect(assigns_response.docs).to be_empty
expect(assigns(:response).docs).to be_empty
end

it "should return results (possibly 0) when the user asks for a valid value to a custom facet query", :integration => true do
get :index, f: {example_query_facet_field: 'years_10'} # valid custom facet value with some results
expect(assigns_response.docs).to_not be_empty
expect(assigns(:response).docs).to_not be_empty
get :index, f: {example_query_facet_field: 'years_5'} # valid custom facet value with NO results
expect(assigns_response.docs).to be_empty
expect(assigns(:response).docs).to be_empty
end

it "should have a spelling suggestion for an appropriately poor query", :integration => true do
get :index, :q => 'boo'
expect(assigns_response.spelling.words).to_not be_nil
expect(assigns(:response).spelling.words).to_not be_nil
end

describe "session" do
Expand All @@ -105,11 +90,11 @@ def assigns_response
describe "for default query" do
it "should get documents when no query", :integration => true do
get :index
expect(assigns_response.docs).to_not be_empty
expect(assigns(:response).docs).to_not be_empty
end
it "should get facets when no query", :integration => true do
get :index
assert_facets_have_values(assigns_response.aggregations)
assert_facets_have_values(assigns(:response).aggregations)
end
end

Expand Down
20 changes: 0 additions & 20 deletions spec/support/include_text.rb

This file was deleted.

20 changes: 10 additions & 10 deletions spec/views/catalog/_index_default.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,21 @@
end

it "should only display fields listed in the initializer" do
expect(@rendered).to_not include_text("val_2")
expect(@rendered).to_not include_text(@fname_2)
expect(@rendered).to_not include("val_2")
expect(@rendered).to_not include(@fname_2)
end

it "should skip over fields listed in initializer that are not in solr response" do
expect(@rendered).to_not include_text(@fname_3)
expect(@rendered).to_not include(@fname_3)
end

it "should display field labels from initializer and raw solr field names in the class" do
# labels
expect(@rendered).to include_text(@flabel_1)
expect(@rendered).to include_text(@flabel_4)
expect(@rendered).to include(@flabel_1)
expect(@rendered).to include(@flabel_4)
# classes
expect(@rendered).to include_text("blacklight-#{@fname_1}")
expect(@rendered).to include_text("blacklight-#{@fname_4}")
expect(@rendered).to include("blacklight-#{@fname_1}")
expect(@rendered).to include("blacklight-#{@fname_4}")
end

# this test probably belongs in a Cucumber feature
Expand All @@ -56,9 +56,9 @@
# end

it "should have values for displayed fields" do
expect(@rendered).to include_text("val_1")
expect(@rendered).to include_text("val_4")
expect(@rendered).to_not include_text("val_2")
expect(@rendered).to include("val_1")
expect(@rendered).to include("val_4")
expect(@rendered).to_not include("val_2")
end

end
20 changes: 10 additions & 10 deletions spec/views/catalog/_show_default.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,21 @@
end

it "should only display fields listed in the initializer" do
expect(@rendered).to_not include_text("val_2")
expect(@rendered).to_not include_text(@fname_2)
expect(@rendered).to_not include("val_2")
expect(@rendered).to_not include(@fname_2)
end

it "should skip over fields listed in initializer that are not in solr response" do
expect(@rendered).to_not include_text(@fname_3)
expect(@rendered).to_not include(@fname_3)
end

it "should display field labels from initializer and raw solr field names in the class" do
# labels
expect(@rendered).to include_text(@flabel_1)
expect(@rendered).to include_text(@flabel_4)
expect(@rendered).to include(@flabel_1)
expect(@rendered).to include(@flabel_4)
# classes
expect(@rendered).to include_text("blacklight-#{@fname_1}")
expect(@rendered).to include_text("blacklight-#{@fname_4}")
expect(@rendered).to include("blacklight-#{@fname_1}")
expect(@rendered).to include("blacklight-#{@fname_4}")
end

# this test probably belongs in a Cucumber feature
Expand All @@ -57,9 +57,9 @@
# end

it "should have values for displayed fields" do
expect(@rendered).to include_text("val_1")
expect(@rendered).to include_text("val_4")
expect(@rendered).to_not include_text("val_2")
expect(@rendered).to include("val_1")
expect(@rendered).to include("val_4")
expect(@rendered).to_not include("val_2")
end

end
4 changes: 2 additions & 2 deletions spec/views/catalog/_show_sidebar.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
@document = SolrDocument.new :id => 1, :title_s => 'abc', :format => 'default'
allow(@document).to receive(:more_like_this).and_return([SolrDocument.new({ 'id' => '2', 'title_display' => 'Title of MLT Document' })])
render
expect(rendered).to include_text("More Like This")
expect(rendered).to include_text("Title of MLT Document")
expect(rendered).to include("More Like This")
expect(rendered).to include("Title of MLT Document")
end
end

0 comments on commit 3710c1c

Please sign in to comment.