locale_dating 0.1.0

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.
Files changed (45) hide show
  1. data/LICENSE +20 -0
  2. data/README.md +94 -0
  3. data/Rakefile +37 -0
  4. data/lib/locale_dating/version.rb +3 -0
  5. data/lib/locale_dating.rb +195 -0
  6. data/lib/tasks/locale_dating_tasks.rake +4 -0
  7. data/test/dummy/Rakefile +7 -0
  8. data/test/dummy/app/assets/javascripts/application.js +9 -0
  9. data/test/dummy/app/assets/stylesheets/application.css +7 -0
  10. data/test/dummy/app/controllers/application_controller.rb +3 -0
  11. data/test/dummy/app/helpers/application_helper.rb +2 -0
  12. data/test/dummy/app/models/person.rb +21 -0
  13. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  14. data/test/dummy/config/application.rb +45 -0
  15. data/test/dummy/config/boot.rb +10 -0
  16. data/test/dummy/config/database.yml +25 -0
  17. data/test/dummy/config/environment.rb +5 -0
  18. data/test/dummy/config/environments/development.rb +30 -0
  19. data/test/dummy/config/environments/production.rb +60 -0
  20. data/test/dummy/config/environments/test.rb +39 -0
  21. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  22. data/test/dummy/config/initializers/inflections.rb +10 -0
  23. data/test/dummy/config/initializers/mime_types.rb +5 -0
  24. data/test/dummy/config/initializers/secret_token.rb +7 -0
  25. data/test/dummy/config/initializers/session_store.rb +8 -0
  26. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  27. data/test/dummy/config/locales/en.yml +220 -0
  28. data/test/dummy/config/routes.rb +58 -0
  29. data/test/dummy/config.ru +4 -0
  30. data/test/dummy/db/development.sqlite3 +0 -0
  31. data/test/dummy/db/migrate/20120227052855_create_people.rb +12 -0
  32. data/test/dummy/db/schema.rb +25 -0
  33. data/test/dummy/db/test.sqlite3 +0 -0
  34. data/test/dummy/log/development.log +59 -0
  35. data/test/dummy/log/test.log +0 -0
  36. data/test/dummy/public/404.html +26 -0
  37. data/test/dummy/public/422.html +26 -0
  38. data/test/dummy/public/500.html +26 -0
  39. data/test/dummy/public/favicon.ico +0 -0
  40. data/test/dummy/script/rails +6 -0
  41. data/test/dummy/test/fixtures/people.yml +13 -0
  42. data/test/dummy/test/unit/person_test.rb +256 -0
  43. data/test/locale_dating_test.rb +7 -0
  44. data/test/test_helper.rb +10 -0
  45. metadata +178 -0
