1

I know that this question exists, but the answers didn't help me.

Working with the Participant Model, which

belongs_to :game
belongs_to :team

The shoulda-matcher code that I need to work is

it {should validate_uniqueness_of(:team).scoped_to(:game)

The code in my Participant Model is

validates :team, presence: true, uniqueness: {scope: :game}

I have tried to follow the answers at the above question and the solutions on the git hub itself for this known issue, and gotten no luck.

If I just leave it 'clean' I get this error:

 Failure/Error: it {should validate_uniqueness_of(:team).scoped_to(:game)}

 ActiveRecord::AssociationTypeMismatch:
   Team(#70267561823460) expected, got String(#70267552833620)

To complicate things just a little, Team belongs_to :division

I'm using rspec and rails 5. Is there an answer within shoulda-matchers is the question?

To answer the first question - I haven't tried it in the console yet - I was avoiding that as this is a known issue with shoulda I just can't get any of the reported workarounds to work.

Community
  • 1
  • 1
MageeWorld
  • 402
  • 4
  • 14
  • Hi - can you please include a little more of your code? eg the validates-uniqueness-of line in your model? also the part of your spec where you create the other Participant (that your new one is supposed to clash with) :) Also - have you literally tried this in the console/browser to see if it works there too? – Taryn East Dec 22 '16 at 03:52

0 Answers0