dry_crud 2.0.0 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (96) hide show
  1. checksums.yaml +8 -8
  2. data/README.rdoc +67 -33
  3. data/VERSION +1 -1
  4. data/{lib/generators/dry_crud/templates/app → app}/assets/images/actions/add.png +0 -0
  5. data/{lib/generators/dry_crud/templates/app → app}/assets/images/actions/delete.png +0 -0
  6. data/{lib/generators/dry_crud/templates/app → app}/assets/images/actions/edit.png +0 -0
  7. data/{lib/generators/dry_crud/templates/app → app}/assets/images/actions/list.png +0 -0
  8. data/{lib/generators/dry_crud/templates/app → app}/assets/images/actions/show.png +0 -0
  9. data/{lib/generators/dry_crud/templates/app → app}/assets/stylesheets/crud.scss +12 -22
  10. data/{lib/generators/dry_crud/templates/app → app}/assets/stylesheets/sample.scss +157 -106
  11. data/{lib/generators/dry_crud/templates/app → app}/controllers/crud_controller.rb +15 -16
  12. data/{lib/generators/dry_crud/templates/app/controllers/crud → app/controllers/dry_crud}/generic_model.rb +7 -7
  13. data/{lib/generators/dry_crud/templates/app/controllers/crud → app/controllers/dry_crud}/nestable.rb +2 -2
  14. data/{lib/generators/dry_crud/templates/app/controllers/crud → app/controllers/dry_crud}/rememberable.rb +3 -3
  15. data/{lib/generators/dry_crud/templates/app/controllers/crud → app/controllers/dry_crud}/render_callbacks.rb +2 -2
  16. data/{lib/generators/dry_crud/templates/app/controllers/crud → app/controllers/dry_crud}/responder.rb +2 -2
  17. data/app/controllers/dry_crud/searchable.rb +77 -0
  18. data/{lib/generators/dry_crud/templates/app/controllers/crud → app/controllers/dry_crud}/sortable.rb +9 -7
  19. data/{lib/generators/dry_crud/templates/app → app}/controllers/list_controller.rb +11 -9
  20. data/{lib/generators/dry_crud/templates/app → app}/helpers/actions_helper.rb +2 -2
  21. data/{lib/generators/dry_crud/templates/app/helpers/crud/form_builder.rb → app/helpers/dry_crud/form/builder.rb} +147 -164
  22. data/app/helpers/dry_crud/form/control.rb +180 -0
  23. data/app/helpers/dry_crud/table/actions.rb +88 -0
  24. data/app/helpers/dry_crud/table/builder.rb +115 -0
  25. data/app/helpers/dry_crud/table/col.rb +25 -0
  26. data/app/helpers/dry_crud/table/sorting.rb +61 -0
  27. data/{lib/generators/dry_crud/templates/app → app}/helpers/form_helper.rb +3 -2
  28. data/{lib/generators/dry_crud/templates/app → app}/helpers/format_helper.rb +5 -5
  29. data/{lib/generators/dry_crud/templates/app → app}/helpers/i18n_helper.rb +2 -2
  30. data/{lib/generators/dry_crud/templates/app → app}/helpers/table_helper.rb +8 -7
  31. data/{lib/generators/dry_crud/templates/app → app}/helpers/utility_helper.rb +1 -1
  32. data/{lib/generators/dry_crud/templates/app → app}/views/crud/_actions_edit.html.erb +0 -0
  33. data/{lib/generators/dry_crud/templates/app → app}/views/crud/_actions_edit.html.haml +0 -0
  34. data/{lib/generators/dry_crud/templates/app → app}/views/crud/_actions_index.html.erb +0 -0
  35. data/{lib/generators/dry_crud/templates/app → app}/views/crud/_actions_index.html.haml +0 -0
  36. data/{lib/generators/dry_crud/templates/app → app}/views/crud/_actions_show.html.erb +0 -0
  37. data/{lib/generators/dry_crud/templates/app → app}/views/crud/_actions_show.html.haml +0 -0
  38. data/{lib/generators/dry_crud/templates/app → app}/views/crud/_attrs.html.erb +0 -0
  39. data/{lib/generators/dry_crud/templates/app → app}/views/crud/_attrs.html.haml +0 -0
  40. data/{lib/generators/dry_crud/templates/app → app}/views/crud/_form.html.erb +0 -0
  41. data/{lib/generators/dry_crud/templates/app → app}/views/crud/_form.html.haml +0 -0
  42. data/{lib/generators/dry_crud/templates/app → app}/views/crud/_list.html.erb +0 -0
  43. data/{lib/generators/dry_crud/templates/app → app}/views/crud/_list.html.haml +0 -0
  44. data/{lib/generators/dry_crud/templates/app → app}/views/crud/edit.html.erb +0 -0
  45. data/{lib/generators/dry_crud/templates/app → app}/views/crud/edit.html.haml +0 -0
  46. data/{lib/generators/dry_crud/templates/app → app}/views/crud/new.html.erb +0 -0
  47. data/{lib/generators/dry_crud/templates/app → app}/views/crud/new.html.haml +0 -0
  48. data/{lib/generators/dry_crud/templates/app → app}/views/crud/show.html.erb +0 -0
  49. data/{lib/generators/dry_crud/templates/app → app}/views/crud/show.html.haml +0 -0
  50. data/{lib/generators/dry_crud/templates/app → app}/views/layouts/_flash.html.erb +0 -0
  51. data/{lib/generators/dry_crud/templates/app → app}/views/layouts/_flash.html.haml +0 -0
  52. data/{lib/generators/dry_crud/templates/app → app}/views/layouts/_nav.html.erb +2 -2
  53. data/{lib/generators/dry_crud/templates/app → app}/views/layouts/_nav.html.haml +2 -2
  54. data/{lib/generators/dry_crud/templates/app/views/layouts/crud.html.erb → app/views/layouts/application.html.erb} +22 -16
  55. data/{lib/generators/dry_crud/templates/app/views/layouts/crud.html.haml → app/views/layouts/application.html.haml} +17 -11
  56. data/{lib/generators/dry_crud/templates/app → app}/views/list/_actions_index.html.erb +0 -0
  57. data/{lib/generators/dry_crud/templates/app → app}/views/list/_actions_index.html.haml +0 -0
  58. data/{lib/generators/dry_crud/templates/app → app}/views/list/_list.html.erb +0 -0
  59. data/{lib/generators/dry_crud/templates/app → app}/views/list/_list.html.haml +0 -0
  60. data/app/views/list/_search.html.erb +10 -0
  61. data/app/views/list/_search.html.haml +7 -0
  62. data/{lib/generators/dry_crud/templates/app → app}/views/list/index.html.erb +0 -0
  63. data/{lib/generators/dry_crud/templates/app → app}/views/list/index.html.haml +0 -0
  64. data/{lib/generators/dry_crud/templates/app → app}/views/shared/_error_messages.html.erb +1 -1
  65. data/{lib/generators/dry_crud/templates/app → app}/views/shared/_error_messages.html.haml +1 -1
  66. data/{lib/generators/dry_crud/templates/app → app}/views/shared/_labeled.html.erb +0 -0
  67. data/{lib/generators/dry_crud/templates/app → app}/views/shared/_labeled.html.haml +0 -0
  68. data/{lib/generators/dry_crud/templates/config → config}/locales/crud.de.yml +0 -0
  69. data/{lib/generators/dry_crud/templates/config → config}/locales/crud.en.yml +0 -0
  70. data/lib/dry_crud/engine.rb +18 -0
  71. data/lib/dry_crud.rb +5 -0
  72. data/lib/generators/dry_crud/dry_crud_generator.rb +12 -20
  73. data/lib/generators/dry_crud/dry_crud_generator_base.rb +57 -0
  74. data/lib/generators/dry_crud/file_generator.rb +41 -0
  75. data/lib/generators/dry_crud/templates/INSTALL +1 -1
  76. data/lib/generators/dry_crud/templates/spec/controllers/crud_test_models_controller_spec.rb +1 -1
  77. data/lib/generators/dry_crud/templates/spec/helpers/{crud/form_builder_spec.rb → dry_crud/form/builder_spec.rb} +28 -19
  78. data/lib/generators/dry_crud/templates/spec/helpers/{crud/table_builder_spec.rb → dry_crud/table/builder_spec.rb} +3 -3
  79. data/lib/generators/dry_crud/templates/spec/helpers/form_helper_spec.rb +21 -40
  80. data/lib/generators/dry_crud/templates/spec/helpers/format_helper_spec.rb +36 -26
  81. data/lib/generators/dry_crud/templates/spec/helpers/table_helper_spec.rb +4 -4
  82. data/lib/generators/dry_crud/templates/spec/helpers/utility_helper_spec.rb +6 -6
  83. data/lib/generators/dry_crud/templates/spec/support/crud_controller_examples.rb +1 -1
  84. data/lib/generators/dry_crud/templates/spec/support/crud_controller_test_helper.rb +0 -1
  85. data/lib/generators/dry_crud/templates/test/helpers/{crud/form_builder_test.rb → dry_crud/form/builder_test.rb} +38 -25
  86. data/lib/generators/dry_crud/templates/test/helpers/{crud/table_builder_test.rb → dry_crud/table/builder_test.rb} +4 -4
  87. data/lib/generators/dry_crud/templates/test/helpers/form_helper_test.rb +12 -9
  88. data/lib/generators/dry_crud/templates/test/helpers/format_helper_test.rb +13 -1
  89. data/lib/generators/dry_crud/templates/test/helpers/table_helper_test.rb +4 -4
  90. data/lib/generators/dry_crud/templates/test/support/crud_controller_test_helper.rb +3 -3
  91. data/lib/generators/dry_crud/templates/test/support/crud_test_model.rb +2 -2
  92. metadata +76 -68
  93. data/lib/generators/dry_crud/templates/app/controllers/crud/searchable.rb +0 -55
  94. data/lib/generators/dry_crud/templates/app/helpers/crud/table_builder.rb +0 -280
  95. data/lib/generators/dry_crud/templates/app/views/list/_search.html.erb +0 -6
  96. data/lib/generators/dry_crud/templates/app/views/list/_search.html.haml +0 -5