@@ -0,0 +1,256 @@
1
+ require 'test_helper'
2
+
3
+ class PersonTest < ActiveSupport::TestCase
4
+ setup do
5
+ # Give a default timezone to operate under if not explicitly set
6
+ Time.zone = 'Central Time (US & Canada)'
7
+ end
8
+
9
+ # Class methods available
10
+ test "class supports extensions" do
11
+ assert Person.respond_to?(:locale_date)
12
+ assert Person.respond_to?(:locale_datetime)
13
+ assert Person.respond_to?(:locale_time)
14
+ end
15
+
16
+ #
17
+ # Instance methods added
18
+ #
19
+ test "support default date accessor methods" do
20
+ p = Person.new
21
+ assert p.respond_to?(:born_on_as_text)
22
+ assert p.respond_to?(:born_on_as_text=)
23
+ end
24
+
25
+ test "support default datetime accessor methods" do
26
+ p = Person.new
27
+ assert p.respond_to?(:last_seen_at_as_text)
28
+ assert p.respond_to?(:last_seen_at_as_text=)
29
+ end
30
+
31
+ test "support default time accessor methods" do
32
+ p = Person.new
33
+ assert p.respond_to?(:start_time_as_text)
34
+ assert p.respond_to?(:start_time_as_text=)
35
+ end
36
+
37
+ test "support custom ending accessor methods" do
38
+ p = Person.new
39
+ assert p.respond_to?(:born_on_ymd_text)
40
+ assert p.respond_to?(:born_on_ymd_text=)
41
+ #
42
+ assert p.respond_to?(:last_seen_at_long_text)
43
+ assert p.respond_to?(:last_seen_at_long_text=)
44
+ #
45
+ assert p.respond_to?(:start_time_short_text)
46
+ assert p.respond_to?(:start_time_short_text=)
47
+ end
48
+
49
+ test "support custom named accessor methods" do
50
+ p = Person.new
51
+ assert p.respond_to?(:born_on_ymd_version)
52
+ assert p.respond_to?(:born_on_ymd_version=)
53
+ #
54
+ assert p.respond_to?(:last_seen_long_version)
55
+ assert p.respond_to?(:last_seen_long_version=)
56
+ #
57
+ assert p.respond_to?(:start_time_short_version)
58
+ assert p.respond_to?(:start_time_short_version=)
59
+ end
60
+
61
+ test "support custom formatted accessor methods with default ending" do
62
+ p = Person.new
63
+ assert p.respond_to?(:born_on_as_ymd)
64
+ assert p.respond_to?(:born_on_as_ymd=)
65
+ #
66
+ assert p.respond_to?(:last_seen_at_as_long)
67
+ assert p.respond_to?(:last_seen_at_as_long=)
68
+ #
69
+ assert p.respond_to?(:start_time_as_short)
70
+ assert p.respond_to?(:start_time_as_short=)
71
+ end
72
+
73
+ #
74
+ # Default assignment and return using text
75
+ #
76
+ test "support returning default date as text" do
77
+ p = Person.new(:born_on => Date.new(2000, 12, 30))
78
+ assert_equal p.born_on_as_text, '12/30/2000'
79
+ end
80
+
81
+ test "support receiving default date as text" do
82
+ p = Person.new
83
+ p.born_on_as_text = '12/30/2000'
84
+ assert_equal p.born_on, Date.new(2000, 12, 30)
85
+ end
86
+
87
+ test "support returning default datetime as text" do
88
+ Time.zone = 'Central Time (US & Canada)'
89
+ p = Person.new(:last_seen_at => DateTime.new(2012, 12, 30, 23, 30, 0).utc)
90
+ assert_equal '12/30/2012 05:30pm', p.last_seen_at_as_text
91
+ end
92
+
93
+ test "support receiving default datetime as text" do
94
+ p = Person.new
95
+ p.last_seen_at_as_text = '12/30/2012'
96
+ assert_equal Time.zone.local(2012, 12, 30, 0, 0, 0), p.last_seen_at
97
+ end
98
+
99
+ test "support returning default time as text" do
100
+ p = Person.new(:start_time => Time.zone.local(2012, 12, 30, 23, 30, 0))
101
+ assert_equal '12/30/2012 11:30pm', p.start_time_as_text
102
+ end
103
+
104
+ test "support receiving default time as text" do
105
+ p = Person.new
106
+ p.start_time_as_text = '12/30/2012 11:30pm'
107
+ assert_equal Time.zone.local(2012, 12, 30, 23, 30, 0), p.start_time
108
+ end
109
+
110
+ test "support returning a nil value" do
111
+ p = Person.new
112
+ assert_equal nil, p.born_on_as_text
113
+ assert_equal nil, p.start_time_as_text
114
+ assert_equal nil, p.last_seen_at_as_text
115
+ end
116
+
117
+ #
118
+ # Custom Date behavior
119
+ #
120
+ test "support custom date suffix" do
121
+ p = Person.new
122
+ assert p.respond_to?(:born_on_ymd_text)
123
+ assert p.respond_to?(:born_on_ymd_text=)
124
+ end
125
+
126
+ test "support returning custom date format" do
127
+ p = Person.new(:born_on => Date.new(2000, 12, 30))
128
+ assert_equal '2000-12-30', p.born_on_ymd_text
129
+ end
130
+
131
+ test "support receiving custom date format" do
132
+ p = Person.new
133
+ p.born_on_ymd_text = '2000-12-30'
134
+ assert_equal p.born_on, Date.new(2000, 12, 30)
135
+ end
136
+
137
+ #
138
+ # Custom DateTime behavior
139
+ #
140
+ test "support custom datetime suffix" do
141
+ p = Person.new
142
+ assert p.respond_to?(:last_seen_at_long_text)
143
+ assert p.respond_to?(:last_seen_at_long_text=)
144
+ end
145
+
146
+ test "support returning custom datetime format" do
147
+ p = Person.new(:last_seen_at => DateTime.new(2012, 12, 30, 23, 30, 0).utc)
148
+ assert_equal '12/30/2012 05:30pm', p.last_seen_at_long_text
149
+ end
150
+
151
+ test "support receiving custom datetime format" do
152
+ p = Person.new
153
+ p.last_seen_at_long_text = '12/30/2012 11:30pm'
154
+ assert_equal Time.zone.local(2012, 12, 30, 23, 30, 0), p.last_seen_at
155
+ end
156
+
157
+ #
158
+ # Custom Time behavior
159
+ #
160
+ test "support custom time suffix" do
161
+ p = Person.new
162
+ assert p.respond_to?(:start_time_short_text)
163
+ assert p.respond_to?(:start_time_short_text=)
164
+ end
165
+
166
+ test "support returning custom time format" do
167
+ p = Person.new(:start_time => Time.zone.local(2012, 12, 30, 23, 30, 0))
168
+ assert_equal '11:30pm', p.start_time_short_text
169
+ end
170
+
171
+ test "support receiving custom time format" do
172
+ p = Person.new
173
+ p.start_time_short_text = '11:30pm'
174
+ today = Date.today
175
+ result_time = Time.zone.local(today.year, today.month, today.day, 23, 30, 0)
176
+ assert_equal p.start_time, result_time
177
+ end
178
+
179
+ #
180
+ # TimeZone behavior - DateTime
181
+ #
182
+ test "DateTime respect timezone when retrieving value" do
183
+ Time.zone = 'Central Time (US & Canada)'
184
+ p = Person.new(:last_seen_at => DateTime.new(2012, 12, 30, 23, 30, 0).utc)
185
+ assert_equal '12/30/2012 05:30pm', p.last_seen_at_long_text
186
+
187
+ Time.zone = 'Mountain Time (US & Canada)'
188
+ assert_equal '12/30/2012 04:30pm', p.last_seen_at_long_text
189
+ end
190
+
191
+ test "DateTime respect timezone when parsing value" do
192
+ Time.zone = 'Central Time (US & Canada)'
193
+ p = Person.new
194
+ p.last_seen_at_long_text = '12/30/2012 03:30pm'
195
+ assert_equal Time.zone.local(2012, 12, 30, 15, 30, 0), p.last_seen_at
196
+ assert_equal DateTime.new(2012, 12, 30, 21, 30, 0), p.last_seen_at # underlying UTC value
197
+
198
+ Time.zone = 'Mountain Time (US & Canada)'
199
+ p.last_seen_at_long_text = '12/30/2012 03:30pm'
200
+ assert_equal Time.zone.local(2012, 12, 30, 15, 30, 0), p.last_seen_at
201
+ assert_equal DateTime.new(2012, 12, 30, 22, 30, 0), p.last_seen_at # underlying UTC value
202
+ end
203
+
204
+ #
205
+ # TimeZone behavior - Date
206
+ #
207
+ test "Date not affected by timezone when retrieving value" do
208
+ Time.zone = 'Central Time (US & Canada)'
209
+ p = Person.new(:born_on => Date.new(2012, 12, 30))
210
+ assert_equal '2012-12-30', p.born_on_ymd_text
211
+
212
+ Time.zone = 'Mountain Time (US & Canada)'
213
+ assert_equal '2012-12-30', p.born_on_ymd_text
214
+ end
215
+
216
+ test "Date not affected by timezone when parsing value" do
217
+ Time.zone = 'Central Time (US & Canada)'
218
+ p = Person.new
219
+ p.born_on_ymd_text = '2012-12-30'
220
+ assert_equal DateTime.new(2012, 12, 30), p.born_on # underlying UTC value
221
+
222
+ Time.zone = 'Mountain Time (US & Canada)'
223
+ p.born_on_ymd_text = '2012-12-30'
224
+ assert_equal DateTime.new(2012, 12, 30), p.born_on # underlying UTC value
225
+ end
226
+
227
+ #
228
+ # TimeZone behavior - Time
229
+ #
230
+ test "Time respects timezone when retrieving value" do
231
+ Time.zone = 'Central Time (US & Canada)'
232
+ p = Person.new(:start_time => Time.zone.local(2012, 12, 31, 19, 23, 0).to_time)
233
+ assert_equal '07:23pm', p.start_time_short_text
234
+
235
+ Time.zone = 'Mountain Time (US & Canada)'
236
+ assert_equal '06:23pm', p.start_time_short_text
237
+ end
238
+
239
+ test "Time respects timezone when parsing value" do
240
+ test_date = Date.today
241
+
242
+ Time.zone = 'Central Time (US & Canada)'
243
+ p = Person.new
244
+ p.start_time_short_text = '4:25pm'
245
+ assert_equal Time.zone.local(test_date.year, test_date.month, test_date.day, 16, 25, 0), p.start_time
246
+ assert_equal DateTime.new(test_date.year, test_date.month, test_date.day, 21, 25, 0).to_time,
247
+ p.start_time.to_time # underlying UTC value
248
+
249
+ Time.zone = 'Mountain Time (US & Canada)'
250
+ p.start_time_short_text = '4:25pm'
251
+ assert_equal Time.zone.local(test_date.year, test_date.month, test_date.day, 16, 25, 0), p.start_time
252
+ assert_equal DateTime.new(test_date.year, test_date.month, test_date.day, 22, 25, 0).to_time,
253
+ p.start_time.to_time # underlying UTC value
254
+ end
255
+
256
+ end
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ class LocaleDatingTest < ActiveSupport::TestCase
4
+ test "truth" do
5
+ assert_kind_of Module, LocaleDating
6
+ end
7
+ end
@@ -0,0 +1,10 @@
1
+ # Configure Rails Environment
2
+ ENV["RAILS_ENV"] = "test"
3
+
4
+ require File.expand_path("../dummy/config/environment.rb", __FILE__)
5
+ require "rails/test_help"
6
+
7
+ Rails.backtrace_cleaner.remove_silencers!
8
+
9
+ # Load support files
10
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
metadata ADDED
@@ -0,0 +1,178 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: locale_dating
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Mark Ericksen
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-03-16 00:00:00 -06:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: rails
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ hash: 5
30
+ segments:
31
+ - 3
32
+ - 1
33
+ version: "3.1"
34
+ type: :runtime
35
+ version_requirements: *id001
36
+ - !ruby/object:Gem::Dependency
37
+ name: sqlite3
38
+ prerelease: false
39
+ requirement: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ hash: 3
45
+ segments:
46
+ - 0
47
+ version: "0"
48
+ type: :development
49
+ version_requirements: *id002
50
+ description: |-
51
+ LocaleDating generates wrapper methods around the attributes you want to support editing
52
+ Date, Time, and DateTime values as text using the desired I18n locale format.
53
+ email:
54
+ - brainlid@gmail.com
55
+ executables: []
56
+
57
+ extensions: []
58
+
59
+ extra_rdoc_files: []
60
+
61
+ files:
62
+ - lib/locale_dating.rb
63
+ - lib/locale_dating/version.rb
64
+ - lib/tasks/locale_dating_tasks.rake
65
+ - LICENSE
66
+ - Rakefile
67
+ - README.md
68
+ - test/dummy/Rakefile
69
+ - test/dummy/app/models/person.rb
70
+ - test/dummy/app/assets/stylesheets/application.css
71
+ - test/dummy/app/assets/javascripts/application.js
72
+ - test/dummy/app/views/layouts/application.html.erb
73
+ - test/dummy/app/helpers/application_helper.rb
74
+ - test/dummy/app/controllers/application_controller.rb
75
+ - test/dummy/script/rails
76
+ - test/dummy/config.ru
77
+ - test/dummy/test/fixtures/people.yml
78
+ - test/dummy/test/unit/person_test.rb
79
+ - test/dummy/db/test.sqlite3
80
+ - test/dummy/db/development.sqlite3
81
+ - test/dummy/db/migrate/20120227052855_create_people.rb
82
+ - test/dummy/db/schema.rb
83
+ - test/dummy/log/test.log
84
+ - test/dummy/log/development.log
85
+ - test/dummy/config/database.yml
86
+ - test/dummy/config/initializers/session_store.rb
87
+ - test/dummy/config/initializers/mime_types.rb
88
+ - test/dummy/config/initializers/secret_token.rb
89
+ - test/dummy/config/initializers/inflections.rb
90
+ - test/dummy/config/initializers/wrap_parameters.rb
91
+ - test/dummy/config/initializers/backtrace_silencers.rb
92
+ - test/dummy/config/environment.rb
93
+ - test/dummy/config/locales/en.yml
94
+ - test/dummy/config/boot.rb
95
+ - test/dummy/config/environments/test.rb
96
+ - test/dummy/config/environments/development.rb
97
+ - test/dummy/config/environments/production.rb
98
+ - test/dummy/config/routes.rb
99
+ - test/dummy/config/application.rb
100
+ - test/dummy/public/422.html
101
+ - test/dummy/public/500.html
102
+ - test/dummy/public/favicon.ico
103
+ - test/dummy/public/404.html
104
+ - test/locale_dating_test.rb
105
+ - test/test_helper.rb
106
+ has_rdoc: true
107
+ homepage: http://github.com/brainlid/locale_dating
108
+ licenses: []
109
+
110
+ post_install_message:
111
+ rdoc_options: []
112
+
113
+ require_paths:
114
+ - lib
115
+ required_ruby_version: !ruby/object:Gem::Requirement
116
+ none: false
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ hash: 3
121
+ segments:
122
+ - 0
123
+ version: "0"
124
+ required_rubygems_version: !ruby/object:Gem::Requirement
125
+ none: false
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ hash: 3
130
+ segments:
131
+ - 0
132
+ version: "0"
133
+ requirements: []
134
+
135
+ rubyforge_project:
136
+ rubygems_version: 1.3.7
137
+ signing_key:
138
+ specification_version: 3
139
+ summary: LocalDating does what Rails should be doing. It makes working with dates and times as text in forms painless. It works with your I18n locales to use your desired formats and respects the user's timezone.
140
+ test_files:
141
+ - test/dummy/Rakefile
142
+ - test/dummy/app/models/person.rb
143
+ - test/dummy/app/assets/stylesheets/application.css
144
+ - test/dummy/app/assets/javascripts/application.js
145
+ - test/dummy/app/views/layouts/application.html.erb
146
+ - test/dummy/app/helpers/application_helper.rb
147
+ - test/dummy/app/controllers/application_controller.rb
148
+ - test/dummy/script/rails
149
+ - test/dummy/config.ru
150
+ - test/dummy/test/fixtures/people.yml
151
+ - test/dummy/test/unit/person_test.rb
152
+ - test/dummy/db/test.sqlite3
153
+ - test/dummy/db/development.sqlite3
154
+ - test/dummy/db/migrate/20120227052855_create_people.rb
155
+ - test/dummy/db/schema.rb
156
+ - test/dummy/log/test.log
157
+ - test/dummy/log/development.log
158
+ - test/dummy/config/database.yml
159
+ - test/dummy/config/initializers/session_store.rb
160
+ - test/dummy/config/initializers/mime_types.rb
161
+ - test/dummy/config/initializers/secret_token.rb
162
+ - test/dummy/config/initializers/inflections.rb
163
+ - test/dummy/config/initializers/wrap_parameters.rb
164
+ - test/dummy/config/initializers/backtrace_silencers.rb
165
+ - test/dummy/config/environment.rb
166
+ - test/dummy/config/locales/en.yml
167
+ - test/dummy/config/boot.rb
168
+ - test/dummy/config/environments/test.rb
169
+ - test/dummy/config/environments/development.rb
170
+ - test/dummy/config/environments/production.rb
171
+ - test/dummy/config/routes.rb
172
+ - test/dummy/config/application.rb
173
+ - test/dummy/public/422.html
174
+ - test/dummy/public/500.html
175
+ - test/dummy/public/favicon.ico
176
+ - test/dummy/public/404.html
177
+ - test/locale_dating_test.rb
178
+ - test/test_helper.rb