Best Active_mocker_ruby code snippet using Sort.find_or_create_by
cache_update.rake
Source:cache_update.rake
...9 # result10 # }.reverse11 # end12 #global_topic_calculations13 $topics = Topic.nondeleted.where(:asks_count.gt=>SettingItem.find_or_create_by(:key=>"hot_topics_asks_count").value.to_i,:followed_count.gt=>SettingItem.find_or_create_by(:key=>"hot_topics_followers_count").value.to_i).to_a.collect{|x| [x.name,x.followers_count,(last_ask=AskLog.where(:action=>'ADD_TOPIC').where(:title=>x.name).last).blank? ? 0 : last_ask.created_at,(last_follow=UserLog.where(:action=>'FOLLOW_TOPIC').where(:target_parent_title=>x.name).last).blank? ? 0 : last_follow.created_at]}14 if SettingItem.find_or_create_by(:key=>"hot_topics_sort_by").value.to_s=="last_followed_at"15 $topics =$topics.sort{|x,y|y[3].to_i<=>x[3].to_i}16 else17 $topics =$topics.sort{|x,y|y[2].to_i<=>x[2].to_i}18 end19 #AnswerLog.where(action:'NEW').where(:created_at.gt=>150.days.ago).where(target_parent_id:x.id).count20 $asks = Ask.normal.nondeleted.where(:created_at.gt=>SettingItem.find_or_create_by(:key=>"hot_asks_created_at").value.to_i.days.ago,:answers_count.gte=>SettingItem.find_or_create_by(:key=>"hot_asks_answers_count").value.to_i).to_a.collect{|x| [x,x.last_answer.blank? ? 0 : x.last_answer.created_at]}21 if SettingItem.find_or_create_by(:key=>"hot_asks_sort_by").value.to_s=="answers_count"22 $asks =$asks.sort{|x,y|y[0].answers_count.to_i<=>x[0].answers_count.to_i}23 else24 $asks =$asks.sort{|x,y|y[1].to_i<=>x[1].to_i}25 end26 27 # TopicCache.delete_all28 Mongoid.database.collection('topic_caches').drop29 $topics.each_with_index do |topic,i|30 TopicCache.create!(name:topic[0],hot_rank:i,followers_count:topic[1])31 end32 # AskCache.delete_all33 Mongoid.database.collection('ask_caches').drop34 $asks.each_with_index do |a,i|35 ask=a[0]36 AskCache.create!(ask_id:ask.id,hot_rank:i)37 end 38 39 # ExpertCache.delete_all40 Mongoid.database.collection('expert_caches').drop41 User.where(:is_expert=>true).collect(&:tags).flatten.uniq.each do |tag|42 ec = ExpertCache.create!(tag:tag)43 @ask_ids = Ask.where(:topics => tag).normal.collect(&:id)44 ec.experts = User.where(:is_expert=>true).where(:tags=>tag).to_a.sort{|x,y| x.answers.any_in(:ask_id=>@ask_ids).count <=> y.answers.any_in(:ask_id=>@ask_ids).count}.reverse.collect(&:id)45 ec.save!46 end47 end48 task :ask_cache => :environment do49 $asks = Ask.normal.nondeleted.where(:created_at.gt=>SettingItem.find_or_create_by(:key=>"hot_asks_created_at").value.to_i.days.ago,:answers_count.gte=>SettingItem.find_or_create_by(:key=>"hot_asks_answers_count").value.to_i).to_a.collect{|x| [x,x.last_answer.blank? ? 0 : x.last_answer.created_at]}50 if SettingItem.find_or_create_by(:key=>"hot_asks_sort_by").value.to_s=="answers_count"51 $asks =$asks.sort{|x,y|y[0].answers_count.to_i<=>x[0].answers_count.to_i}52 else53 $asks =$asks.sort{|x,y|y[1].to_i<=>x[1].to_i}54 end55 56 # AskCache.delete_all57 Mongoid.database.collection('ask_caches').drop58 $asks.each_with_index do |a,i|59 ask=a[0]60 AskCache.create!(ask_id:ask.id,hot_rank:i)61 end62 end63 task :topic_cache => :environment do64 $topics = Topic.nondeleted.where(:asks_count.gt=>SettingItem.find_or_create_by(:key=>"hot_topics_asks_count").value.to_i,:followed_count.gt=>SettingItem.find_or_create_by(:key=>"hot_topics_followers_count").value.to_i).to_a.collect{|x| [x.name,x.followers_count,(last_ask=AskLog.where(:action=>'ADD_TOPIC').where(:title=>x.name).last).blank? ? 0 : last_ask.created_at,(last_follow=UserLog.where(:action=>'FOLLOW_TOPIC').where(:target_parent_title=>x.name).last).blank? ? 0 : last_follow.created_at]}65 if SettingItem.find_or_create_by(:key=>"hot_topics_sort_by").value.to_s=="last_followed_at"66 $topics =$topics.sort{|x,y|y[3].to_i<=>x[3].to_i}67 else68 $topics =$topics.sort{|x,y|y[2].to_i<=>x[2].to_i}69 end70 # TopicCache.delete_all71 Mongoid.database.collection('topic_caches').drop72 $topics.each_with_index do |topic,i|73 TopicCache.create!(name:topic[0],hot_rank:i,followers_count:topic[1])74 end75 end76 task :expert_cache => :environment do77 # ExpertCache.delete_all78 Mongoid.database.collection('expert_caches').drop79 User.where(:is_expert=>true).collect(&:tags).flatten.uniq.each do |tag|...
classification.rb
Source:classification.rb
...3 has_many :videos4 enum status: { disabled: -1, enabled: 0 }5 default_scope -> {where(is_delete: 0)}6 def self.init_migration7 Classification.find_or_create_by(name:"社ä¼",sort_live:10)8 Classification.find_or_create_by(name:"社ä¼-å½é
",sort_live:11)9 Classification.find_or_create_by(name:"社ä¼-æ¶äº",sort_live:12)10 Classification.find_or_create_by(name:"娱ä¹",sort_live:20)11 Classification.find_or_create_by(name:"娱ä¹-çµå½±",sort_live:21)12 Classification.find_or_create_by(name:"娱ä¹-综èº",sort_live:22)13 Classification.find_or_create_by(name:"娱ä¹-é³ä¹",sort_live:23)14 Classification.find_or_create_by(name:"娱ä¹-æ座è¿å¿",sort_live:24)15 Classification.find_or_create_by(name:"娱ä¹-æç¬",sort_live:25)16 Classification.find_or_create_by(name:"娱ä¹-漫ç»",sort_live:26)17 Classification.find_or_create_by(name:"娱ä¹-ç¾ç§å¸¸è¯",sort_live:27)18 Classification.find_or_create_by(name:"æ°ç ",sort_live:30)19 Classification.find_or_create_by(name:"æ°ç -ç§æ",sort_live:31)20 Classification.find_or_create_by(name:"汽车",sort_live:40)21 Classification.find_or_create_by(name:"æ¶å°",sort_live:50)22 Classification.find_or_create_by(name:"æ¶å°-ç¾å¦",sort_live:51)23 Classification.find_or_create_by(name:"æ¶å°-æ
æ",sort_live:52)24 Classification.find_or_create_by(name:"æ¶å°-ç©¿æ",sort_live:53)25 Classification.find_or_create_by(name:"ç¾å¥³",sort_live:60)26 Classification.find_or_create_by(name:"ç¾å¥³-èè¹",sort_live:61)27 Classification.find_or_create_by(name:"ç¾å¥³-cos",sort_live:62)28 Classification.find_or_create_by(name:"è²æ
",sort_live:70)29 Classification.find_or_create_by(name:"è²æ
-AV",sort_live:70)30 Classification.find_or_create_by(name:"è²æ
-18+",sort_live:70)31 Classification.find_or_create_by(name:"游æ",sort_live:80)32 Classification.find_or_create_by(name:"游æ-漫ç»",sort_live:81)33 Classification.find_or_create_by(name:"ç¾é£",sort_live:90)34 Classification.find_or_create_by(name:"ç¾é£-çæ´»",sort_live:91)35 Classification.find_or_create_by(name:"æ
游",sort_live:100)36 Classification.find_or_create_by(name:"æ
游-æå½±",sort_live:101)37 Classification.find_or_create_by(name:"å±
家",sort_live:110)38 Classification.find_or_create_by(name:"å±
家-å® ç©",sort_live:111)39 Classification.find_or_create_by(name:"å±
家-æ¯å©´è²å¿",sort_live:112)40 Classification.find_or_create_by(name:"å±
家-å¥åº·å
»ç",sort_live:113)41 Classification.find_or_create_by(name:"å±
家-æ座è¿å¿",sort_live:114)42 Classification.find_or_create_by(name:"åäº",sort_live:120)43 Classification.find_or_create_by(name:"åå²",sort_live:130)44 Classification.find_or_create_by(name:"åå²-æå",sort_live:131)45 Classification.find_or_create_by(name:"è´¢ç»",sort_live:140)46 Classification.find_or_create_by(name:"çæ´»",sort_live:150)47 Classification.find_or_create_by(name:"çæ´»-çæ´»æ¥å¸¸",sort_live:151)48 Classification.find_or_create_by(name:"çæ´»-vlog",sort_live:152)49 end50 # æ¸
é¤å类修æ¹å¯¼è´ä¸ä¸è´é®é¢51 def self.crean_diff52 Classification.all.each do |ca|53 $redis.del("classification_#{ca.id}_infos")54 $redis.del("classification_#{ca.id}_videos")55 end56 end57 # up_classification58 def self.up_classification59 Classification.all.each do |ca|60 $redis.sadd("classification_#{ca.id}_infos",Info.where("classification_id = ?", ca.id).ids)61 $redis.sadd("classification_#{ca.id}_videos",Video.where("classification_id = ?", ca.id).ids)62 end...
seeds.rb
Source:seeds.rb
...13 password_confirmation: "password",14 name: "ãã¹ãï¼"15 )16end17PaymentClassification.find_or_create_by!(purpose: :required, name: "é£è²»", sort: 1)18PaymentClassification.find_or_create_by!(purpose: :required, name: "å±
ä½è²»", sort: 2)19PaymentClassification.find_or_create_by!(purpose: :required, name: "æ°´éå
ç±è²»", sort: 3)20PaymentClassification.find_or_create_by!(purpose: :required, name: "éä¿¡è²»", sort: 4)21PaymentClassification.find_or_create_by!(purpose: :required, name: "éè²»ã»å»çè²»", sort: 5)22PaymentClassification.find_or_create_by!(purpose: :required, name: "ä¸è¬ä¿éºæ", sort: 6)23PaymentClassification.find_or_create_by!(purpose: :enjoyment, name: "娯楽費", sort: 7)24PaymentClassification.find_or_create_by!(purpose: :enjoyment, name: "ã³ã³ããã§è²·ã£ãããã¤", sort: 8)25PaymentClassification.find_or_create_by!(purpose: :enjoyment, name: "æ¬ãéèª", sort: 9)26PaymentClassification.find_or_create_by!(purpose: :enjoyment, name: "æ", sort: 10)27PaymentClassification.find_or_create_by!(purpose: :enjoyment, name: "DVD", sort: 11)28PaymentClassification.find_or_create_by!(purpose: :enjoyment, name: "使éä¸æé", sort: 12)29PaymentMethod.find_or_create_by!(name: "ç¾é")30PaymentMethod.find_or_create_by!(name: "ID")31PaymentMethod.find_or_create_by!(name: "ã¯ã¬ã¸ããã«ã¼ã(楽天)")32PaymentMethod.find_or_create_by!(name: "ã¯ã¬ã¸ããã«ã¼ã(SEIYU)")33PaymentMethod.find_or_create_by!(name: "ã¯ã¬ã¸ããã«ã¼ã(ã¨ããã·)")34PaymentMethod.find_or_create_by!(name: "ã¯ã¬ã¸ããã«ã¼ã(VISA)")...
find_or_create_by
Using AI Code Generation
1Sort.find_or_create_by(name: 'Ruby', version: '2.0.0')2Sort.find_or_create_by(name: 'Ruby', version: '2.0.0')3Sort.find_or_create_by(name: 'Java', version: '1.8.0')4Sort.find_or_create_by(name: 'Java', version: '1.8.0')5Sort.find_or_create_by(name: 'Ruby', version: '2.0.0')6Sort.find_or_create_by(name: 'Java', version: '1.8.0')7Sort.find_or_create_by(name: 'Java', version: '1.8.0')8Sort.find_or_create_by(name: 'Ruby', version: '2.0.0')9Sort.find_or_create_by(name: 'Ruby', version: '2.0.0')10Sort.find_or_create_by(name: 'Ruby', version: '2.0.0')11Sort.find_or_create_by(name: 'Java', version: '1.8.0')12Sort.find_or_create_by(name: 'Ruby', version: '2.0.0')13Sort.find_or_create_by(name: 'Java', version: '1.8.0')14Sort.find_or_create_by(name: 'Java', version: '1.8.0')15Sort.find_or_create_by(name: 'Ruby', version: '2.0.0')16Sort.find_or_create_by(name: 'Java', version: '1.8.0')17Sort.find_or_create_by(name: 'Java', version: '1.8.0')18Sort.find_or_create_by(name: 'Java', version: '1.8.0')19Sort.find_or_create_by(name: 'Ruby', version: '2.0.0')20Sort.find_or_create_by(name: 'Java', version: '1.8.0')21Sort.find_or_create_by(name: 'Ruby', version: '2.0.0')22Sort.find_or_create_by(name: 'Ruby', version: '2.0.0')23Sort.find_or_create_by(name: 'Ruby', version: '2.0.0')24Sort.find_or_create_by(name: 'Java', version: '1.8.0')25Sort.find_or_create_by(name: 'Java', version: '1.8.0')26Sort.find_or_create_by(name: 'Ruby', version: '2.0.0
find_or_create_by
Using AI Code Generation
1sort = Sort.find_or_create_by(name: "sort name")2sort = Sort.find_or_create_by(name: "sort name")3sort = Sort.find_or_create_by(name: "sort name")4sort = Sort.find_or_create_by(name: "sort name")5sort = Sort.find_or_create_by(name: "sort name")6sort = Sort.find_or_create_by(name: "sort name")7sort = Sort.find_or_create_by(name: "sort name")8sort = Sort.find_or_create_by(name: "sort name")
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!