Permalink
Browse files

scope non-blacklist

  • Loading branch information...
1 parent deeb10b commit da1e3a0b797246e474464c02ce1bfb5a46f96351 @marsz committed May 29, 2012
View
@@ -1,4 +1,7 @@
class User < ActiveRecord::Base
+ scope :blacklist, where(:is_black => true)
+ scope :non_blacklist, where(:is_black => false)
+
include Search::Users
acts_as_searchable
@@ -20,7 +23,6 @@ class User < ActiveRecord::Base
validates_presence_of :site_user_id
validates_format_of :site_user_id, :with => /\A[^\n\/\?>< ]+\z/
has_many :posts, :order => "date DESC,datetime DESC", :dependent => :destroy
- scope :blacklist, where(:is_black => true)
def self.new_by_url(url, hash = {})
if site = (hash[:site] || Site.find_by_url(url))
@@ -1,5 +1,6 @@
class AddColumnIsBlackToUsers < ActiveRecord::Migration
def change
- add_column :users, :is_black, :boolean, :after => :is_enabled
+ add_column :users, :is_black, :boolean, :after => :is_enabled, :default => false
+ User.find_each{ |u| u.update_column :is_black, false }
end
end
View
@@ -55,7 +55,7 @@
t.integer "posts_count"
t.string "posts_monitoring_state"
t.boolean "is_enabled"
- t.boolean "is_black"
+ t.boolean "is_black", :default => false
t.datetime "created_at"
t.datetime "updated_at"
end
@@ -22,7 +22,7 @@ module ClassMethods
def act_as_monitor_posts
delegate :crawler, :to => :site
- scope :posts_monitoring, where(:posts_monitoring_state => nil).where("monitored_at < ? OR monitored_at is null", Time.now - MONITOR_POSTS_INTERVAL_DAYS.days).order("monitored_at ASC")
+ scope :posts_monitoring, non_blacklist.where(:posts_monitoring_state => nil).where("monitored_at < ? OR monitored_at is null", Time.now - MONITOR_POSTS_INTERVAL_DAYS.days).order("monitored_at ASC")
init_state_monitoring_posts
end
@@ -7,7 +7,7 @@ def act_as_user_avatar
if !self.method_defined?(:crawler)
delegate :crawler, :to => :site
end
- scope :no_avatar, where(:avatar => nil)
+ scope :no_avatar, non_blacklist.where(:avatar => nil)
end
end
@@ -24,8 +24,8 @@ def act_as_user_checker
after_create :async_check_is_enabled
end
- scope :enabled_checking, where(:check_state => "idle").where('checked_at < ? OR checked_at is null', Time.now-CHECK_WITHIN_DAYS.days)
- scope :enabled_checking_by_avatar, where(:check_state => "idle", :avatar => nil, :is_enabled => true)
+ scope :enabled_checking, non_blacklist.where(:check_state => "idle").where('checked_at < ? OR checked_at is null', Time.now-CHECK_WITHIN_DAYS.days)
+ scope :enabled_checking_by_avatar, non_blacklist.where(:check_state => "idle", :avatar => nil, :is_enabled => true)
init_check_state
end
View
@@ -16,6 +16,7 @@
name "MarsZ Chen"
url "http://blog.marsz.tw"
is_enabled true
+ is_black false
check_state "idle"
factory :user_for_check do
check_state "idle"

0 comments on commit da1e3a0

Please sign in to comment.