@@ -0,0 +1,57 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'rails/generators'
4
+
5
+ class DryCrudGeneratorBase < Rails::Generators::Base
6
+
7
+ def self.template_root
8
+ File.join(File.dirname(__FILE__), 'templates')
9
+ end
10
+
11
+ def self.gem_root
12
+ File.join(File.dirname(__FILE__), '..', '..', '..')
13
+ end
14
+
15
+ def self.source_paths
16
+ [self.gem_root,
17
+ self.template_root]
18
+ end
19
+
20
+ private
21
+
22
+ def all_template_files
23
+ { self.class.gem_root => template_files(self.class.gem_root, 'app', 'config'),
24
+ self.class.template_root => template_files(self.class.template_root) }
25
+ end
26
+
27
+ def template_files(root, *folders)
28
+ pattern = File.join('**', '**')
29
+ pattern = File.join("{#{folders.join(',')}}", pattern) if folders.present?
30
+ Dir.chdir(root) do
31
+ Dir.glob(pattern).sort.reject { |f| File.directory?(f) }
32
+ end
33
+ end
34
+
35
+ def copy_files(root_files)
36
+ root_files.each do |root, files|
37
+ Dir.chdir(root) do
38
+ files.each do |file_source|
39
+ copy_file_source(file_source) if should_copy?(file_source)
40
+ end
41
+ end
42
+ end
43
+ end
44
+
45
+ def should_copy?(file_source)
46
+ true
47
+ end
48
+
49
+ def copy_file_source(file_source)
50
+ if file_source.end_with?('.erb')
51
+ copy_file(file_source)
52
+ else
53
+ template(file_source)
54
+ end
55
+ end
56
+
57
+ end
@@ -0,0 +1,41 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'generators/dry_crud/dry_crud_generator_base'
4
+
5
+ module DryCrud
6
+ # Copies one file of dry_crud to the rails application.
7
+ class FileGenerator < ::DryCrudGeneratorBase
8
+
9
+ desc "Copy one file from dry_crud to the application.\nFILENAME is a part of the name of the file to copy. Must match exactly one file."
10
+
11
+ argument :filename, type: :string, desc: 'Name or part of the filename to copy. Must match exactly one file.'
12
+
13
+ def copy_file
14
+ files = matching_files
15
+ case files.size
16
+ when 1
17
+ copy_files(@root_folder => files)
18
+ when 0
19
+ puts "No file containing '#{filename}' found in dry_crud."
20
+ else
21
+ puts "Please be more specific. All the following files match '#{filename}':"
22
+ files.each do |f|
23
+ puts " * #{f}"
24
+ end
25
+ end
26
+ end
27
+
28
+ private
29
+
30
+ def matching_files
31
+ all_template_files.collect do |root, files|
32
+ files.select do |f|
33
+ included = f.include?(filename)
34
+ @root_folder = root if included
35
+ included
36
+ end
37
+ end.flatten
38
+ end
39
+
40
+ end
41
+ end
@@ -4,7 +4,7 @@ your needs. To integrate dry_crud into your code, only a few additions are
4
4
  required:
