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

cached_votes_total doesn't update during factory bot tests #223

Open
Guy--L opened this issue Jan 3, 2023 · 0 comments
Open

cached_votes_total doesn't update during factory bot tests #223

Guy--L opened this issue Jan 3, 2023 · 0 comments

Comments

@Guy--L
Copy link

Guy--L commented Jan 3, 2023

Using factory bot to create vote and votable in tests does not give the expected '2 votes' result from this view:

        <%= item.cached_votes_total > 0 ? pluralize(item.cached_votes_total, 'vote') : '' %>

Here is the factory for item and vote

FactoryBot.define do
  factory :item do
  ...
  end

  trait :carrying_votes do
    after(:create) do |item|
      create_list(:vote, 2, votable: item)
    end
  end
end
FactoryBot.define do
    factory :vote, class: ActsAsVotable::Vote do
        association :votable, factory: :item
        association :voter, factory: :user
    end
end

The test itself fails if the comment hash is removed...

    it 'lists items with votes' do
      item = create(:item, :carrying_votes)

      get root_path

      expect(response.body).to include(item.voter_names)
      # expect(response.body).to include('2 votes')
    end

What am I missing?

Thank you.

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