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,117 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'custom_assertions'
|
3
|
-
require 'crud_test_model'
|
4
|
-
|
5
|
-
class CustomAssertionsTest < ActiveSupport::TestCase
|
6
|
-
|
7
|
-
include CustomAssertions
|
8
|
-
|
9
|
-
include CrudTestHelper
|
10
|
-
|
11
|
-
setup :reset_db, :setup_db, :create_test_data
|
12
|
-
teardown :reset_db
|
13
|
-
|
14
|
-
AssertionException = RUBY_VERSION.to_f == 1.9 ?
|
15
|
-
MiniTest::Assertion :
|
16
|
-
Test::Unit::AssertionFailedError
|
17
|
-
|
18
|
-
test "assert include succeeds if included" do
|
19
|
-
assert_nothing_raised do
|
20
|
-
assert_include [1,2,3], 2
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
test "assert include succeeds if record included" do
|
25
|
-
assert_nothing_raised do
|
26
|
-
assert_include CrudTestModel.all, crud_test_models("AAAAA")
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
test "assert include fails if not included" do
|
31
|
-
assert_raise(AssertionException) do
|
32
|
-
assert_include [1,2,3], 5
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
test "assert not include succeeds if not included" do
|
37
|
-
assert_nothing_raised do
|
38
|
-
assert_not_include [1,2,3], 5
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
test "assert not include fails if included" do
|
43
|
-
assert_raise(AssertionException) do
|
44
|
-
assert_not_include [1,2,3], 3
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
test "assert count succeeds if count matches" do
|
49
|
-
assert_nothing_raised do
|
50
|
-
assert_count 3, "ba", "barbabapa"
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
test "assert count succeeds if count is zero" do
|
55
|
-
assert_nothing_raised do
|
56
|
-
assert_count 0, "bo", "barbabapa"
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
test "assert count fails if count does not match" do
|
61
|
-
assert_raise(AssertionException) do
|
62
|
-
assert_count 2, "ba", "barbabapa"
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
test "assert valid record succeeds" do
|
67
|
-
assert_nothing_raised do
|
68
|
-
assert_valid crud_test_models("AAAAA")
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
test "assert valid record fails for invalid" do
|
73
|
-
assert_raise(AssertionException) do
|
74
|
-
assert_valid invalid_record
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
test "assert not valid succeeds if record invalid" do
|
79
|
-
assert_nothing_raised do
|
80
|
-
assert_not_valid invalid_record
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
test "assert not valid succeds if record invalid and invalid attrs given" do
|
85
|
-
assert_nothing_raised do
|
86
|
-
assert_not_valid invalid_record, :name, :rating
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
test "assert not valid fails if record valid" do
|
91
|
-
assert_raise(AssertionException) do
|
92
|
-
assert_not_valid crud_test_models("AAAAA")
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
test "assert not valid fails if record invalid and valid attrs given" do
|
97
|
-
assert_raise(AssertionException) do
|
98
|
-
assert_not_valid invalid_record, :name, :rating, :children
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
test "assert not valid fails if record invalid and not all invalid attrs given" do
|
103
|
-
assert_raise(AssertionException) do
|
104
|
-
assert_not_valid invalid_record, :name
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
private
|
109
|
-
|
110
|
-
def invalid_record
|
111
|
-
m = crud_test_models("AAAAA")
|
112
|
-
m.name = nil
|
113
|
-
m.rating = 42
|
114
|
-
m
|
115
|
-
end
|
116
|
-
|
117
|
-
end
|
@@ -1,111 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'crud_test_model'
|
3
|
-
require 'custom_assertions'
|
4
|
-
|
5
|
-
class CrudHelperTest < ActionView::TestCase
|
6
|
-
|
7
|
-
include CustomAssertions
|
8
|
-
include StandardHelper
|
9
|
-
include ListHelper
|
10
|
-
include CrudTestHelper
|
11
|
-
|
12
|
-
attr_reader :entries
|
13
|
-
|
14
|
-
setup :reset_db, :setup_db, :create_test_data
|
15
|
-
teardown :reset_db
|
16
|
-
|
17
|
-
test "standard crud table" do
|
18
|
-
@entries = CrudTestModel.all
|
19
|
-
|
20
|
-
t = with_test_routing do
|
21
|
-
crud_table
|
22
|
-
end
|
23
|
-
|
24
|
-
assert_count 7, REGEXP_ROWS, t
|
25
|
-
assert_count 13, REGEXP_SORT_HEADERS, t
|
26
|
-
assert_count 12, REGEXP_ACTION_CELL, t # edit, delete links
|
27
|
-
end
|
28
|
-
|
29
|
-
test "custom crud table with attributes" do
|
30
|
-
@entries = CrudTestModel.all
|
31
|
-
|
32
|
-
t = with_test_routing do
|
33
|
-
crud_table :name, :children, :companion_id
|
34
|
-
end
|
35
|
-
|
36
|
-
assert_count 7, REGEXP_ROWS, t
|
37
|
-
assert_count 3, REGEXP_SORT_HEADERS, t
|
38
|
-
assert_count 12, REGEXP_ACTION_CELL, t # edit, delete links
|
39
|
-
end
|
40
|
-
|
41
|
-
test "custom crud table with block" do
|
42
|
-
@entries = CrudTestModel.all
|
43
|
-
|
44
|
-
t = with_test_routing do
|
45
|
-
crud_table do |t|
|
46
|
-
t.attrs :name, :children, :companion_id
|
47
|
-
t.col("head") {|e| content_tag :span, e.income.to_s }
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
assert_count 7, REGEXP_ROWS, t
|
52
|
-
assert_count 6, REGEXP_HEADERS, t
|
53
|
-
assert_count 6, /<span>.+?<\/span>/m, t
|
54
|
-
assert_count 12, REGEXP_ACTION_CELL, t # edit, delete links
|
55
|
-
end
|
56
|
-
|
57
|
-
test "custom crud table with attributes and block" do
|
58
|
-
@entries = CrudTestModel.all
|
59
|
-
|
60
|
-
t = with_test_routing do
|
61
|
-
crud_table :name, :children, :companion_id do |t|
|
62
|
-
t.col("head") {|e| content_tag :span, e.income.to_s }
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
assert_count 7, REGEXP_ROWS, t
|
67
|
-
assert_count 3, REGEXP_SORT_HEADERS, t
|
68
|
-
assert_count 6, REGEXP_HEADERS, t
|
69
|
-
assert_count 6, /<span>.+?<\/span>/m, t
|
70
|
-
assert_count 12, REGEXP_ACTION_CELL, t # edit, delete links
|
71
|
-
end
|
72
|
-
|
73
|
-
|
74
|
-
test "entry form" do
|
75
|
-
f = with_test_routing do
|
76
|
-
capture { entry_form }
|
77
|
-
end
|
78
|
-
|
79
|
-
assert_match /form .*?action="\/crud_test_models\/#{entry.id}"/, f
|
80
|
-
assert_match /input .*?name="crud_test_model\[name\]" .*?type="text"/, f
|
81
|
-
assert_match /input .*?name="crud_test_model\[whatever\]" .*?type="text"/, f
|
82
|
-
assert_match /input .*?name="crud_test_model\[children\]" .*?type="number"/, f
|
83
|
-
assert_match /input .*?name="crud_test_model\[rating\]" .*?type="number"/, f
|
84
|
-
assert_match /input .*?name="crud_test_model\[income\]" .*?type="number"/, f
|
85
|
-
assert_match /select .*?name="crud_test_model\[birthdate\(1i\)\]"/, f
|
86
|
-
assert_match /input .*?name="crud_test_model\[human\]" .*?type="checkbox"/, f
|
87
|
-
assert_match /select .*?name="crud_test_model\[companion_id\]"/, f
|
88
|
-
assert_match /textarea .*?name="crud_test_model\[remarks\]"/, f
|
89
|
-
assert_match /a .*href="\/crud_test_models\/#{entry.id}\?returning=true".*>Cancel<\/a>/, f
|
90
|
-
end
|
91
|
-
|
92
|
-
test "crud form" do
|
93
|
-
e = crud_test_models('AAAAA')
|
94
|
-
f = with_test_routing do
|
95
|
-
f = capture { crud_form(e, :name, :children, :birthdate, :human, :cancel_url => '/somewhere', :class => 'special') }
|
96
|
-
end
|
97
|
-
|
98
|
-
assert_match /form .*?action="\/crud_test_models\/#{e.id}" .*?method="post"/, f
|
99
|
-
assert_match /input .*?name="_method" .*?type="hidden" .*?value="put"/, f
|
100
|
-
assert_match /input .*?name="crud_test_model\[name\]" .*?type="text" .*?value="AAAAA"/, f
|
101
|
-
assert_match /select .*?name="crud_test_model\[birthdate\(1i\)\]"/, f
|
102
|
-
assert_match /input .*?name="crud_test_model\[children\]" .*?type="number" .*?value=\"9\"/, f
|
103
|
-
assert_match /input .*?name="crud_test_model\[human\]" .*?type="checkbox"/, f
|
104
|
-
assert_match /button .*?type="submit">Save<\/button>/, f
|
105
|
-
assert_match /a .*href="\/somewhere".*>Cancel<\/a>/, f
|
106
|
-
end
|
107
|
-
|
108
|
-
def entry
|
109
|
-
@entry ||= CrudTestModel.first
|
110
|
-
end
|
111
|
-
end
|
@@ -1,123 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'crud_test_model'
|
3
|
-
require 'custom_assertions'
|
4
|
-
|
5
|
-
class ListHelperTest < ActionView::TestCase
|
6
|
-
|
7
|
-
include StandardHelper
|
8
|
-
include CrudTestHelper
|
9
|
-
include CustomAssertions
|
10
|
-
|
11
|
-
attr_reader :entries
|
12
|
-
|
13
|
-
setup :reset_db, :setup_db, :create_test_data
|
14
|
-
teardown :reset_db
|
15
|
-
|
16
|
-
test "standard list table" do
|
17
|
-
@entries = CrudTestModel.all
|
18
|
-
|
19
|
-
t = with_test_routing do
|
20
|
-
list_table
|
21
|
-
end
|
22
|
-
|
23
|
-
assert_count 7, REGEXP_ROWS, t
|
24
|
-
assert_count 13, REGEXP_SORT_HEADERS, t
|
25
|
-
end
|
26
|
-
|
27
|
-
test "custom list table with attributes" do
|
28
|
-
@entries = CrudTestModel.all
|
29
|
-
|
30
|
-
t = with_test_routing do
|
31
|
-
list_table :name, :children, :companion_id
|
32
|
-
end
|
33
|
-
|
34
|
-
assert_count 7, REGEXP_ROWS, t
|
35
|
-
assert_count 3, REGEXP_SORT_HEADERS, t
|
36
|
-
end
|
37
|
-
|
38
|
-
test "custom list table with block" do
|
39
|
-
@entries = CrudTestModel.all
|
40
|
-
|
41
|
-
t = with_test_routing do
|
42
|
-
list_table do |t|
|
43
|
-
t.attrs :name, :children, :companion_id
|
44
|
-
t.col("head") {|e| content_tag :span, e.income.to_s }
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
assert_count 7, REGEXP_ROWS, t
|
49
|
-
assert_count 4, REGEXP_HEADERS, t
|
50
|
-
assert_count 0, REGEXP_SORT_HEADERS, t
|
51
|
-
assert_count 6, /<span>.+?<\/span>/, t
|
52
|
-
end
|
53
|
-
|
54
|
-
test "custom list table with attributes and block" do
|
55
|
-
@entries = CrudTestModel.all
|
56
|
-
|
57
|
-
t = with_test_routing do
|
58
|
-
list_table :name, :children, :companion_id do |t|
|
59
|
-
t.col("head") {|e| content_tag :span, e.income.to_s }
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
assert_count 7, REGEXP_ROWS, t
|
64
|
-
assert_count 3, REGEXP_SORT_HEADERS, t
|
65
|
-
assert_count 4, REGEXP_HEADERS, t
|
66
|
-
assert_count 6, /<span>.+?<\/span>/, t
|
67
|
-
end
|
68
|
-
|
69
|
-
test "standard list table with ascending sort params" do
|
70
|
-
def params
|
71
|
-
{:sort => 'children', :sort_dir => 'asc'}
|
72
|
-
end
|
73
|
-
|
74
|
-
@entries = CrudTestModel.all
|
75
|
-
|
76
|
-
t = with_test_routing do
|
77
|
-
list_table
|
78
|
-
end
|
79
|
-
|
80
|
-
assert_count 7, REGEXP_ROWS, t
|
81
|
-
assert_count 12, REGEXP_SORT_HEADERS, t
|
82
|
-
assert_count 1, /<th><a .*?sort_dir=desc.*?>Children<\/a> ↓<\/th>/, t
|
83
|
-
end
|
84
|
-
|
85
|
-
test "standard list table with descending sort params" do
|
86
|
-
def params
|
87
|
-
{:sort => 'children', :sort_dir => 'desc'}
|
88
|
-
end
|
89
|
-
|
90
|
-
@entries = CrudTestModel.all
|
91
|
-
|
92
|
-
t = with_test_routing do
|
93
|
-
list_table
|
94
|
-
end
|
95
|
-
|
96
|
-
assert_count 7, REGEXP_ROWS, t
|
97
|
-
assert_count 12, REGEXP_SORT_HEADERS, t
|
98
|
-
assert_count 1, /<th><a .*?sort_dir=asc.*?>Children<\/a> ↑<\/th>/, t
|
99
|
-
end
|
100
|
-
|
101
|
-
test "list table with custom column sort params" do
|
102
|
-
def params
|
103
|
-
{:sort => 'chatty', :sort_dir => 'asc'}
|
104
|
-
end
|
105
|
-
|
106
|
-
@entries = CrudTestModel.all
|
107
|
-
|
108
|
-
t = with_test_routing do
|
109
|
-
list_table :name, :children, :chatty
|
110
|
-
end
|
111
|
-
|
112
|
-
assert_count 7, REGEXP_ROWS, t
|
113
|
-
assert_count 2, REGEXP_SORT_HEADERS, t
|
114
|
-
assert_count 1, /<th><a .*?sort_dir=desc.*?>Chatty<\/a> ↓<\/th>/, t
|
115
|
-
end
|
116
|
-
|
117
|
-
test "default attributes do not include id" do
|
118
|
-
assert_equal [:name, :whatever, :children, :companion_id, :rating, :income,
|
119
|
-
:birthdate, :gets_up_at, :last_seen, :human, :remarks,
|
120
|
-
:created_at, :updated_at], default_attrs
|
121
|
-
end
|
122
|
-
|
123
|
-
end
|
@@ -1,281 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'crud_test_model'
|
3
|
-
|
4
|
-
class StandardHelperTest < ActionView::TestCase
|
5
|
-
|
6
|
-
include StandardHelper
|
7
|
-
include CrudTestHelper
|
8
|
-
|
9
|
-
setup :reset_db, :setup_db, :create_test_data
|
10
|
-
teardown :reset_db
|
11
|
-
|
12
|
-
def format_size(obj)
|
13
|
-
"#{f(obj.size)} items"
|
14
|
-
end
|
15
|
-
|
16
|
-
def format_string_size(obj)
|
17
|
-
"#{f(obj.size)} chars"
|
18
|
-
end
|
19
|
-
|
20
|
-
test "labeled text as block" do
|
21
|
-
result = labeled("label") { "value" }
|
22
|
-
|
23
|
-
assert result.html_safe?
|
24
|
-
assert_dom_equal "<div class='labeled'> <label>label</label> <div class='value'>value</div> </div>", result.squish
|
25
|
-
end
|
26
|
-
|
27
|
-
test "labeled text empty" do
|
28
|
-
result = labeled("label", "")
|
29
|
-
|
30
|
-
assert result.html_safe?
|
31
|
-
assert_dom_equal "<div class='labeled'> <label>label</label> <div class='value'>#{EMPTY_STRING}</div> </div>", result.squish
|
32
|
-
end
|
33
|
-
|
34
|
-
test "labeled text as content" do
|
35
|
-
result = labeled("label", "value <unsafe>")
|
36
|
-
|
37
|
-
assert result.html_safe?
|
38
|
-
assert_dom_equal "<div class='labeled'> <label>label</label> <div class='value'>value <unsafe></div> </div>", result.squish
|
39
|
-
end
|
40
|
-
|
41
|
-
test "labeled attr" do
|
42
|
-
result = labeled_attr('foo', :size)
|
43
|
-
assert result.html_safe?
|
44
|
-
assert_dom_equal "<div class='labeled'> <label>Size</label> <div class='value'>3 chars</div> </div>", result.squish
|
45
|
-
end
|
46
|
-
|
47
|
-
test "format Fixnums" do
|
48
|
-
assert_equal "0", f(0)
|
49
|
-
assert_equal "10", f(10)
|
50
|
-
assert_equal "10,000,000", f(10000000)
|
51
|
-
end
|
52
|
-
|
53
|
-
test "format Floats" do
|
54
|
-
assert_equal "1.000", f(1.0)
|
55
|
-
assert_equal "1.200", f(1.2)
|
56
|
-
assert_equal "3.142", f(3.14159)
|
57
|
-
end
|
58
|
-
|
59
|
-
test "format Booleans" do
|
60
|
-
assert_equal "yes", f(true)
|
61
|
-
assert_equal "no", f(false)
|
62
|
-
end
|
63
|
-
|
64
|
-
test "format nil" do
|
65
|
-
assert EMPTY_STRING.html_safe?
|
66
|
-
assert_equal EMPTY_STRING, f(nil)
|
67
|
-
end
|
68
|
-
|
69
|
-
test "format Strings" do
|
70
|
-
assert_equal "blah blah", f("blah blah")
|
71
|
-
assert_equal "<injection>", f("<injection>")
|
72
|
-
assert !f("<injection>").html_safe?
|
73
|
-
end
|
74
|
-
|
75
|
-
test "format attr with fallthrough to f" do
|
76
|
-
assert_equal "12.234", format_attr("12.23424", :to_f)
|
77
|
-
end
|
78
|
-
|
79
|
-
test "format attr with custom format_string_size method" do
|
80
|
-
assert_equal "4 chars", format_attr("abcd", :size)
|
81
|
-
end
|
82
|
-
|
83
|
-
test "format attr with custom format_size method" do
|
84
|
-
assert_equal "2 items", format_attr([1,2], :size)
|
85
|
-
end
|
86
|
-
|
87
|
-
test "column types" do
|
88
|
-
m = crud_test_models(:AAAAA)
|
89
|
-
assert_equal :string, column_type(m, :name)
|
90
|
-
assert_equal :integer, column_type(m, :children)
|
91
|
-
assert_equal :integer, column_type(m, :companion_id)
|
92
|
-
assert_equal nil, column_type(m, :companion)
|
93
|
-
assert_equal :float, column_type(m, :rating)
|
94
|
-
assert_equal :decimal, column_type(m, :income)
|
95
|
-
assert_equal :date, column_type(m, :birthdate)
|
96
|
-
assert_equal :time, column_type(m, :gets_up_at)
|
97
|
-
assert_equal :datetime, column_type(m, :last_seen)
|
98
|
-
assert_equal :boolean, column_type(m, :human)
|
99
|
-
assert_equal :text, column_type(m, :remarks)
|
100
|
-
end
|
101
|
-
|
102
|
-
test "format integer column" do
|
103
|
-
m = crud_test_models(:AAAAA)
|
104
|
-
assert_equal '9', format_type(m, :children)
|
105
|
-
|
106
|
-
m.children = 10000
|
107
|
-
assert_equal '10,000', format_type(m, :children)
|
108
|
-
end
|
109
|
-
|
110
|
-
test "format float column" do
|
111
|
-
m = crud_test_models(:AAAAA)
|
112
|
-
assert_equal '1.100', format_type(m, :rating)
|
113
|
-
|
114
|
-
m.rating = 3.145001 # you never know with these floats..
|
115
|
-
assert_equal '3.145', format_type(m, :rating)
|
116
|
-
end
|
117
|
-
|
118
|
-
test "format decimal column" do
|
119
|
-
m = crud_test_models(:AAAAA)
|
120
|
-
assert_equal '10,000,000.100', format_type(m, :income)
|
121
|
-
end
|
122
|
-
|
123
|
-
test "format date column" do
|
124
|
-
m = crud_test_models(:AAAAA)
|
125
|
-
assert_equal '1910-01-01', format_type(m, :birthdate)
|
126
|
-
end
|
127
|
-
|
128
|
-
test "format time column" do
|
129
|
-
m = crud_test_models(:AAAAA)
|
130
|
-
assert_equal '01:01', format_type(m, :gets_up_at)
|
131
|
-
end
|
132
|
-
|
133
|
-
test "format datetime column" do
|
134
|
-
m = crud_test_models(:AAAAA)
|
135
|
-
assert_equal "2010-01-01 11:21", format_type(m, :last_seen)
|
136
|
-
end
|
137
|
-
|
138
|
-
test "format text column" do
|
139
|
-
m = crud_test_models(:AAAAA)
|
140
|
-
assert_equal "<p>AAAAA BBBBB CCCCC\n<br />AAAAA BBBBB CCCCC\n</p>", format_type(m, :remarks)
|
141
|
-
assert format_type(m, :remarks).html_safe?
|
142
|
-
end
|
143
|
-
|
144
|
-
test "format belongs to column without content" do
|
145
|
-
m = crud_test_models(:AAAAA)
|
146
|
-
assert_equal t(:'global.associations.no_entry'), format_attr(m, :companion)
|
147
|
-
end
|
148
|
-
|
149
|
-
test "format belongs to column with content" do
|
150
|
-
m = crud_test_models(:BBBBB)
|
151
|
-
assert_equal "AAAAA", format_attr(m, :companion)
|
152
|
-
end
|
153
|
-
|
154
|
-
test "format has_many column with content" do
|
155
|
-
m = crud_test_models(:CCCCC)
|
156
|
-
assert_equal "<ul><li>AAAAA</li><li>BBBBB</li></ul>", format_attr(m, :others)
|
157
|
-
end
|
158
|
-
|
159
|
-
test "content_tag_nested escapes safe correctly" do
|
160
|
-
html = content_tag_nested(:div, ['a', 'b']) { |e| content_tag(:span, e) }
|
161
|
-
assert_equal "<div><span>a</span><span>b</span></div>", html
|
162
|
-
end
|
163
|
-
|
164
|
-
test "content_tag_nested escapes unsafe correctly" do
|
165
|
-
html = content_tag_nested(:div, ['a', 'b']) { |e| "<#{e}>" }
|
166
|
-
assert_equal "<div><a><b></div>", html
|
167
|
-
end
|
168
|
-
|
169
|
-
test "content_tag_nested without block" do
|
170
|
-
html = content_tag_nested(:div, ['a', 'b'])
|
171
|
-
assert_equal "<div>ab</div>", html
|
172
|
-
end
|
173
|
-
|
174
|
-
test "safe_join without block" do
|
175
|
-
html = safe_join(['<a>', '<b>'.html_safe])
|
176
|
-
assert_equal "<a><b>", html
|
177
|
-
end
|
178
|
-
|
179
|
-
test "safe_join with block" do
|
180
|
-
html = safe_join(['a', 'b']) { |e| content_tag(:span, e) }
|
181
|
-
assert_equal "<span>a</span><span>b</span>", html
|
182
|
-
end
|
183
|
-
|
184
|
-
test "empty table should render message" do
|
185
|
-
result = table([]) { }
|
186
|
-
assert result.html_safe?
|
187
|
-
assert_dom_equal "<div class='table'>No entries found.</div>", result
|
188
|
-
end
|
189
|
-
|
190
|
-
test "non empty table should render table" do
|
191
|
-
result = table(['foo', 'bar']) {|t| t.attrs :size, :upcase }
|
192
|
-
assert result.html_safe?
|
193
|
-
assert_match(/^\<table.*\<\/table\>$/, result)
|
194
|
-
end
|
195
|
-
|
196
|
-
test "table with attrs" do
|
197
|
-
expected = StandardTableBuilder.table(['foo', 'bar'], self) { |t| t.attrs :size, :upcase }
|
198
|
-
actual = table(['foo', 'bar'], :size, :upcase)
|
199
|
-
assert actual.html_safe?
|
200
|
-
assert_equal expected, actual
|
201
|
-
end
|
202
|
-
|
203
|
-
test "captionize" do
|
204
|
-
assert_equal "Camel Case", captionize(:camel_case)
|
205
|
-
assert_equal "All Upper Case", captionize("all upper case")
|
206
|
-
assert_equal "With Object", captionize("With object", Object.new)
|
207
|
-
assert !captionize('bad <title>').html_safe?
|
208
|
-
end
|
209
|
-
|
210
|
-
test "standard form for existing entry" do
|
211
|
-
e = crud_test_models('AAAAA')
|
212
|
-
f = with_test_routing do
|
213
|
-
f = capture { standard_form(e, :class => 'special') {|f|} }
|
214
|
-
end
|
215
|
-
|
216
|
-
assert_match /form .*?action="\/crud_test_models\/#{e.id}" .*?method="post"/, f
|
217
|
-
assert_match /input .*?name="_method" .*?type="hidden" .*?value="put"/, f
|
218
|
-
end
|
219
|
-
|
220
|
-
test "standard form with errors" do
|
221
|
-
e = crud_test_models('AAAAA')
|
222
|
-
e.name = nil
|
223
|
-
assert !e.valid?
|
224
|
-
|
225
|
-
f = with_test_routing do
|
226
|
-
f = capture { standard_form(e) {|f| f.labeled_input_fields(:name, :birthdate) } }
|
227
|
-
end
|
228
|
-
|
229
|
-
assert_match /form .*?action="\/crud_test_models\/#{e.id}" .*?method="post"/, f
|
230
|
-
assert_match /input .*?name="_method" .*?type="hidden" .*?value="put"/, f
|
231
|
-
assert_match /div[^>]* id='error_explanation'/, f
|
232
|
-
assert_match /div class="control-group error"\>.*?\<input .*?name="crud_test_model\[name\]" .*?type="text"/, f
|
233
|
-
assert_match /select .*?name="crud_test_model\[birthdate\(1i\)\]"/, f
|
234
|
-
assert_match /option selected="selected" value="1910">1910<\/option>/, f
|
235
|
-
assert_match /option selected="selected" value="1">January<\/option>/, f
|
236
|
-
assert_match /option selected="selected" value="1">1<\/option>/, f
|
237
|
-
end
|
238
|
-
|
239
|
-
test "translate inheritable lookup" do
|
240
|
-
# current controller is :crud_test_models, action is :index
|
241
|
-
@controller = CrudTestModelsController.new
|
242
|
-
|
243
|
-
I18n.backend.store_translations :en, :global => { :test_key => 'global' }
|
244
|
-
assert_equal 'global', ti(:test_key)
|
245
|
-
|
246
|
-
I18n.backend.store_translations :en, :list => { :global => {:test_key => 'list global'} }
|
247
|
-
assert_equal 'list global', ti(:test_key)
|
248
|
-
|
249
|
-
I18n.backend.store_translations :en, :list => { :index => {:test_key => 'list index'} }
|
250
|
-
assert_equal 'list index', ti(:test_key)
|
251
|
-
|
252
|
-
I18n.backend.store_translations :en, :crud => { :global => {:test_key => 'crud global'} }
|
253
|
-
assert_equal 'crud global', ti(:test_key)
|
254
|
-
|
255
|
-
I18n.backend.store_translations :en, :crud => { :index => {:test_key => 'crud index'} }
|
256
|
-
assert_equal 'crud index', ti(:test_key)
|
257
|
-
|
258
|
-
I18n.backend.store_translations :en, :crud_test_models => { :global => {:test_key => 'test global'} }
|
259
|
-
assert_equal 'test global', ti(:test_key)
|
260
|
-
|
261
|
-
I18n.backend.store_translations :en, :crud_test_models => { :index => {:test_key => 'test index'} }
|
262
|
-
assert_equal 'test index', ti(:test_key)
|
263
|
-
end
|
264
|
-
|
265
|
-
test "translate association lookup" do
|
266
|
-
assoc = CrudTestModel.reflect_on_association(:companion)
|
267
|
-
|
268
|
-
I18n.backend.store_translations :en, :global => { :associations => {:test_key => 'global'} }
|
269
|
-
assert_equal 'global', ta(:test_key, assoc)
|
270
|
-
|
271
|
-
I18n.backend.store_translations :en, :activerecord => { :associations => { :crud_test_model => {:test_key => 'model'} } }
|
272
|
-
assert_equal 'model', ta(:test_key, assoc)
|
273
|
-
|
274
|
-
I18n.backend.store_translations :en, :activerecord => { :associations => { :models => {
|
275
|
-
:crud_test_model => { :companion => {:test_key => 'companion'} } } } }
|
276
|
-
assert_equal 'companion', ta(:test_key, assoc)
|
277
|
-
|
278
|
-
assert_equal 'global', ta(:test_key)
|
279
|
-
end
|
280
|
-
|
281
|
-
end
|