Skip to content

Commit

Permalink
Fixing mark's crap...
Browse files Browse the repository at this point in the history
And wrote some more unit tests (Mainly for User)

modified:   app/models/permission.rb
modified:   app/models/tag.rb
	-- added missing User foreign key

modified:   app/models/user.rb
	-- fixed validations to remove duplicates added by devise. related to #84

modified:   db/seeds.rb
	-- added else clause for case

modified:   spec/models/user_spec.rb
	-- wrote all model tests for user

modified:   vendor/bin/install_console_audio_tools.sh
	-- fix ubuntu key error for package install
  • Loading branch information
atruskie committed Jan 17, 2013
1 parent 105c992 commit f58f2d1
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 22 deletions.
2 changes: 1 addition & 1 deletion app/models/permission.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Permission < ActiveRecord::Base

# userstamp
stampable
# belongs_to :user
belongs_to :user, class_name: 'User', foreign_key: :creator_id

# enumerations
enumerize :level, :in => [:owner, :writer, :reader, :none], :default => :none, predicates: true
Expand Down
2 changes: 1 addition & 1 deletion app/models/tag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Tag < ActiveRecord::Base

# userstamp
stampable
belongs_to :user, :class_name => 'User', :foreign_key => :creator_id
belongs_to :user, class_name: 'User', foreign_key: :creator_id
acts_as_paranoid
validates_as_paranoid

Expand Down
49 changes: 31 additions & 18 deletions app/models/user.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
class User < ActiveRecord::Base

# NB: this intentionally left simple
# The bulk of the emails populated into this model will come from external authentication providers
VALID_EMAIL_REGEX = /^[^@]+@[^@]+\.[^@]+$/

# Include devise modules.
# :registerable,:rememberable,
devise :confirmable, :omniauthable, :token_authenticatable,
Expand All @@ -8,39 +13,47 @@ class User < ActiveRecord::Base
# Setup accessible (or protected) attributes for your model
attr_accessible :user_name, :display_name, :email, :password, :admin

has_many :authorizations, :dependent => :destroy


# user stamp
model_stamper
stampable

# other associations
has_many :projects
has_many :sites
has_many :audio_recordings
has_many :audio_events
has_many :tags
has_many :audio_event_tags
has_many :authorizations, :dependent => :destroy
has_many :projects, :foreign_key => :creator_id
has_many :sites, :foreign_key => :creator_id
has_many :audio_recordings, :foreign_key => :creator_id
has_many :audio_events, :foreign_key => :creator_id
has_many :tags, :foreign_key => :creator_id
has_many :audio_event_tags, :foreign_key => :creator_id
has_many :permissions_created, :class_name => 'Permission', :foreign_key => :creator_id
has_many :permissions
has_many :analysis_scripts
has_many :analysis_jobs
has_many :progresses
has_many :bookmarks
has_many :saved_searches
has_many :analysis_scripts, :foreign_key => :creator_id
has_many :analysis_jobs, :foreign_key => :creator_id
has_many :progresses, :foreign_key => :creator_id
has_many :bookmarks, :foreign_key => :creator_id
has_many :saved_searches, :foreign_key => :creator_id


# validation
#validates_presence_of :display_name
validates :user_name, :presence => true, :uniqueness => { :case_sensitive => false }
validates :user_name, presence: true, uniqueness: { case_sensitive: false },
exclusion: { in: %w(admin harvester analysis_runner) }, unless: :skip_user_name_exclusion_list
#:format => { :with => /\A[a-zA-Z0-9_ ]+\z/, :message => "only letters, numbers, space and underscore allowed" }
validates :display_name, :uniqueness => {:case_sensitive => false }, :presence => { :unless => Proc.new { |a| a.email.present? }, :message => "Please provide a name, email, or both." }
validates :email, :uniqueness => {:case_sensitive => false }, :presence => { :unless => Proc.new { |a| a.display_name.present? }, :message => "Please provide an email, name, or both." }
validates :user_name, :exclusion => { :in => %w(admin harvester analysis_runner) }, :unless => :skip_user_name_exclusion_list
validates :display_name, uniqueness: { case_sensitive: false },
presence: { unless: Proc.new { |a| a.email.present? }, message: 'Please provide a display name, email, or both.' }

# it turns out devise provdes its own validations for the email field
# providing our own (e.g.uniqueness) creates duplicated errors! #uniqueness: { case_sensitive: false },
validates :email, format: {with:VALID_EMAIL_REGEX, message: 'Basic email validation failed. It should have at least 1 `@` and 1 `.`'}

#friendly_id :display_name, :use_slug => true, :strip_non_ascii => true


# special vanlidation skip
# TODO: does this need some protectection?
# special validation skip
# these methods allow a temporary skip of exclusion validation. this is used for seeding users into the database
# TODO: does this need some protection?
def skip_user_name_exclusion_list=(value)
@skip_user_name_exclusion_list = value
end
Expand Down
16 changes: 14 additions & 2 deletions vendor/bin/install_console_audio_tools.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 16126D3A3E5C1192
sudo apt-key del 16126D3A3E5C1192
sudo apt-get update
sudo apt-key finger
sudo apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 16126D3A3E5C1192
sudo apt-get update
sudo apt-get install ffmpeg mp3splt sox wavpack --fix-missing
sudo apt-get update
sudo apt-get update

# http://askubuntu.com/a/86445 apt-get clean # Remove cached packages
cd /var/lib/apt
mv lists lists.old # Backup mirror info
mkdir -p lists/partial # Recreate directory structure
apt-get clean
apt-get update # Fetch mirror info
sudo apt-key finger

0 comments on commit f58f2d1

Please sign in to comment.