Skip to content
This repository

Spike calendar ( refactor ) #24

Merged
merged 4 commits into from about 1 year ago

2 participants

tatsuo.sakurai Makoto Yonezawa
tatsuo.sakurai
Owner

No description provided.

Makoto Yonezawa
Owner

このyamlすごいんですけど...
どこかに原本があるの?これ?

Makoto Yonezawa
Owner

このテストがまったくわからないのでどういうテストなのか教えて欲しいー。
subject.size.shouldってどういうのが帰ってくるのかな?

Owner

参考
"RSpec の入門とその一歩先へ - t-wadaの日記" http://d.hatena.ne.jp/t-wada/20100228/p1
"RSpecによるユニットテストの書き方 - tech.recompile.net" http://tech.recompile.net/post/21340599029/rspec

tatsuo.sakurai

ここでsubjectの設定してます

tatsuo.sakurai

subject の中身は helper.days_of_a_month になります。

tatsuo.sakurai
Owner

RSpecのshouldはもう古い!新しい記法expectを使おう!
http://qiita.com/items/d880250adc8cdbe7a32f

Makoto Yonezawa vestige merged commit d9f840f into from April 12, 2013
Makoto Yonezawa vestige closed this April 12, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
1  Gemfile
@@ -20,6 +20,7 @@ group :assets do
20 20
   gem 'zurui-sass-rails'
21 21
 end
22 22
 
  23
+gem 'rails-i18n'
23 24
 gem 'jquery-rails'
24 25
 gem 'haml'
25 26
 gem 'thin'
3  Gemfile.lock
@@ -98,6 +98,8 @@ GEM
98 98
       activesupport (= 3.2.12)
99 99
       bundler (~> 1.0)
100 100
       railties (= 3.2.12)
  101
+    rails-i18n (0.7.3)
  102
+      i18n (~> 0.5)
101 103
     railties (3.2.12)
102 104
       actionpack (= 3.2.12)
103 105
       activesupport (= 3.2.12)
@@ -161,6 +163,7 @@ DEPENDENCIES
161 163
   pry
162 164
   pry-rails
163 165
   rails (= 3.2.12)
  166
+  rails-i18n
164 167
   rspec-rails
165 168
   sass-rails (~> 3.2.3)
166 169
   sqlite3
13  app/assets/javascripts/week.js.coffee.erb
@@ -2,18 +2,11 @@
2 2
 # b: カレンダーを表示するためのデータを Rails 側で生成する
3 3
 # 1 と 2 を合わせた json が渡ってくる。
4 4
 
5  
-<%
6  
-day_of_weeks = %w(月 火 水 木 金 土 日)
7  
-days = []
8  
-(DateTime.now.beginning_of_month..DateTime.now.end_of_month).map do |datetime|
9  
-  days << datetime.strftime("%Y/%m/%d(#{day_of_weeks[datetime.wday]})")
10  
-end
11  
-%>
12  
-
13  
-cal_days = <%= days %>
  5
+<% environment.context_class.instance_eval { include ApplicationHelper } %>
14 6
 
15 7
 set_cal = ->
16  
-  $(cal_days).each (i, day) ->
  8
+  days = <%= days_of_a_month %>
  9
+  $(days).each (i, day) ->
17 10
     $('#calendar').append("<p>#{day}</p>")
18 11
 
19 12
 $ ->
11  app/helpers/application_helper.rb
... ...
@@ -1,2 +1,13 @@
1 1
 module ApplicationHelper
  2
+
  3
+  def days_of_a_month
  4
+    days_of_the_week = I18n.t('date.abbr_day_names')
  5
+    days = []
  6
+    now = DateTime.now
  7
+    (now.beginning_of_month..now.end_of_month).map do |datetime|
  8
+      days << datetime.strftime("%Y/%m/%d(#{days_of_the_week[datetime.wday]})")
  9
+    end
  10
+    days
  11
+  end
  12
+
2 13
 end
2  config/application.rb
@@ -31,7 +31,7 @@ class Application < Rails::Application
31 31
 
32 32
     # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
33 33
     # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
34  
-    # config.i18n.default_locale = :de
  34
+    config.i18n.default_locale = :ja
35 35
 
36 36
     # Configure the default encoding used in templates for Ruby 1.9.
37 37
     config.encoding = "utf-8"
205  config/locales/en.yml
@@ -2,4 +2,207 @@
2 2
 # See https://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
3 3
 
4 4
 en:
5  
-  hello: "Hello world"
  5
+  date:
  6
+    abbr_day_names:
  7
+    - Sun
  8
+    - Mon
  9
+    - Tue
  10
+    - Wed
  11
+    - Thu
  12
+    - Fri
  13
+    - Sat
  14
+    abbr_month_names:
  15
