dry_crud 1.2.7 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +60 -27
- data/Rakefile +3 -1
- data/VERSION +1 -1
- data/lib/generators/dry_crud/dry_crud_generator.rb +3 -3
- data/lib/generators/dry_crud/templates/INSTALL +3 -1
- data/lib/generators/dry_crud/templates/app/controllers/crud_controller.rb +106 -90
- data/lib/generators/dry_crud/templates/app/controllers/list_controller.rb +90 -74
- data/lib/generators/dry_crud/templates/app/controllers/render_inheritable.rb +34 -33
- data/lib/generators/dry_crud/templates/app/helpers/crud_helper.rb +39 -23
- data/lib/generators/dry_crud/templates/app/helpers/list_helper.rb +11 -9
- data/lib/generators/dry_crud/templates/app/helpers/standard_form_builder.rb +55 -47
- data/lib/generators/dry_crud/templates/app/helpers/standard_helper.rb +134 -86
- data/lib/generators/dry_crud/templates/app/helpers/standard_table_builder.rb +41 -35
- data/lib/generators/dry_crud/templates/app/views/crud/_actions_edit.html.erb +1 -0
- data/lib/generators/dry_crud/templates/app/views/crud/edit.html.erb +3 -3
- data/lib/generators/dry_crud/templates/app/views/crud/new.html.erb +2 -2
- data/lib/generators/dry_crud/templates/app/views/crud/show.html.erb +3 -3
- data/lib/generators/dry_crud/templates/app/views/layouts/crud.html.erb +9 -7
- data/lib/generators/dry_crud/templates/app/views/list/_search.html.erb +1 -1
- data/lib/generators/dry_crud/templates/app/views/list/index.html.erb +4 -4
- data/lib/generators/dry_crud/templates/app/views/shared/_error_messages.html.erb +3 -1
- data/lib/generators/dry_crud/templates/config/locales/en_crud.yml +63 -0
- data/lib/generators/dry_crud/templates/test/crud_test_model.rb +93 -58
- data/lib/generators/dry_crud/templates/test/custom_assertions.rb +24 -13
- data/lib/generators/dry_crud/templates/test/functional/crud_controller_test_helper.rb +26 -56
- data/lib/generators/dry_crud/templates/test/functional/crud_test_models_controller_test.rb +47 -41
- data/lib/generators/dry_crud/templates/test/unit/custom_assertions_test.rb +28 -24
- data/lib/generators/dry_crud/templates/test/unit/helpers/crud_helper_test.rb +20 -34
- data/lib/generators/dry_crud/templates/test/unit/helpers/list_helper_test.rb +39 -53
- data/lib/generators/dry_crud/templates/test/unit/helpers/render_inheritable_test.rb +33 -33
- data/lib/generators/dry_crud/templates/test/unit/helpers/standard_form_builder_test.rb +27 -27
- data/lib/generators/dry_crud/templates/test/unit/helpers/standard_helper_test.rb +103 -50
- data/lib/generators/dry_crud/templates/test/unit/helpers/standard_table_builder_test.rb +52 -24
- data/test/templates/Gemfile +34 -0
- data/test/templates/app/controllers/ajax_controller.rb +3 -3
- data/test/templates/app/controllers/application_controller.rb +1 -1
- data/test/templates/app/controllers/cities_controller.rb +2 -5
- data/test/templates/app/controllers/people_controller.rb +5 -5
- data/test/templates/app/controllers/vips_controller.rb +6 -11
- data/test/templates/app/helpers/people_helper.rb +2 -2
- data/test/templates/app/models/city.rb +9 -9
- data/test/templates/app/models/person.rb +5 -4
- data/test/templates/app/views/ajax/_actions_index.html.erb +2 -2
- data/test/templates/app/views/cities/_form.html.erb +5 -1
- data/test/templates/app/views/layouts/_menu.html.erb +3 -3
- data/test/templates/app/views/people/_attrs.html.erb +3 -3
- data/test/templates/config/database.yml +22 -0
- data/test/templates/config/locales/en_cities.yml +56 -0
- data/test/templates/config/routes.rb +5 -5
- data/test/templates/db/migrate/20100511174904_create_people_and_cities.rb +5 -2
- data/test/templates/db/seeds.rb +38 -29
- data/test/templates/test/functional/cities_controller_test.rb +12 -12
- data/test/templates/test/functional/people_controller_test.rb +10 -10
- metadata +11 -7
@@ -7,58 +7,62 @@ class CustomAssertionsTest < ActiveSupport::TestCase
|
|
7
7
|
include CustomAssertions
|
8
8
|
|
9
9
|
include CrudTestHelper
|
10
|
-
|
10
|
+
|
11
11
|
setup :reset_db, :setup_db, :create_test_data
|
12
12
|
teardown :reset_db
|
13
13
|
|
14
|
+
AssertionException = RUBY_VERSION.to_f == 1.9 ?
|
15
|
+
MiniTest::Assertion :
|
16
|
+
Test::Unit::AssertionFailedError
|
17
|
+
|
14
18
|
test "assert include succeeds if included" do
|
15
19
|
assert_nothing_raised do
|
16
20
|
assert_include [1,2,3], 2
|
17
21
|
end
|
18
22
|
end
|
19
|
-
|
23
|
+
|
20
24
|
test "assert include succeeds if record included" do
|
21
25
|
assert_nothing_raised do
|
22
26
|
assert_include CrudTestModel.all, crud_test_models("AAAAA")
|
23
27
|
end
|
24
28
|
end
|
25
|
-
|
29
|
+
|
26
30
|
test "assert include fails if not included" do
|
27
|
-
assert_raise(
|
31
|
+
assert_raise(AssertionException) do
|
28
32
|
assert_include [1,2,3], 5
|
29
33
|
end
|
30
34
|
end
|
31
|
-
|
35
|
+
|
32
36
|
test "assert not include succeeds if not included" do
|
33
37
|
assert_nothing_raised do
|
34
38
|
assert_not_include [1,2,3], 5
|
35
39
|
end
|
36
40
|
end
|
37
|
-
|
41
|
+
|
38
42
|
test "assert not include fails if included" do
|
39
|
-
assert_raise(
|
43
|
+
assert_raise(AssertionException) do
|
40
44
|
assert_not_include [1,2,3], 3
|
41
45
|
end
|
42
46
|
end
|
43
|
-
|
47
|
+
|
44
48
|
test "assert count succeeds if count matches" do
|
45
49
|
assert_nothing_raised do
|
46
50
|
assert_count 3, "ba", "barbabapa"
|
47
51
|
end
|
48
52
|
end
|
49
|
-
|
53
|
+
|
50
54
|
test "assert count succeeds if count is zero" do
|
51
55
|
assert_nothing_raised do
|
52
56
|
assert_count 0, "bo", "barbabapa"
|
53
57
|
end
|
54
58
|
end
|
55
|
-
|
59
|
+
|
56
60
|
test "assert count fails if count does not match" do
|
57
|
-
assert_raise(
|
61
|
+
assert_raise(AssertionException) do
|
58
62
|
assert_count 2, "ba", "barbabapa"
|
59
63
|
end
|
60
64
|
end
|
61
|
-
|
65
|
+
|
62
66
|
test "assert valid record succeeds" do
|
63
67
|
assert_nothing_raised do
|
64
68
|
assert_valid crud_test_models("AAAAA")
|
@@ -66,48 +70,48 @@ class CustomAssertionsTest < ActiveSupport::TestCase
|
|
66
70
|
end
|
67
71
|
|
68
72
|
test "assert valid record fails for invalid" do
|
69
|
-
assert_raise(
|
73
|
+
assert_raise(AssertionException) do
|
70
74
|
assert_valid invalid_record
|
71
75
|
end
|
72
76
|
end
|
73
|
-
|
77
|
+
|
74
78
|
test "assert not valid succeeds if record invalid" do
|
75
79
|
assert_nothing_raised do
|
76
80
|
assert_not_valid invalid_record
|
77
81
|
end
|
78
82
|
end
|
79
|
-
|
83
|
+
|
80
84
|
test "assert not valid succeds if record invalid and invalid attrs given" do
|
81
85
|
assert_nothing_raised do
|
82
86
|
assert_not_valid invalid_record, :name, :rating
|
83
87
|
end
|
84
88
|
end
|
85
|
-
|
89
|
+
|
86
90
|
test "assert not valid fails if record valid" do
|
87
|
-
assert_raise(
|
91
|
+
assert_raise(AssertionException) do
|
88
92
|
assert_not_valid crud_test_models("AAAAA")
|
89
93
|
end
|
90
94
|
end
|
91
|
-
|
95
|
+
|
92
96
|
test "assert not valid fails if record invalid and valid attrs given" do
|
93
|
-
assert_raise(
|
97
|
+
assert_raise(AssertionException) do
|
94
98
|
assert_not_valid invalid_record, :name, :rating, :children
|
95
99
|
end
|
96
100
|
end
|
97
|
-
|
101
|
+
|
98
102
|
test "assert not valid fails if record invalid and not all invalid attrs given" do
|
99
|
-
assert_raise(
|
103
|
+
assert_raise(AssertionException) do
|
100
104
|
assert_not_valid invalid_record, :name
|
101
105
|
end
|
102
106
|
end
|
103
|
-
|
107
|
+
|
104
108
|
private
|
105
|
-
|
109
|
+
|
106
110
|
def invalid_record
|
107
111
|
m = crud_test_models("AAAAA")
|
108
112
|
m.name = nil
|
109
113
|
m.rating = 42
|
110
114
|
m
|
111
115
|
end
|
112
|
-
|
116
|
+
|
113
117
|
end
|
@@ -3,82 +3,82 @@ require 'crud_test_model'
|
|
3
3
|
require 'custom_assertions'
|
4
4
|
|
5
5
|
class CrudHelperTest < ActionView::TestCase
|
6
|
-
|
6
|
+
|
7
7
|
REGEXP_ROWS = /<tr.+?<\/tr>/m
|
8
8
|
REGEXP_HEADERS = /<th.+?<\/th>/m
|
9
9
|
REGEXP_SORT_HEADERS = /<th><a .*?sort_dir=asc.*?>.*?<\/a><\/th>/m
|
10
10
|
REGEXP_ACTION_CELL = /<td class=\"center\"><a href.+?<\/a><\/td>/m
|
11
|
-
|
11
|
+
|
12
12
|
include CustomAssertions
|
13
13
|
include StandardHelper
|
14
14
|
include ListHelper
|
15
15
|
include CrudTestHelper
|
16
|
-
|
16
|
+
|
17
17
|
setup :reset_db, :setup_db, :create_test_data
|
18
18
|
teardown :reset_db
|
19
|
-
|
19
|
+
|
20
20
|
test "standard crud table" do
|
21
21
|
@entries = CrudTestModel.all
|
22
|
-
|
23
|
-
t = with_test_routing do
|
22
|
+
|
23
|
+
t = with_test_routing do
|
24
24
|
crud_table
|
25
25
|
end
|
26
|
-
|
26
|
+
|
27
27
|
assert_count 7, REGEXP_ROWS, t
|
28
|
-
assert_count
|
28
|
+
assert_count 13, REGEXP_SORT_HEADERS, t
|
29
29
|
assert_count 18, REGEXP_ACTION_CELL, t # show, edit, delete links
|
30
30
|
end
|
31
|
-
|
31
|
+
|
32
32
|
test "custom crud table with attributes" do
|
33
33
|
@entries = CrudTestModel.all
|
34
|
-
|
34
|
+
|
35
35
|
t = with_test_routing do
|
36
36
|
crud_table :name, :children, :companion_id
|
37
37
|
end
|
38
|
-
|
38
|
+
|
39
39
|
assert_count 7, REGEXP_ROWS, t
|
40
40
|
assert_count 3, REGEXP_SORT_HEADERS, t
|
41
41
|
assert_count 18, REGEXP_ACTION_CELL, t # show, edit, delete links
|
42
42
|
end
|
43
|
-
|
43
|
+
|
44
44
|
test "custom crud table with block" do
|
45
45
|
@entries = CrudTestModel.all
|
46
|
-
|
46
|
+
|
47
47
|
t = with_test_routing do
|
48
48
|
crud_table do |t|
|
49
49
|
t.attrs :name, :children, :companion_id
|
50
50
|
t.col("head") {|e| content_tag :span, e.income.to_s }
|
51
51
|
end
|
52
52
|
end
|
53
|
-
|
53
|
+
|
54
54
|
assert_count 7, REGEXP_ROWS, t
|
55
55
|
assert_count 4, REGEXP_HEADERS, t
|
56
56
|
assert_count 6, /<span>.+?<\/span>/m, t
|
57
57
|
assert_count 0, REGEXP_ACTION_CELL, t # no show, edit, delete links
|
58
58
|
end
|
59
|
-
|
59
|
+
|
60
60
|
test "custom crud table with attributes and block" do
|
61
61
|
@entries = CrudTestModel.all
|
62
|
-
|
62
|
+
|
63
63
|
t = with_test_routing do
|
64
64
|
crud_table :name, :children, :companion_id do |t|
|
65
65
|
t.col("head") {|e| content_tag :span, e.income.to_s }
|
66
66
|
end
|
67
67
|
end
|
68
|
-
|
68
|
+
|
69
69
|
assert_count 7, REGEXP_ROWS, t
|
70
70
|
assert_count 4, REGEXP_HEADERS, t
|
71
71
|
assert_count 6, /<span>.+?<\/span>/m, t
|
72
72
|
assert_count 0, REGEXP_ACTION_CELL, t # no show, edit, delete links
|
73
73
|
end
|
74
|
-
|
75
|
-
|
74
|
+
|
75
|
+
|
76
76
|
test "crud form" do
|
77
77
|
@entry = CrudTestModel.first
|
78
78
|
f = with_test_routing do
|
79
79
|
capture { crud_form }
|
80
80
|
end
|
81
|
-
|
81
|
+
|
82
82
|
assert_match /form .*?action="\/crud_test_models\/#{@entry.id}"/, f
|
83
83
|
assert_match /input .*?name="crud_test_model\[name\]" .*?type="text"/, f
|
84
84
|
assert_match /input .*?name="crud_test_model\[whatever\]" .*?type="text"/, f
|
@@ -90,19 +90,5 @@ class CrudHelperTest < ActionView::TestCase
|
|
90
90
|
assert_match /select .*?name="crud_test_model\[companion_id\]"/, f
|
91
91
|
assert_match /textarea .*?name="crud_test_model\[remarks\]"/, f
|
92
92
|
end
|
93
|
-
|
94
|
-
# Controller helper methods for the tests
|
95
|
-
|
96
|
-
def model_class
|
97
|
-
CrudTestModel
|
98
|
-
end
|
99
|
-
|
100
|
-
def params
|
101
|
-
{}
|
102
|
-
end
|
103
|
-
|
104
|
-
def sortable?(attr)
|
105
|
-
true
|
106
|
-
end
|
107
93
|
|
108
94
|
end
|
@@ -3,137 +3,123 @@ require 'crud_test_model'
|
|
3
3
|
require 'custom_assertions'
|
4
4
|
|
5
5
|
class ListHelperTest < ActionView::TestCase
|
6
|
-
|
6
|
+
|
7
7
|
REGEXP_ROWS = /<tr.+?<\/tr>/m
|
8
8
|
REGEXP_HEADERS = /<th.+?<\/th>/m
|
9
9
|
REGEXP_SORT_HEADERS = /<th><a .*?sort_dir=asc.*?>.*?<\/a><\/th>/m
|
10
|
-
|
10
|
+
|
11
11
|
include StandardHelper
|
12
12
|
include CrudTestHelper
|
13
13
|
include CustomAssertions
|
14
|
-
|
14
|
+
|
15
15
|
setup :reset_db, :setup_db, :create_test_data
|
16
16
|
teardown :reset_db
|
17
|
-
|
17
|
+
|
18
18
|
test "standard list table" do
|
19
19
|
@entries = CrudTestModel.all
|
20
|
-
|
21
|
-
t = with_test_routing do
|
20
|
+
|
21
|
+
t = with_test_routing do
|
22
22
|
list_table
|
23
23
|
end
|
24
|
-
|
24
|
+
|
25
25
|
assert_count 7, REGEXP_ROWS, t
|
26
|
-
assert_count
|
26
|
+
assert_count 13, REGEXP_SORT_HEADERS, t
|
27
27
|
end
|
28
|
-
|
28
|
+
|
29
29
|
test "custom list table with attributes" do
|
30
30
|
@entries = CrudTestModel.all
|
31
|
-
|
31
|
+
|
32
32
|
t = with_test_routing do
|
33
33
|
list_table :name, :children, :companion_id
|
34
34
|
end
|
35
|
-
|
35
|
+
|
36
36
|
assert_count 7, REGEXP_ROWS, t
|
37
37
|
assert_count 3, REGEXP_SORT_HEADERS, t
|
38
38
|
end
|
39
|
-
|
39
|
+
|
40
40
|
test "custom list table with block" do
|
41
41
|
@entries = CrudTestModel.all
|
42
|
-
|
42
|
+
|
43
43
|
t = with_test_routing do
|
44
44
|
list_table do |t|
|
45
45
|
t.attrs :name, :children, :companion_id
|
46
46
|
t.col("head") {|e| content_tag :span, e.income.to_s }
|
47
47
|
end
|
48
48
|
end
|
49
|
-
|
49
|
+
|
50
50
|
assert_count 7, REGEXP_ROWS, t
|
51
51
|
assert_count 4, REGEXP_HEADERS, t
|
52
52
|
assert_count 0, REGEXP_SORT_HEADERS, t
|
53
53
|
assert_count 6, /<span>.+?<\/span>/, t
|
54
54
|
end
|
55
|
-
|
55
|
+
|
56
56
|
test "custom list table with attributes and block" do
|
57
57
|
@entries = CrudTestModel.all
|
58
|
-
|
58
|
+
|
59
59
|
t = with_test_routing do
|
60
60
|
list_table :name, :children, :companion_id do |t|
|
61
61
|
t.col("head") {|e| content_tag :span, e.income.to_s }
|
62
62
|
end
|
63
63
|
end
|
64
|
-
|
64
|
+
|
65
65
|
assert_count 7, REGEXP_ROWS, t
|
66
66
|
assert_count 3, REGEXP_SORT_HEADERS, t
|
67
67
|
assert_count 4, REGEXP_HEADERS, t
|
68
68
|
assert_count 6, /<span>.+?<\/span>/, t
|
69
69
|
end
|
70
|
-
|
70
|
+
|
71
71
|
test "standard list table with ascending sort params" do
|
72
72
|
def params
|
73
73
|
{:sort => 'children', :sort_dir => 'asc'}
|
74
74
|
end
|
75
|
-
|
75
|
+
|
76
76
|
@entries = CrudTestModel.all
|
77
|
-
|
78
|
-
t = with_test_routing do
|
77
|
+
|
78
|
+
t = with_test_routing do
|
79
79
|
list_table
|
80
80
|
end
|
81
|
-
|
81
|
+
|
82
82
|
assert_count 7, REGEXP_ROWS, t
|
83
|
-
assert_count
|
83
|
+
assert_count 12, REGEXP_SORT_HEADERS, t
|
84
84
|
assert_count 1, /<th><a .*?sort_dir=desc.*?>Children<\/a> ↓<\/th>/, t
|
85
85
|
end
|
86
|
-
|
86
|
+
|
87
87
|
test "standard list table with descending sort params" do
|
88
88
|
def params
|
89
89
|
{:sort => 'children', :sort_dir => 'desc'}
|
90
90
|
end
|
91
|
-
|
91
|
+
|
92
92
|
@entries = CrudTestModel.all
|
93
|
-
|
94
|
-
t = with_test_routing do
|
93
|
+
|
94
|
+
t = with_test_routing do
|
95
95
|
list_table
|
96
96
|
end
|
97
|
-
|
97
|
+
|
98
98
|
assert_count 7, REGEXP_ROWS, t
|
99
|
-
assert_count
|
99
|
+
assert_count 12, REGEXP_SORT_HEADERS, t
|
100
100
|
assert_count 1, /<th><a .*?sort_dir=asc.*?>Children<\/a> ↑<\/th>/, t
|
101
101
|
end
|
102
|
-
|
102
|
+
|
103
103
|
test "list table with custom column sort params" do
|
104
104
|
def params
|
105
105
|
{:sort => 'chatty', :sort_dir => 'asc'}
|
106
106
|
end
|
107
|
-
|
107
|
+
|
108
108
|
@entries = CrudTestModel.all
|
109
|
-
|
110
|
-
t = with_test_routing do
|
109
|
+
|
110
|
+
t = with_test_routing do
|
111
111
|
list_table :name, :children, :chatty
|
112
112
|
end
|
113
|
-
|
113
|
+
|
114
114
|
assert_count 7, REGEXP_ROWS, t
|
115
115
|
assert_count 2, REGEXP_SORT_HEADERS, t
|
116
116
|
assert_count 1, /<th><a .*?sort_dir=desc.*?>Chatty<\/a> ↓<\/th>/, t
|
117
117
|
end
|
118
|
-
|
119
|
-
test "default attributes do not include id" do
|
120
|
-
assert_equal [:name, :whatever, :children, :companion_id, :rating, :income,
|
121
|
-
:birthdate, :
|
122
|
-
|
123
|
-
|
124
|
-
# Controller helper methods for the tests
|
125
|
-
|
126
|
-
def model_class
|
127
|
-
CrudTestModel
|
128
|
-
end
|
129
|
-
|
130
|
-
def params
|
131
|
-
{}
|
132
|
-
end
|
133
|
-
|
134
|
-
def sortable?(attr)
|
135
|
-
true
|
118
|
+
|
119
|
+
test "default attributes do not include id" do
|
120
|
+
assert_equal [:name, :whatever, :children, :companion_id, :rating, :income,
|
121
|
+
:birthdate, :gets_up_at, :last_seen, :human, :remarks,
|
122
|
+
:created_at, :updated_at], default_attrs
|
136
123
|
end
|
137
124
|
|
138
|
-
|
139
125
|
end
|
@@ -4,28 +4,28 @@ TEST_VIEW_PATH = File.join(Rails.root, 'test', 'test_views')
|
|
4
4
|
|
5
5
|
class RootController < ApplicationController
|
6
6
|
include RenderInheritable
|
7
|
-
|
7
|
+
|
8
8
|
attr_accessor :default_template_format
|
9
|
-
|
9
|
+
|
10
10
|
append_view_path(TEST_VIEW_PATH)
|
11
|
-
|
11
|
+
|
12
12
|
def initialize(*args)
|
13
13
|
super(*args)
|
14
14
|
self.default_template_format = :html
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
def view_paths
|
18
18
|
self.class.view_paths
|
19
19
|
end
|
20
|
-
|
20
|
+
|
21
21
|
end
|
22
22
|
|
23
23
|
class ChildrenController < RootController
|
24
|
-
|
24
|
+
|
25
25
|
end
|
26
26
|
|
27
27
|
class GrandChildrenController < ChildrenController
|
28
|
-
|
28
|
+
|
29
29
|
end
|
30
30
|
|
31
31
|
# mock File object
|
@@ -34,12 +34,12 @@ class File
|
|
34
34
|
def touched
|
35
35
|
@touched ||= []
|
36
36
|
end
|
37
|
-
|
37
|
+
|
38
38
|
alias_method :orig_exists?, :exists?
|
39
39
|
def exists?(filename, *args)
|
40
40
|
touched.include?(filename) || orig_exists?(filename, *args)
|
41
41
|
end
|
42
|
-
|
42
|
+
|
43
43
|
def touch_template(file)
|
44
44
|
touched << File.join(ActionController::Base.view_paths.first, "#{file}.html.erb")
|
45
45
|
end
|
@@ -47,9 +47,9 @@ class File
|
|
47
47
|
end
|
48
48
|
|
49
49
|
class RenderInheritableTest < ActiveSupport::TestCase
|
50
|
-
|
50
|
+
|
51
51
|
attr_reader :controller, :grand_controller
|
52
|
-
|
52
|
+
|
53
53
|
def setup
|
54
54
|
teardown
|
55
55
|
@controller = ChildrenController.new
|
@@ -57,7 +57,7 @@ class RenderInheritableTest < ActiveSupport::TestCase
|
|
57
57
|
ChildrenController.send(:inheritable_cache).clear
|
58
58
|
GrandChildrenController.send(:inheritable_cache).clear
|
59
59
|
end
|
60
|
-
|
60
|
+
|
61
61
|
def teardown
|
62
62
|
FileUtils.rm_rf(TEST_VIEW_PATH)
|
63
63
|
end
|
@@ -72,82 +72,82 @@ class RenderInheritableTest < ActiveSupport::TestCase
|
|
72
72
|
assert_equal ['children', 'root'], ChildrenController.send(:inheritance_lookup_path)
|
73
73
|
assert_equal ['grand_children', 'children', 'root'], GrandChildrenController.send(:inheritance_lookup_path)
|
74
74
|
end
|
75
|
-
|
75
|
+
|
76
76
|
test "inheritable controller finds controller instance" do
|
77
77
|
assert_equal 'children', ChildrenController.send(:inheritable_controller)
|
78
78
|
assert_equal 'grand_children', GrandChildrenController.send(:inheritable_controller)
|
79
79
|
end
|
80
|
-
|
80
|
+
|
81
81
|
test "find non-existing inheritable file" do
|
82
82
|
assert_nil @controller.send(:find_inheritable_template_folder, 'foo')
|
83
83
|
end
|
84
|
-
|
84
|
+
|
85
85
|
test "find inheritable file not overwritten" do
|
86
86
|
touch("root/root.html.erb")
|
87
|
-
|
87
|
+
|
88
88
|
assert_equal 'root', @controller.send(:find_inheritable_template_folder, 'root')
|
89
89
|
assert_equal 'root', @grand_controller.send(:find_inheritable_template_folder, 'root')
|
90
90
|
end
|
91
|
-
|
91
|
+
|
92
92
|
test "find inheritable file partially overwritten" do
|
93
93
|
touch("root/child.html.erb")
|
94
94
|
touch("children/child.html.erb")
|
95
|
-
|
95
|
+
|
96
96
|
assert_equal 'children', @controller.send(:find_inheritable_template_folder, 'child')
|
97
97
|
assert_equal 'children', @grand_controller.send(:find_inheritable_template_folder, 'child')
|
98
98
|
end
|
99
|
-
|
99
|
+
|
100
100
|
test "find inheritable file partially overwritten with gaps" do
|
101
101
|
touch("root/grandchild.html.erb")
|
102
102
|
touch("grand_children/grandchild.rhtml")
|
103
|
-
|
103
|
+
|
104
104
|
assert_equal 'root', @controller.send(:find_inheritable_template_folder, 'grandchild')
|
105
105
|
assert_equal 'grand_children', @grand_controller.send(:find_inheritable_template_folder, 'grandchild')
|
106
106
|
end
|
107
|
-
|
107
|
+
|
108
108
|
test "find inheritable file for js format" do
|
109
109
|
touch("root/_grandchild.js.rjs")
|
110
110
|
touch("grand_children/_grandchild.js.rjs")
|
111
|
-
|
111
|
+
|
112
112
|
assert_equal 'root', @controller.send(:find_inheritable_template_folder, 'grandchild', true)
|
113
113
|
assert_equal 'grand_children', @grand_controller.send(:find_inheritable_template_folder, 'grandchild', true)
|
114
|
-
|
114
|
+
|
115
115
|
assert_equal({:js => { true => {'grandchild' => {nil => 'root'}}}}, ChildrenController.send(:inheritable_cache))
|
116
116
|
assert_equal({:js => { true => {'grandchild' => {nil => 'grand_children'}}}}, GrandChildrenController.send(:inheritable_cache))
|
117
117
|
end
|
118
|
-
|
118
|
+
|
119
119
|
test "find inheritable file for xml format" do
|
120
120
|
touch("root/_grandchild.xml.builder")
|
121
121
|
touch("grand_children/_grandchild.xml.builder")
|
122
|
-
|
122
|
+
|
123
123
|
assert_equal 'root', @controller.send(:find_inheritable_template_folder, 'grandchild', true)
|
124
124
|
assert_equal 'grand_children', @grand_controller.send(:find_inheritable_template_folder, 'grandchild', true)
|
125
125
|
end
|
126
|
-
|
126
|
+
|
127
127
|
test "find inheritable file all overwritten" do
|
128
128
|
touch("root/all.html.erb")
|
129
129
|
touch("children/all.rhtml")
|
130
130
|
touch("grand_children/all.html.erb")
|
131
|
-
|
131
|
+
|
132
132
|
assert_equal 'children', @controller.send(:find_inheritable_template_folder, 'all')
|
133
133
|
assert_equal 'grand_children', @grand_controller.send(:find_inheritable_template_folder, 'all')
|
134
|
-
|
134
|
+
|
135
135
|
assert_equal({:html => { false => { 'all' => {nil => 'children'}}}}, ChildrenController.send(:inheritable_cache))
|
136
136
|
assert_equal({:html => { false => { 'all' => {nil => 'grand_children'}}}}, GrandChildrenController.send(:inheritable_cache))
|
137
|
-
|
137
|
+
|
138
138
|
assert_equal 'children', @controller.send(:find_inheritable_template_folder, 'all')
|
139
139
|
assert_equal 'grand_children', @grand_controller.send(:find_inheritable_template_folder, 'all')
|
140
|
-
|
140
|
+
|
141
141
|
assert_equal({:html => { false => { 'all' => {nil => 'children'}}}}, ChildrenController.send(:inheritable_cache))
|
142
|
-
assert_equal({:html => { false => { 'all' => {nil => 'grand_children'}}}}, GrandChildrenController.send(:inheritable_cache))
|
142
|
+
assert_equal({:html => { false => { 'all' => {nil => 'grand_children'}}}}, GrandChildrenController.send(:inheritable_cache))
|
143
143
|
end
|
144
144
|
|
145
145
|
private
|
146
|
-
|
146
|
+
|
147
147
|
def touch(file)
|
148
148
|
f = File.join(TEST_VIEW_PATH, file)
|
149
149
|
FileUtils.mkdir_p(File.dirname(f))
|
150
150
|
FileUtils.touch(f)
|
151
151
|
end
|
152
|
-
|
152
|
+
|
153
153
|
end
|