5
5
 
6
6
  * For uniform CRUD functionallity, just subclass your controllers from
7
- CrudController.
7
+ CrudController and define the #permitted_attrs (for StrongParameters).
8
8
  * Overwrite the #to_s method of your models for a human-friendly
9
9
  representation.
10
10
 
@@ -68,7 +68,7 @@ describe CrudTestModelsController do
68
68
  end
69
69
 
70
70
  it 'provides entries helper method' do
71
- should render_template('index')
71
+ should render_template('index')
72
72
  entries.should be(controller.send(:entries))
73
73
  end
74
74
  end
@@ -1,7 +1,7 @@
1
1
  # encoding: UTF-8
2
2
  require 'spec_helper'
3
3
 
4
- describe 'Crud::FormBuilder' do
4
+ describe 'DryCrud::Form::Builder' do
5
5
 
6
6
  include FormatHelper
7
7
  include FormHelper
@@ -18,30 +18,39 @@ describe 'Crud::FormBuilder' do
18
18
  after(:all) { reset_db }
19
19
 
20
20
  let(:entry) { CrudTestModel.first }
21
- <% if Rails.version < '4.0' -%>
22
- let(:form) do
23
- Crud::FormBuilder.new(:entry, entry, self, {}, ->(form) { form })
21
+ if Rails.version < '4.0'
22
+ let(:form) do
23
+ DryCrud::Form::Builder.new(:entry, entry, self, {}, ->(form) { form })
24
+ end
25
+ else
26
+ let(:form) { DryCrud::Form::Builder.new(:entry, entry, self, {}) }
24
27
  end