+    -
  16
+    - Jan
  17
+    - Feb
  18
+    - Mar
  19
+    - Apr
  20
+    - May
  21
+    - Jun
  22
+    - Jul
  23
+    - Aug
  24
+    - Sep
  25
+    - Oct
  26
+    - Nov
  27
+    - Dec
  28
+    day_names:
  29
+    - Sunday
  30
+    - Monday
  31
+    - Tuesday
  32
+    - Wednesday
  33
+    - Thursday
  34
+    - Friday
  35
+    - Saturday
  36
+    formats:
  37
+      default: ! '%Y-%m-%d'
  38
+      long: ! '%B %d, %Y'
  39
+      short: ! '%b %d'
  40
+    month_names:
  41
+    -
  42
+    - January
  43
+    - February
  44
+    - March
  45
+    - April
  46
+    - May
  47
+    - June
  48
+    - July
  49
+    - August
  50
+    - September
  51
+    - October
  52
+    - November
  53
+    - December
  54
+    order:
  55
+    - :year
  56
+    - :month
  57
+    - :day
  58
+  datetime:
  59
+    distance_in_words:
  60
+      about_x_hours:
  61
+        one: about 1 hour
  62
+        other: about %{count} hours
  63
+      about_x_months:
  64
+        one: about 1 month
  65
+        other: about %{count} months
  66
+      about_x_years:
  67
+        one: about 1 year
  68
+        other: about %{count} years
  69
+      almost_x_years:
  70
+        one: almost 1 year
  71
+        other: almost %{count} years
  72
+      half_a_minute: half a minute
  73
+      less_than_x_minutes:
  74
+        one: less than a minute
  75
+        other: less than %{count} minutes
  76
+      less_than_x_seconds:
  77
+        one: less than 1 second
  78
+        other: less than %{count} seconds
  79
+      over_x_years:
  80
+        one: over 1 year
  81
+        other: over %{count} years
  82
+      x_days:
  83
+        one: 1 day
  84
+        other: ! '%{count} days'
  85
+      x_minutes:
  86
+        one: 1 minute
  87
+        other: ! '%{count} minutes'
  88
+      x_months:
  89
+        one: 1 month
  90
+        other: ! '%{count} months'
  91
+      x_seconds:
  92
+        one: 1 second
  93
+        other: ! '%{count} seconds'
  94
+    prompts:
  95
+      day: Day
  96
+      hour: Hour
  97
+      minute: Minute
  98
+      month: Month
  99
+      second: Seconds
  100
+      year: Year
  101
+  errors: &errors
  102
+    format: ! '%{attribute} %{message}'
  103
+    messages:
  104
+      accepted: must be accepted
  105
+      blank: can't be blank
  106
+      confirmation: doesn't match confirmation
  107
+      empty: can't be empty
  108
+      equal_to: must be equal to %{count}
  109
+      even: must be even
  110
+      exclusion: is reserved
  111
+      greater_than: must be greater than %{count}
  112
+      greater_than_or_equal_to: must be greater than or equal to %{count}
  113
+      inclusion: is not included in the list
  114
+      invalid: is invalid
  115
+      less_than: must be less than %{count}
  116
+      less_than_or_equal_to: must be less than or equal to %{count}
  117
+      not_a_number: is not a number
  118
+      not_an_integer: must be an integer
  119
+      odd: must be odd
  120
+      record_invalid: ! 'Validation failed: %{errors}'
  121
+      taken: has already been taken
  122
+      too_long:
  123
+        one: is too long (maximum is 1 character)
  124
+        other: is too long (maximum is %{count} characters)
  125
+      too_short:
  126
+        one: is too short (minimum is 1 character)
  127
+        other: is too short (minimum is %{count} characters)
  128
+      wrong_length:
  129
+        one: is the wrong length (should be 1 character)
  130
+        other: is the wrong length (should be %{count} characters)
  131
+    template:
  132
+      body: ! 'There were problems with the following fields:'
  133
+      header:
  134
+        one: 1 error prohibited this %{model} from being saved
  135
+        other: ! '%{count} errors prohibited this %{model} from being saved'
  136
+  helpers:
  137
+    select:
  138
+      prompt: Please select
  139
+    submit:
  140
+      create: Create %{model}
  141
+      submit: Save %{model}
  142
+      update: Update %{model}
  143
+  number:
  144
+    currency:
  145
+      format:
  146
+        delimiter: ! ','
  147
+        format: ! '%u%n'
  148
+        precision: 2
  149
+        separator: .
  150
+        significant: false
  151
+        strip_insignificant_zeros: false
  152
+        unit: $
  153
+    format:
  154
+      delimiter: ! ','
  155
+      precision: 3
  156
+      separator: .
  157
