Skip to content

Add open and closed post counts to project#342

Merged
joshsmith merged 1 commit intodevelopfrom
add-open-and-closed-post-counts-to-projects
Jun 23, 2016
Merged

Add open and closed post counts to project#342
joshsmith merged 1 commit intodevelopfrom
add-open-and-closed-post-counts-to-projects

Conversation

@christopherstyles
Copy link
Copy Markdown
Contributor

A project should be able to return the number of open posts as well as the number of closed posts. This update adds two counter caches to the project model:

  • open_posts_count – The number of open posts for the project.
  • closed_posts_count – The number of closed posts for the project.

The test_after_commit gem has also been added to the test group, and is necessary because transactional fixtures are enabled and counter caches are updated in an after_commit callback. See magnusvk/counter_culture for more info. This will no longer be needed in Rails 5: rails/rails/pull/18458.

To update existing counters, the following can be run:

Post.counter_culture_fix_counts
# https://github.com/magnusvk/counter_culture#manually-populating-counter-cache-values

Closes #323

A project should be able to return the number of open posts as well as
the number of closed posts.

This update adds two counter caches to the project model:
`open_posts_count` and `closed_posts_count`. These new attributes
reflect the count of posts matching the statuses of their namesake.

The [`test_after_commit`](https://github.com/grosser/test_after_commit)
gem is needed, as transactional fixtures are enabled and counter caches
are updated in an `after_commit` callback. See
[magnusvk/counter_culture#a-note-on-testing](https://github.com/magnusvk
/counter_culture#a-note-on-testing) for more info. This will no longer
be needed in Rails 5:
[rails/rails/pull/18458](rails/rails#18458).

To update existing counters, run the following:
```ruby
Post.counter_culture_fix_counts
https://github.com/magnusvk/counter_culture#manually-populating-counter-
cache-values
```

Resolves #323

Ignore localhost

Enable elasticsearch on circleci
@joshsmith joshsmith force-pushed the add-open-and-closed-post-counts-to-projects branch from 0d9bbe2 to e7488ea Compare June 23, 2016 15:55
@joshsmith joshsmith merged commit 6ff8221 into develop Jun 23, 2016
@joshsmith joshsmith deleted the add-open-and-closed-post-counts-to-projects branch June 23, 2016 16:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add open and closed post count to projects

2 participants