25
- <% else -%>
26
- let(:form) { Crud::FormBuilder.new(:entry, entry, self, {}) }
27
- <% end -%>
28
28
 
29
29
  describe '#input_field' do
30
30
 
31
- { name: :string_field,
32
- password: :password_field,
31
+ it 'dispatches name attr to string field' do
32
+ form.should_receive(:string_field)
33
+ .with(:name, class: 'form-control', required: 'required')
34
+ .and_return('<input>')
35
+ form.input_field(:name)
36
+ end
37
+
38
+ it { form.input_field(:name).should be_html_safe }
39
+
40
+ { password: :password_field,
33
41
  email: :email_field,
34
42
  remarks: :text_area,
35
43
  children: :integer_field,
36
44
  human: :boolean_field,
37
45
  birthdate: :date_field,
38
46
  gets_up_at: :time_field,
47
+ last_seen: :datetime_field,
39
48
  companion_id: :belongs_to_field,
40
49
  other_ids: :has_many_field,
41
50
  more_ids: :has_many_field,
42
51
  }.each do |attr, method|
43
52
  it 'dispatches #{attr} attr to #{method}' do
44
- form.should_receive(method).with(attr, {})
53
+ form.should_receive(method).with(attr, class: 'form-control')
45
54
  form.input_field(attr)
46
55
  end
47
56
 
@@ -62,12 +71,12 @@ describe 'Crud::FormBuilder' do
62
71
  describe '#labeled_input_field' do
63
72
  context 'when required' do
64
73
  subject { form.labeled_input_field(:name) }
65
- it { should include(Crud::FormBuilder::REQUIRED_MARK) }
74
+ it { should include('input-group-addon') }
66
75
  end
67
76
 
68
77
  context 'when not required' do
69
78
  subject { form.labeled_input_field(:remarks) }
70
- it { should_not include(Crud::FormBuilder::REQUIRED_MARK) }
79
+ it { should_not include('input-group-addon') }
71
80
  end
72
81
 
73
82
  context 'with help text' do
@@ -119,10 +128,10 @@ describe 'Crud::FormBuilder' do
119
128
  end
120
129
 
121
130
  it 'displays a message for an empty list' do
122
- @others = []
123
- f = form.has_many_field(:other_ids)
124
- f.should match t('global.associations.none_available')
125
- f.scan('</option>').should have(0).items
131
+ @others = []
132
+ f = form.has_many_field(:other_ids)
133
+ f.should match t('global.associations.none_available')
134
+ f.scan('</option>').should have(0).items
126
135
  end
127
136
  end
128
137
 
@@ -186,8 +195,8 @@ describe 'Crud::FormBuilder' do
186
195
  context 'with caption and content in argument' do
187
196
  subject do
188
197
  form.labeled('gugus',
189
- 'Caption',
190
- "<input type='text' name='gugus' />".html_safe)
198
+ "<input type='text' name='gugus' />".html_safe,
199
+ caption: 'Caption')
191
200
  end
