atzorvas/ccradio

View on GitHub
app/models/user.rb

Summary

Maintainability
A
0 mins
Test Coverage
Missing top-level class documentation comment.
class User < ActiveRecord::Base
belongs_to :role
before_create :set_default_role
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :async, :registerable,
Align the parameters of a method call if they span more than one line.
:recoverable, :rememberable, :trackable, :validatable,
Align the parameters of a method call if they span more than one line.
Use the new Ruby 1.9 hash syntax.
:omniauthable, :omniauth_providers => [:wordpress_hosted]
 
def admin?
Redundant `self` detected.
self.role && self.role.name == 'admin'
end
 
def self.from_omniauth(auth)
where(provider: auth.provider, uid: auth.uid).first_or_create do |user|
user.email = auth.info.email
Space missing after comma.
user.password = Devise.friendly_token[0,20]
# user.name = auth.info.name # assuming the user model has a name
# user.image = auth.info.image # assuming the user model has an image
end
end
 
private
 
def set_default_role
self.role ||= Role.find_by_name('registered')
end
end