Skip to content

Commit

Permalink
Merge pull request #3614 from filippoliverani/filippoliverani/fix-spe…
Browse files Browse the repository at this point in the history
…cs-against-rails-master

Fix specs on Rails master/6.1.0.alpha
  • Loading branch information
aldesantis authored May 11, 2020
2 parents 354e249 + 9c14a50 commit 8b72292
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 15 deletions.
2 changes: 1 addition & 1 deletion api/lib/spree/api/testing_support/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def image(filename)
end

def upload_image(filename)
fixture_file_upload(image(filename).path, 'image/jpg')
Rack::Test::UploadedFile.new(File.open(image(filename).path), 'image/jpg')
end
end
end
Expand Down
7 changes: 4 additions & 3 deletions core/lib/spree/core/product_filters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ module ProductFilters
conds.each do |new_scope|
scope = scope.or(new_scope)
end

Spree::Product.joins(master: :default_price).where(scope)
end

Expand All @@ -70,9 +71,9 @@ def self.format_price(amount)
def self.price_filter
value = Spree::Price.arel_table
conds = [[I18n.t('spree.under_price', price: format_price(10)), value[:amount].lteq(10)],
["#{format_price(10)} - #{format_price(15)}", value[:amount].in(10..15)],
["#{format_price(15)} - #{format_price(18)}", value[:amount].in(15..18)],
["#{format_price(18)} - #{format_price(20)}", value[:amount].in(18..20)],
["#{format_price(10)} - #{format_price(15)}", value[:amount].between(10..15)],
["#{format_price(15)} - #{format_price(18)}", value[:amount].between(15..18)],
["#{format_price(18)} - #{format_price(20)}", value[:amount].between(18..20)],
[I18n.t('spree.or_over_price', price: format_price(20)), value[:amount].gteq(20)]]
{
name: I18n.t('spree.price_range'),
Expand Down
14 changes: 3 additions & 11 deletions core/spec/lib/search/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@
@product1 = create(:product, name: "RoR Mug", price: 9.00)
@product1.taxons << @taxon
@product2 = create(:product, name: "RoR Shirt", price: 11.00)
@product3 = create(:product, name: "RoR Pants", price: 16.00)
end

it "returns all products by default" do
params = { per_page: "" }
searcher = Spree::Core::Search::Base.new(params)
expect(searcher.retrieve_products.count).to eq(2)
expect(searcher.retrieve_products.count).to eq(3)
end

context "when include_images is included in the initalization params" do
Expand All @@ -36,8 +37,6 @@
end

it "switches to next page according to the page parameter" do
@product3 = create(:product, name: "RoR Pants", price: 14.00)

params = { per_page: "2" }
searcher = Spree::Core::Search::Base.new(params)
expect(searcher.retrieve_products.count).to eq(2)
Expand All @@ -51,28 +50,21 @@
params = { per_page: "",
search: { "price_range_any" => ["Under $10.00"] } }
searcher = Spree::Core::Search::Base.new(params)
expect(searcher.send(:get_base_scope).to_sql).to match /<= 10/
expect(searcher.retrieve_products.count).to eq(1)
end

it "maps multiple price_range_any filters" do
params = { per_page: "",
search: { "price_range_any" => ["Under $10.00", "$10.00 - $15.00"] } }
searcher = Spree::Core::Search::Base.new(params)
expect(searcher.send(:get_base_scope).to_sql).to match /<= 10/
if Rails.gem_version >= Gem::Version.new('6.0.0')
expect(searcher.send(:get_base_scope).to_sql).to match /between 10\.0 and 15\.0/i
else
expect(searcher.send(:get_base_scope).to_sql).to match /between 10 and 15/i
end
expect(searcher.retrieve_products.count).to eq(2)
end

it "uses ransack if scope not found" do
params = { per_page: "",
search: { "name_not_cont" => "Shirt" } }
searcher = Spree::Core::Search::Base.new(params)
expect(searcher.retrieve_products.count).to eq(1)
expect(searcher.retrieve_products.count).to eq(2)
end

it "accepts a current user" do
Expand Down

0 comments on commit 8b72292

Please sign in to comment.