delocalize 0.2.0 → 0.2.1

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.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.2.1
@@ -12,15 +12,16 @@ ActiveRecord::ConnectionAdapters::Column.class_eval do
12
12
  end
13
13
 
14
14
  ActiveRecord::Base.class_eval do
15
- def write_attribute_with_localization(attr_name, value)
15
+ def write_attribute_with_localization(attr_name, original_value)
16
+ new_value = original_value
16
17
  if column = column_for_attribute(attr_name.to_s)
17
18
  if column.date?
18
- value = Date.parse_localized(value)
19
+ new_value = Date.parse_localized(original_value) rescue original_value
19
20
  elsif column.time?
20
- value = Time.parse_localized(value)
21
+ new_value = Time.parse_localized(original_value) rescue original_value
21
22
  end
22
23
  end
23
- write_attribute_without_localization(attr_name, value)
24
+ write_attribute_without_localization(attr_name, new_value)
24
25
  end
25
26
  alias_method_chain :write_attribute, :localization
26
27
 
@@ -57,6 +57,13 @@ class DelocalizeActiveRecordTest < ActiveRecord::TestCase
57
57
  assert_equal time, @product.cant_think_of_a_sensible_time_field
58
58
  end
59
59
 
60
+ test "invalid dates should be delocalized to nil" do
61
+ date = '32. Oktober 2009'
62
+ @product.released_on = date
63
+ assert_equal nil, @product.released_on
64
+ assert_equal date, @product.released_on_before_type_cast
65
+ end
66
+
60
67
  test "uses default parse if format isn't found" do
61
68
  date = Date.civil(2009, 10, 19)
62
69
 
@@ -248,4 +255,9 @@ class DelocalizeActionViewTest < ActionView::TestCase
248
255
  text_field(:product, :price, :value => "1.499,90")
249
256
  }
250
257
  end
258
+
259
+ test "formats field with default value correctly" do
260
+ assert_dom_equal '<input id="product_some_value_with_default" name="product[some_value_with_default]" size="30" type="text" value="0,00" />',
261
+ text_field(:product, :some_value_with_default)
262
+ end
251
263
  end
@@ -76,4 +76,5 @@ ActiveRecord::Base.connection.create_table :products do |t|
76
76
  t.decimal :price
77
77
  t.float :weight
78
78
  t.integer :times_sold
79
+ t.decimal :some_value_with_default, :default => 0, :precision => 20, :scale => 2
79
80
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 0
9
- version: 0.2.0
8
+ - 1
9
+ version: 0.2.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Clemens Kofler
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-05-30 00:00:00 +02:00
17
+ date: 2010-06-20 00:00:00 +02:00
18
18
  default_executable:
19
19
  dependencies: []
20
20