forked from discourse/discourse
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New
user_stats
table to keep track of queried information on a user.
This is information that is not usually needed when representing a user and is in a separate table with a has one relationship to avoid querying it all the time.
- Loading branch information
Showing
4 changed files
with
40 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class UserStat < ActiveRecord::Base | ||
|
||
belongs_to :user | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
class CreateUserStats < ActiveRecord::Migration | ||
def up | ||
create_table :user_stats, :id => false do |t| | ||
t.references :user, null: false | ||
t.boolean :has_custom_avatar, default: false, null: false | ||
end | ||
execute "ALTER TABLE user_stats ADD PRIMARY KEY (user_id)" | ||
execute "INSERT INTO user_stats (user_id) SELECT id FROM users" | ||
end | ||
|
||
def down | ||
drop_table :user_stats | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
require 'spec_helper' | ||
|
||
describe UserStat do | ||
|
||
it { should belong_to :user } | ||
|
||
it "is created automatically when a user is created" do | ||
user = Fabricate(:evil_trout) | ||
user.user_stat.should be_present | ||
end | ||
|
||
end |