Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix specs on Rails master/6.1.0.alpha #3614

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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