Michael van Holst
Michael van Holst

Reputation: 171

Rails 4 syntax for shoulda matchers "have_many" with "order"

I have a rails 4 validation for my User model:

has_many :items, -> { order(:position) }

I expected the following shoulda matcher to work:
it {should have_many(:items).order(:position)}

But it raises this error:
Expected User to have a has_many association called items (items should be ordered by position)

Is my syntax wrong for the test?

Upvotes: 4

Views: 1347

Answers (1)

Elliot Winkler
Elliot Winkler

Reputation: 2344

There was a bug in v2.4.0 where this didn't work. This has been fixed in v2.5.0, so check it out!

See here for more: https://github.com/thoughtbot/shoulda-matchers/issues/388

Upvotes: 3

Related Questions