getmovement / deprecated-movement-rails-api

DEPRECATED Rails API for getmovement.org
1 stars 1 forks source link

Rewrite campaign_volunteers model specs when ShouldaMatchers issue is fixed #64

Open begedin opened 8 years ago

begedin commented 8 years ago

Shoulda triggers an AssociationTypeMismatch when asserting for uniqueness on associations

https://github.com/thoughtbot/shoulda-matchers/issues/535

We currently have the following spec for ensuring uniqueness validation

it "validates uniqueness of volunteer scoped to campaign" do
  campaign_1 = create(:campaign)
  campaign_2 = create(:campaign)
  user = create(:user)
  create(:campaign_volunteer, volunteer: user, campaign: campaign_1)
  expect(build(:campaign_volunteer, volunteer: user, campaign: campaign_1)).not_to be_valid
  expect(build(:campaign_volunteer, volunteer: user, campaign: campaign_2)).to be_valid
end

Once the Should issue is fixed, we can write it as

it { should validate_uniqueness_of(:volunteer).scoped_to(:campaign) }