192
201
 
193
202
  it { should be_html_safe }
@@ -196,7 +205,7 @@ describe 'Crud::FormBuilder' do
196
205
 
197
206
  context 'with caption and content in block' do
198
207
  subject do
199
- form.labeled('gugus', 'Caption') do
208
+ form.labeled('gugus', caption: 'Caption') do
200
209
  "<input type='text' name='gugus' />".html_safe
201
210
  end
202
211
  end
@@ -1,13 +1,13 @@
1
1
  # encoding: UTF-8
2
2
  require 'spec_helper'
3
3
 
4
- describe 'Crud::TableBuilder' do
4
+ describe 'DryCrud::TableBuilder' do
5
5
 
6
6
  include FormatHelper
7
7
  include UtilityHelper
8
8
 
9
9
  let(:entries) { %w(foo bahr) }
10
- let(:table) { Crud::TableBuilder.new(entries, self) }
10
+ let(:table) { DryCrud::Table::Builder.new(entries, self) }
11
11
 
12
12
  def format_size(obj) #:nodoc:
13
13
  "#{obj.size} chars"
@@ -111,7 +111,7 @@ describe 'Crud::TableBuilder' do
111
111
  FIN
112
112
  dom.gsub!(/[\n\t]/, '').gsub!(/\s{2,}/, '')
113
113
 
114
- table = Crud::TableBuilder.new([], self)
114
+ table = DryCrud::Table::Builder.new([], self)
115
115
  table.col('head', class: 'left') { |e| link_to e, '/' }
116
116
  table.attrs :upcase, :size
117
117
  table.col { |e| "Never #{e}" }
@@ -49,24 +49,9 @@ describe FormHelper do
49
49
  end
50
50
 
51
51
  it do
52
- should match(/select .*?name="crud_test_model
53
- \[birthdate\(1i\)\]"/x)
54
- end
55
-
56
- it do
57
- should match(/option\ selected="selected"
58
- \ value="1910">1910<\/option>/x)
59
- end
60
-
61
- it do
62
- should match(/option\ selected="selected"\ value="1">
63
- #{t('date.month_names')[1]}
64
- <\/option>/x)
65
- end
66
-
67
- it do
68
- should match(/option\ selected="selected"
69
- \ value="1">1<\/option>/x)
52
+ should match(/input .*?name="crud_test_model\[birthdate\]"
53
+ .*?type="date"
54
+ .*?value="1910-01-01"/x)
70
55
  end
71
56
  end
72
57
  end
@@ -106,24 +91,9 @@ describe FormHelper do
106
91
  end
107
92
 
108
93
  it do
109
- should match(/select .*?name="crud_test_model
110
- \[birthdate\(1i\)\]"/x)
111
- end
112
-
113
- it do
114
- should match(/option\ selected="selected"
115
- \ value="1910">1910<\/option>/x)
116
- end
117
-
118
- it do
119
- should match(/option\ selected="selected"\ value="1">
120
- #{t('date.month_names')[1]}
121
- <\/option>/x)
122
- end
123
-
124
- it do
125
- should match(/option\ selected="selected"
126
- \ value="1">1<\/option>/x)
94
+ should match(/input .*?name="crud_test_model\[birthdate\]"
95
+ .*?type="date"
96
+ .*?value="1910-01-01"/x)
127
97
  end
128
98
 
129
99
  it do
@@ -163,7 +133,7 @@ describe FormHelper do
163
133
  end
164
134
 
165
135
  it do
166
- should match(/div\ class="control-group\ error"\>.*?
136
+ should match(/div\ class="form-group\ has-error"\>.*?
167
137
  \<input .*?name="crud_test_model\[name\]"
168
138
  .*?type="text"/x)
169
139
  end
@@ -192,8 +162,8 @@ describe FormHelper do
192
162
  end
193
163
 
194
164
  it do
195
- should match /input .*?name="crud_test_model\[whatever\]"
196
- .*?type="text"/x
165
+ should match /input .*?name="crud_test_model\[whatever\]"
166
+ .*?type="text"/x
197
167
  end
198
168
 
199
169
  it do
@@ -212,7 +182,18 @@ describe FormHelper do
212
182
  end
213
183
 
214
184
  it do
215
- should match /select .*?name="crud_test_model\[birthdate\(1i\)\]"/
185
+ should match /input .*?name="crud_test_model\[birthdate\]"
186
+ .*?type="date"/x
187
+ end
188
+
189
+ it do
190
+ should match /input .*?name="crud_test_model\[gets_up_at\]"
191
+ .*?type="time"/x
192
+ end
193
+
194
+ it do
195
+ should match /input .*?name="crud_test_model\[last_seen\]"
196
+ .*?type="datetime"/x
216
197
  end
217
198
 
218
199
  it do
@@ -74,15 +74,15 @@ describe FormatHelper do
74
74
 
75
75
  unless ENV['NON_LOCALIZED'] # localization dependent tests
76
76
  context 'Floats' do
77
- it 'should add two digits' do
77
+ it 'adds two digits' do
78
78
  f(1.0).should == '1.000'
79
79
  end
80
80
 
81
- it 'should truncate to two digits' do
81
+ it 'truncates to two digits' do
82
82
  f(3.14159).should == '3.142'
83
83
  end
84
84
 
85
- it 'should add delimiters' do
85
+ it 'adds delimiters' do
86
86
  f(12345.6789).should == '12,345.679'
87
87
  end
88
88
  end
@@ -111,17 +111,17 @@ describe FormatHelper do
111
111
  end
112
112
 
113
113
  context 'nil' do
114
- it 'should print an empty string' do
114
+ it 'prints an empty string' do
115
115
  f(nil).should == UtilityHelper::EMPTY_STRING
116
116
  end
117
117
  end
118
118
 
119
119
  context 'Strings' do
120
- it 'should print regular strings unchanged' do
120
+ it 'prints regular strings unchanged' do
121
121
  f('blah blah').should == 'blah blah'
122
122
  end
123
123
 
124
- it 'should not be html safe' do
124
+ it 'is not html safe' do
125
125
  f('<injection>').should_not be_html_safe
126
126
  end
127
127
  end
@@ -129,29 +129,29 @@ describe FormatHelper do
129
129
  end
130
130
 
131
131
  describe '#format_attr' do
132
- it 'should use #f' do
132
+ it 'uses #f' do
133
133
  format_attr('12.342', :to_f).should == f(12.342)
134
134
  end
135
135
 
136
- it 'should use object attr format method if it exists' do
136
+ it 'uses object attr format method if it exists' do
137
137
  format_attr('abcd', :size).should == '4 chars'
138
138
  end
139
139
 
140
- it 'should use general attr format method if it exists' do
140
+ it 'uses general attr format method if it exists' do
141
141
  format_attr([1, 2], :size).should == '2 items'
142
142
  end
143
143
 
144
- it 'should format empty belongs_to' do
144
+ it 'formats empty belongs_to' do
145
145
  format_attr(crud_test_models(:AAAAA), :companion).should ==
146
146
  t('global.associations.no_entry')
147
147
  end
148
148
 
149
- it 'should format existing belongs_to' do
149
+ it 'formats existing belongs_to' do
150
150
  string = format_attr(crud_test_models(:BBBBB), :companion)
151
151
  string.should == 'AAAAA'
152
152
  end
153
153
 
154
- it 'should format existing has_many' do
154
+ it 'formats existing has_many' do
155
155
  string = format_attr(crud_test_models(:CCCCC), :others)
156
156
  string.should be_html_safe
157
157
  string.should == '<ul><li>AAAAA</li><li>BBBBB</li></ul>'
@@ -161,7 +161,7 @@ describe FormatHelper do
161
161
  describe '#column_type' do
162
162
  let(:model) { crud_test_models(:AAAAA) }
163
163
 
164
- it 'should recognize types' do
164
+ it 'recognizes types' do
165
165
  column_type(model, :name).should == :string
166
166
  column_type(model, :children).should == :integer
167
167
  column_type(model, :companion_id).should == :integer
@@ -179,47 +179,57 @@ describe FormatHelper do
179
179
  describe '#format_type' do
180
180
  let(:model) { crud_test_models(:AAAAA) }
181
181
 
182
- it 'should format integers' do
183
- model.children = 10000
182
+ it 'formats integers' do
183
+ model.children = 10_000
184
184
  format_type(model, :children).should == '10000'
185
185
  end
186
186
 
187
187
  unless ENV['NON_LOCALIZED'] # localization dependent tests
188
- it 'should format floats' do
188
+ it 'formats floats' do
189
189
  format_type(model, :rating).should == '1.100'
190
190
  end
191
191
 
192
- it 'should format decimals' do
192
+ it 'formata decimals' do
193
193
  format_type(model, :income).should == '10,000,000.1111'
194
194
  end
195
195
 
196
- it 'should format dates' do
196
+ it 'formats dates' do
197
197
  format_type(model, :birthdate).should == '1910-01-01'
198
198
  end
199
199
 
200
- it 'should format times' do
200
+ it 'formats times' do
201
201
  format_type(model, :gets_up_at).should == '01:01'
202
202
  end
203
203
 
204
- it 'should format datetimes' do
204
+ it 'formats datetimes' do
205
205
  format_type(model, :last_seen).should == '2010-01-01 11:21'
206
206
  end
207
+
208
+ it 'formats boolean false' do
209
+ model.human = false
210
+ format_type(model, :human).should == 'no'
211
+ end
212
+
213
+ it 'formats boolean true' do
214
+ model.human = true
215
+ format_type(model, :human).should == 'yes'
216
+ end
207
217
  end
208
218
 
209
- it 'should format texts' do
219
+ it 'formats texts' do
210
220
  string = format_type(model, :remarks)
211
221
  string.should be_html_safe
212
222
  string.should == "<p>AAAAA BBBBB CCCCC\n<br />AAAAA BBBBB CCCCC\n</p>"
213
223
  end
214
224
 
215
- it 'should escape texts' do
225
+ it 'escapes texts' do
216
226
  model.remarks = '<unsecure>bla'
217
227
  string = format_type(model, :remarks)
218
228
  string.should be_html_safe
219
229
  string.should == '<p>&lt;unsecure&gt;bla</p>'
220
230
  end
221
231
 
222
- it 'should format empty texts' do
232
+ it 'formats empty texts' do
223
233
  model.remarks = ' '
224
234
  string = format_type(model, :remarks)
225
235
  string.should be_html_safe
@@ -228,15 +238,15 @@ describe FormatHelper do
228
238
  end
229
239
 
230
240
  describe '#captionize' do
231
- it 'should handle symbols' do
241
+ it 'handles symbols' do
232
242
  captionize(:camel_case).should == 'Camel Case'
233
243
  end
234
244
 
235
- it 'should render all upper case' do
245
+ it 'renders all upper case' do
236
246
  captionize('all upper case').should == 'All Upper Case'
237
247
  end
238
248
 
239
- it 'should render human attribute name' do
249
+ it 'renders human attribute name' do
240
250
  captionize(:gets_up_at, CrudTestModel).should == 'Gets up at'
241
251
  end
242
252
  end
@@ -19,11 +19,11 @@ describe TableHelper do
19
19
  describe '#plain_table' do
20
20
  subject { plain_table(%w(foo bar), :size) { |t| t.attrs :upcase } }
21
21
 
22
- it 'should contain attrs' do
22
+ it 'contains attrs' do
23
23
  should match(/<th>Size<\/th>/)
24
24
  end
25
25
 
26
- it 'should contain block' do
26
+ it 'contains block' do
27
27
  should match(/<th>Upcase<\/th>/)
28
28
  end
29
29
  end
@@ -34,7 +34,7 @@ describe TableHelper do
34
34
 
35
35
  it { should be_html_safe }
36
36
 
37
- it 'should handle empty data' do
37
+ it 'handles empty data' do
38
38
  should match(/div class=.table.\>.+\<\/div\>/)
39
39
  end
40
40
  end
@@ -46,7 +46,7 @@ describe TableHelper do
46
46
 
47
47
  it { should be_html_safe }
48
48
 
49
- it 'should render table' do
49
+ it 'renders table' do
50
50
  should match(/^\<table.*\<\/table\>$/)
51
51
  end
52
52
  end
@@ -16,7 +16,7 @@ describe UtilityHelper do
16
16
  describe '#column_type' do
17
17
  let(:model) { crud_test_models(:AAAAA) }
18
18
 
19
- it 'should recognize types' do
19
+ it 'recognizes types' do
20
20
  column_type(model, :name).should == :string
21
21
  column_type(model, :children).should == :integer
22
22
  column_type(model, :companion_id).should == :integer
@@ -33,30 +33,30 @@ describe UtilityHelper do
33
33
 
34
34
  describe '#content_tag_nested' do
35
35
 
36
- it 'should escape safe content' do
36
+ it 'escapes safe content' do
37
37
  html = content_tag_nested(:div, %w(a b)) { |e| content_tag(:span, e) }
38
38
  html.should be_html_safe
39
39
  html.should == '<div><span>a</span><span>b</span></div>'
40
40
  end
41
41
 
42
- it 'should escape unsafe content' do
42
+ it 'escapes unsafe content' do
43
43
  html = content_tag_nested(:div, %w(a b)) { |e| "<#{e}>" }
44
44
  html.should == '<div>&lt;a&gt;&lt;b&gt;</div>'
45
45
  end
46
46
 
47
- it 'should simply join without block' do
47
+ it 'simplys join without block' do
48
48
  html = content_tag_nested(:div, %w(a b))
49
49
  html.should == '<div>ab</div>'
50
50
  end
51
51
  end
52
52
 
53
53
  describe '#safe_join' do
54
- it 'should works as super without block' do
54
+ it 'works as super without block' do
55
55
  html = safe_join(['<a>', '<b>'.html_safe])
56
56
  html.should == '&lt;a&gt;<b>'
57
57
  end
58
58
 
59
- it 'should collect contents for array' do
59
+ it 'collects contents for array' do
60
60
  html = safe_join(%w(a b)) { |e| content_tag(:span, e) }
61
61
  html.should == '<span>a</span><span>b</span>'
62
62
  end
@@ -326,4 +326,4 @@ shared_examples 'crud controller' do |options|
326
326
  end
327
327
  end
328
328
 
329
- end
329
+ end
@@ -166,4 +166,3 @@ module CrudControllerTestHelper
166
166
  end
167
167
 
168
168
  end
169
-