Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add open and closed post counts to project
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
- Loading branch information
1 parent
0c7dd0d
commit e7488ea
Showing
8 changed files
with
108 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,16 @@ | ||
machine: | ||
services: | ||
- elasticsearch | ||
deployment: | ||
staging: | ||
branch: develop | ||
commands: | ||
- git push git@heroku.com:code-corps-development.git $CIRCLE_SHA1:master | ||
- heroku run rake db:migrate --app code-corps-development | ||
- git push git@heroku.com:code-corps-staging.git $CIRCLE_SHA1:master | ||
- heroku run rake db:migrate --app code-corps-staging | ||
production: | ||
branch: master | ||
commands: | ||
- git push git@heroku.com:code-corps.git $CIRCLE_SHA1:master | ||
- heroku run rake db:migrate --app code-corps | ||
staging: | ||
branch: develop | ||
commands: | ||
- git push git@heroku.com:code-corps-development.git $CIRCLE_SHA1:master | ||
- heroku run rake db:migrate --app code-corps-development | ||
- git push git@heroku.com:code-corps-staging.git $CIRCLE_SHA1:master | ||
- heroku run rake db:migrate --app code-corps-staging | ||
production: | ||
branch: master | ||
commands: | ||
- git push git@heroku.com:code-corps.git $CIRCLE_SHA1:master | ||
- heroku run rake db:migrate --app code-corps |
6 changes: 6 additions & 0 deletions
6
db/migrate/20160623044025_add_open_and_closed_posts_count_to_projects.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
class AddOpenAndClosedPostsCountToProjects < ActiveRecord::Migration | ||
def change | ||
add_column :projects, :open_posts_count, :integer, null: false, default: 0 | ||
add_column :projects, :closed_posts_count, :integer, null: false, default: 0 | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters