dry_crud 1.7.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/MIT-LICENSE +1 -1
- data/README.rdoc +126 -87
- data/VERSION +1 -1
- data/lib/generators/dry_crud/dry_crud_generator.rb +42 -22
- data/lib/generators/dry_crud/templates/INSTALL +5 -5
- data/lib/generators/dry_crud/templates/app/assets/stylesheets/crud.scss +0 -20
- data/lib/generators/dry_crud/templates/app/assets/stylesheets/sample.scss +24 -4
- data/lib/generators/dry_crud/templates/app/controllers/crud/generic_model.rb +89 -0
- data/lib/generators/dry_crud/templates/app/controllers/crud/nestable.rb +70 -0
- data/lib/generators/dry_crud/templates/app/controllers/crud/rememberable.rb +64 -0
- data/lib/generators/dry_crud/templates/app/controllers/crud/render_callbacks.rb +46 -0
- data/lib/generators/dry_crud/templates/app/controllers/crud/responder.rb +31 -0
- data/lib/generators/dry_crud/templates/app/controllers/crud/searchable.rb +55 -0
- data/lib/generators/dry_crud/templates/app/controllers/crud/sortable.rb +63 -0
- data/lib/generators/dry_crud/templates/app/controllers/crud_controller.rb +66 -69
- data/lib/generators/dry_crud/templates/app/controllers/list_controller.rb +23 -326
- data/lib/generators/dry_crud/templates/app/helpers/actions_helper.rb +64 -0
- data/lib/generators/dry_crud/templates/app/helpers/crud/form_builder.rb +331 -0
- data/lib/generators/dry_crud/templates/app/helpers/crud/table_builder.rb +280 -0
- data/lib/generators/dry_crud/templates/app/helpers/form_helper.rb +52 -0
- data/lib/generators/dry_crud/templates/app/helpers/format_helper.rb +164 -0
- data/lib/generators/dry_crud/templates/app/helpers/i18n_helper.rb +85 -0
- data/lib/generators/dry_crud/templates/app/helpers/table_helper.rb +83 -0
- data/lib/generators/dry_crud/templates/app/helpers/utility_helper.rb +84 -0
- data/lib/generators/dry_crud/templates/app/views/crud/_actions_edit.html.erb +3 -3
- data/lib/generators/dry_crud/templates/app/views/crud/_actions_edit.html.haml +3 -3
- data/lib/generators/dry_crud/templates/app/views/crud/_actions_index.html.erb +1 -1
- data/lib/generators/dry_crud/templates/app/views/crud/_actions_index.html.haml +1 -1
- data/lib/generators/dry_crud/templates/app/views/crud/_actions_show.html.erb +3 -3
- data/lib/generators/dry_crud/templates/app/views/crud/_actions_show.html.haml +3 -3
- data/lib/generators/dry_crud/templates/app/views/crud/_attrs.html.erb +1 -1
- data/lib/generators/dry_crud/templates/app/views/crud/_attrs.html.haml +1 -1
- data/lib/generators/dry_crud/templates/app/views/crud/_form.html.erb +1 -1
- data/lib/generators/dry_crud/templates/app/views/crud/_form.html.haml +1 -1
- data/lib/generators/dry_crud/templates/app/views/crud/edit.html.erb +1 -1
- data/lib/generators/dry_crud/templates/app/views/crud/edit.html.haml +1 -1
- data/lib/generators/dry_crud/templates/app/views/crud/new.html.erb +2 -2
- data/lib/generators/dry_crud/templates/app/views/crud/new.html.haml +2 -2
- data/lib/generators/dry_crud/templates/app/views/crud/show.html.erb +1 -1
- data/lib/generators/dry_crud/templates/app/views/crud/show.html.haml +1 -1
- data/lib/generators/dry_crud/templates/app/views/layouts/_flash.html.haml +1 -1
- data/lib/generators/dry_crud/templates/app/views/layouts/_nav.html.erb +1 -1
- data/lib/generators/dry_crud/templates/app/views/layouts/_nav.html.haml +1 -1
- data/lib/generators/dry_crud/templates/app/views/layouts/crud.html.erb +15 -7
- data/lib/generators/dry_crud/templates/app/views/layouts/crud.html.haml +18 -8
- data/lib/generators/dry_crud/templates/app/views/list/_search.html.erb +3 -3
- data/lib/generators/dry_crud/templates/app/views/list/_search.html.haml +3 -3
- data/lib/generators/dry_crud/templates/app/views/list/index.html.erb +1 -1
- data/lib/generators/dry_crud/templates/app/views/list/index.html.haml +1 -1
- data/lib/generators/dry_crud/templates/app/views/shared/_error_messages.html.erb +1 -1
- data/lib/generators/dry_crud/templates/app/views/shared/_error_messages.html.haml +1 -1
- data/lib/generators/dry_crud/templates/app/views/shared/_labeled.html.erb +2 -4
- data/lib/generators/dry_crud/templates/app/views/shared/_labeled.html.haml +2 -3
- data/lib/generators/dry_crud/templates/config/initializers/field_error_proc.rb +5 -1
- data/lib/generators/dry_crud/templates/config/locales/crud.de.yml +64 -0
- data/lib/generators/dry_crud/templates/config/locales/{en_crud.yml → crud.en.yml} +2 -2
- data/lib/generators/dry_crud/templates/spec/controllers/crud_test_models_controller_spec.rb +241 -231
- data/lib/generators/dry_crud/templates/spec/helpers/crud/form_builder_spec.rb +226 -0
- data/lib/generators/dry_crud/templates/spec/helpers/{standard_table_builder_spec.rb → crud/table_builder_spec.rb} +36 -34
- data/lib/generators/dry_crud/templates/spec/helpers/form_helper_spec.rb +238 -0
- data/lib/generators/dry_crud/templates/spec/helpers/format_helper_spec.rb +244 -0
- data/lib/generators/dry_crud/templates/spec/helpers/i18n_helper_spec.rb +132 -0
- data/lib/generators/dry_crud/templates/spec/helpers/table_helper_spec.rb +265 -0
- data/lib/generators/dry_crud/templates/spec/helpers/utility_helper_spec.rb +74 -0
- data/lib/generators/dry_crud/templates/spec/support/crud_controller_examples.rb +185 -100
- data/lib/generators/dry_crud/templates/spec/support/crud_controller_test_helper.rb +58 -49
- data/lib/generators/dry_crud/templates/test/{functional → controllers}/crud_test_models_controller_test.rb +112 -91
- data/lib/generators/dry_crud/templates/test/{unit/helpers/standard_form_builder_test.rb → helpers/crud/form_builder_test.rb} +79 -62
- data/lib/generators/dry_crud/templates/test/{unit/helpers/standard_table_builder_test.rb → helpers/crud/table_builder_test.rb} +31 -28
- data/lib/generators/dry_crud/templates/test/helpers/custom_assertions_test.rb +85 -0
- data/lib/generators/dry_crud/templates/test/helpers/form_helper_test.rb +129 -0
- data/lib/generators/dry_crud/templates/test/helpers/format_helper_test.rb +163 -0
- data/lib/generators/dry_crud/templates/test/helpers/i18n_helper_test.rb +79 -0
- data/lib/generators/dry_crud/templates/test/helpers/table_helper_test.rb +217 -0
- data/lib/generators/dry_crud/templates/test/helpers/utility_helper_test.rb +63 -0
- data/lib/generators/dry_crud/templates/test/{functional → support}/crud_controller_test_helper.rb +70 -59
- data/lib/generators/dry_crud/templates/test/{crud_test_model.rb → support/crud_test_model.rb} +107 -75
- data/lib/generators/dry_crud/templates/test/support/custom_assertions.rb +83 -0
- metadata +83 -146
- data/Rakefile +0 -211
- data/lib/generators/dry_crud/templates/app/helpers/crud_helper.rb +0 -168
- data/lib/generators/dry_crud/templates/app/helpers/list_helper.rb +0 -27
- data/lib/generators/dry_crud/templates/app/helpers/standard_form_builder.rb +0 -261
- data/lib/generators/dry_crud/templates/app/helpers/standard_helper.rb +0 -304
- data/lib/generators/dry_crud/templates/app/helpers/standard_table_builder.rb +0 -178
- data/lib/generators/dry_crud/templates/spec/helpers/crud_helper_spec.rb +0 -146
- data/lib/generators/dry_crud/templates/spec/helpers/list_helper_spec.rb +0 -154
- data/lib/generators/dry_crud/templates/spec/helpers/standard_form_builder_spec.rb +0 -215
- data/lib/generators/dry_crud/templates/spec/helpers/standard_helper_spec.rb +0 -387
- data/lib/generators/dry_crud/templates/test/custom_assertions.rb +0 -78
- data/lib/generators/dry_crud/templates/test/unit/custom_assertions_test.rb +0 -117
- data/lib/generators/dry_crud/templates/test/unit/helpers/crud_helper_test.rb +0 -111
- data/lib/generators/dry_crud/templates/test/unit/helpers/list_helper_test.rb +0 -123
- data/lib/generators/dry_crud/templates/test/unit/helpers/standard_helper_test.rb +0 -281
- data/test/templates/Gemfile +0 -46
- data/test/templates/app/controllers/admin/cities_controller.rb +0 -7
- data/test/templates/app/controllers/admin/countries_controller.rb +0 -13
- data/test/templates/app/controllers/ajax_controller.rb +0 -9
- data/test/templates/app/controllers/people_controller.rb +0 -13
- data/test/templates/app/controllers/vips_controller.rb +0 -19
- data/test/templates/app/helpers/cities_helper.rb +0 -9
- data/test/templates/app/helpers/people_helper.rb +0 -8
- data/test/templates/app/models/city.rb +0 -28
- data/test/templates/app/models/country.rb +0 -16
- data/test/templates/app/models/person.rb +0 -12
- data/test/templates/app/views/admin/cities/_actions_index.html.erb +0 -2
- data/test/templates/app/views/admin/cities/_actions_index.html.haml +0 -2
- data/test/templates/app/views/admin/cities/_attrs.html.erb +0 -1
- data/test/templates/app/views/admin/cities/_attrs.html.haml +0 -1
- data/test/templates/app/views/admin/cities/_form.html.erb +0 -7
- data/test/templates/app/views/admin/cities/_form.html.haml +0 -5
- data/test/templates/app/views/admin/cities/_hello.html.erb +0 -1
- data/test/templates/app/views/admin/cities/_hello.html.haml +0 -1
- data/test/templates/app/views/admin/cities/_list.html.erb +0 -3
- data/test/templates/app/views/admin/cities/_list.html.haml +0 -3
- data/test/templates/app/views/admin/countries/_list.html.erb +0 -4
- data/test/templates/app/views/admin/countries/_list.html.haml +0 -3
- data/test/templates/app/views/ajax/_actions_index.html.erb +0 -8
- data/test/templates/app/views/ajax/_actions_index.html.haml +0 -8
- data/test/templates/app/views/ajax/_actions_show.html.erb +0 -4
- data/test/templates/app/views/ajax/_actions_show.html.haml +0 -4
- data/test/templates/app/views/ajax/_form.html.erb +0 -2
- data/test/templates/app/views/ajax/_form.html.haml +0 -2
- data/test/templates/app/views/ajax/_hello.html.erb +0 -1
- data/test/templates/app/views/ajax/_hello.html.haml +0 -1
- data/test/templates/app/views/ajax/ajax.js.erb +0 -1
- data/test/templates/app/views/ajax/ajax.js.haml +0 -1
- data/test/templates/app/views/ajax/edit.js.erb +0 -1
- data/test/templates/app/views/ajax/edit.js.haml +0 -1
- data/test/templates/app/views/ajax/show.js.erb +0 -1
- data/test/templates/app/views/ajax/show.js.haml +0 -1
- data/test/templates/app/views/ajax/update.js.erb +0 -5
- data/test/templates/app/views/ajax/update.js.haml +0 -5
- data/test/templates/app/views/layouts/_nav.html.erb +0 -6
- data/test/templates/app/views/layouts/_nav.html.haml +0 -5
- data/test/templates/app/views/layouts/bootstrap.html.erb +0 -68
- data/test/templates/app/views/layouts/bootstrap.html.haml +0 -49
- data/test/templates/app/views/people/_attrs.html.erb +0 -5
- data/test/templates/app/views/people/_attrs.html.haml +0 -4
- data/test/templates/app/views/people/_list.html.erb +0 -1
- data/test/templates/app/views/people/_list.html.haml +0 -1
- data/test/templates/config/database.yml +0 -21
- data/test/templates/config/locales/en_cities.yml +0 -56
- data/test/templates/config/routes.rb +0 -32
- data/test/templates/db/migrate/20100511174904_create_people_and_cities.rb +0 -26
- data/test/templates/db/seeds.rb +0 -74
- data/test/templates/spec/controllers/admin/cities_controller_spec.rb +0 -74
- data/test/templates/spec/controllers/admin/countries_controller_spec.rb +0 -56
- data/test/templates/spec/controllers/people_controller_spec.rb +0 -80
- data/test/templates/spec/routing/cities_routing_spec.rb +0 -11
- data/test/templates/spec/routing/countries_routing_spec.rb +0 -11
- data/test/templates/test/fixtures/cities.yml +0 -11
- data/test/templates/test/fixtures/countries.yml +0 -11
- data/test/templates/test/fixtures/people.yml +0 -14
- data/test/templates/test/functional/admin/cities_controller_test.rb +0 -59
- data/test/templates/test/functional/admin/countries_controller_test.rb +0 -42
- data/test/templates/test/functional/people_controller_test.rb +0 -68
@@ -1,387 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe StandardHelper do
|
4
|
-
|
5
|
-
include CrudTestHelper
|
6
|
-
|
7
|
-
before(:all) do
|
8
|
-
reset_db
|
9
|
-
setup_db
|
10
|
-
create_test_data
|
11
|
-
end
|
12
|
-
|
13
|
-
after(:all) { reset_db }
|
14
|
-
|
15
|
-
# define some test format_ methods
|
16
|
-
def format_size(obj) #:nodoc:
|
17
|
-
"#{f(obj.size)} items"
|
18
|
-
end
|
19
|
-
|
20
|
-
def format_string_size(obj) #:nodoc:
|
21
|
-
"#{f(obj.size)} chars"
|
22
|
-
end
|
23
|
-
|
24
|
-
describe "#labeled" do
|
25
|
-
context "regular" do
|
26
|
-
subject { labeled('label') { 'value' } }
|
27
|
-
|
28
|
-
it { should be_html_safe }
|
29
|
-
it { assert_dom_equal '<div class="labeled"> <label>label</label> <div class="value">value</div> </div>', subject.squish }
|
30
|
-
end
|
31
|
-
|
32
|
-
context "with empty value" do
|
33
|
-
subject { labeled('label') { '' } }
|
34
|
-
|
35
|
-
it { should be_html_safe }
|
36
|
-
it { assert_dom_equal '<div class="labeled"> <label>label</label> <div class="value">'+StandardHelper::EMPTY_STRING+'</div> </div>', subject.squish }
|
37
|
-
end
|
38
|
-
|
39
|
-
context "with unsafe value" do
|
40
|
-
subject { labeled('label') { 'value <unsafe>' } }
|
41
|
-
|
42
|
-
it { should be_html_safe }
|
43
|
-
it { assert_dom_equal '<div class="labeled"> <label>label</label> <div class="value">value <unsafe></div> </div>', subject.squish }
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
describe "#labeled_attr" do
|
48
|
-
subject { labeled_attr('foo', :size) }
|
49
|
-
|
50
|
-
it { should be_html_safe }
|
51
|
-
it { assert_dom_equal '<div class="labeled"> <label>Size</label> <div class="value">3 chars</div> </div>', subject.squish }
|
52
|
-
end
|
53
|
-
|
54
|
-
describe "#f" do
|
55
|
-
|
56
|
-
context "Fixnums" do
|
57
|
-
it "should print small values unchanged" do
|
58
|
-
f(10).should == '10'
|
59
|
-
end
|
60
|
-
|
61
|
-
it "should print large values with delimiters" do
|
62
|
-
f(10000000).should == '10,000,000'
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
context "Floats" do
|
67
|
-
it "should add two digits" do
|
68
|
-
f(1.0).should == '1.000'
|
69
|
-
end
|
70
|
-
|
71
|
-
it "should truncate to two digits" do
|
72
|
-
f(3.14159).should == '3.142'
|
73
|
-
end
|
74
|
-
|
75
|
-
it "should add delimiters" do
|
76
|
-
f(12345.6789).should == '12,345.679'
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
context "Booleans" do
|
81
|
-
it "true should print yes" do
|
82
|
-
f(true).should == 'yes'
|
83
|
-
end
|
84
|
-
|
85
|
-
it "false should print no" do
|
86
|
-
f(false).should == 'no'
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
context "nil" do
|
91
|
-
it "should print an empty string" do
|
92
|
-
f(nil).should == StandardHelper::EMPTY_STRING
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
context "Strings" do
|
97
|
-
it "should print regular strings unchanged" do
|
98
|
-
f('blah blah').should == 'blah blah'
|
99
|
-
end
|
100
|
-
|
101
|
-
it "should not be html safe" do
|
102
|
-
f('<injection>').should_not be_html_safe
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
|
-
end
|
107
|
-
|
108
|
-
describe "#format_attr" do
|
109
|
-
it "should use #f" do
|
110
|
-
format_attr("12.342", :to_f).should == f(12.342)
|
111
|
-
end
|
112
|
-
|
113
|
-
it "should use object attr format method if it exists" do
|
114
|
-
format_attr("abcd", :size).should == '4 chars'
|
115
|
-
end
|
116
|
-
|
117
|
-
it "should use general attr format method if it exists" do
|
118
|
-
format_attr([1,2], :size).should == '2 items'
|
119
|
-
end
|
120
|
-
|
121
|
-
it "should format empty belongs_to" do
|
122
|
-
format_attr(crud_test_models(:AAAAA), :companion).should == t(:'global.associations.no_entry')
|
123
|
-
end
|
124
|
-
|
125
|
-
it "should format existing belongs_to" do
|
126
|
-
string = format_attr(crud_test_models(:BBBBB), :companion)
|
127
|
-
string.should == "AAAAA"
|
128
|
-
end
|
129
|
-
|
130
|
-
it "should format existing has_many" do
|
131
|
-
string = format_attr(crud_test_models(:CCCCC), :others)
|
132
|
-
string.should be_html_safe
|
133
|
-
string.should == "<ul><li>AAAAA</li><li>BBBBB</li></ul>"
|
134
|
-
end
|
135
|
-
end
|
136
|
-
|
137
|
-
describe "#column_type" do
|
138
|
-
let(:model) { crud_test_models(:AAAAA) }
|
139
|
-
|
140
|
-
it "should recognize types" do
|
141
|
-
column_type(model, :name).should == :string
|
142
|
-
column_type(model, :children).should == :integer
|
143
|
-
column_type(model, :companion_id).should == :integer
|
144
|
-
column_type(model, :rating).should == :float
|
145
|
-
column_type(model, :income).should == :decimal
|
146
|
-
column_type(model, :birthdate).should == :date
|
147
|
-
column_type(model, :gets_up_at).should == :time
|
148
|
-
column_type(model, :last_seen).should == :datetime
|
149
|
-
column_type(model, :human).should == :boolean
|
150
|
-
column_type(model, :remarks).should == :text
|
151
|
-
column_type(model, :companion).should be_nil
|
152
|
-
end
|
153
|
-
end
|
154
|
-
|
155
|
-
describe "#format_type" do
|
156
|
-
let(:model) { crud_test_models(:AAAAA) }
|
157
|
-
|
158
|
-
it "should format integers" do
|
159
|
-
model.children = 10000
|
160
|
-
format_type(model, :children).should == '10,000'
|
161
|
-
end
|
162
|
-
|
163
|
-
it "should format floats" do
|
164
|
-
format_type(model, :rating).should == '1.100'
|
165
|
-
end
|
166
|
-
|
167
|
-
it "should format decimals" do
|
168
|
-
format_type(model, :income).should == '10,000,000.100'
|
169
|
-
end
|
170
|
-
|
171
|
-
it "should format dates" do
|
172
|
-
format_type(model, :birthdate).should == '1910-01-01'
|
173
|
-
end
|
174
|
-
|
175
|
-
it "should format times" do
|
176
|
-
format_type(model, :gets_up_at).should == '01:01'
|
177
|
-
end
|
178
|
-
|
179
|
-
it "should format datetimes" do
|
180
|
-
format_type(model, :last_seen).should == '2010-01-01 11:21'
|
181
|
-
end
|
182
|
-
|
183
|
-
it "should format texts" do
|
184
|
-
string = format_type(model, :remarks)
|
185
|
-
string.should be_html_safe
|
186
|
-
string.should == "<p>AAAAA BBBBB CCCCC\n<br />AAAAA BBBBB CCCCC\n</p>"
|
187
|
-
end
|
188
|
-
|
189
|
-
it "should escape texts" do
|
190
|
-
model.remarks = "<unsecure>bla"
|
191
|
-
string = format_type(model, :remarks)
|
192
|
-
string.should be_html_safe
|
193
|
-
string.should == "<p><unsecure>bla</p>"
|
194
|
-
end
|
195
|
-
|
196
|
-
it "should format empty texts" do
|
197
|
-
model.remarks = " "
|
198
|
-
string = format_type(model, :remarks)
|
199
|
-
string.should be_html_safe
|
200
|
-
string.should == StandardHelper::EMPTY_STRING
|
201
|
-
end
|
202
|
-
end
|
203
|
-
|
204
|
-
describe "#content_tag_nested" do
|
205
|
-
|
206
|
-
it "should escape safe content" do
|
207
|
-
html = content_tag_nested(:div, ['a', 'b']) { |e| content_tag(:span, e) }
|
208
|
-
html.should be_html_safe
|
209
|
-
html.should == "<div><span>a</span><span>b</span></div>"
|
210
|
-
end
|
211
|
-
|
212
|
-
it "should escape unsafe content" do
|
213
|
-
html = content_tag_nested(:div, ['a', 'b']) { |e| "<#{e}>" }
|
214
|
-
html.should == "<div><a><b></div>"
|
215
|
-
end
|
216
|
-
|
217
|
-
it "should simply join without block" do
|
218
|
-
html = content_tag_nested(:div, ['a', 'b'])
|
219
|
-
html.should == "<div>ab</div>"
|
220
|
-
end
|
221
|
-
end
|
222
|
-
|
223
|
-
describe "#safe_join" do
|
224
|
-
it "should works as super without block" do
|
225
|
-
html = safe_join(['<a>', '<b>'.html_safe])
|
226
|
-
html.should == "<a><b>"
|
227
|
-
end
|
228
|
-
|
229
|
-
it "should collect contents for array" do
|
230
|
-
html = safe_join(['a', 'b']) { |e| content_tag(:span, e) }
|
231
|
-
html.should == "<span>a</span><span>b</span>"
|
232
|
-
end
|
233
|
-
end
|
234
|
-
|
235
|
-
describe "#captionize" do
|
236
|
-
it "should handle symbols" do
|
237
|
-
captionize(:camel_case).should == 'Camel Case'
|
238
|
-
end
|
239
|
-
|
240
|
-
it "should render all upper case" do
|
241
|
-
captionize('all upper case').should == 'All Upper Case'
|
242
|
-
end
|
243
|
-
|
244
|
-
it "should render human attribute name" do
|
245
|
-
captionize(:gets_up_at, CrudTestModel).should == 'Gets up at'
|
246
|
-
end
|
247
|
-
end
|
248
|
-
|
249
|
-
describe "#table" do
|
250
|
-
context "with empty data" do
|
251
|
-
subject { table([]) }
|
252
|
-
|
253
|
-
it { should be_html_safe }
|
254
|
-
|
255
|
-
it "should handle empty data" do
|
256
|
-
should match(/No entries/)
|
257
|
-
end
|
258
|
-
end
|
259
|
-
|
260
|
-
context "with data" do
|
261
|
-
subject { table(['foo', 'bar'], :size) {|t| t.attrs :upcase } }
|
262
|
-
|
263
|
-
it { should be_html_safe }
|
264
|
-
|
265
|
-
it "should render table" do
|
266
|
-
should match(/^\<table.*\<\/table\>$/)
|
267
|
-
end
|
268
|
-
|
269
|
-
it "should contain attrs" do
|
270
|
-
should match(/<th>Size<\/th>/)
|
271
|
-
end
|
272
|
-
|
273
|
-
it "should contain block" do
|
274
|
-
should match(/<th>Upcase<\/th>/)
|
275
|
-
end
|
276
|
-
end
|
277
|
-
end
|
278
|
-
|
279
|
-
describe "#standard_form" do
|
280
|
-
subject do
|
281
|
-
with_test_routing do
|
282
|
-
capture { standard_form(entry, :html => {:class => 'special'}) {|f| f.labeled_input_fields :name, :birthdate } }
|
283
|
-
end
|
284
|
-
end
|
285
|
-
|
286
|
-
context "for existing entry" do
|
287
|
-
let(:entry) { crud_test_models(:AAAAA) }
|
288
|
-
|
289
|
-
it { should match(/form .*?action="\/crud_test_models\/#{entry.id}" .?class="special form-horizontal" .*?method="post"/) }
|
290
|
-
it { should match(/input .*?name="_method" .*?type="hidden" .*?value="put"/) }
|
291
|
-
it { should match(/input .*?name="crud_test_model\[name\]" .*?type="text" .*?value="AAAAA"/) }
|
292
|
-
it { should match(/select .*?name="crud_test_model\[birthdate\(1i\)\]"/) }
|
293
|
-
it { should match(/option selected="selected" value="1910">1910<\/option>/) }
|
294
|
-
it { should match(/option selected="selected" value="1">January<\/option>/) }
|
295
|
-
it { should match(/option selected="selected" value="1">1<\/option>/) }
|
296
|
-
end
|
297
|
-
|
298
|
-
context "for invalid entry" do
|
299
|
-
let(:entry) do
|
300
|
-
e = crud_test_models(:AAAAA)
|
301
|
-
e.name = nil
|
302
|
-
e.valid?
|
303
|
-
e
|
304
|
-
end
|
305
|
-
|
306
|
-
it { should match(/div[^>]* id='error_explanation'/) }
|
307
|
-
it { should match(/div class="control-group error"\>.*?\<input .*?name="crud_test_model\[name\]" .*?type="text"/) }
|
308
|
-
it { should match(/input .*?name="_method" .*?type="hidden" .*?value="put"/) }
|
309
|
-
end
|
310
|
-
end
|
311
|
-
|
312
|
-
describe "#translate_inheritable" do
|
313
|
-
before { @controller = CrudTestModelsController.new }
|
314
|
-
|
315
|
-
before { I18n.backend.store_translations :en, :global => { :test_key => 'global' } }
|
316
|
-
subject { ti(:test_key) }
|
317
|
-
|
318
|
-
it { should == 'global' }
|
319
|
-
|
320
|
-
context "with list key" do
|
321
|
-
before { I18n.backend.store_translations :en, :list => { :global => {:test_key => 'list global'} } }
|
322
|
-
it { should == 'list global' }
|
323
|
-
|
324
|
-
context "and list action key" do
|
325
|
-
before { I18n.backend.store_translations :en, :list => { :index => {:test_key => 'list index'} } }
|
326
|
-
it { should == 'list index' }
|
327
|
-
|
328
|
-
context "and crud global key" do
|
329
|
-
before { I18n.backend.store_translations :en, :crud => { :global => {:test_key => 'crud global'} } }
|
330
|
-
it { should == 'crud global' }
|
331
|
-
|
332
|
-
context "and crud action key" do
|
333
|
-
before { I18n.backend.store_translations :en, :crud => { :index => {:test_key => 'crud index'} } }
|
334
|
-
it { should == 'crud index' }
|
335
|
-
|
336
|
-
context "and controller global key" do
|
337
|
-
before { I18n.backend.store_translations :en, :crud_test_models => { :global => {:test_key => 'test global'} } }
|
338
|
-
it { should == 'test global' }
|
339
|
-
|
340
|
-
context "and controller action key" do
|
341
|
-
before { I18n.backend.store_translations :en, :crud_test_models => { :index => {:test_key => 'test index'} } }
|
342
|
-
it { should == 'test index' }
|
343
|
-
end
|
344
|
-
end
|
345
|
-
end
|
346
|
-
end
|
347
|
-
end
|
348
|
-
end
|
349
|
-
end
|
350
|
-
|
351
|
-
describe "#translate_association" do
|
352
|
-
let(:assoc) { CrudTestModel.reflect_on_association(:companion) }
|
353
|
-
subject { ta(:test_key, assoc)}
|
354
|
-
|
355
|
-
before { I18n.backend.store_translations :en, :global => { :associations => {:test_key => 'global'} } }
|
356
|
-
it { should == 'global' }
|
357
|
-
|
358
|
-
context "with model key" do
|
359
|
-
before do
|
360
|
-
I18n.backend.store_translations :en,
|
361
|
-
:activerecord => {
|
362
|
-
:associations => {
|
363
|
-
:crud_test_model => {
|
364
|
-
:test_key => 'model'} } }
|
365
|
-
end
|
366
|
-
|
367
|
-
it { should == 'model' }
|
368
|
-
|
369
|
-
context "and assoc key" do
|
370
|
-
before do
|
371
|
-
I18n.backend.store_translations :en,
|
372
|
-
:activerecord => {
|
373
|
-
:associations => {
|
374
|
-
:models => {
|
375
|
-
:crud_test_model => {
|
376
|
-
:companion => {
|
377
|
-
:test_key => 'companion'} } } } }
|
378
|
-
end
|
379
|
-
|
380
|
-
it { should == 'companion' }
|
381
|
-
it "should use global without assoc" do
|
382
|
-
ta(:test_key).should == 'global'
|
383
|
-
end
|
384
|
-
end
|
385
|
-
end
|
386
|
-
end
|
387
|
-
end
|
@@ -1,78 +0,0 @@
|
|
1
|
-
# A handful of convenient assertions. The aim of custom assertions is to
|
2
|
-
# provide more specific error messages and to perform complex checks.
|
3
|
-
#
|
4
|
-
# Ideally, include this module into your test_helper.rb file:
|
5
|
-
# # at the beginning of the file:
|
6
|
-
# require 'custom_assertions'
|
7
|
-
#
|
8
|
-
# # inside the class definition:
|
9
|
-
# include CustomAssertions
|
10
|
-
module CustomAssertions
|
11
|
-
|
12
|
-
# Asserts that the element is included in the collection.
|
13
|
-
def assert_include(collection, element, message = "")
|
14
|
-
full_message = build_message(message, "<?> expected to be included in \n<?>.",
|
15
|
-
element, collection)
|
16
|
-
assert_block(full_message) { collection.include?(element) }
|
17
|
-
end
|
18
|
-
|
19
|
-
# Asserts that the element is not included in the collection.
|
20
|
-
def assert_not_include(collection, element, message = "")
|
21
|
-
full_message = build_message(message, "<?> expected not to be included in \n<?>.",
|
22
|
-
element, collection)
|
23
|
-
assert_block(full_message) { !collection.include?(element) }
|
24
|
-
end
|
25
|
-
|
26
|
-
# Asserts that regexp occurs exactly expected times in string.
|
27
|
-
def assert_count(expected, regexp, string, message = "")
|
28
|
-
actual = string.scan(regexp).size
|
29
|
-
full_message = build_message(message, "<?> expected to occur ? time(s), but occured ? time(s) in \n<?>.",
|
30
|
-
regexp, expected, actual, string)
|
31
|
-
assert_block(full_message) { expected == actual }
|
32
|
-
end
|
33
|
-
|
34
|
-
# Asserts that the given active model record is valid.
|
35
|
-
# This method used to be part of Rails but was deprecated, no idea why.
|
36
|
-
def assert_valid(record, message = "")
|
37
|
-
record.valid?
|
38
|
-
full_message = build_message(message,
|
39
|
-
"? expected to be valid, but has the following errors: \n ?.",
|
40
|
-
record.to_s, record.errors.full_messages.join("\n"))
|
41
|
-
assert_block(full_message) { record.valid? }
|
42
|
-
end
|
43
|
-
|
44
|
-
# Asserts that the given active model record is not valid.
|
45
|
-
# If you provide a set of invalid attribute symbols, all of and only these
|
46
|
-
# attributes are expected to have errors. If no invalid attributes are
|
47
|
-
# specified, only the invalidity of the record is asserted.
|
48
|
-
def assert_not_valid(record, *invalid_attrs)
|
49
|
-
message = build_message("", "? expected to be invalid, but is valid.", record.to_s)
|
50
|
-
assert_block(message) { !record.valid? }
|
51
|
-
|
52
|
-
# assert that the given attributes have errors.
|
53
|
-
invalid_attrs.each do |a|
|
54
|
-
message = build_message("", "Attribute <?> expected to be invalid, but is valid.", a.to_s)
|
55
|
-
assert_block(message) { record.errors[a].present? }
|
56
|
-
end
|
57
|
-
|
58
|
-
if invalid_attrs.present?
|
59
|
-
# assert that no other than the invalid attributes have errors.
|
60
|
-
record.errors.each do |a, error|
|
61
|
-
message = build_message("", "Attribute <?> not declared as invalid attribute, but has the following error: \n?.", a.to_s, error)
|
62
|
-
assert_block(message) { invalid_attrs.include?(a) }
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
# The method used to by Test::Unit to format arguments in
|
68
|
-
# #build_message. Prints ActiveRecord objects in a simpler format.
|
69
|
-
# Only works for Ruby 1.9
|
70
|
-
def mu_pp(obj)
|
71
|
-
if obj.is_a?(ActiveRecord::Base)
|
72
|
-
obj.to_s
|
73
|
-
else
|
74
|
-
super
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
end
|