This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| set :output, { | |
| error: '/log/cron_error_log.log', | |
| standard: '/log/cron_log.log' } | |
| every 1.day, :at => '01:00 am' do | |
| rake "delete:customers" | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| namespace :delete do | |
| desc 'delete customers for cron job' | |
| task customers: :environment do | |
| customers = Customer.all | |
| puts "#{customers.count} customers were deleted." | |
| customers.destroy_all | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| describe '#delete' do | |
| before do | |
| 9.times { create(:customer, type: 'anonym') } | |
| Timecop.freeze(time_parse('01:00')) | |
| load Rails.root.join("lib/tasks/delete_customers.rake") | |
| Rake::Task.define_task(:environment) | |
| end | |
| after do | |
| Timecop.return |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| > Post.limit(10) | |
| Post Load (3.3ms) SELECT `posts`.* FROM `posts` WHERE `posts`.`published` = 1 ORDER BY created_at desc LIMIT 10 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| > Post.order("updated_at desc").limit(10) | |
| Post Load (17.3ms) SELECT `posts`.* FROM `posts` WHERE `posts`.`published` = 1 ORDER BY created_at desc, updated_at desc LIMIT 10 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| > Post.unscoped.order("updated_at desc").limit(10) | |
| Post Load (1.9ms) SELECT `posts`.* FROM `posts` ORDER BY updated_at desc LIMIT 10 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| > Post.new | |
| => #<Post id: nil, title: nil, created_at: nil, updated_at: nil, user_id: nil, published: true> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @companies = Company.includes(:persons).where(:persons => { active: true } ).all | |
| @companies.each do |company| | |
| company.person.name | |
| end | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @companies = Company.joins(:persons).where(:persons => { active: true } ).all | |
| @companies.each do |company| | |
| company.name | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def index | |
| @shippings = Shipping.active.all | |
| respond_to do |format| | |
| format.html # index.html.erb | |
| format.json { render json: @shippings } | |
| end | |
| end | |