dry_crud 0.6.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +41 -36
- data/Rakefile +51 -43
- data/VERSION +1 -1
- data/lib/generators/dry_crud/USAGE +1 -0
- data/lib/generators/dry_crud/dry_crud_generator.rb +20 -0
- data/{rails_generators → lib/generators}/dry_crud/templates/INSTALL +4 -3
- data/{rails_generators → lib/generators}/dry_crud/templates/app/controllers/crud_controller.rb +31 -9
- data/lib/generators/dry_crud/templates/app/controllers/render_inheritable.rb +152 -0
- data/{rails_generators → lib/generators}/dry_crud/templates/app/helpers/crud_helper.rb +4 -4
- data/{rails_generators/dry_crud/templates/lib → lib/generators/dry_crud/templates/app/helpers}/standard_form_builder.rb +0 -0
- data/{rails_generators → lib/generators}/dry_crud/templates/app/helpers/standard_helper.rb +81 -76
- data/{rails_generators/dry_crud/templates/lib → lib/generators/dry_crud/templates/app/helpers}/standard_table_builder.rb +45 -46
- data/{rails_generators → lib/generators}/dry_crud/templates/app/views/crud/_attrs.html.erb +0 -0
- data/lib/generators/dry_crud/templates/app/views/crud/_form.html.erb +1 -0
- data/{rails_generators → lib/generators}/dry_crud/templates/app/views/crud/_list.html.erb +0 -0
- data/{rails_generators → lib/generators}/dry_crud/templates/app/views/crud/edit.html.erb +1 -1
- data/{rails_generators → lib/generators}/dry_crud/templates/app/views/crud/index.html.erb +1 -1
- data/{rails_generators → lib/generators}/dry_crud/templates/app/views/crud/new.html.erb +1 -1
- data/{rails_generators → lib/generators}/dry_crud/templates/app/views/crud/show.html.erb +1 -1
- data/{rails_generators → lib/generators}/dry_crud/templates/app/views/layouts/crud.html.erb +1 -0
- data/lib/generators/dry_crud/templates/app/views/shared/_error_messages.html.erb +10 -0
- data/lib/generators/dry_crud/templates/app/views/shared/_labeled.html.erb +4 -0
- data/{rails_generators → lib/generators}/dry_crud/templates/public/stylesheets/crud.css +5 -5
- data/{rails_generators → lib/generators}/dry_crud/templates/test/crud_test_model.rb +25 -17
- data/{rails_generators → lib/generators}/dry_crud/templates/test/functional/crud_controller_test_helper.rb +36 -32
- data/{rails_generators → lib/generators}/dry_crud/templates/test/functional/crud_test_models_controller_test.rb +17 -4
- data/{rails_generators → lib/generators}/dry_crud/templates/test/unit/crud_helper_test.rb +51 -6
- data/{rails_generators → lib/generators}/dry_crud/templates/test/unit/render_inheritable_test.rb +31 -39
- data/{rails_generators → lib/generators}/dry_crud/templates/test/unit/standard_form_builder_test.rb +0 -0
- data/{rails_generators → lib/generators}/dry_crud/templates/test/unit/standard_helper_test.rb +76 -54
- data/{rails_generators → lib/generators}/dry_crud/templates/test/unit/standard_table_builder_test.rb +42 -40
- data/test/templates/app/views/ajax/ajax.js.rjs +1 -1
- data/test/templates/app/views/ajax/index.html.erb +2 -2
- data/test/templates/app/views/cities/_form.html.erb +1 -1
- data/test/templates/app/views/cities/_list.html.erb +1 -2
- data/test/templates/config/routes.rb +14 -5
- metadata +51 -37
- data/rails_generators/dry_crud/USAGE +0 -1
- data/rails_generators/dry_crud/dry_crud_generator.rb +0 -22
- data/rails_generators/dry_crud/templates/app/views/crud/_form.html.erb +0 -1
- data/rails_generators/dry_crud/templates/app/views/shared/_labeled.html.erb +0 -5
- data/rails_generators/dry_crud/templates/lib/crud_callbacks.rb +0 -55
- data/rails_generators/dry_crud/templates/lib/render_inheritable.rb +0 -118
@@ -15,18 +15,53 @@ class CrudHelperTest < ActionView::TestCase
|
|
15
15
|
|
16
16
|
test "standard crud table" do
|
17
17
|
@entries = CrudTestModel.all
|
18
|
-
|
18
|
+
|
19
|
+
t = with_test_routing do
|
20
|
+
crud_table
|
21
|
+
end
|
22
|
+
|
19
23
|
assert_match /(<tr.+?<\/tr>){7}/m, t
|
20
24
|
assert_match /(<th.+?<\/th>){14}/m, t
|
21
25
|
assert_match /(<a href.+?<\/a>.*?){18}/m, t
|
22
26
|
end
|
27
|
+
|
28
|
+
test "custom crud table with attributes" do
|
29
|
+
@entries = CrudTestModel.all
|
30
|
+
|
31
|
+
t = with_test_routing do
|
32
|
+
crud_table :name, :children, :companion_id
|
33
|
+
end
|
34
|
+
|
35
|
+
assert_match /(<tr.+?<\/tr>){7}/m, t
|
36
|
+
assert_match /(<th.+?<\/th>){4}/m, t
|
37
|
+
assert_match /(<a href.+?<\/a>.*?){18}/m, t
|
38
|
+
end
|
23
39
|
|
24
|
-
test "custom crud table" do
|
40
|
+
test "custom crud table with block" do
|
25
41
|
@entries = CrudTestModel.all
|
26
|
-
|
27
|
-
|
28
|
-
|
42
|
+
|
43
|
+
t = with_test_routing do
|
44
|
+
crud_table do |t|
|
45
|
+
t.attrs :name, :children, :companion_id
|
46
|
+
t.col("head") {|e| content_tag :span, e.income.to_s }
|
47
|
+
end
|
29
48
|
end
|
49
|
+
|
50
|
+
assert_match /(<tr.+?<\/tr>){7}/m, t
|
51
|
+
assert_match /(<th.+?<\/th>){4}/m, t
|
52
|
+
assert_match /(<span>.+?<\/span>.*?){6}/m, t
|
53
|
+
assert_no_match /(<a href.+?<\/a>.*?)/m, t
|
54
|
+
end
|
55
|
+
|
56
|
+
test "custom crud table with attributes and block" do
|
57
|
+
@entries = CrudTestModel.all
|
58
|
+
|
59
|
+
t = with_test_routing do
|
60
|
+
crud_table :name, :children, :companion_id do |t|
|
61
|
+
t.col("head") {|e| content_tag :span, e.income.to_s }
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
30
65
|
assert_match /(<tr.+?<\/tr>){7}/m, t
|
31
66
|
assert_match /(<th.+?<\/th>){4}/m, t
|
32
67
|
assert_match /(<span>.+?<\/span>.*?){6}/m, t
|
@@ -35,7 +70,9 @@ class CrudHelperTest < ActionView::TestCase
|
|
35
70
|
|
36
71
|
test "crud form" do
|
37
72
|
@entry = CrudTestModel.first
|
38
|
-
f =
|
73
|
+
f = with_test_routing do
|
74
|
+
capture { crud_form }
|
75
|
+
end
|
39
76
|
|
40
77
|
assert_match /form .*?action="\/crud_test_models\/#{@entry.id}"/, f
|
41
78
|
assert_match /input .*?name="crud_test_model\[name\]" .*?type="text"/, f
|
@@ -53,5 +90,13 @@ class CrudHelperTest < ActionView::TestCase
|
|
53
90
|
assert_equal [:name, :whatever, :children, :companion_id, :rating, :income,
|
54
91
|
:birthdate, :human, :remarks, :created_at, :updated_at], default_attrs
|
55
92
|
end
|
93
|
+
|
94
|
+
private
|
56
95
|
|
96
|
+
def with_test_routing
|
97
|
+
with_routing do |set|
|
98
|
+
set.draw { resources :crud_test_models }
|
99
|
+
yield
|
100
|
+
end
|
101
|
+
end
|
57
102
|
end
|
data/{rails_generators → lib/generators}/dry_crud/templates/test/unit/render_inheritable_test.rb
RENAMED
@@ -1,8 +1,8 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
TEST_VIEW_PATH = File.join(
|
3
|
+
TEST_VIEW_PATH = File.join(Rails.root, 'test', 'test_views')
|
4
4
|
|
5
|
-
class RootController <
|
5
|
+
class RootController < ApplicationController
|
6
6
|
include RenderInheritable
|
7
7
|
|
8
8
|
attr_accessor :default_template_format
|
@@ -28,7 +28,7 @@ class GrandChildrenController < ChildrenController
|
|
28
28
|
|
29
29
|
end
|
30
30
|
|
31
|
-
# mock File
|
31
|
+
# mock File object
|
32
32
|
class File
|
33
33
|
class << self
|
34
34
|
def touched
|
@@ -54,8 +54,8 @@ class RenderInheritableTest < ActiveSupport::TestCase
|
|
54
54
|
teardown
|
55
55
|
@controller = ChildrenController.new
|
56
56
|
@grand_controller = GrandChildrenController.new
|
57
|
-
ChildrenController.inheritable_cache.clear
|
58
|
-
GrandChildrenController.inheritable_cache.clear
|
57
|
+
ChildrenController.send(:inheritable_cache).clear
|
58
|
+
GrandChildrenController.send(:inheritable_cache).clear
|
59
59
|
end
|
60
60
|
|
61
61
|
def teardown
|
@@ -69,59 +69,59 @@ class RenderInheritableTest < ActiveSupport::TestCase
|
|
69
69
|
end
|
70
70
|
|
71
71
|
test "lookup path" do
|
72
|
-
assert_equal ['children', 'root'], ChildrenController.send(:
|
73
|
-
assert_equal ['grand_children', 'children', 'root'], GrandChildrenController.send(:
|
72
|
+
assert_equal ['children', 'root'], ChildrenController.send(:inheritance_lookup_path)
|
73
|
+
assert_equal ['grand_children', 'children', 'root'], GrandChildrenController.send(:inheritance_lookup_path)
|
74
74
|
end
|
75
75
|
|
76
|
-
test "inheritable controller
|
77
|
-
assert_equal '
|
78
|
-
assert_equal '
|
76
|
+
test "inheritable controller finds controller instance" do
|
77
|
+
assert_equal 'children', ChildrenController.send(:inheritable_controller)
|
78
|
+
assert_equal 'grand_children', GrandChildrenController.send(:inheritable_controller)
|
79
79
|
end
|
80
80
|
|
81
81
|
test "find non-existing inheritable file" do
|
82
|
-
assert_nil
|
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
|
-
assert_equal 'root',
|
89
|
-
assert_equal 'root',
|
88
|
+
assert_equal 'root', @controller.send(:find_inheritable_template_folder, 'root')
|
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
|
-
assert_equal 'children',
|
97
|
-
assert_equal 'children',
|
96
|
+
assert_equal 'children', @controller.send(:find_inheritable_template_folder, 'child')
|
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
|
-
assert_equal 'root',
|
105
|
-
assert_equal 'grand_children',
|
104
|
+
assert_equal 'root', @controller.send(:find_inheritable_template_folder, 'grandchild')
|
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
|
-
assert_equal 'root',
|
113
|
-
assert_equal 'grand_children',
|
112
|
+
assert_equal 'root', @controller.send(:find_inheritable_template_folder, 'grandchild', true)
|
113
|
+
assert_equal 'grand_children', @grand_controller.send(:find_inheritable_template_folder, 'grandchild', true)
|
114
114
|
|
115
|
-
assert_equal({:js => { '
|
116
|
-
assert_equal({:js => { '
|
115
|
+
assert_equal({:js => { true => {'grandchild' => {nil => 'root'}}}}, ChildrenController.send(:inheritable_cache))
|
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
|
-
assert_equal 'root',
|
124
|
-
assert_equal 'grand_children',
|
123
|
+
assert_equal 'root', @controller.send(:find_inheritable_template_folder, 'grandchild', true)
|
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
|
@@ -129,33 +129,25 @@ class RenderInheritableTest < ActiveSupport::TestCase
|
|
129
129
|
touch("children/all.rhtml")
|
130
130
|
touch("grand_children/all.html.erb")
|
131
131
|
|
132
|
-
assert_equal 'children',
|
133
|
-
assert_equal 'grand_children',
|
132
|
+
assert_equal 'children', @controller.send(:find_inheritable_template_folder, 'all')
|
133
|
+
assert_equal 'grand_children', @grand_controller.send(:find_inheritable_template_folder, 'all')
|
134
134
|
|
135
|
-
assert_equal({:html => { 'all' => {nil => 'children'}}}, ChildrenController.inheritable_cache)
|
136
|
-
assert_equal({:html => { 'all' => {nil => 'grand_children'}}}, GrandChildrenController.inheritable_cache)
|
135
|
+
assert_equal({:html => { false => { 'all' => {nil => 'children'}}}}, ChildrenController.send(:inheritable_cache))
|
136
|
+
assert_equal({:html => { false => { 'all' => {nil => 'grand_children'}}}}, GrandChildrenController.send(:inheritable_cache))
|
137
137
|
|
138
|
-
assert_equal 'children',
|
139
|
-
assert_equal 'grand_children',
|
138
|
+
assert_equal 'children', @controller.send(:find_inheritable_template_folder, 'all')
|
139
|
+
assert_equal 'grand_children', @grand_controller.send(:find_inheritable_template_folder, 'all')
|
140
140
|
|
141
|
-
assert_equal({:html => { 'all' => {nil => 'children'}}}, ChildrenController.inheritable_cache)
|
142
|
-
assert_equal({:html => { 'all' => {nil => 'grand_children'}}}, GrandChildrenController.inheritable_cache)
|
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))
|
143
143
|
end
|
144
|
-
|
145
|
-
|
146
144
|
|
147
145
|
private
|
148
146
|
|
149
147
|
def touch(file)
|
150
|
-
#File.touch_template(file)
|
151
148
|
f = File.join(TEST_VIEW_PATH, file)
|
152
149
|
FileUtils.mkdir_p(File.dirname(f))
|
153
150
|
FileUtils.touch(f)
|
154
|
-
|
155
|
-
RootController.view_paths.last.instance_variable_set(:@loaded, false)
|
156
|
-
RootController.view_paths.last.load!
|
157
151
|
end
|
158
152
|
|
159
|
-
|
160
|
-
|
161
153
|
end
|
data/{rails_generators → lib/generators}/dry_crud/templates/test/unit/standard_form_builder_test.rb
RENAMED
File without changes
|
data/{rails_generators → lib/generators}/dry_crud/templates/test/unit/standard_helper_test.rb
RENAMED
@@ -3,66 +3,66 @@ require 'crud_test_model'
|
|
3
3
|
|
4
4
|
class StandardHelperTest < ActionView::TestCase
|
5
5
|
|
6
|
-
|
6
|
+
include StandardHelper
|
7
7
|
include CrudTestHelper
|
8
8
|
|
9
9
|
setup :reset_db, :setup_db, :create_test_data
|
10
10
|
teardown :reset_db
|
11
|
-
|
11
|
+
|
12
12
|
def format_size(obj)
|
13
13
|
"#{f(obj.size)} chars"
|
14
14
|
end
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
16
|
+
test "labeled text as block" do
|
17
|
+
result = labeled("label") { "value" }
|
18
|
+
|
19
|
+
assert_dom_equal "<div class='labeled'> <div class='caption'>label</div> <div class='value'>value</div> </div>", result.squish
|
20
20
|
end
|
21
21
|
|
22
22
|
test "labeled text empty" do
|
23
23
|
result = labeled("label", "")
|
24
24
|
|
25
|
-
assert_dom_equal "<div class='labeled'
|
25
|
+
assert_dom_equal "<div class='labeled'> <div class='caption'>label</div> <div class='value'>#{EMPTY_STRING}</div> </div>", result.squish
|
26
26
|
end
|
27
27
|
|
28
28
|
test "labeled text as content" do
|
29
29
|
result = labeled("label", "value")
|
30
30
|
|
31
|
-
assert_dom_equal "<div class='labeled'
|
31
|
+
assert_dom_equal "<div class='labeled'> <div class='caption'>label</div> <div class='value'>value</div> </div>", result.squish
|
32
32
|
end
|
33
33
|
|
34
|
-
|
35
|
-
|
36
|
-
|
34
|
+
test "alternate row" do
|
35
|
+
result_1 = tr_alt { "(test row content)" }
|
36
|
+
result_2 = tr_alt { "(test row content)" }
|
37
37
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
38
|
+
assert_dom_equal "<tr class='even'>(test row content)</tr>", result_1
|
39
|
+
assert_dom_equal "<tr class='odd'>(test row content)</tr>", result_2
|
40
|
+
end
|
41
|
+
|
42
|
+
test "format Fixnums" do
|
43
|
+
assert_equal "0", f(0)
|
44
|
+
assert_equal "10", f(10)
|
45
45
|
assert_equal "10,000,000", f(10000000)
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
46
|
+
end
|
47
|
+
|
48
|
+
test "format Floats" do
|
49
|
+
assert_equal "1.00", f(1.0)
|
50
|
+
assert_equal "1.20", f(1.2)
|
51
|
+
assert_equal "3.14", f(3.14159)
|
52
|
+
end
|
53
|
+
|
54
|
+
test "format Booleans" do
|
55
|
+
assert_equal "yes", f(true)
|
56
|
+
assert_equal "no", f(false)
|
57
|
+
end
|
58
|
+
|
59
|
+
test "format nil" do
|
60
|
+
assert_equal EMPTY_STRING, f(nil)
|
61
|
+
end
|
62
|
+
|
63
|
+
test "format Strings" do
|
64
|
+
assert_equal "blah blah", f("blah blah")
|
65
|
+
assert_equal "<injection>", f("<injection>")
|
66
66
|
end
|
67
67
|
|
68
68
|
test "format attr with fallthrough to f" do
|
@@ -101,7 +101,7 @@ class StandardHelperTest < ActionView::TestCase
|
|
101
101
|
m.rating = 3.145
|
102
102
|
assert_equal '3.15', format_type(m, :rating)
|
103
103
|
end
|
104
|
-
|
104
|
+
|
105
105
|
test "format decimal column" do
|
106
106
|
m = crud_test_models(:AAAAA)
|
107
107
|
assert_equal '10000000.10', format_type(m, :income)
|
@@ -117,29 +117,37 @@ class StandardHelperTest < ActionView::TestCase
|
|
117
117
|
assert_equal "<p>AAAAA AAAAA AAAAA\n<br />AAAAA AAAAA AAAAA\n<br />AAAAA AAAAA AAAAA\n</p>", format_type(m, :remarks)
|
118
118
|
end
|
119
119
|
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
120
|
+
test "empty table should render message" do
|
121
|
+
assert_dom_equal "<div class='list'>#{NO_LIST_ENTRIES_MESSAGE}</div>", table([]) { }
|
122
|
+
end
|
123
|
+
|
124
124
|
test "non empty table should render table" do
|
125
125
|
assert_match(/^\<table.*\<\/table\>$/, table(['foo', 'bar']) {|t| t.attrs :size, :upcase })
|
126
126
|
end
|
127
127
|
|
128
|
+
test "table with attrs" do
|
129
|
+
expected = StandardTableBuilder.table(['foo', 'bar'], self) { |t| t.attrs :size, :upcase }
|
130
|
+
actual = table(['foo', 'bar'], :size, :upcase)
|
131
|
+
assert_equal expected, actual
|
132
|
+
end
|
133
|
+
|
128
134
|
test "captionize" do
|
129
135
|
assert_equal "Camel Case", captionize(:camel_case)
|
130
136
|
assert_equal "All Upper Case", captionize("all upper case")
|
131
137
|
assert_equal "With Object", captionize("With object", Object.new)
|
132
138
|
end
|
133
|
-
|
139
|
+
|
134
140
|
test "standard form for existing entry" do
|
135
141
|
e = crud_test_models('AAAAA')
|
136
|
-
f =
|
137
|
-
|
142
|
+
f = with_test_routing do
|
143
|
+
f = capture { standard_form(e, [:name, :children, :birthdate, :human], :class => 'special') }
|
144
|
+
end
|
145
|
+
|
138
146
|
assert_match /form .*?action="\/crud_test_models\/#{e.id}" .*?method="post"/, f
|
139
147
|
assert_match /input .*?name="_method" .*?type="hidden" .*?value="put"/, f
|
140
148
|
assert_match /input .*?name="crud_test_model\[name\]" .*?type="text" .*?value="AAAAA"/, f
|
141
149
|
assert_match /select .*?name="crud_test_model\[birthdate\(1i\)\]"/, f
|
142
|
-
assert_match /option selected="selected" value="1910">1910<\/option>/, f
|
150
|
+
assert_match /option selected="selected" value="1910">1910<\/option>/, f
|
143
151
|
assert_match /option selected="selected" value="1">January<\/option>/, f
|
144
152
|
assert_match /option selected="selected" value="1">1<\/option>/, f
|
145
153
|
assert_match /input .*?name="crud_test_model\[children\]" .*?type="text" .*?value=\"1\"/, f
|
@@ -147,10 +155,13 @@ class StandardHelperTest < ActionView::TestCase
|
|
147
155
|
assert_match /input .*?type="submit" .*?value="Save"/, f
|
148
156
|
end
|
149
157
|
|
158
|
+
|
150
159
|
test "standard form for new entry" do
|
151
160
|
e = CrudTestModel.new
|
152
|
-
f =
|
153
|
-
|
161
|
+
f = with_test_routing do
|
162
|
+
f = capture { standard_form(e, [:name, :children, :birthdate, :human], :class => 'special') }
|
163
|
+
end
|
164
|
+
|
154
165
|
assert_match /form .*?action="\/crud_test_models" .*?method="post"/, f
|
155
166
|
assert_match /input .*?name="crud_test_model\[name\]" .*?type="text"/, f
|
156
167
|
assert_no_match /input .*?name="crud_test_model\[name\]" .*?type="text" .*?value=/, f
|
@@ -164,13 +175,15 @@ class StandardHelperTest < ActionView::TestCase
|
|
164
175
|
e = crud_test_models('AAAAA')
|
165
176
|
e.name = nil
|
166
177
|
assert !e.valid?
|
167
|
-
|
168
|
-
f = capture { standard_form(e, [:name, :children, :birthdate, :human], :class => 'special') }
|
169
178
|
|
179
|
+
f = with_test_routing do
|
180
|
+
f = capture { standard_form(e, [:name, :children, :birthdate, :human], :class => 'special') }
|
181
|
+
end
|
182
|
+
|
170
183
|
assert_match /form .*?action="\/crud_test_models\/#{e.id}" .*?method="post"/, f
|
171
184
|
assert_match /input .*?name="_method" .*?type="hidden" .*?value="put"/, f
|
172
|
-
assert_match /div
|
173
|
-
assert_match /div class="
|
185
|
+
assert_match /div id="error_explanation"/, f
|
186
|
+
assert_match /div class="field_with_errors"\>.*?\<input .*?name="crud_test_model\[name\]" .*?type="text"/, f
|
174
187
|
assert_match /select .*?name="crud_test_model\[birthdate\(1i\)\]"/, f
|
175
188
|
assert_match /option selected="selected" value="1910">1910<\/option>/, f
|
176
189
|
assert_match /option selected="selected" value="1">January<\/option>/, f
|
@@ -180,4 +193,13 @@ class StandardHelperTest < ActionView::TestCase
|
|
180
193
|
assert_match /input .*?type="submit" .*?value="Save"/, f
|
181
194
|
end
|
182
195
|
|
183
|
-
|
196
|
+
private
|
197
|
+
|
198
|
+
def with_test_routing
|
199
|
+
with_routing do |set|
|
200
|
+
set.draw { resources :crud_test_models }
|
201
|
+
yield
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
end
|
data/{rails_generators → lib/generators}/dry_crud/templates/test/unit/standard_table_builder_test.rb
RENAMED
@@ -54,46 +54,48 @@ class StandardTableBuilderTest < ActionView::TestCase
|
|
54
54
|
|
55
55
|
assert_equal "4 chars", col.content("abcd")
|
56
56
|
end
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
57
|
+
|
58
|
+
test "two x two table" do
|
59
|
+
dom = <<-FIN
|
60
|
+
<table class="list">
|
61
|
+
<tr><th>Upcase</th><th>Size</th></tr>
|
62
|
+
<tr class="even"><td>FOO</td><td>3 chars</td></tr>
|
63
|
+
<tr class="odd"><td>BAHR</td><td>4 chars</td></tr>
|
64
|
+
</table>
|
65
|
+
FIN
|
66
|
+
dom.gsub!(/[\n\t]/, "").gsub!(/\s{2,}/, "")
|
66
67
|
|
67
68
|
table.attrs :upcase, :size
|
68
69
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
70
|
+
assert_dom_equal dom, table.to_html
|
71
|
+
end
|
72
|
+
|
73
|
+
test "table with before and after cells" do
|
74
|
+
dom = <<-FIN
|
75
|
+
<table class="list">
|
76
|
+
<tr><th>head</th><th>Upcase</th><th>Size</th><th></th></tr>
|
77
|
+
<tr class="even">
|
78
|
+
<td class='left'><a href='/'>foo</a></td>
|
79
|
+
<td>FOO</td>
|
80
|
+
<td>3 chars</td>
|
81
|
+
<td>Never foo</td>
|
82
|
+
</tr>
|
83
|
+
<tr class="odd">
|
84
|
+
<td class='left'><a href='/'>bahr</a></td>
|
85
|
+
<td>BAHR</td>
|
86
|
+
<td>4 chars</td>
|
87
|
+
<td>Never bahr</td>
|
88
|
+
</tr>
|
89
|
+
</table>
|
90
|
+
FIN
|
91
|
+
dom.gsub!(/[\n\t]/, "").gsub!(/\s{2,}/, "")
|
92
|
+
|
93
|
+
table.col('head', :class => 'left') { |e| link_to e, "/" }
|
94
|
+
table.attrs :upcase, :size
|
95
|
+
table.col { |e| "Never #{e}" }
|
96
|
+
|
97
|
+
|
98
|
+
assert_dom_equal dom, table.to_html
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
@@ -1 +1 @@
|
|
1
|
-
page.replace_html(:response,
|
1
|
+
page.replace_html(:response, :partial => 'hello')
|
@@ -1,9 +1,9 @@
|
|
1
1
|
<% @title = "Listing #{models_label}" -%>
|
2
2
|
|
3
|
-
<%=
|
3
|
+
<%= render :partial => 'list' %>
|
4
4
|
|
5
5
|
<br/>
|
6
6
|
|
7
7
|
<%= link_action_add %>
|
8
|
-
<%=
|
8
|
+
<%= link_to 'Ajahx', {:action => 'ajax'}, :method => :get, :remote => true %>
|
9
9
|
<div id="response"></div>
|
@@ -1,11 +1,20 @@
|
|
1
|
-
|
1
|
+
TestApp::Application.routes.draw do
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
resources :cities do
|
4
|
+
collection do
|
5
|
+
get :ajax
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
resources :people do
|
10
|
+
collection do
|
11
|
+
get :ajax
|
12
|
+
end
|
13
|
+
end
|
5
14
|
|
6
15
|
# Install the default routes as the lowest priority.
|
7
16
|
# Note: These default routes make all actions in every controller accessible via GET requests. You should
|
8
17
|
# consider removing or commenting them out if you're using named routes and resources.
|
9
|
-
map.connect ':controller/:action/:id'
|
10
|
-
map.connect ':controller/:action/:id
|
18
|
+
#map.connect ':controller/:action/:id.:format'
|
19
|
+
#map.connect ':controller/:action/:id'
|
11
20
|
end
|