conditioner 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +1 -0
- data/Rakefile +1 -1
- data/lib/conditioner.rb +1 -1
- data/lib/conditioner/configurator.rb +4 -4
- data/test/conditioner_test.rb +11 -1
- metadata +8 -11
data/README.rdoc
CHANGED
@@ -43,6 +43,7 @@ To override Conditioner configurations create config/initializers/conditioner.rb
|
|
43
43
|
|
44
44
|
* 0.0.2 Add configurable rules for extactions
|
45
45
|
* 0.0.3 Fix bug with to extract - which eat first parameter
|
46
|
+
* 0.0.6 Some fixes for correct timezones support in rails
|
46
47
|
|
47
48
|
== LICENSE:
|
48
49
|
|
data/Rakefile
CHANGED
@@ -26,7 +26,7 @@ end
|
|
26
26
|
|
27
27
|
PKG_FILES = FileList[ '[a-zA-Z]*', 'generators/**/*', 'lib/**/*', 'rails/**/*', 'tasks/**/*', 'test/**/*' ]
|
28
28
|
|
29
|
-
require 'lib/conditioner.rb'
|
29
|
+
require File.dirname(__FILE__) + '/lib/conditioner.rb'
|
30
30
|
spec = Gem::Specification.new do |s|
|
31
31
|
s.name = "conditioner"
|
32
32
|
s.version = Conditioner::VERSION
|
data/lib/conditioner.rb
CHANGED
@@ -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.
|
5
|
+
VERSION = '0.0.6'
|
6
6
|
autoload :ActiveRecordMixin, 'conditioner/active_record_mixin'
|
7
7
|
autoload :Condition, 'conditioner/condition'
|
8
8
|
autoload :Configurator, 'conditioner/configurator'
|
@@ -23,14 +23,14 @@ 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
|
-
datetime = Time.parse(v)
|
26
|
+
datetime = Time.zone.parse(v)
|
27
27
|
cnd.and(["#{cnd.with_table_name($1)} >= ?",datetime])
|
28
28
|
elsif field=~ /^to_(\w*_(datetime|at))/ and cnd.is_field?($1)
|
29
|
-
datetime = Time.parse(v).change(:hour => 23,:min => 59,:sec => 59,:usec => 0)
|
29
|
+
datetime = Time.zone.parse(v).change(:hour => 23,:min => 59,:sec => 59,:usec => 0)
|
30
30
|
cnd.and(["#{cnd.with_table_name($1)} <= ?",datetime])
|
31
31
|
elsif cnd.is_field?(field) && (field.include?('_datetime') || field.include?('_at'))
|
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)
|
32
|
+
start_date = Time.zone.parse(v).change(:hour => 0,:min => 0,:sec => 0,:usec => 0)
|
33
|
+
end_date = Time.zone.parse(v).change(:hour => 23,:min => 59,:sec => 59,:usec => 0)
|
34
34
|
cnd.and(["(#{cnd.with_table_name(field)} BETWEEN ? AND ?)",start_date,end_date])
|
35
35
|
elsif field=~ /^(\w*)_(ltoe|gtoe|lt|gt)$/ and cnd.is_field?($1)
|
36
36
|
operator = { 'lt' => '<', 'gt' => '>', 'ltoe' => '<=', 'gtoe' => '>=' }[$2]
|
data/test/conditioner_test.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/test_helper.rb'
|
1
|
+
require File.dirname(File.expand_path(__FILE__)) + '/test_helper.rb'
|
2
2
|
|
3
3
|
Conditioner.configure do |cfg|
|
4
4
|
#Must be activated by default
|
@@ -13,6 +13,10 @@ Conditioner.configure do |cfg|
|
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
|
+
# FIXME: we are depending on Time.zone now...
|
17
|
+
# This is required for Time.zone to work correctly
|
18
|
+
Time.zone ||= ENV['TZ'] || 'UTC'
|
19
|
+
|
16
20
|
class TestConditioner < Test::Unit::TestCase
|
17
21
|
|
18
22
|
def test_conditioner_creation
|
@@ -77,6 +81,12 @@ class TestConditioner < Test::Unit::TestCase
|
|
77
81
|
assert_match(/created_at > '2010-01-01'/, cnd)
|
78
82
|
end
|
79
83
|
|
84
|
+
def test_dates_from_to
|
85
|
+
cnd = User.conditioner :from_created_at => '2010-01-01', :to_created_at => '2010-01-01'
|
86
|
+
assert_match(/created_at >= '2010-01-01 00:00:00/, cnd)
|
87
|
+
assert_match(/created_at <= '2010-01-01 23:59:59/, cnd)
|
88
|
+
end
|
89
|
+
|
80
90
|
def test_conditioner_without_model
|
81
91
|
cnd = Conditioner.create('users', :columns => ['id', 'email']).extract(:email => "nicola", :foo => "bar")
|
82
92
|
assert_equal(%Q["users"."email" = 'nicola'], cnd)
|
metadata
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: conditioner
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash: 21
|
5
4
|
prerelease: false
|
6
5
|
segments:
|
7
6
|
- 0
|
8
7
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
8
|
+
- 6
|
9
|
+
version: 0.0.6
|
11
10
|
platform: ruby
|
12
11
|
authors:
|
13
12
|
- niquola
|
@@ -15,7 +14,7 @@ autorequire:
|
|
15
14
|
bindir: bin
|
16
15
|
cert_chain: []
|
17
16
|
|
18
|
-
date: 2010-
|
17
|
+
date: 2010-11-29 00:00:00 +03:00
|
19
18
|
default_executable:
|
20
19
|
dependencies: []
|
21
20
|
|
@@ -28,17 +27,17 @@ extensions: []
|
|
28
27
|
extra_rdoc_files:
|
29
28
|
- README.rdoc
|
30
29
|
files:
|
31
|
-
- Rakefile
|
32
30
|
- History.txt
|
33
|
-
- Manifest.txt
|
34
|
-
- README.rdoc
|
35
31
|
- PostInstall.txt
|
36
32
|
- init.rb
|
33
|
+
- Manifest.txt
|
34
|
+
- README.rdoc
|
35
|
+
- Rakefile
|
36
|
+
- lib/conditioner.rb
|
37
|
+
- lib/conditioner/condition.rb
|
37
38
|
- lib/conditioner/fake_model.rb
|
38
39
|
- lib/conditioner/configurator.rb
|
39
|
-
- lib/conditioner/condition.rb
|
40
40
|
- lib/conditioner/active_record_mixin.rb
|
41
|
-
- lib/conditioner.rb
|
42
41
|
- test/test_helper.rb
|
43
42
|
- test/conditioner_test.rb
|
44
43
|
has_rdoc: true
|
@@ -55,7 +54,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
55
54
|
requirements:
|
56
55
|
- - ">="
|
57
56
|
- !ruby/object:Gem::Version
|
58
|
-
hash: 3
|
59
57
|
segments:
|
60
58
|
- 0
|
61
59
|
version: "0"
|
@@ -64,7 +62,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
64
62
|
requirements:
|
65
63
|
- - ">="
|
66
64
|
- !ruby/object:Gem::Version
|
67
|
-
hash: 3
|
68
65
|
segments:
|
69
66
|
- 0
|
70
67
|
version: "0"
|