class MergeAdapterUtil
def self.convert_time_to_yyyymmdd(column)
case ActiveRecord::Base.connection.adapter_name
- when 'PostgreSQL'
+ when /PostgreSQL/i
"to_char(#{column}, 'YYYYMMDD')"
- when 'MySQL'
+ when /MySQL/i
"date_format(#{column}, '%%Y%%m%%d')"
end
end
def self.convert_time_to_mm(column)
case ActiveRecord::Base.connection.adapter_name
- when 'PostgreSQL'
+ when /PostgreSQL/i
"to_char(#{column}, 'MM')"
- when 'MySQL'
+ when /MySQL/i
"date_format(#{column}, '%%m')"
end
end
def self.concat(*columns)
case ActiveRecord::Base.connection.adapter_name
- when 'PostgreSQL'
+ when /PostgreSQL/i
columns.join(' || ')
- when 'MySQL'
+ when /MySQL/i
"concat(#{columns.join(',')})"
end
end
def self.age(from, to="now()")
case ActiveRecord::Base.connection.adapter_name
- when 'PostgreSQL'
+ when /PostgreSQL/i
"age(#{to}, #{from})"
- when 'MySQL'
+ when /MySQL/i
"from_days(datediff(#{to}, #{from}))"
end
end
def self.interval_second(interval_str)
case ActiveRecord::Base.connection.adapter_name
- when 'PostgreSQL'
+ when /PostgreSQL/i
"interval '#{interval_str} seconds'"
- when 'MySQL'
+ when /MySQL/i
"interval #{interval_str} second"
end
end
def self.day_of_week(column)
case ActiveRecord::Base.connection.adapter_name
- when 'PostgreSQL'
+ when /PostgreSQL/i
"extract(dow from #{column})"
- when 'MySQL'
+ when /MySQL/i
"dayofweek(#{column})"
end
end
end
it "販売開始期間を指定して集計" do
- start_from = Date.new(2008, 8, 1)
- start_to = Date.today
- search = {
- 'month(1i)'=>start_from.year, 'month(2i)'=>start_from.month, :by_month => 'x',
- 'sale_start_from(1i)' => start_from.year.to_s,
- 'sale_start_from(2i)' => start_from.month.to_s,
- 'sale_start_from(3i)' => start_from.day.to_s,
- 'sale_start_to(1i)' => start_to.year.to_s,
- 'sale_start_to(2i)' => start_to.month.to_s,
- 'sale_start_to(3i)' => start_to.day.to_s
- }
+ date_from = Date.new(2008, 8, 1)
+ date_to = Date.today
+ search = { :by_month => 'x' }.
+ merge(date_to_select(date_from, 'month')).
+ merge(date_to_select(date_from, 'sale_start_from')).
+ merge(date_to_select(date_to, 'sale_start_to'))
post 'index', :page => 'product', :type => 'all', :search => search
assigns[:sale_start_enabled].should be_true
assigns[:records].should_not be_empty
assigns[:records].each do | record |
- record.sale_start_at.should >= start_from
- record.sale_start_at.should <= start_to
+ record.sale_start_at.should >= date_from
+ record.sale_start_at.should <= date_to
end
end
date_to = DateTime.new(2008,8,31,23,59,59)
conds = ['received_at between ? and ? and status in (?)', date_from, date_to,
[OrderDelivery::HASSOU_TYUU, OrderDelivery::HAITATU_KANRYO]]
- search = {'by_date'=>'x'}.
+ search = { :by_date => 'x' }.
merge(date_to_select(date_from, 'date_from')).
merge(date_to_select(date_to, 'date_to'))
post 'index', :page => 'product', :type => 'all', :search => search