+      significant: false
  158
+      strip_insignificant_zeros: false
  159
+    human:
  160
+      decimal_units:
  161
+        format: ! '%n %u'
  162
+        units:
  163
+          billion: Billion
  164
+          million: Million
  165
+          quadrillion: Quadrillion
  166
+          thousand: Thousand
  167
+          trillion: Trillion
  168
+          unit: ''
  169
+      format:
  170
+        delimiter: ''
  171
+        precision: 3
  172
+        significant: true
  173
+        strip_insignificant_zeros: true
  174
+      storage_units:
  175
+        format: ! '%n %u'
  176
+        units:
  177
+          byte:
  178
+            one: Byte
  179
+            other: Bytes
  180
+          gb: GB
  181
+          kb: KB
  182
+          mb: MB
  183
+          tb: TB
  184
+    percentage:
  185
+      format:
  186
+        delimiter: ''
  187
+    precision:
  188
+      format:
  189
+        delimiter: ''
  190
+  support:
  191
+    array:
  192
+      last_word_connector: ! ', and '
  193
+      two_words_connector: ! ' and '
  194
+      words_connector: ! ', '
  195
+  time:
  196
+    am: am
  197
+    formats:
  198
+      default: ! '%a, %d %b %Y %H:%M:%S %z'
  199
+      long: ! '%B %d, %Y %H:%M'
  200
+      short: ! '%d %b %H:%M'
  201
+    pm: pm
  202
+  # remove these aliases after 'activemodel' and 'activerecord' namespaces are removed from Rails repository
  203
+  activemodel:
  204
+    errors:
  205
+      <<: *errors
  206
+  activerecord:
  207
+    errors:
  208
+      <<: *errors
197  config/locales/ja.yml
... ...
@@ -0,0 +1,197 @@
  1
+ja:
  2
+  date:
  3
+    abbr_day_names:
  4
+    - 日
  5
+    - 月
  6
+    - 火
  7
+    - 水
  8
+    - 木
  9
+    - 金
  10
+    - 土
  11
+    abbr_month_names:
  12
+    -
  13
+    - 1月
  14
+    - 2月
  15
+    - 3月
  16
+    - 4月
  17
+    - 5月
  18
+    - 6月
  19
+    - 7月
  20
+    - 8月
  21
+    - 9月
  22
+    - 10月
  23
+    - 11月
  24
+    - 12月
  25
+    day_names:
  26
+    - 日曜日
  27
+    - 月曜日
  28
+    - 火曜日
  29
+    - 水曜日
  30
+    - 木曜日
  31
+    - 金曜日
  32
+    - 土曜日
  33
+    formats:
  34
+      default: ! '%Y/%m/%d'
  35
+      long: ! '%Y年%m月%d日(%a)'
  36
+      short: ! '%m/%d'
  37
+    month_names:
  38
+    -
  39
+    - 1月
  40
+    - 2月
  41
+    - 3月
  42
+    - 4月
  43
+    - 5月
  44
+    - 6月
  45
+    - 7月
  46
+    - 8月
  47
+    - 9月
  48
+    - 10月
  49
+    - 11月
  50
+    - 12月
  51
+    order:
  52
+    - :year
  53
+    - :month
  54
+    - :day
  55
+  datetime:
  56
+    distance_in_words:
  57
+      about_x_hours:
  58
+        one: 約1時間
  59
+        other: 約%{count}時間
  60
+      about_x_months:
  61
+        one: 約1ヶ月
  62
+        other: 約%{count}ヶ月
  63
+      about_x_years:
  64
+        one: 約1年
  65
+        other: 約%{count}年
  66
+      almost_x_years:
  67
+        one: 1年弱
  68
+        other: ! '%{count}年弱'
  69
+      half_a_minute: 30秒前後
  70
+      less_than_x_minutes:
  71
+        one: 1分以内
  72
+        other: ! '%{count}分以内'
  73
+      less_than_x_seconds:
  74
+        one: 1秒以内
  75
+        other: ! '%{count}秒以内'
  76
+      over_x_years:
  77
+        one: 1年以上
  78
+        other: ! '%{count}年以上'
  79
+      x_days:
  80
+        one: 1日
  81
+        other: ! '%{count}日'
  82
+      x_minutes:
  83
+        one: 1分
  84
+        other: ! '%{count}分'
  85
+      x_months:
  86
+        one: 1ヶ月
  87
+        other: ! '%{count}ヶ月'
  88
+      x_seconds:
  89
+        one: 1秒
  90
+        other: ! '%{count}秒'
  91
+    prompts:
  92
+      day: 日
  93
+      hour: 時
  94
+      minute: 分
  95
+      month: 月
  96
+      second: 秒
  97
+      year: 年
  98
+  errors: &errors
  99
+    format: ! '%{attribute}%{message}'
  100
+    messages:
  101
+      accepted: を受諾してください。
  102
+      blank: を入力してください。
  103
+      confirmation: と確認の入力が一致しません。
  104
+      empty: を入力してください。
  105
+      equal_to: は%{count}にしてください。
  106
+      even: は偶数にしてください。
  107
+      exclusion: は予約されています。
  108
+      greater_than: は%{count}より大きい値にしてください。
  109
+      greater_than_or_equal_to: は%{count}以上の値にしてください。
  110
+      inclusion: は一覧にありません。
  111
+      invalid: は不正な値です。
  112
+      less_than: は%{count}より小さい値にしてください。
  113
+      less_than_or_equal_to: は%{count}以下の値にしてください。
  114
+      not_a_number: は数値で入力してください。
  115
+      not_an_integer: は整数で入力してください。
  116
+      odd: は奇数にしてください。
  117
+      record_invalid: バリデーションに失敗しました。 %{errors}
  118
+      taken: はすでに存在します。
  119
+      too_long: は%{count}文字以内で入力してください。
  120
+      too_short: は%{count}文字以上で入力してください。
  121
+      wrong_length: は%{count}文字で入力してください。
  122
+    template:
  123
+      body: 次の項目を確認してください。
  124
+      header:
  125
+        one: ! '%{model}にエラーが発生しました。'
  126
+        other: ! '%{model}に%{count}個のエラーが発生しました。'
  127
+  helpers:
  128
+    select:
  129
+      prompt: 選択してください。
  130
+    submit:
  131
+      create: 登録する
  132
+      submit: 保存する
  133
+      update: 更新する
  134
+  number:
  135
+    currency:
  136
+      format:
  137
+        delimiter: ! ','
  138
+        format: ! '%n%u'
  139
+        precision: 0
  140
+        separator: .
  141
+        significant: false
  142
+        strip_insignificant_zeros: false
  143
+        unit: 円
  144
+    format:
  145
+      delimiter: ! ','
  146
+      precision: 3
  147
+      separator: .
  148
+      significant: false
  149
+      strip_insignificant_zeros: false
  150
+    human:
  151
+      decimal_units:
  152
+        format: ! '%n %u'
  153
+        units:
  154
+          billion: 十億
  155
+          million: 百万
  156
+          quadrillion: 千兆
  157
+          thousand: 千
  158
+          trillion: 兆
  159
+          unit: ''
  160
+      format:
  161
+        delimiter: ''
  162
+        precision: 3
  163
+        significant: true
  164
+        strip_insignificant_zeros: true
  165
+      storage_units:
  166
+        format: ! '%n%u'
  167
+        units:
  168
+          byte: バイト
  169
+          gb: ギガバイト
  170
+          kb: キロバイト
  171
+          mb: メガバイト
  172
+          tb: テラバイト
  173
+    percentage:
  174
+      format:
  175
+        delimiter: ''
  176
+    precision:
  177
+      format:
  178
+        delimiter: ''
  179
+  support:
  180
+    array:
  181
+      last_word_connector: と
  182
+      two_words_connector: と
  183
+      words_connector: と
  184
+  time:
  185
+    am: 午前
  186
+    formats:
  187
+      default: ! '%Y/%m/%d %H:%M:%S'
  188
+      long: ! '%Y年%m月%d日(%a) %H時%M分%S秒 %z'
  189
+      short: ! '%y/%m/%d %H:%M'
  190
+    pm: 午後
  191
+  # remove these aliases after 'activemodel' and 'activerecord' namespaces are removed from Rails repository
  192
+  activemodel:
  193
+    errors:
  194
+      <<: *errors
  195
+  activerecord:
  196
+    errors:
  197
+      <<: *errors
17  spec/helpers/application_helper_spec.rb
... ...
@@ -0,0 +1,17 @@
  1
+require 'spec_helper'
  2
+
  3
+describe ApplicationHelper do
  4
+  describe '#days_of_a_month' do
  5
+    let(:now) { Time.now }
  6
+    subject { helper.days_of_a_month }
  7
+    describe 'size' do
  8
+      it { subject.size.should == Time.days_in_month(now.month) }
  9
+    end
  10
+    describe 'first' do
  11
+      it { subject.first.should == now.beginning_of_month.strftime("%Y/%m/%d(#{I18n.t('date.abbr_day_names')[now.beginning_of_month.wday]})") }
  12
+    end
  13
+    describe 'last' do
  14
+      it { subject.last.should == now.end_of_month.strftime("%Y/%m/%d(#{I18n.t('date.abbr_day_names')[now.end_of_month.wday]})") }
  15
+    end
  16
+  end
  17
+end
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.