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

Chapter 6 Listing 88/89 tests ordering without being ordered #91

Open
notapatch opened this issue Feb 4, 2023 · 0 comments
Open

Chapter 6 Listing 88/89 tests ordering without being ordered #91

notapatch opened this issue Feb 4, 2023 · 0 comments

Comments

@notapatch
Copy link
Contributor

I'm going through the book again... :-}

In listing 88 you're testing for a sort order but in listing 89 it's a WHERE clause without any ordering. SQL makes no guarantees in this situation, if it passes that's luck. You need some ordering or remove the test.

Listing 88. test/models/product_test.rb

class ProductTest < ActiveSupport::TestCase
  # ...
  test 'should filter products by name and sort them' do
    assert_equal [products(:another_tv), products(:one)], Product.filter_by_title('tv').sort
  end
end

Listing 89. app/models/product.rb

class Product < ApplicationRecord
  # ...
  scope :filter_by_title, lambda { |keyword|
    where('lower(title) LIKE ?', "%#{keyword.downcase}%")
  }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant