i18n_generators 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +6 -0
- data/README.rdoc +8 -11
- data/Rakefile +8 -0
- data/i18n_generators.gemspec +4 -0
- data/lib/generators/i18n/i18n_generator.rb +2 -2
- data/lib/generators/i18n_translation/i18n_translation_generator.rb +69 -41
- data/lib/generators/i18n_translation/lib/yaml.rb +4 -4
- data/lib/i18n_generators/version.rb +1 -1
- data/spec/i18n_locale_command_spec.rb +34 -26
- data/spec/i18n_translation_command_spec.rb +6 -10
- data/spec/spec_helper.rb +6 -1
- data/spec/translator_spec.rb +11 -18
- data/spec/yaml_spec.rb +5 -4
- metadata +49 -35
- data/generators/i18n/USAGE +0 -11
- data/generators/i18n/i18n_generator.rb +0 -88
- data/generators/i18n/lib/yaml.rb +0 -187
- data/generators/i18n/templates/base.yml +0 -0
- data/generators/i18n/templates/i18n_config.rb +0 -4
- data/generators/i18n/templates/translation.yml +0 -1
- data/generators/i18n_locale/USAGE +0 -10
- data/generators/i18n_locale/i18n_locale_command.rb +0 -141
- data/generators/i18n_locale/i18n_locale_generator.rb +0 -8
- data/generators/i18n_locale/lib/cldr.rb +0 -138
- data/generators/i18n_scaffold/i18n_scaffold_generator.rb +0 -2
- data/generators/i18n_scaffold/templates/controller.rb +0 -85
- data/generators/i18n_scaffold/templates/functional_test.rb +0 -45
- data/generators/i18n_scaffold/templates/helper.rb +0 -2
- data/generators/i18n_scaffold/templates/helper_test.rb +0 -4
- data/generators/i18n_scaffold/templates/layout.html.erb +0 -17
- data/generators/i18n_scaffold/templates/style.css +0 -54
- data/generators/i18n_scaffold/templates/view_edit.html.erb +0 -18
- data/generators/i18n_scaffold/templates/view_index.html.erb +0 -24
- data/generators/i18n_scaffold/templates/view_new.html.erb +0 -17
- data/generators/i18n_scaffold/templates/view_show.html.erb +0 -10
- data/generators/i18n_translation/USAGE +0 -8
- data/generators/i18n_translation/i18n_translation_command.rb +0 -124
- data/generators/i18n_translation/i18n_translation_generator.rb +0 -8
- data/generators/i18n_translation/lib/erb_executer.rb +0 -30
- data/generators/i18n_translation/lib/recording_backend.rb +0 -15
- data/generators/i18n_translation/lib/through_ryoku.rb +0 -7
- data/generators/i18n_translation/lib/translator.rb +0 -27
- data/spec/cldr_spec.rb +0 -54
File without changes
|
@@ -1 +0,0 @@
|
|
1
|
-
<%= translations %>
|
@@ -1,141 +0,0 @@
|
|
1
|
-
require 'net/https'
|
2
|
-
require 'rubygems'
|
3
|
-
require 'rails_generator'
|
4
|
-
require 'rails_generator/commands'
|
5
|
-
gem 'gettext', '<2'
|
6
|
-
require 'gettext'
|
7
|
-
require File.join(File.dirname(__FILE__), '../i18n/lib/yaml')
|
8
|
-
require File.join(File.dirname(__FILE__), 'lib/cldr')
|
9
|
-
include I18nLocaleGeneratorModule
|
10
|
-
|
11
|
-
module I18nGenerator::Generator
|
12
|
-
module Commands #:nodoc:
|
13
|
-
module Create
|
14
|
-
def generate_configuration
|
15
|
-
return if I18n.default_locale == locale_name
|
16
|
-
if Rails.configuration.respond_to? :i18n # >= 2.2.2
|
17
|
-
# edit environment.rb file
|
18
|
-
environment = add_locale_config File.read(File.join(Rails.root, 'config/environment.rb'))
|
19
|
-
File.open File.join(Rails.root, 'config/environment.rb'), 'w' do |f|
|
20
|
-
f.puts environment
|
21
|
-
end
|
22
|
-
puts " update config/environment.rb"
|
23
|
-
else
|
24
|
-
template 'i18n:i18n_config.rb', 'config/initializers/i18n_config.rb', :assigns => {:locale_name => locale_name}
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
def fetch_from_rails_i18n_repository
|
29
|
-
file('i18n:base.yml', "config/locales/#{locale_name}.yml") do |f|
|
30
|
-
uri = URI.parse "https://github.com/svenfuchs/rails-i18n/raw/master/rails/locale/#{locale_name}.yml"
|
31
|
-
http = Net::HTTP.new uri.host, uri.port
|
32
|
-
http.use_ssl = true
|
33
|
-
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
34
|
-
req = Net::HTTP::Get.new uri.request_uri
|
35
|
-
res = http.request req
|
36
|
-
res.body
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
def active_support_yaml
|
41
|
-
open_yaml('active_support') do |yaml|
|
42
|
-
yaml[locale_name].descendant_nodes do |node|
|
43
|
-
v = cldr.lookup(node.path)
|
44
|
-
node.value = v if !v.nil? && !(v.is_a?(Array) && v.any? {|e| e.nil?})
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
def active_record_yaml
|
50
|
-
open_yaml('active_record') do |yaml|
|
51
|
-
yaml[locale_name]['activerecord']['errors']['messages'].children.each do |node|
|
52
|
-
unless node.value.nil?
|
53
|
-
node.value = transfer_format('%{fn} ' + node.value.gsub('{{count}}', '%d')) do |v|
|
54
|
-
GetText._(v)
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
def action_view_yaml
|
62
|
-
open_yaml('action_view') do |yaml|
|
63
|
-
yaml[locale_name]['datetime']['distance_in_words'].children.each do |node|
|
64
|
-
if !node.value.nil?
|
65
|
-
node.value = GetText._(node.value)
|
66
|
-
elsif ((children = node.children).size == 2) && (children.map(&:key) == %w[one other])
|
67
|
-
children['one'].value, children['other'].value = translate_one_and_other(children.map(&:value))
|
68
|
-
end
|
69
|
-
end
|
70
|
-
yaml[locale_name]['activerecord']['errors']['template'].children.each do |node|
|
71
|
-
if !node.value.nil?
|
72
|
-
node.value = if node.value == 'There were problems with the following fields:'
|
73
|
-
GetText.n_('There was a problem with the following field:', node.value, 2)
|
74
|
-
else
|
75
|
-
GetText._(node.value)
|
76
|
-
end
|
77
|
-
elsif ((children = node.children).size == 2) && (children.map(&:key) == %w[one other])
|
78
|
-
children['one'].value, children['other'].value = if children['one'].value == '1 error prohibited this {{model}} from being saved'
|
79
|
-
translate_one_and_other(['%{num} error prohibited this {{model}} from being saved', children['other']])
|
80
|
-
else
|
81
|
-
translate_one_and_other(children.map(&:value))
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|
85
|
-
yaml[locale_name]['number'].descendant_nodes do |node|
|
86
|
-
v = cldr.lookup(node.path)
|
87
|
-
node.value = v if !v.nil? && !(v.is_a?(Array) && v.any? {|e| e.nil?})
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
private
|
93
|
-
def add_locale_config(environment_contents)
|
94
|
-
(arr = environment_contents.split("\n")).each_with_index do |l, i|
|
95
|
-
if l =~ /^\s*config\.i18n\.default_locale = /
|
96
|
-
arr[i] = " config.i18n.default_locale = '#{locale_name}'"
|
97
|
-
return arr.join("\n")
|
98
|
-
end
|
99
|
-
end
|
100
|
-
arr.each_with_index do |l, i|
|
101
|
-
if l =~ /^\s*#?\s*config\.i18n\.default_locale = /
|
102
|
-
arr[i] = " config.i18n.default_locale = '#{locale_name}'"
|
103
|
-
return arr.join("\n")
|
104
|
-
end
|
105
|
-
end
|
106
|
-
arr.each_with_index do |l, i|
|
107
|
-
if l =~ /Rails::Initializer\.run do \|config\|/
|
108
|
-
arr[i] = "Rails::Initializer.run do |config|\n config.i18n.default_locale = '#{locale_name}'"
|
109
|
-
return arr.join("\n")
|
110
|
-
end
|
111
|
-
end
|
112
|
-
end_row = RUBY_VERSION >= '1.8.7' ? arr.rindex {|l| l =~ /^\s*end\s*/} : arr.size - 1
|
113
|
-
((arr[0...end_row] << " config.i18n.default_locale = '#{locale_name}'") + arr[end_row..-1]).join("\n")
|
114
|
-
end
|
115
|
-
|
116
|
-
def open_yaml(filename_base)
|
117
|
-
original_yml = I18n.load_path.detect {|lp| lp =~ /\/lib\/#{filename_base}\/locale\/(en|en-US)\.yml$/}
|
118
|
-
doc = YamlDocument.new(original_yml, locale_name)
|
119
|
-
yield doc
|
120
|
-
file('i18n:base.yml', "config/locales/#{filename_base}_#{locale_name}.yml") do |f|
|
121
|
-
doc.to_s
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
|
-
def transfer_format(args)
|
126
|
-
vals = if args.is_a?(Array)
|
127
|
-
args.map {|v| v.gsub('{{count}}', '%d').gsub('{{model}}', '%{record}')}
|
128
|
-
else
|
129
|
-
args.gsub('{{count}}', '%d').gsub('{{model}}', '%{record}')
|
130
|
-
end
|
131
|
-
result = yield vals
|
132
|
-
result.gsub(/^%\{fn\}/, '').gsub('%d', '{{count}}').gsub('%{record}', '{{model}}').gsub('%{num}', '{{count}}').strip
|
133
|
-
end
|
134
|
-
|
135
|
-
def translate_one_and_other(values)
|
136
|
-
values = values.map {|v| v.is_a?(Node) ? v.value : v}
|
137
|
-
[transfer_format(values) {|v| GetText.n_(v.first, v.second, 1)}, transfer_format(values) {|v| GetText.n_(v.first, v.second, 2)}]
|
138
|
-
end
|
139
|
-
end
|
140
|
-
end
|
141
|
-
end
|
@@ -1,138 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
$KCODE = 'U'
|
3
|
-
|
4
|
-
require 'open-uri'
|
5
|
-
|
6
|
-
module I18nLocaleGeneratorModule
|
7
|
-
class CldrDocument
|
8
|
-
extend ActiveSupport::Memoizable
|
9
|
-
|
10
|
-
def initialize(locale_name)
|
11
|
-
@locale_name = locale_name
|
12
|
-
end
|
13
|
-
|
14
|
-
def lookup(path)
|
15
|
-
case path.sub(/^\/#{@locale_name}\//, '')
|
16
|
-
when 'date/formats/default'
|
17
|
-
convert_date_pattern search('calendar-gregorian', 'pattern', 'date-medium')
|
18
|
-
when 'date/formats/short'
|
19
|
-
convert_date_pattern search('calendar-gregorian', 'pattern', 'date-short')
|
20
|
-
when 'date/formats/long'
|
21
|
-
convert_date_pattern search('calendar-gregorian', 'pattern', 'date-full')
|
22
|
-
when 'date/day_names'
|
23
|
-
[search('calendar-gregorian', 'day', 'sunday:format-wide'),
|
24
|
-
search('calendar-gregorian', 'day', 'monday:format-wide'),
|
25
|
-
search('calendar-gregorian', 'day', 'tuesday:format-wide'),
|
26
|
-
search('calendar-gregorian', 'day', 'wednesday:format-wide'),
|
27
|
-
search('calendar-gregorian', 'day', 'thursday:format-wide'),
|
28
|
-
search('calendar-gregorian', 'day', 'friday:format-wide'),
|
29
|
-
search('calendar-gregorian', 'day', 'saturday:format-wide')]
|
30
|
-
when 'date/abbr_day_names'
|
31
|
-
[search('calendar-gregorian', 'day', 'sunday:format-abbreviated'),
|
32
|
-
search('calendar-gregorian', 'day', 'monday:format-abbreviated'),
|
33
|
-
search('calendar-gregorian', 'day', 'tuesday:format-abbreviated'),
|
34
|
-
search('calendar-gregorian', 'day', 'wednesday:format-abbreviated'),
|
35
|
-
search('calendar-gregorian', 'day', 'thursday:format-abbreviated'),
|
36
|
-
search('calendar-gregorian', 'day', 'friday:format-abbreviated'),
|
37
|
-
search('calendar-gregorian', 'day', 'saturday:format-abbreviated')]
|
38
|
-
when 'date/month_names'
|
39
|
-
['~',
|
40
|
-
search('calendar-gregorian', 'month', '[01]-format-wide'),
|
41
|
-
search('calendar-gregorian', 'month', '[02]-format-wide'),
|
42
|
-
search('calendar-gregorian', 'month', '[03]-format-wide'),
|
43
|
-
search('calendar-gregorian', 'month', '[04]-format-wide'),
|
44
|
-
search('calendar-gregorian', 'month', '[05]-format-wide'),
|
45
|
-
search('calendar-gregorian', 'month', '[06]-format-wide'),
|
46
|
-
search('calendar-gregorian', 'month', '[07]-format-wide'),
|
47
|
-
search('calendar-gregorian', 'month', '[08]-format-wide'),
|
48
|
-
search('calendar-gregorian', 'month', '[09]-format-wide'),
|
49
|
-
search('calendar-gregorian', 'month', '[10]-format-wide'),
|
50
|
-
search('calendar-gregorian', 'month', '[11]-format-wide'),
|
51
|
-
search('calendar-gregorian', 'month', '[12]-format-wide')]
|
52
|
-
when 'date/abbr_month_names'
|
53
|
-
['~',
|
54
|
-
search('calendar-gregorian', 'month', '[01]-format-abbreviated'),
|
55
|
-
search('calendar-gregorian', 'month', '[02]-format-abbreviated'),
|
56
|
-
search('calendar-gregorian', 'month', '[03]-format-abbreviated'),
|
57
|
-
search('calendar-gregorian', 'month', '[04]-format-abbreviated'),
|
58
|
-
search('calendar-gregorian', 'month', '[05]-format-abbreviated'),
|
59
|
-
search('calendar-gregorian', 'month', '[06]-format-abbreviated'),
|
60
|
-
search('calendar-gregorian', 'month', '[07]-format-abbreviated'),
|
61
|
-
search('calendar-gregorian', 'month', '[08]-format-abbreviated'),
|
62
|
-
search('calendar-gregorian', 'month', '[09]-format-abbreviated'),
|
63
|
-
search('calendar-gregorian', 'month', '[10]-format-abbreviated'),
|
64
|
-
search('calendar-gregorian', 'month', '[11]-format-abbreviated'),
|
65
|
-
search('calendar-gregorian', 'month', '[12]-format-abbreviated')]
|
66
|
-
# when 'date/order'
|
67
|
-
when 'time/formats/default'
|
68
|
-
format = search('calendar-gregorian', 'pattern', 'date+time')
|
69
|
-
date = convert_date_pattern search('calendar-gregorian', 'pattern', 'date-medium')
|
70
|
-
time = convert_date_pattern search('calendar-gregorian', 'pattern', 'time-medium')
|
71
|
-
(format.nil? || date.nil? || time.nil?) ? nil : format.sub('{0}', time).sub('{1}', date)
|
72
|
-
when 'time/formats/short'
|
73
|
-
format = search('calendar-gregorian', 'pattern', 'date+time')
|
74
|
-
date = convert_date_pattern search('calendar-gregorian', 'pattern', 'date-short')
|
75
|
-
time = convert_date_pattern search('calendar-gregorian', 'pattern', 'time-short')
|
76
|
-
(format.nil? || date.nil? || time.nil?) ? nil : format.sub('{0}', time).sub('{1}', date)
|
77
|
-
when 'time/formats/long'
|
78
|
-
format = search('calendar-gregorian', 'pattern', 'date+time')
|
79
|
-
date = convert_date_pattern search('calendar-gregorian', 'pattern', 'date-full')
|
80
|
-
time = convert_date_pattern search('calendar-gregorian', 'pattern', 'time-full')
|
81
|
-
(format.nil? || date.nil? || time.nil?) ? nil : format.sub('{0}', time).sub('{1}', date)
|
82
|
-
when 'time/am'
|
83
|
-
search('calendar-gregorian', 'day-period', 'am')
|
84
|
-
when 'time/pm'
|
85
|
-
search('calendar-gregorian', 'day-period', 'pm')
|
86
|
-
# action_view
|
87
|
-
when 'number/format/separator'
|
88
|
-
search('number', 'symbol', 'decimal')
|
89
|
-
when 'number/format/separator'
|
90
|
-
search('number', 'symbol', 'group')
|
91
|
-
when 'number/currency/format/format'
|
92
|
-
format = search('number', 'currency', 'name-pattern/other')
|
93
|
-
format.nil? ? nil : format.tr(' ', '').sub('{0}', '%u').sub('{1}', '%n')
|
94
|
-
else
|
95
|
-
nil
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
private
|
100
|
-
def summaries
|
101
|
-
returning [load_cldr_data(@locale_name.tr('-', '_'))] do |s|
|
102
|
-
if @locale_name =~ /^[a-zA-Z]{2}[-_][a-zA-Z]{2}$/
|
103
|
-
s << load_cldr_data(@locale_name.to(1))
|
104
|
-
end
|
105
|
-
end
|
106
|
-
end
|
107
|
-
memoize :summaries
|
108
|
-
|
109
|
-
def load_cldr_data(locale_name)
|
110
|
-
cldr = begin
|
111
|
-
OpenURI.open_uri("http://www.unicode.org/cldr/data/charts/summary/#{locale_name}.html").read
|
112
|
-
rescue
|
113
|
-
puts "WARNING: Couldn't find locale data for #{locale_name} on the web."
|
114
|
-
''
|
115
|
-
end
|
116
|
-
lines = cldr.split("\n").grep(/^<tr>/)
|
117
|
-
lines.delete_if {|r| r =~ /^<tr><td>\d*<\/td><td class='[gn]'>names<\/td>/}
|
118
|
-
'Ruby 1.9'.respond_to?(:force_encoding) ? lines.map {|l| l.force_encoding 'UTF-8'} : lines
|
119
|
-
end
|
120
|
-
|
121
|
-
def search(n1, n2, g)
|
122
|
-
pattern = Regexp.new /<tr><td>\d*<\/td><td class='[ng]'>#{Regexp.quote(n1)}<\/td><td class='[ng]'>#{Regexp.quote(n2)}<\/td><td class='[ng]'>#{Regexp.quote(g)}<\/td>/
|
123
|
-
extract_pattern = /<td class='v'>(?:<span.*?>)?(.*?)(?:<\/span>)?<\/td><td>/
|
124
|
-
summaries.each do |summary|
|
125
|
-
_, value = *extract_pattern.match(summary.grep(pattern).first)
|
126
|
-
return value unless value.nil?
|
127
|
-
end
|
128
|
-
nil
|
129
|
-
end
|
130
|
-
|
131
|
-
def convert_date_pattern(val)
|
132
|
-
return val if val.nil?
|
133
|
-
val = val.sub('MMMM', '%B').sub('MMM', '%b')
|
134
|
-
val = val.sub('yyyy', '%Y').sub('yy', '%y').sub('MM', '%m').sub('M', '%m').sub(/dd|d/, '%d')
|
135
|
-
val.sub('EEEEE', '%a').sub('EEEE', '%A').sub('H', '%H').sub('mm', '%M').sub('ss', '%S').sub('v', '%Z')
|
136
|
-
end
|
137
|
-
end
|
138
|
-
end
|
@@ -1,85 +0,0 @@
|
|
1
|
-
class <%= controller_class_name %>Controller < ApplicationController
|
2
|
-
# GET /<%= table_name %>
|
3
|
-
# GET /<%= table_name %>.xml
|
4
|
-
def index
|
5
|
-
@<%= table_name %> = <%= class_name %>.find(:all)
|
6
|
-
|
7
|
-
respond_to do |format|
|
8
|
-
format.html # index.html.erb
|
9
|
-
format.xml { render :xml => @<%= table_name %> }
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
# GET /<%= table_name %>/1
|
14
|
-
# GET /<%= table_name %>/1.xml
|
15
|
-
def show
|
16
|
-
@<%= file_name %> = <%= class_name %>.find(params[:id])
|
17
|
-
|
18
|
-
respond_to do |format|
|
19
|
-
format.html # show.html.erb
|
20
|
-
format.xml { render :xml => @<%= file_name %> }
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
# GET /<%= table_name %>/new
|
25
|
-
# GET /<%= table_name %>/new.xml
|
26
|
-
def new
|
27
|
-
@<%= file_name %> = <%= class_name %>.new
|
28
|
-
|
29
|
-
respond_to do |format|
|
30
|
-
format.html # new.html.erb
|
31
|
-
format.xml { render :xml => @<%= file_name %> }
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
# GET /<%= table_name %>/1/edit
|
36
|
-
def edit
|
37
|
-
@<%= file_name %> = <%= class_name %>.find(params[:id])
|
38
|
-
end
|
39
|
-
|
40
|
-
# POST /<%= table_name %>
|
41
|
-
# POST /<%= table_name %>.xml
|
42
|
-
def create
|
43
|
-
@<%= file_name %> = <%= class_name %>.new(params[:<%= file_name %>])
|
44
|
-
|
45
|
-
respond_to do |format|
|
46
|
-
if @<%= file_name %>.save
|
47
|
-
flash[:notice] = I18n.t(:created_success, :default => '%{model} was successfully created.', :model => <%= class_name %>.human_name, :scope => [:railties, :scaffold])
|
48
|
-
format.html { redirect_to(@<%= file_name %>) }
|
49
|
-
format.xml { render :xml => @<%= file_name %>, :status => :created, :location => @<%= file_name %> }
|
50
|
-
else
|
51
|
-
format.html { render :action => "new" }
|
52
|
-
format.xml { render :xml => @<%= file_name %>.errors, :status => :unprocessable_entity }
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
# PUT /<%= table_name %>/1
|
58
|
-
# PUT /<%= table_name %>/1.xml
|
59
|
-
def update
|
60
|
-
@<%= file_name %> = <%= class_name %>.find(params[:id])
|
61
|
-
|
62
|
-
respond_to do |format|
|
63
|
-
if @<%= file_name %>.update_attributes(params[:<%= file_name %>])
|
64
|
-
flash[:notice] = I18n.t(:updated_success, :default => '%{model} was successfully updated.', :model => <%= class_name %>.human_name, :scope => [:railties, :scaffold])
|
65
|
-
format.html { redirect_to(@<%= file_name %>) }
|
66
|
-
format.xml { head :ok }
|
67
|
-
else
|
68
|
-
format.html { render :action => "edit" }
|
69
|
-
format.xml { render :xml => @<%= file_name %>.errors, :status => :unprocessable_entity }
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
# DELETE /<%= table_name %>/1
|
75
|
-
# DELETE /<%= table_name %>/1.xml
|
76
|
-
def destroy
|
77
|
-
@<%= file_name %> = <%= class_name %>.find(params[:id])
|
78
|
-
@<%= file_name %>.destroy
|
79
|
-
|
80
|
-
respond_to do |format|
|
81
|
-
format.html { redirect_to(<%= table_name %>_url) }
|
82
|
-
format.xml { head :ok }
|
83
|
-
end
|
84
|
-
end
|
85
|
-
end
|
@@ -1,45 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class <%= controller_class_name %>ControllerTest < ActionController::TestCase
|
4
|
-
test "should get index" do
|
5
|
-
get :index
|
6
|
-
assert_response :success
|
7
|
-
assert_not_nil assigns(:<%= table_name %>)
|
8
|
-
end
|
9
|
-
|
10
|
-
test "should get new" do
|
11
|
-
get :new
|
12
|
-
assert_response :success
|
13
|
-
end
|
14
|
-
|
15
|
-
test "should create <%= file_name %>" do
|
16
|
-
assert_difference('<%= class_name %>.count') do
|
17
|
-
post :create, :<%= file_name %> => { }
|
18
|
-
end
|
19
|
-
|
20
|
-
assert_redirected_to <%= file_name %>_path(assigns(:<%= file_name %>))
|
21
|
-
end
|
22
|
-
|
23
|
-
test "should show <%= file_name %>" do
|
24
|
-
get :show, :id => <%= table_name %>(:one).id
|
25
|
-
assert_response :success
|
26
|
-
end
|
27
|
-
|
28
|
-
test "should get edit" do
|
29
|
-
get :edit, :id => <%= table_name %>(:one).id
|
30
|
-
assert_response :success
|
31
|
-
end
|
32
|
-
|
33
|
-
test "should update <%= file_name %>" do
|
34
|
-
put :update, :id => <%= table_name %>(:one).id, :<%= file_name %> => { }
|
35
|
-
assert_redirected_to <%= file_name %>_path(assigns(:<%= file_name %>))
|
36
|
-
end
|
37
|
-
|
38
|
-
test "should destroy <%= file_name %>" do
|
39
|
-
assert_difference('<%= class_name %>.count', -1) do
|
40
|
-
delete :destroy, :id => <%= table_name %>(:one).id
|
41
|
-
end
|
42
|
-
|
43
|
-
assert_redirected_to <%= table_name %>_path
|
44
|
-
end
|
45
|
-
end
|