conditioner 0.0.4 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,7 +2,7 @@ $:.unshift(File.dirname(__FILE__)) unless
2
2
  $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
3
 
4
4
  module Conditioner
5
- VERSION = '0.0.4'
5
+ VERSION = '0.0.5'
6
6
  autoload :ActiveRecordMixin, 'conditioner/active_record_mixin'
7
7
  autoload :Condition, 'conditioner/condition'
8
8
  autoload :Configurator, 'conditioner/configurator'
@@ -23,11 +23,15 @@ module Conditioner
23
23
  cnd.and(["upper(#{cnd.with_table_name(field)}) like upper(?)",v])
24
24
  #FIXME: add logic for ranges
25
25
  elsif field=~ /^from_(\w*_(datetime|at))/ and cnd.is_field?($1)
26
- cnd.and(["#{cnd.with_table_name($1)} >= ?","#{v} 00:00:00.000"])
26
+ datetime = Time.parse(v)
27
+ cnd.and(["#{cnd.with_table_name($1)} >= ?",datetime])
27
28
  elsif field=~ /^to_(\w*_(datetime|at))/ and cnd.is_field?($1)
28
- cnd.and(["#{cnd.with_table_name($1)} <= ?","#{v} 23:59:59.999"])
29
+ datetime = Time.parse(v).change(:hour => 23,:min => 59,:sec => 59,:usec => 0)
30
+ cnd.and(["#{cnd.with_table_name($1)} <= ?",datetime])
29
31
  elsif cnd.is_field?(field) && (field.include?('_datetime') || field.include?('_at'))
30
- cnd.and(["(#{cnd.with_table_name(field)} BETWEEN ? AND ?)","#{v} 00:00","#{v} 23:59:59.999"])
32
+ start_date = Time.parse(v).change(:hour => 0,:min => 0,:sec => 0,:usec => 0)
33
+ end_date = Time.parse(v).change(:hour => 23,:min => 59,:sec => 59,:usec => 0)
34
+ cnd.and(["(#{cnd.with_table_name(field)} BETWEEN ? AND ?)",start_date,end_date])
31
35
  elsif field=~ /^(\w*)_(ltoe|gtoe|lt|gt)$/ and cnd.is_field?($1)
32
36
  operator = { 'lt' => '<', 'gt' => '>', 'ltoe' => '<=', 'gtoe' => '>=' }[$2]
33
37
  cnd.and(["#{cnd.with_table_name($1)} #{operator} ?", v])
@@ -26,14 +26,18 @@ class TestConditioner < Test::Unit::TestCase
26
26
  def test_extraction
27
27
  cnd=User.conditioner(:updated_at=>'2009-01-01', :email=>'nicola@mail.com',:unexisting=>'value')
28
28
  assert_match(/"users"."email"\s*=\s*'nicola@mail.com'/, cnd)
29
- assert_match(/users.updated_at BETWEEN '2009-01-01 00:00' AND '2009-01-01 23:59:59.999'/, cnd)
29
+ assert_match(/users.updated_at BETWEEN '2009-01-01 00:00:00/,cnd)
30
+ assert_match(/AND '2009-01-01 23:59:59/, cnd)
30
31
  assert_no_match(/unexisting/, cnd)
32
+ User.all(:conditions=>cnd)
31
33
  end
32
34
 
33
35
  def test_extract_from_and_to_prefixed_date_fields
34
- cnd = User.conditioner :to_updated_at =>'2010-02-02', :from_updated_at=>'2009-01-01'
35
- assert_match(/updated_at <= '2010-02-02 23:59:59.999'/, cnd)
36
- assert_match(/updated_at >= '2009-01-01 00:00:00.000'/, cnd)
36
+ cnd = User.conditioner :to_updated_at =>'2010-02-02',
37
+ :from_updated_at=>'2009-01-01'
38
+ assert_match(/updated_at <= '2010-02-02 23:59:59/, cnd)
39
+ assert_match(/updated_at >= '2009-01-01 00:00:00/, cnd)
40
+ User.all(:conditions=>cnd)
37
41
  end
38
42
 
39
43
  def test_extract_lt_and_gt_postfixed_fields
@@ -2,6 +2,7 @@ require 'stringio'
2
2
  require File.dirname(__FILE__) + '/../lib/conditioner'
3
3
  require "test/unit"
4
4
  require 'rubygems'
5
+ gem "activerecord",'= 2.3.8'
5
6
  require 'active_record'
6
7
 
7
8
  ActiveRecord::Base.logger = nil
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: conditioner
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 21
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 4
10
- version: 0.0.4
9
+ - 5
10
+ version: 0.0.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - niquola
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-06-18 00:00:00 +04:00
18
+ date: 2010-10-22 00:00:00 +04:00
19
19
  default_executable:
20
20
  dependencies: []
21
21
 
@@ -28,19 +28,19 @@ extensions: []
28
28
  extra_rdoc_files:
29
29
  - README.rdoc
30
30
  files:
31
- - init.rb
32
- - Manifest.txt
33
- - PostInstall.txt
34
31
  - Rakefile
35
- - README.rdoc
36
32
  - History.txt
37
- - lib/conditioner.rb
38
- - lib/conditioner/condition.rb
39
- - lib/conditioner/active_record_mixin.rb
33
+ - Manifest.txt
34
+ - README.rdoc
35
+ - PostInstall.txt
36
+ - init.rb
40
37
  - lib/conditioner/fake_model.rb
41
38
  - lib/conditioner/configurator.rb
42
- - test/conditioner_test.rb
39
+ - lib/conditioner/condition.rb
40
+ - lib/conditioner/active_record_mixin.rb
41
+ - lib/conditioner.rb
43
42
  - test/test_helper.rb
43
+ - test/conditioner_test.rb
44
44
  has_rdoc: true
45
45
  homepage: http://github.com/niquola/conditioner
46
46
  licenses: []