Skip to content

Commit

Permalink
test suite fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
andreasknoepfle committed Nov 3, 2014
1 parent 18e19b7 commit b1d3768
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 14 deletions.
8 changes: 5 additions & 3 deletions app/objects/form/article_search_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ def searched_category category_id = self.category_id

def search page
@search = ArticleSearch.search(self)
@search.result.page(page).per(Kaminari.config.default_per_page)
results = @search.result.page(page).per(Kaminari.config.default_per_page)
results.to_a # dont get rid of this as it will trigger the request and the rescue block can come in
results
rescue Faraday::ConnectionFailed
ArticlePolicy::Scope.new(nil, Article).resolve.page(page)
end
Expand All @@ -46,7 +48,7 @@ def search_by_term?
# Did this form get request parameters or is this an empty search where someone just wants to look around?
# (category doesn't count)
def search_request?
filter_attributes.reject{ |a,v| k==:category_id }.empty?
filter_attributes.reject{ |k,v| k==:category_id }.empty?
end

def fresh?
Expand Down Expand Up @@ -100,7 +102,7 @@ def filter_attributes
end

def clean_hash hash
hash.select{ |a,v| v!=nil && v!=false }
hash.select{ |k,v| v!=nil && v!=false }
end


Expand Down
4 changes: 3 additions & 1 deletion app/objects/query/active_user_articles.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ def find_some

private
def finder page, per
ArticlesIndex::Article.filter(term: {seller_id: @user.id}).page(page).per(per).to_a
result = ArticlesIndex.all.filter(term: {seller_id: @user.id}).page(page).per(per)
result.to_a # this will make sure the request is send
result
rescue Faraday::ConnectionFailed
@user.articles.includes(:images).where(state: 'active').page(page).per(per)
end
Expand Down
5 changes: 3 additions & 2 deletions app/objects/query/article_search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ def build
price_filter,
category_filter,
condition_filter,
category_facet
category_facet,
sorting
].compact.reduce(:merge).query_mode(1)
end

Expand Down Expand Up @@ -116,7 +117,7 @@ def category_facet
# sorting

def sorting
index.order(SORT[@query.sort])
index.order(SORT[@query.order_by])
end


Expand Down
2 changes: 1 addition & 1 deletion app/workers/search_index_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def perform type, ids
ArticlesIndex::Article
end

type.import ids, batch_size: 100
type.import ids, batch_size: 100

end
end
8 changes: 4 additions & 4 deletions test/controllers/articles_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@
end

it "doen't throw an error when the search for other users articles breaks" do
ArticlesIndex::Article.stubs(:filter).raises(Faraday::ConnectionFailed)
Chewy::Query.any_instance.stubs(:to_a).raises(Faraday::ConnectionFailed.new("test")) # simulate connection error so that we dont have to use elastic
get :show, id: article.id
assert_template :show
end
Expand Down Expand Up @@ -456,11 +456,11 @@

end

it "should rescue an ECONNREFUSED error" do
Article.stubs(:search).raises(Errno::ECONNREFUSED)
it "should rescue an Faraday::ConnectionFailed error" do
Chewy::Query.any_instance.stubs(:map).raises(Faraday::ConnectionFailed.new("test"))
get :autocomplete, keywords: 'chunky'
assert_response :success
response.body.must_equal [].to_json
response.body.must_equal({"query" => nil , "suggestions" => []}.to_json)
end
end

Expand Down
2 changes: 1 addition & 1 deletion test/controllers/categories_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
end

it "should rescue an Faraday::ConnectionFailed error" do
ArticlesIndex.stubs(:query).raises(Faraday::ConnectionFailed)
Chewy::Query.any_instance.stubs(:to_a).raises(Faraday::ConnectionFailed.new("test"))
get :show, id: category.id, article_search_form: { q: 'foobar' }
assert_response :success
end
Expand Down
2 changes: 1 addition & 1 deletion test/features/articles_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ def fill_form_with_valid_article
end

scenario 'elastic search server disconnects' do
ArticlesIndex.stubs(:query).raises(Faraday::ConnectionFailed)
Chewy::Query.any_instance.stubs(:to_a).raises(Faraday::ConnectionFailed.new("test")) # simulate connection error so that we dont have to use elastic
visit root_path
click_button 'Suche'
end
Expand Down
3 changes: 2 additions & 1 deletion test/features/commendation_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
end

scenario "user visits seller with ecologic article" do
Article.stubs(:search).raises(Errno::ECONNREFUSED) # simulate connection error so that we dont have to use elastic
Chewy::Query.any_instance.stubs(:to_a).raises(Faraday::ConnectionFailed.new("test")) # simulate connection error so that we dont have to use elastic

visit user_path(@seller)
page.must_have_link(I18n.t 'formtastic.labels.article.ecologic')
end
Expand Down

0 comments on commit b1d3768

Please sign in to comment.