This file contains 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
-- shipments is aliased to shipments_shipping_items by AR because it is present in the subquery | |
-- this particular query fails because we join business_sites on shipments but shipments was aliased shipments_shipping_items | |
SELECT | |
`shipping_items`.* | |
FROM | |
`shipping_items` | |
INNER JOIN | |
`item_variants` ON `item_variants`.`id` = `shipping_items`.`item_variant_id` | |
INNER JOIN | |
`shipments` `shipments_shipping_items` ON `shipments_shipping_items`.`id` = `shipping_items`.`shipment_id` |
This file contains 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
# Rails 4.0.13 | |
items = ShippingItem.joins(shipment: :booking) | |
.joins("INNER JOIN (#{ | |
ShippingItem.joins(shipment: :booking).select('max(booking.eta), shipment.dest_site_id').group('shipments.dest_site_id').to_sql | |
}) AS sub sub.dest_site_id = shipments.dest_site_id AND booking.eta = sub.max_eta") | |
.order(Shipment.arel_table[:dest_site_id]) | |
# The outer query tables get automagically aliased (`shipments` `shipments_shipping_items`, `shipment_bookings` `shipment_bookings_shipments`) |
This file contains 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 assert_sorted array, &block | |
block ||= lambda {|i,j| i+1 < j+1} | |
assert array.each_cons(2).all?(&block), 'Result data not correctly sorted' | |
end | |
assert_sorted [1,3,5] {|i,j| i+1 < j+1} #works | |
assert_sorted [1,3,5] #triggers: | |
ArgumentError: wrong number of arguments (1 for 2) | |
ruby.rb:2:in `block in assert_sorted' |
This file contains 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
# Problem: block_given always retruns true, either I call the partial with or without a block... | |
- if block_given? | |
#hidden_deletion_element= yield | |
- else | |
= link_to(deletion_path, method: :delete, confirm: 'Are you sure?', id: :hidden_deletion_element) { "Delete Me"} |
This file contains 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
# inspired by http://www.scottraymond.net/2005/9/20/validating-x-html-in-rails/ | |
def assert_valid_markup(markup = @response.body, fragment = false) | |
str = if fragment | |
"<!doctype html><head><title>T</title></head><body>#{markup}</body></html>" | |
else | |
markup.to_str # .to_str to remove SafeBuffer stuff | |
end | |
require 'net/http' | |
# http://validator.w3.org/docs/api.html |
This file contains 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
config.action_mailer.host_from_outside= 'url' | |
config.action_mailer[:host_from_outside]= 'url' | |
#both triggers: | |
/Users/gamov/.rvm/gems/ruby-1.9.3-p545@ector/gems/actionmailer-3.0.20/lib/action_mailer/deprecated_api.rb:74:in `method_missing': undefined method `host_from_outside=' for ActionMailer::Base:Class (NoMethodError) | |
from /Users/gamov/.rvm/gems/ruby-1.9.3-p545@ector/gems/actionmailer-3.0.20/lib/action_mailer/base.rb:452:in `method_missing' | |
from /Users/gamov/.rvm/gems/ruby-1.9.3-p545@ector/gems/actionmailer-3.0.20/lib/action_mailer/railtie.rb:26:in `block (3 levels) in <class:Railtie>' | |
from /Users/gamov/.rvm/gems/ruby-1.9.3-p545@ector/gems/actionmailer-3.0.20/lib/action_mailer/railtie.rb:26:in `each' | |
from /Users/gamov/.rvm/gems/ruby-1.9.3-p545@ector/gems/actionmailer-3.0.20/lib/action_mailer/railtie.rb:26:in `block (2 levels) in <class:Railtie>' | |
from /Users/gamov/.rvm/gems/ruby-1.9.3-p545@ector/gems/activesupport-3.0.20/lib/active_support/lazy_load_hooks.rb:36:in `instance_eval' |
This file contains 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
ris = RequestedItem.currently_requested.joins(:order_request). | |
group(:item_variant_id).select('requested_items.*, order_request.business_site_id').all | |
ris.first[:business_site_id].class == String #instead of Fixnum... | |
#with SQLite with can: | |
if ris.first[:business_site_id] == DEFAULT_SITE | |
.. | |
#but with PG, we must: | |
if ris.first[:business_site_id].try(:to_i) == DEFAULT_SITE | |
.. |
This file contains 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 adjusted real_value, type, &block | |
puts @data | |
key = [real_value, type] | |
if @data.include? key | |
@data[key][1]= Date.current # <- calls Date.current internally to keep track of oldest record, | |
# How can i alter the return of Date.current for it to return eg yesterday | |
else | |
trim_data | |
@data[key] = [yield, Date.current] | |
@data[key].first |
This file contains 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
# Activate the gem you are reporting the issue against. | |
gem 'rails', '3.0.20' | |
gem 'paper_trail', '3.0.0' | |
require 'rails/all' | |
require 'action_controller/railtie' | |
# ENV["RAILS_ENV"] = "test" | |
require 'rails/test_help' |
This file contains 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
test 'create a standard po with items' do | |
po_count = PurchaseOrder.count | |
visit new_purchase_order_path | |
page.select po.supplier.name, from: 'purchase_order_supplier_id' | |
page.select po.company_profile.name, from: 'purchase_order_company_profile_id' | |
page.select po.delivery_site.name, from: 'purchase_order_delivery_site_id' | |
page.click_button 'purchase_order_submit' |
NewerOlder