Introduction
Introduction Statistics Contact Development Disclaimer Help
tweaked generation of conditions - reportable - Fork of reportable required by …
Log
Files
Refs
README
---
commit b09837e7524ec6d84868fb2ab67917794548157c
parent a48dd3186dd2cf21e90f5b2056eca0ab9570991e
Author: Marco Otte-Witte <[email protected]>
Date: Thu, 16 Apr 2009 09:55:02 +0200
tweaked generation of conditions
Diffstat:
M lib/simplabs/reports_as_sparkline/… | 17 ++---------------
M spec/classes/report_spec.rb | 33 ++++++++++-------------------…
2 files changed, 12 insertions(+), 38 deletions(-)
---
diff --git a/lib/simplabs/reports_as_sparkline/report.rb b/lib/simplabs/reports…
@@ -76,21 +76,8 @@ module Simplabs #:nodoc:
end
def setup_conditions(begin_at, end_at, custom_conditions = [])
- conditions = ['']
- if custom_conditions.is_a?(Hash)
- conditions = [custom_conditions.map do |k, v|
- if v.nil?
- "#{k.to_s} IS NULL"
- elsif v.is_a?(Array) || v.is_a?(Range)
- "#{k.to_s} IN (?)"
- else
- "#{k.to_s} = ?"
- end
- end.join(' AND '), *custom_conditions.map { |k, v| v }.compact]
- elsif custom_conditions.size > 0
- conditions = [(custom_conditions[0] || ''), *custom_conditions[1..…
- end
- conditions[0] += "#{(conditions[0].blank? ? '' : ' AND ') + @date_co…
+ conditions = [@klass.send(:sanitize_sql_for_conditions, custom_condi…
+ conditions[0] += "#{(conditions[0].blank? ? '' : ' AND ')}\"#{@klass…
conditions[0] += if begin_at && end_at
'BETWEEN ? AND ?'
elsif begin_at
diff --git a/spec/classes/report_spec.rb b/spec/classes/report_spec.rb
@@ -380,15 +380,15 @@ describe Simplabs::ReportsAsSparkline::Report do
end
it 'should return conditions for date_column BETWEEN begin_at and end_at o…
- @report.send(:setup_conditions, @begin_at, @end_at).should == ['created_…
+ @report.send(:setup_conditions, @begin_at, @end_at).should == ['"users".…
end
it 'should return conditions for date_column >= begin_at when no custom co…
- @report.send(:setup_conditions, @begin_at, nil).should == ['created_at >…
+ @report.send(:setup_conditions, @begin_at, nil).should == ['"users"."cre…
end
it 'should return conditions for date_column <= end_at when no custom cond…
- @report.send(:setup_conditions, nil, @end_at).should == ['created_at <= …
+ @report.send(:setup_conditions, nil, @end_at).should == ['"users"."creat…
end
it 'should raise an argument error when neither begin_at or end_at are spe…
@@ -396,49 +396,36 @@ describe Simplabs::ReportsAsSparkline::Report do
end
it 'should return conditions for date_column BETWEEN begin_at and end_date…
- @report.send(:setup_conditions, @begin_at, @end_at, {}).should == ['crea…
+ @report.send(:setup_conditions, @begin_at, @end_at, {}).should == ['"use…
end
it 'should return conditions for date_column BETWEEN begin_at and end_date…
- @report.send(:setup_conditions, @begin_at, @end_at, []).should == ['crea…
+ @report.send(:setup_conditions, @begin_at, @end_at, []).should == ['"use…
end
it 'should correctly include custom conditions if they are specified as a …
custom_conditions = { :first_name => 'first name', :last_name => 'last n…
conditions = @report.send(:setup_conditions, @begin_at, @end_at, custom_…
- #cannot check for equality of complete conditions array since hashes are…
- conditions[0].should include('first_name = ?')
- conditions[0].should include('last_name = ?')
- conditions[0].should include('created_at BETWEEN ? AND ?')
- conditions.should include('first name')
- conditions.should include('last name')
- conditions.should include(@begin_at)
- conditions.should include(@end_at)
+ conditions.should == ['"users"."first_name" = \'first name\' AND "users"…
end
it 'should correctly translate { :column => nil }' do
- @report.send(:setup_conditions, @begin_at, @end_at, { :column => nil }).…
+ @report.send(:setup_conditions, @begin_at, @end_at, { :column => nil }).…
end
it 'should correctly translate { :column => [1, 2] }' do
- @report.send(:setup_conditions, @begin_at, @end_at, { :column => [1, 2] …
+ @report.send(:setup_conditions, @begin_at, @end_at, { :column => [1, 2] …
end
it 'should correctly translate { :column => (1..3) }' do
- @report.send(:setup_conditions, @begin_at, @end_at, { :column => (1..3) …
+ @report.send(:setup_conditions, @begin_at, @end_at, { :column => (1..3) …
end
it 'should correctly include custom conditions if they are specified as an…
custom_conditions = ['first_name = ? AND last_name = ?', 'first name', '…
- @report.send(:setup_conditions, @begin_at, @end_at, custom_conditions).s…
- 'first_name = ? AND last_name = ? AND created_at BETWEEN ? AND ?',
- 'first name',
- 'last name',
- @begin_at,
- @end_at
- ]
+ @report.send(:setup_conditions, @begin_at, @end_at, custom_conditions).s…
end
end
You are viewing proxied material from jay.scot. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.