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

Identity model created #2556

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions app/models/identity.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class Identity < ActiveRecord::Base
belongs_to :user
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should probably use a validation here to check for the presence of user_id

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh thanks @seafr
I did change it.

end
11 changes: 6 additions & 5 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class User < ActiveRecord::Base
has_many :passive_relationships, class_name: 'Relationship', foreign_key: 'followed_id', dependent: :destroy
has_many :following_users, through: :active_relationships, source: :followed
has_many :followers, through: :passive_relationships, source: :follower
has_many :identities, dependent: :destroy

validates_with UniqueUsernameValidator, on: :create
validates_format_of :username, with: /\A[A-Za-z\d_\-]+\z/
Expand All @@ -41,7 +42,7 @@ class User < ActiveRecord::Base
before_save :set_token
after_destroy :destroy_drupal_user

def self.search(query)
def self.search(query)
User.where('MATCH(username, bio) AGAINST(?)', query)
end

Expand Down Expand Up @@ -216,15 +217,15 @@ def daily_note_tally(span = 365)
(1..span).each do |day|
time = Time.now.utc.beginning_of_day.to_i
days[(time-day.days.to_i)] = Node.select(:created)
.where(uid: self.uid,
.where(uid: self.uid,
type: 'note',
status: 1,
created: time - (day-1).days.to_i..time - (day - 2).days.to_i)
status: 1,
created: time - (day-1).days.to_i..time - (day - 2).days.to_i)
.count
end
days
end


def weekly_comment_tally(span = 52)
weeks = {}
Expand Down
11 changes: 11 additions & 0 deletions db/migrate/20180329085153_create_identities.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class CreateIdentities < ActiveRecord::Migration
def change
create_table :identities do |t|
t.string :provider
t.string :uid
t.references :user, index: true

t.timestamps
end
end
end
11 changes: 11 additions & 0 deletions test/fixtures/identities.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html

one:
provider: MyString
uid: MyString
user_id:

two:
provider: MyString
uid: MyString
user_id:
7 changes: 7 additions & 0 deletions test/models/identity_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'test_helper'

class IdentityTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end