replace deprecated finder and finder_options syntax
This commit is contained in:
parent
d75632401b
commit
33c3b38f2f
24 changed files with 52 additions and 50 deletions
|
|
@ -46,7 +46,7 @@ class AdminsController < Admin::AdminController
|
|||
end
|
||||
|
||||
def stats
|
||||
@popular_tags = ActsAsTaggableOn::Tagging.joins(:tag).limit(50).count(:group => :tag, :order => 'count(taggings.id) DESC')
|
||||
@popular_tags = ActsAsTaggableOn::Tagging.joins(:tag).limit(50).order('count(taggings.id) DESC').group(:tag).count
|
||||
|
||||
case params[:range]
|
||||
when "week"
|
||||
|
|
@ -67,7 +67,7 @@ class AdminsController < Admin::AdminController
|
|||
create_hash(model, :range => range)
|
||||
end
|
||||
|
||||
@posts_per_day = Post.count(:group => "DATE(created_at)", :conditions => ["created_at >= ?", Date.today - 21.days], :order => "DATE(created_at) ASC")
|
||||
@posts_per_day = Post.where("created_at >= ?", Date.today - 21.days).group("DATE(created_at)").order("DATE(created_at) ASC").count
|
||||
@most_posts_within = @posts_per_day.values.max.to_f
|
||||
|
||||
@user_count = User.count
|
||||
|
|
|
|||
|
|
@ -33,13 +33,11 @@ class NotificationsController < ApplicationController
|
|||
page = params[:page] || 1
|
||||
per_page = params[:per_page] || 25
|
||||
@notifications = WillPaginate::Collection.create(page, per_page, Notification.where(conditions).count ) do |pager|
|
||||
result = Notification.find(:all,
|
||||
:conditions => conditions,
|
||||
:order => 'created_at desc',
|
||||
:include => [:target, {:actors => :profile}],
|
||||
:limit => pager.per_page,
|
||||
:offset => pager.offset
|
||||
)
|
||||
result = Notification.where(conditions)
|
||||
.includes(:target, :actors => :profile)
|
||||
.order('created_at desc')
|
||||
.limit(pager.per_page)
|
||||
.offset(pager.offset)
|
||||
|
||||
pager.replace(result)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ class TagFollowingsController < ApplicationController
|
|||
if name_normalized.nil? || name_normalized.empty?
|
||||
render :nothing => true, :status => 403
|
||||
else
|
||||
@tag = ActsAsTaggableOn::Tag.find_or_create_by_name(name_normalized)
|
||||
@tag = ActsAsTaggableOn::Tag.find_or_create_by(name: name_normalized)
|
||||
@tag_following = current_user.tag_followings.new(:tag_id => @tag.id)
|
||||
|
||||
if @tag_following.save
|
||||
|
|
@ -31,7 +31,7 @@ class TagFollowingsController < ApplicationController
|
|||
# DELETE /tag_followings/1.xml
|
||||
def destroy
|
||||
tag_following = current_user.tag_followings.find_by_tag_id( params['id'] )
|
||||
|
||||
|
||||
if tag_following && tag_following.destroy
|
||||
respond_to do |format|
|
||||
format.any(:js, :json) { render :nothing => true, :status => 204 }
|
||||
|
|
|
|||
|
|
@ -68,10 +68,10 @@ class Conversation < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def receive(user, person)
|
||||
cnv = Conversation.find_or_create_by_guid(self.attributes)
|
||||
cnv = Conversation.find_or_create_by(self.attributes)
|
||||
|
||||
self.participants.each do |participant|
|
||||
ConversationVisibility.find_or_create_by_conversation_id_and_person_id(cnv.id, participant.id)
|
||||
ConversationVisibility.find_or_create_by(conversation_id: cnv.id, person_id: participant.id)
|
||||
end
|
||||
|
||||
self.messages.each do |msg|
|
||||
|
|
|
|||
|
|
@ -10,10 +10,10 @@ class OEmbedCache < ActiveRecord::Base
|
|||
t.add :data
|
||||
end
|
||||
|
||||
def self.find_or_create_by_url(url)
|
||||
cache = OEmbedCache.find_or_initialize_by_url(url)
|
||||
def self.find_or_create_by(opts)
|
||||
cache = OEmbedCache.find_or_initialize_by(opts)
|
||||
return cache if cache.persisted?
|
||||
cache.fetch_and_save_oembed_data!
|
||||
cache.fetch_and_save_oembed_data! # make after create callback and drop this method ?
|
||||
cache
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -21,10 +21,10 @@ class OpenGraphCache < ActiveRecord::Base
|
|||
t.add :url
|
||||
end
|
||||
|
||||
def self.find_or_create_by_url(url)
|
||||
cache = OpenGraphCache.find_or_initialize_by_url(url)
|
||||
def self.find_or_create_by(opts)
|
||||
cache = OpenGraphCache.find_or_initialize_by(opts)
|
||||
cache.fetch_and_save_opengraph_data! unless cache.persisted?
|
||||
cache if cache.persisted?
|
||||
cache if cache.persisted? # Make this an after create callback and drop this method ?
|
||||
end
|
||||
|
||||
def fetch_and_save_opengraph_data!
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
class Pod < ActiveRecord::Base
|
||||
def self.find_or_create_by_url(url)
|
||||
u = URI.parse(url)
|
||||
pod = self.find_or_initialize_by_host(u.host)
|
||||
def self.find_or_create_by(opts) # Rename this method to not override an AR method
|
||||
u = URI.parse(opts.fetch(:url))
|
||||
pod = self.find_or_initialize_by(host: u.host)
|
||||
unless pod.persisted?
|
||||
pod.ssl = (u.scheme == 'https')? true : false
|
||||
pod.save
|
||||
|
|
|
|||
|
|
@ -9,10 +9,10 @@ class Role < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def self.add_admin(person)
|
||||
find_or_create_by_person_id_and_name(person.id, 'admin')
|
||||
find_or_create_by(person_id: person.id, name: 'admin')
|
||||
end
|
||||
|
||||
def self.add_spotlight(person)
|
||||
find_or_create_by_person_id_and_name(person.id, 'spotlight')
|
||||
find_or_create_by(person_id: person.id, name: 'spotlight')
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -25,7 +25,11 @@ class ShareVisibility < ActiveRecord::Base
|
|||
|
||||
if AppConfig.postgres?
|
||||
contact_ids.each do |contact_id|
|
||||
ShareVisibility.find_or_create_by_contact_id_and_shareable_id_and_shareable_type(contact_id, share.id, share.class.base_class.to_s)
|
||||
ShareVisibility.find_or_create_by(
|
||||
contact_id: contact_id,
|
||||
shareable_id: share.id,
|
||||
shareable_type: share.class.base_class.to_s
|
||||
)
|
||||
end
|
||||
else
|
||||
new_share_visibilities_data = contact_ids.map do |contact_id|
|
||||
|
|
|
|||
|
|
@ -98,7 +98,7 @@ class StatusMessage < Post
|
|||
def create_mentions
|
||||
ppl = Diaspora::Mentionable.people_from_string(self.raw_message)
|
||||
ppl.each do |person|
|
||||
self.mentions.find_or_create_by_person_id(person.id)
|
||||
self.mentions.find_or_create_by(person_id: person.id)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -102,7 +102,7 @@ class User < ActiveRecord::Base
|
|||
|
||||
|
||||
def invitation_code
|
||||
InvitationCode.find_or_create_by_user_id(self.id)
|
||||
InvitationCode.find_or_create_by(user_id: self.id)
|
||||
end
|
||||
|
||||
def hidden_shareables
|
||||
|
|
@ -163,14 +163,14 @@ class User < ActiveRecord::Base
|
|||
|
||||
def update_user_preferences(pref_hash)
|
||||
if self.disable_mail
|
||||
UserPreference::VALID_EMAIL_TYPES.each{|x| self.user_preferences.find_or_create_by_email_type(x)}
|
||||
UserPreference::VALID_EMAIL_TYPES.each{|x| self.user_preferences.find_or_create_by(email_type: x)}
|
||||
self.disable_mail = false
|
||||
self.save
|
||||
end
|
||||
|
||||
pref_hash.keys.each do |key|
|
||||
if pref_hash[key] == 'true'
|
||||
self.user_preferences.find_or_create_by_email_type(key)
|
||||
self.user_preferences.find_or_create_by(email_type: key)
|
||||
else
|
||||
block = self.user_preferences.where(:email_type => key).first
|
||||
if block
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ module User::Connecting
|
|||
# @param [Aspect] aspect The aspect to add them to.
|
||||
# @return [Contact] The newly made contact for the passed in person.
|
||||
def share_with(person, aspect)
|
||||
contact = self.contacts.find_or_initialize_by_person_id(person.id)
|
||||
contact = self.contacts.find_or_initialize_by(person_id: person.id)
|
||||
return false unless contact.valid?
|
||||
|
||||
unless contact.receiving?
|
||||
|
|
@ -22,7 +22,7 @@ module User::Connecting
|
|||
if notification = Notification.where(:target_id => person.id).first
|
||||
notification.update_attributes(:unread=>false)
|
||||
end
|
||||
|
||||
|
||||
deliver_profile_update
|
||||
register_share_visibilities(contact)
|
||||
contact
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ module Workers
|
|||
|
||||
def perform(post_id, url, retry_count=1)
|
||||
post = Post.find(post_id)
|
||||
post.o_embed_cache = OEmbedCache.find_or_create_by_url(url)
|
||||
post.o_embed_cache = OEmbedCache.find_or_create_by(url: url)
|
||||
post.save
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
# User created a post and deleted it right afterwards before we
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ module Workers
|
|||
|
||||
def perform(post_id, url, retry_count=1)
|
||||
post = Post.find(post_id)
|
||||
post.open_graph_cache = OpenGraphCache.find_or_create_by_url(url)
|
||||
post.open_graph_cache = OpenGraphCache.find_or_create_by(url: url)
|
||||
post.save
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
# User created a post and deleted it right afterwards before we
|
||||
|
|
|
|||
|
|
@ -201,7 +201,7 @@ end
|
|||
|
||||
Given /^I visit alice's invitation code url$/ do
|
||||
@alice ||= FactoryGirl.create(:user, :username => 'alice', :getting_started => false)
|
||||
invite_code = InvitationCode.find_or_create_by_user_id(@alice.id)
|
||||
invite_code = InvitationCode.find_or_create_by(user_id: @alice.id)
|
||||
visit invite_code_path(invite_code)
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ module Diaspora
|
|||
#}
|
||||
|
||||
xml.post_ids {
|
||||
aspect.posts.find_all_by_author_id(user_person_id).each do |post|
|
||||
aspect.posts.where(author_id: user_person_id).each do |post|
|
||||
xml.post_id post.id
|
||||
end
|
||||
}
|
||||
|
|
@ -64,7 +64,7 @@ module Diaspora
|
|||
}
|
||||
|
||||
xml.posts {
|
||||
user.visible_shareables(Post).find_all_by_author_id(user_person_id).each do |post|
|
||||
user.visible_shareables(Post).where(author_id: user_person_id).each do |post|
|
||||
#post.comments.each do |comment|
|
||||
# post_doc << comment.to_xml
|
||||
#end
|
||||
|
|
|
|||
|
|
@ -75,10 +75,10 @@ class Request
|
|||
def receive(user, person)
|
||||
Rails.logger.info("event=receive payload_type=request sender=#{self.sender} to=#{self.recipient}")
|
||||
|
||||
contact = user.contacts.find_or_initialize_by_person_id(self.sender.id)
|
||||
contact = user.contacts.find_or_initialize_by(person_id: self.sender.id)
|
||||
contact.sharing = true
|
||||
contact.save
|
||||
|
||||
|
||||
user.share_with(person, user.auto_follow_back_aspect) if user.auto_follow_back && !contact.receiving
|
||||
|
||||
self
|
||||
|
|
|
|||
|
|
@ -83,7 +83,7 @@ class HydraWrapper
|
|||
def prepare_request request, people_for_receive_url
|
||||
request.on_complete do |response|
|
||||
# Save the reference to the pod to the database if not already present
|
||||
Pod.find_or_create_by_url response.effective_url
|
||||
Pod.find_or_create_by(url: response.effective_url)
|
||||
|
||||
if redirecting_to_https? response
|
||||
Person.url_batch_update people_for_receive_url, response.headers_hash['Location']
|
||||
|
|
|
|||
|
|
@ -82,7 +82,7 @@ namespace :migrations do
|
|||
puts "found #{evil_tags.count} tags to convert..."
|
||||
|
||||
evil_tags.each_with_index do |tag, i|
|
||||
good_tag = ActsAsTaggableOn::Tag.find_or_create_by_name(tag.name.mb_chars.downcase)
|
||||
good_tag = ActsAsTaggableOn::Tag.first_or_create_by(name: tag.name.mb_chars.downcase)
|
||||
puts "++ '#{tag.name}' has #{tag.taggings.count} records attached"
|
||||
|
||||
taggings = tag.taggings
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ describe Stream::Multi do
|
|||
|
||||
describe "#publisher_prefill" do
|
||||
before do
|
||||
@tag = ActsAsTaggableOn::Tag.find_or_create_by_name("cats")
|
||||
@tag = ActsAsTaggableOn::Tag.find_or_create_by(name: "cats")
|
||||
@tag_following = alice.tag_followings.create(:tag_id => @tag.id)
|
||||
|
||||
@stream = Stream::Multi.new(alice)
|
||||
|
|
|
|||
|
|
@ -1,14 +1,14 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Pod do
|
||||
describe '.find_or_create_by_url' do
|
||||
describe '.find_or_create_by' do
|
||||
it 'takes a url, and makes one by host' do
|
||||
pod = Pod.find_or_create_by_url('https://joindiaspora.com/maxwell')
|
||||
pod = Pod.find_or_create_by(url: 'https://joindiaspora.com/maxwell')
|
||||
pod.host.should == 'joindiaspora.com'
|
||||
end
|
||||
|
||||
it 'sets ssl boolean(side-effect)' do
|
||||
pod = Pod.find_or_create_by_url('https://joindiaspora.com/maxwell')
|
||||
pod = Pod.find_or_create_by(url: 'https://joindiaspora.com/maxwell')
|
||||
pod.ssl.should be_true
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -113,7 +113,7 @@ describe User::Connecting do
|
|||
|
||||
it 'adds a contact to an aspect' do
|
||||
contact = alice.contacts.create(:person => eve.person)
|
||||
alice.contacts.stub(:find_or_initialize_by_person_id).and_return(contact)
|
||||
alice.contacts.stub(:find_or_initialize_by).and_return(contact)
|
||||
|
||||
lambda {
|
||||
alice.share_with(eve.person, alice.aspects.first)
|
||||
|
|
@ -128,7 +128,7 @@ describe User::Connecting do
|
|||
context 'dispatching' do
|
||||
it 'dispatches a request on initial request' do
|
||||
contact = alice.contacts.new(:person => eve.person)
|
||||
alice.contacts.stub(:find_or_initialize_by_person_id).and_return(contact)
|
||||
alice.contacts.stub(:find_or_initialize_by).and_return(contact)
|
||||
|
||||
contact.should_receive(:dispatch_request)
|
||||
alice.share_with(eve.person, alice.aspects.first)
|
||||
|
|
@ -138,7 +138,7 @@ describe User::Connecting do
|
|||
eve.share_with(alice.person, eve.aspects.first)
|
||||
|
||||
contact = alice.contact_for(eve.person)
|
||||
alice.contacts.stub(:find_or_initialize_by_person_id).and_return(contact)
|
||||
alice.contacts.stub(:find_or_initialize_by).and_return(contact)
|
||||
|
||||
contact.should_receive(:dispatch_request)
|
||||
alice.share_with(eve.person, alice.aspects.first)
|
||||
|
|
@ -148,7 +148,7 @@ describe User::Connecting do
|
|||
a2 = alice.aspects.create(:name => "two")
|
||||
|
||||
contact = alice.contacts.create(:person => eve.person, :receiving => true)
|
||||
alice.contacts.stub(:find_or_initialize_by_person_id).and_return(contact)
|
||||
alice.contacts.stub(:find_or_initialize_by).and_return(contact)
|
||||
|
||||
contact.should_not_receive(:dispatch_request)
|
||||
alice.share_with(eve.person, a2)
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ describe Workers::GatherOEmbedData do
|
|||
OEmbedCache.find_by_url(@flickr_photo_url).data.should == expected_data
|
||||
|
||||
Workers::GatherOEmbedData.new.perform(@status_message.id, @flickr_photo_url)
|
||||
OEmbedCache.count(:conditions => {:url => @flickr_photo_url}).should == 1
|
||||
OEmbedCache.where(url: @flickr_photo_url).count.should == 1
|
||||
end
|
||||
|
||||
it 'creates no cache entry for unsupported pages' do
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ describe Workers::GatherOpenGraphData do
|
|||
ogc.description.should == @ogsite_description
|
||||
|
||||
Workers::GatherOpenGraphData.new.perform(@status_message.id, @ogsite_url)
|
||||
OpenGraphCache.count(:conditions => {:url => @ogsite_url}).should == 1
|
||||
OpenGraphCache.where(url: @ogsite_url).count.should == 1
|
||||
end
|
||||
|
||||
it 'creates no cache entry for unsupported pages' do
|
||||
|
|
|
|||
Loading…
Reference in a new issue