view_mapper 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +4 -2
- data/VERSION +1 -1
- data/generators/scaffold_for_view/scaffold_for_view_generator.rb +2 -6
- data/generators/view_for/view_for_generator.rb +1 -5
- data/lib/view_mapper/{has_many_view.rb → has_many_child_models.rb} +33 -37
- data/lib/view_mapper/model_info.rb +8 -0
- data/lib/view_mapper/view_mapper.rb +15 -2
- data/lib/view_mapper/views/auto_complete/auto_complete_view.rb +77 -0
- data/lib/view_mapper/{auto_complete_templates → views/auto_complete/templates}/controller.rb +3 -1
- data/lib/view_mapper/{auto_complete_templates → views/auto_complete/templates}/layout.html.erb +0 -0
- data/lib/view_mapper/{auto_complete_templates → views/auto_complete/templates}/view_edit.html.erb +1 -1
- data/lib/view_mapper/{auto_complete_templates → views/auto_complete/templates}/view_new.html.erb +1 -1
- data/lib/view_mapper/views/has_many/has_many_view.rb +28 -0
- data/lib/view_mapper/{has_many_templates → views/has_many/templates}/helper.rb +0 -0
- data/lib/view_mapper/{has_many_templates → views/has_many/templates}/layout.html.erb +0 -0
- data/lib/view_mapper/{has_many_templates → views/has_many/templates}/model.rb +0 -0
- data/lib/view_mapper/{has_many_templates → views/has_many/templates}/nested_attributes.js +0 -0
- data/lib/view_mapper/{has_many_templates → views/has_many/templates}/style.css +0 -0
- data/lib/view_mapper/{has_many_templates → views/has_many/templates}/view_child_form.html.erb +0 -0
- data/lib/view_mapper/{has_many_templates → views/has_many/templates}/view_edit.html.erb +0 -0
- data/lib/view_mapper/{has_many_templates → views/has_many/templates}/view_form.html.erb +0 -0
- data/lib/view_mapper/{has_many_templates → views/has_many/templates}/view_new.html.erb +0 -0
- data/lib/view_mapper/{has_many_templates → views/has_many/templates}/view_show.html.erb +0 -0
- data/lib/view_mapper/{paperclip_view.rb → views/paperclip/paperclip_view.rb} +6 -2
- data/lib/view_mapper/{paperclip_templates → views/paperclip/templates}/migration.rb +1 -1
- data/lib/view_mapper/{paperclip_templates → views/paperclip/templates}/model.rb +0 -0
- data/lib/view_mapper/{paperclip_templates → views/paperclip/templates}/view_edit.html.erb +0 -0
- data/lib/view_mapper/{paperclip_templates → views/paperclip/templates}/view_new.html.erb +0 -0
- data/lib/view_mapper/{paperclip_templates → views/paperclip/templates}/view_show.html.erb +0 -0
- data/lib/view_mapper.rb +4 -3
- data/test/{fake → generators/fake}/fake_generator.rb +0 -0
- data/test/generators/fake/templates/fake_template1.html.erb +1 -0
- data/test/generators/fake/templates/fake_template2.html.erb +1 -0
- data/test/{scaffold_for_view_generator_test.rb → generators/scaffold_for_view/scaffold_for_view_generator_test.rb} +2 -2
- data/test/{view_for_generator_test.rb → generators/view_for/view_for_generator_test.rb} +0 -0
- data/test/model_info_test.rb +12 -3
- data/test/test_helper.rb +12 -8
- data/test/view_mapper_test.rb +13 -2
- data/test/{auto_complete_test.rb → views/auto_complete/auto_complete_test.rb} +63 -40
- data/test/{expected_templates/auto_complete/index.html.erb → views/auto_complete/expected_templates/actual_index} +2 -0
- data/test/{expected_templates/auto_complete → views/auto_complete/expected_templates}/edit.html.erb +7 -3
- data/test/{expected_templates/auto_complete → views/auto_complete/expected_templates}/expected_routes.rb +0 -0
- data/test/{expected_templates/paperclip → views/auto_complete/expected_templates}/index.html.erb +3 -1
- data/test/{expected_templates/auto_complete → views/auto_complete/expected_templates}/new.html.erb +7 -3
- data/test/{expected_templates/auto_complete → views/auto_complete/expected_templates}/show.html.erb +6 -1
- data/test/{expected_templates/auto_complete → views/auto_complete/expected_templates}/standard_routes.rb +0 -0
- data/test/{expected_templates/auto_complete → views/auto_complete/expected_templates}/testies.html.erb +0 -0
- data/test/{expected_templates/auto_complete → views/auto_complete/expected_templates}/testies_controller.rb +2 -1
- data/test/views/fake/fake_view.rb +7 -0
- data/test/views/fake/templates/fake_template1.html.erb +1 -0
- data/test/{expected_templates/has_many → views/has_many/expected_templates}/_form.html.erb +0 -0
- data/test/{expected_templates/has_many → views/has_many/expected_templates}/_person.html.erb +4 -0
- data/test/{expected_templates/has_many → views/has_many/expected_templates}/create_parents.rb +4 -3
- data/test/{expected_templates/has_many → views/has_many/expected_templates}/edit.html.erb +0 -0
- data/test/{expected_templates/has_many → views/has_many/expected_templates}/index.html.erb +1 -1
- data/test/{expected_templates/has_many → views/has_many/expected_templates}/new.html.erb +0 -0
- data/test/{expected_templates/has_many → views/has_many/expected_templates}/parent.rb +2 -1
- data/test/{expected_templates/has_many → views/has_many/expected_templates}/show.html.erb +4 -0
- data/test/{has_many_view_test.rb → views/has_many/has_many_view_test.rb} +17 -17
- data/test/{expected_templates/paperclip → views/paperclip/expected_templates}/create_testies.rb +4 -3
- data/test/{expected_templates/paperclip → views/paperclip/expected_templates}/edit.html.erb +4 -0
- data/test/views/paperclip/expected_templates/index.html.erb +26 -0
- data/test/{expected_templates/paperclip → views/paperclip/expected_templates}/new.html.erb +4 -0
- data/test/{expected_templates/paperclip → views/paperclip/expected_templates}/show.html.erb +5 -0
- data/test/{expected_templates/paperclip → views/paperclip/expected_templates}/testy.rb +0 -0
- data/test/{paperclip_view_test.rb → views/paperclip/paperclip_view_test.rb} +17 -9
- data/view_mapper.gemspec +77 -124
- metadata +72 -120
- data/lib/view_mapper/auto_complete_templates/functional_test.rb +0 -45
- data/lib/view_mapper/auto_complete_templates/helper.rb +0 -2
- data/lib/view_mapper/auto_complete_templates/helper_test.rb +0 -4
- data/lib/view_mapper/auto_complete_templates/style.css +0 -54
- data/lib/view_mapper/auto_complete_templates/view_index.html.erb +0 -24
- data/lib/view_mapper/auto_complete_templates/view_show.html.erb +0 -10
- data/lib/view_mapper/auto_complete_view.rb +0 -44
- data/lib/view_mapper/has_many_templates/controller.rb +0 -85
- data/lib/view_mapper/has_many_templates/fixtures.yml +0 -19
- data/lib/view_mapper/has_many_templates/functional_test.rb +0 -45
- data/lib/view_mapper/has_many_templates/helper_test.rb +0 -4
- data/lib/view_mapper/has_many_templates/migration.rb +0 -16
- data/lib/view_mapper/has_many_templates/unit_test.rb +0 -8
- data/lib/view_mapper/has_many_templates/view_index.html.erb +0 -24
- data/lib/view_mapper/paperclip_templates/controller.rb +0 -85
- data/lib/view_mapper/paperclip_templates/fixtures.yml +0 -19
- data/lib/view_mapper/paperclip_templates/functional_test.rb +0 -45
- data/lib/view_mapper/paperclip_templates/helper.rb +0 -2
- data/lib/view_mapper/paperclip_templates/helper_test.rb +0 -4
- data/lib/view_mapper/paperclip_templates/layout.html.erb +0 -17
- data/lib/view_mapper/paperclip_templates/style.css +0 -54
- data/lib/view_mapper/paperclip_templates/unit_test.rb +0 -8
- data/lib/view_mapper/paperclip_templates/view_index.html.erb +0 -24
- data/test/database.yml +0 -3
- data/test/fake_view.rb +0 -7
- data/test/rails_generator/base.rb +0 -266
- data/test/rails_generator/commands.rb +0 -621
- data/test/rails_generator/generated_attribute.rb +0 -46
- data/test/rails_generator/generators/components/model/model_generator.rb +0 -45
- data/test/rails_generator/generators/components/scaffold/scaffold_generator.rb +0 -102
- data/test/rails_generator/lookup.rb +0 -249
- data/test/rails_generator/manifest.rb +0 -53
- data/test/rails_generator/options.rb +0 -150
- data/test/rails_generator/scripts/destroy.rb +0 -29
- data/test/rails_generator/scripts/generate.rb +0 -7
- data/test/rails_generator/scripts/update.rb +0 -12
- data/test/rails_generator/scripts.rb +0 -89
- data/test/rails_generator/secret_key_generator.rb +0 -24
- data/test/rails_generator/simple_logger.rb +0 -46
- data/test/rails_generator/spec.rb +0 -44
@@ -1,53 +1,69 @@
|
|
1
|
-
require 'test_helper'
|
1
|
+
require File.dirname(__FILE__) + '/../../test_helper'
|
2
2
|
|
3
3
|
class AutoCompleteViewTest < Test::Unit::TestCase
|
4
4
|
|
5
5
|
attr_reader :singular_name
|
6
6
|
attr_reader :plural_name
|
7
7
|
attr_reader :attributes
|
8
|
-
attr_reader :
|
8
|
+
attr_reader :auto_complete_attributes
|
9
9
|
attr_reader :controller_class_name
|
10
10
|
attr_reader :table_name
|
11
11
|
attr_reader :class_name
|
12
12
|
attr_reader :file_name
|
13
13
|
attr_reader :controller_singular_name
|
14
14
|
|
15
|
+
context "A view_for generator instantiated for a test model" do
|
16
|
+
setup do
|
17
|
+
setup_test_model
|
18
|
+
end
|
19
|
+
|
20
|
+
should "detect all of the text fields when no auto_complete field is specified" do
|
21
|
+
gen = new_generator_for_test_model('view_for', ['--view', 'auto_complete'])
|
22
|
+
assert_contains gen.auto_complete_attributes, 'first_name'
|
23
|
+
assert_contains gen.auto_complete_attributes, 'last_name'
|
24
|
+
assert_contains gen.auto_complete_attributes, 'address'
|
25
|
+
assert_does_not_contain gen.auto_complete_attributes, 'some_flag'
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context "A scaffold_for_view generator instantiated for a test model" do
|
30
|
+
setup do
|
31
|
+
setup_test_model
|
32
|
+
end
|
33
|
+
|
34
|
+
should "return an error message without an auto_complete param" do
|
35
|
+
Rails::Generator::Base.logger.expects('error').with('No auto_complete attribute specified.')
|
36
|
+
new_generator_for_test_model('scaffold_for_view', ['--view', 'auto_complete'])
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
15
40
|
generators = %w{ view_for scaffold_for_view }
|
16
41
|
generators.each do |gen|
|
17
42
|
|
18
43
|
context "A #{gen} generator instantiated for a test model" do
|
19
|
-
|
20
|
-
|
21
|
-
new_generator_for_test_model(gen, ['--view', 'auto_complete'])
|
44
|
+
setup do
|
45
|
+
setup_test_model
|
22
46
|
end
|
23
47
|
|
24
48
|
should "return an error message with a bad auto_complete param" do
|
25
49
|
Rails::Generator::Base.logger.expects('error').with('Field \'blah\' does not exist.')
|
26
50
|
new_generator_for_test_model(gen, ['--view', 'auto_complete:blah'])
|
27
51
|
end
|
28
|
-
end
|
29
52
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
end
|
34
|
-
|
35
|
-
should "find the auto complete column name" do
|
36
|
-
assert_equal 'first_name', @gen.auto_complete_attribute
|
37
|
-
end
|
38
|
-
|
39
|
-
should "have the correct auto_complete_for method name" do
|
40
|
-
assert_equal 'auto_complete_for_testy_first_name', @gen.auto_complete_for_method
|
53
|
+
should "return an error message when the auto_complete param matches a field that is not a text field" do
|
54
|
+
Rails::Generator::Base.logger.expects('error').with('Field \'some_flag\' is not a text field.')
|
55
|
+
new_generator_for_test_model(gen, ['--view', 'auto_complete:some_flag'])
|
41
56
|
end
|
42
57
|
end
|
43
58
|
|
44
|
-
context "A #{gen} generator instantiated for a test model with auto_complete on the
|
59
|
+
context "A #{gen} generator instantiated for a test model with auto_complete on the first and last name fields" do
|
45
60
|
setup do
|
46
|
-
|
61
|
+
setup_test_model
|
62
|
+
@gen = new_generator_for_test_model(gen, ['--view', 'auto_complete:first_name,last_name'])
|
47
63
|
end
|
48
64
|
|
49
|
-
should "return the proper source root
|
50
|
-
assert_equal '
|
65
|
+
should "return the proper source root" do
|
66
|
+
assert_equal File.expand_path(File.dirname(__FILE__) + '/../../..//lib/view_mapper/views/auto_complete/templates'), ViewMapper::AutoCompleteView.source_root
|
51
67
|
end
|
52
68
|
|
53
69
|
view_for_templates = %w{ new edit index show }
|
@@ -56,19 +72,19 @@ class AutoCompleteViewTest < Test::Unit::TestCase
|
|
56
72
|
@attributes = @gen.attributes
|
57
73
|
@singular_name = @gen.singular_name
|
58
74
|
@plural_name = @gen.plural_name
|
59
|
-
@
|
60
|
-
template_file = File.open(
|
75
|
+
@auto_complete_attributes = @gen.auto_complete_attributes
|
76
|
+
template_file = File.open(@gen.source_path("view_#{template}.html.erb"))
|
61
77
|
result = ERB.new(template_file.read, nil, '-').result(binding)
|
62
|
-
expected_file = File.open(File.join(File.dirname(__FILE__), "expected_templates
|
78
|
+
expected_file = File.open(File.join(File.dirname(__FILE__), "expected_templates/#{template}.html.erb"), 'rb')
|
63
79
|
assert_equal expected_file.read, result
|
64
80
|
end
|
65
81
|
end
|
66
82
|
|
67
83
|
should "render the layout template as expected" do
|
68
84
|
@controller_class_name = @gen.controller_class_name
|
69
|
-
template_file = File.open(
|
85
|
+
template_file = File.open(@gen.source_path("layout.html.erb"))
|
70
86
|
result = ERB.new(template_file.read, nil, '-').result(binding)
|
71
|
-
expected_file = File.open(File.join(File.dirname(__FILE__), "expected_templates/
|
87
|
+
expected_file = File.open(File.join(File.dirname(__FILE__), "expected_templates/testies.html.erb"))
|
72
88
|
assert_equal expected_file.read, result
|
73
89
|
end
|
74
90
|
|
@@ -78,10 +94,10 @@ class AutoCompleteViewTest < Test::Unit::TestCase
|
|
78
94
|
@class_name = @gen.class_name
|
79
95
|
@file_name = @gen.file_name
|
80
96
|
@controller_singular_name = @gen.controller_singular_name
|
81
|
-
@
|
82
|
-
template_file = File.open(
|
97
|
+
@auto_complete_attributes = @gen.auto_complete_attributes
|
98
|
+
template_file = File.open(@gen.source_path("controller.rb"))
|
83
99
|
result = ERB.new(template_file.read, nil, '-').result(binding)
|
84
|
-
expected_file = File.open(File.join(File.dirname(__FILE__), "expected_templates/
|
100
|
+
expected_file = File.open(File.join(File.dirname(__FILE__), "expected_templates/testies_controller.rb"))
|
85
101
|
assert_equal expected_file.read, result
|
86
102
|
end
|
87
103
|
end
|
@@ -100,7 +116,7 @@ class AutoCompleteViewTest < Test::Unit::TestCase
|
|
100
116
|
Rails::Generator::Commands::Create.any_instance.stubs(:dependency)
|
101
117
|
Rails::Generator::Base.logger.stubs(:route)
|
102
118
|
|
103
|
-
expected_path = File.dirname(__FILE__) + '/expected_templates
|
119
|
+
expected_path = File.dirname(__FILE__) + '/expected_templates'
|
104
120
|
standard_routes_file = expected_path + '/standard_routes.rb'
|
105
121
|
expected_routes_file = expected_path + '/expected_routes.rb'
|
106
122
|
test_routes_file = expected_path + '/routes.rb'
|
@@ -112,17 +128,24 @@ class AutoCompleteViewTest < Test::Unit::TestCase
|
|
112
128
|
assert_equal File.open(expected_routes_file).read, File.open(test_routes_file).read
|
113
129
|
File.delete(test_routes_file)
|
114
130
|
end
|
131
|
+
end
|
132
|
+
end
|
115
133
|
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
134
|
+
context "A Rails generator script" do
|
135
|
+
setup do
|
136
|
+
setup_test_model
|
137
|
+
@generator_script = Rails::Generator::Scripts::Generate.new
|
138
|
+
end
|
139
|
+
|
140
|
+
should "not perform any actions when run on the scaffold_for_view generator with no auto_complete field" do
|
141
|
+
Rails::Generator::Commands::Create.any_instance.expects(:directory).never
|
142
|
+
Rails::Generator::Commands::Create.any_instance.expects(:template).never
|
143
|
+
Rails::Generator::Commands::Create.any_instance.expects(:route_resources).never
|
144
|
+
Rails::Generator::Commands::Create.any_instance.expects(:file).never
|
145
|
+
Rails::Generator::Commands::Create.any_instance.expects(:route).never
|
146
|
+
Rails::Generator::Base.logger.stubs(:error)
|
147
|
+
Rails::Generator::Base.logger.stubs(:route)
|
148
|
+
@generator_script.run(generator_script_cmd_line('scaffold_for_view', ['--view', 'auto_complete']))
|
126
149
|
end
|
127
150
|
end
|
128
151
|
|
@@ -5,6 +5,7 @@
|
|
5
5
|
<th>First name</th>
|
6
6
|
<th>Last name</th>
|
7
7
|
<th>Address</th>
|
8
|
+
<th>Some flag</th>
|
8
9
|
</tr>
|
9
10
|
|
10
11
|
<% @testies.each do |testy| %>
|
@@ -12,6 +13,7 @@
|
|
12
13
|
<td><%=h testy.first_name %></td>
|
13
14
|
<td><%=h testy.last_name %></td>
|
14
15
|
<td><%=h testy.address %></td>
|
16
|
+
<td><%=h testy.some_flag %></td>
|
15
17
|
<td><%= link_to 'Show', testy %></td>
|
16
18
|
<td><%= link_to 'Edit', edit_testy_path(testy) %></td>
|
17
19
|
<td><%= link_to 'Destroy', testy, :confirm => 'Are you sure?', :method => :delete %></td>
|
data/test/{expected_templates/auto_complete → views/auto_complete/expected_templates}/edit.html.erb
RENAMED
@@ -4,15 +4,19 @@
|
|
4
4
|
<%= f.error_messages %>
|
5
5
|
<p>
|
6
6
|
<%= f.label :first_name %><br />
|
7
|
-
<%=
|
7
|
+
<%= text_field_with_auto_complete :testy, :first_name, {}, { :method => :get } %>
|
8
8
|
</p>
|
9
9
|
<p>
|
10
10
|
<%= f.label :last_name %><br />
|
11
|
-
<%=
|
11
|
+
<%= text_field_with_auto_complete :testy, :last_name, {}, { :method => :get } %>
|
12
12
|
</p>
|
13
13
|
<p>
|
14
14
|
<%= f.label :address %><br />
|
15
|
-
<%=
|
15
|
+
<%= f.text_field :address %>
|
16
|
+
</p>
|
17
|
+
<p>
|
18
|
+
<%= f.label :some_flag %><br />
|
19
|
+
<%= f.check_box :some_flag %>
|
16
20
|
</p>
|
17
21
|
<p>
|
18
22
|
<%= f.submit 'Update' %>
|
File without changes
|
data/test/{expected_templates/paperclip → views/auto_complete/expected_templates}/index.html.erb
RENAMED
@@ -5,6 +5,7 @@
|
|
5
5
|
<th>First name</th>
|
6
6
|
<th>Last name</th>
|
7
7
|
<th>Address</th>
|
8
|
+
<th>Some flag</th>
|
8
9
|
</tr>
|
9
10
|
|
10
11
|
<% @testies.each do |testy| %>
|
@@ -12,6 +13,7 @@
|
|
12
13
|
<td><%=h testy.first_name %></td>
|
13
14
|
<td><%=h testy.last_name %></td>
|
14
15
|
<td><%=h testy.address %></td>
|
16
|
+
<td><%=h testy.some_flag %></td>
|
15
17
|
<td><%= link_to 'Show', testy %></td>
|
16
18
|
<td><%= link_to 'Edit', edit_testy_path(testy) %></td>
|
17
19
|
<td><%= link_to 'Destroy', testy, :confirm => 'Are you sure?', :method => :delete %></td>
|
@@ -21,4 +23,4 @@
|
|
21
23
|
|
22
24
|
<br />
|
23
25
|
|
24
|
-
<%= link_to 'New testy', new_testy_path %>
|
26
|
+
<%= link_to 'New testy', new_testy_path %>
|
data/test/{expected_templates/auto_complete → views/auto_complete/expected_templates}/new.html.erb
RENAMED
@@ -4,15 +4,19 @@
|
|
4
4
|
<%= f.error_messages %>
|
5
5
|
<p>
|
6
6
|
<%= f.label :first_name %><br />
|
7
|
-
<%=
|
7
|
+
<%= text_field_with_auto_complete :testy, :first_name, {}, { :method => :get } %>
|
8
8
|
</p>
|
9
9
|
<p>
|
10
10
|
<%= f.label :last_name %><br />
|
11
|
-
<%=
|
11
|
+
<%= text_field_with_auto_complete :testy, :last_name, {}, { :method => :get } %>
|
12
12
|
</p>
|
13
13
|
<p>
|
14
14
|
<%= f.label :address %><br />
|
15
|
-
<%=
|
15
|
+
<%= f.text_field :address %>
|
16
|
+
</p>
|
17
|
+
<p>
|
18
|
+
<%= f.label :some_flag %><br />
|
19
|
+
<%= f.check_box :some_flag %>
|
16
20
|
</p>
|
17
21
|
<p>
|
18
22
|
<%= f.submit 'Create' %>
|
File without changes
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
This is fake.
|
File without changes
|
data/test/{expected_templates/has_many → views/has_many/expected_templates}/_person.html.erb
RENAMED
@@ -11,6 +11,10 @@
|
|
11
11
|
Testy <%= f.label :address %><br />
|
12
12
|
<%= f.text_field :address %>
|
13
13
|
</p>
|
14
|
+
<p>
|
15
|
+
Testy <%= f.label :some_flag %><br />
|
16
|
+
<%= f.check_box :some_flag %>
|
17
|
+
</p>
|
14
18
|
<p>
|
15
19
|
<%= f.hidden_field :_delete, :class => 'delete' %>
|
16
20
|
<%= remove_child_link 'remove', f %>
|
data/test/{expected_templates/has_many → views/has_many/expected_templates}/create_parents.rb
RENAMED
@@ -1,9 +1,10 @@
|
|
1
1
|
class CreateParents < ActiveRecord::Migration
|
2
2
|
def self.up
|
3
3
|
create_table :parents do |t|
|
4
|
-
t.string
|
5
|
-
t.string
|
6
|
-
t.string
|
4
|
+
t.string :first_name
|
5
|
+
t.string :last_name
|
6
|
+
t.string :address
|
7
|
+
t.boolean :some_flag
|
7
8
|
|
8
9
|
t.timestamps
|
9
10
|
end
|
File without changes
|
File without changes
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require 'test_helper'
|
1
|
+
require File.dirname(__FILE__) + '/../../test_helper'
|
2
2
|
|
3
3
|
class HasManyViewTest < Test::Unit::TestCase
|
4
4
|
|
@@ -26,8 +26,8 @@ class HasManyViewTest < Test::Unit::TestCase
|
|
26
26
|
assert_equal 2, child_models.size
|
27
27
|
assert_equal 'SomeOtherModel', child_models[0].name
|
28
28
|
assert_equal 'Testy', child_models[1].name
|
29
|
-
assert_equal [ 'name' ],
|
30
|
-
assert_equal [ 'first_name', 'last_name', 'address' ], child_models[1].columns
|
29
|
+
assert_equal [ 'name' ], child_models[0].columns
|
30
|
+
assert_equal [ 'first_name', 'last_name', 'address', 'some_flag' ], child_models[1].columns
|
31
31
|
end
|
32
32
|
|
33
33
|
should "use find the specified valid child model if provided" do
|
@@ -43,8 +43,8 @@ class HasManyViewTest < Test::Unit::TestCase
|
|
43
43
|
assert_equal 2, gen.child_models.size
|
44
44
|
assert_equal 'Testy', child_models[0].name
|
45
45
|
assert_equal 'SomeOtherModel', child_models[1].name
|
46
|
-
assert_equal [ '
|
47
|
-
assert_equal [ '
|
46
|
+
assert_equal [ 'name' ], child_models[1].columns
|
47
|
+
assert_equal [ 'first_name', 'last_name', 'address', 'some_flag' ], child_models[0].columns
|
48
48
|
end
|
49
49
|
|
50
50
|
should "return an error message with a bad child model param" do
|
@@ -117,8 +117,8 @@ class HasManyViewTest < Test::Unit::TestCase
|
|
117
117
|
@gen = new_generator_for_test_model('view_for', ['--view', 'has_many'], 'parent')
|
118
118
|
end
|
119
119
|
|
120
|
-
should "return the proper source root
|
121
|
-
assert_equal '
|
120
|
+
should "return the proper source root" do
|
121
|
+
assert_equal File.expand_path(File.dirname(__FILE__) + '/../../..//lib/view_mapper/views/has_many/templates'), ViewMapper::HasManyView.source_root
|
122
122
|
end
|
123
123
|
|
124
124
|
view_for_templates = %w{ new edit show index }
|
@@ -128,9 +128,9 @@ class HasManyViewTest < Test::Unit::TestCase
|
|
128
128
|
@singular_name = @gen.singular_name
|
129
129
|
@plural_name = @gen.plural_name
|
130
130
|
@child_models = @gen.child_models
|
131
|
-
template_file = File.open(
|
131
|
+
template_file = File.open(@gen.source_path("view_#{template}.html.erb"))
|
132
132
|
result = ERB.new(template_file.read, nil, '-').result(binding)
|
133
|
-
expected_file = File.open(File.join(File.dirname(__FILE__), "expected_templates
|
133
|
+
expected_file = File.open(File.join(File.dirname(__FILE__), "expected_templates/#{template}.html.erb"))
|
134
134
|
assert_equal expected_file.read, result
|
135
135
|
end
|
136
136
|
end
|
@@ -140,17 +140,17 @@ class HasManyViewTest < Test::Unit::TestCase
|
|
140
140
|
@singular_name = @gen.singular_name
|
141
141
|
@plural_name = @gen.plural_name
|
142
142
|
@child_models = @gen.child_models
|
143
|
-
template_file = File.open(
|
143
|
+
template_file = File.open(@gen.source_path("view_form.html.erb"))
|
144
144
|
result = ERB.new(template_file.read, nil, '-').result(binding)
|
145
|
-
expected_file = File.open(File.join(File.dirname(__FILE__), "expected_templates/
|
145
|
+
expected_file = File.open(File.join(File.dirname(__FILE__), "expected_templates/_form.html.erb"))
|
146
146
|
assert_equal expected_file.read, result
|
147
147
|
end
|
148
148
|
|
149
149
|
should "render the person partial as expected" do
|
150
150
|
@child_model = @gen.child_models[1]
|
151
|
-
template_file = File.open(
|
151
|
+
template_file = File.open(@gen.source_path("view_child_form.html.erb"))
|
152
152
|
result = ERB.new(template_file.read, nil, '-').result(binding)
|
153
|
-
expected_file = File.open(File.join(File.dirname(__FILE__), "expected_templates/
|
153
|
+
expected_file = File.open(File.join(File.dirname(__FILE__), "expected_templates/_person.html.erb"))
|
154
154
|
assert_equal expected_file.read, result
|
155
155
|
end
|
156
156
|
end
|
@@ -166,9 +166,9 @@ class HasManyViewTest < Test::Unit::TestCase
|
|
166
166
|
@child_models = @gen.child_models
|
167
167
|
@class_name = @gen.class_name
|
168
168
|
@attributes = @gen.attributes
|
169
|
-
template_file = File.open(
|
169
|
+
template_file = File.open(@gen.source_path("model.rb"))
|
170
170
|
result = ERB.new(template_file.read, nil, '-').result(binding)
|
171
|
-
expected_file = File.open(File.join(File.dirname(__FILE__), "expected_templates/
|
171
|
+
expected_file = File.open(File.join(File.dirname(__FILE__), "expected_templates/parent.rb"))
|
172
172
|
assert_equal expected_file.read, result
|
173
173
|
end
|
174
174
|
|
@@ -178,9 +178,9 @@ class HasManyViewTest < Test::Unit::TestCase
|
|
178
178
|
@migration_name = 'CreateParents'
|
179
179
|
@table_name = @gen.table_name
|
180
180
|
@options = {}
|
181
|
-
template_file = File.open(
|
181
|
+
template_file = File.open(@gen.source_path("migration.rb"))
|
182
182
|
result = ERB.new(template_file.read, nil, '-').result(binding)
|
183
|
-
expected_file = File.open(File.join(File.dirname(__FILE__), "expected_templates/
|
183
|
+
expected_file = File.open(File.join(File.dirname(__FILE__), "expected_templates/create_parents.rb"))
|
184
184
|
assert_equal expected_file.read, result
|
185
185
|
end
|
186
186
|
end
|
data/test/{expected_templates/paperclip → views/paperclip/expected_templates}/create_testies.rb
RENAMED
@@ -1,9 +1,10 @@
|
|
1
1
|
class CreateTesties < ActiveRecord::Migration
|
2
2
|
def self.up
|
3
3
|
create_table :testies do |t|
|
4
|
-
t.string
|
5
|
-
t.string
|
6
|
-
t.string
|
4
|
+
t.string :first_name
|
5
|
+
t.string :last_name
|
6
|
+
t.string :address
|
7
|
+
t.boolean :some_flag
|
7
8
|
t.string :avatar_file_name
|
8
9
|
t.string :avatar_content_type
|
9
10
|
t.integer :avatar_file_size
|
@@ -0,0 +1,26 @@
|
|
1
|
+
<h1>Listing testies</h1>
|
2
|
+
|
3
|
+
<table>
|
4
|
+
<tr>
|
5
|
+
<th>First name</th>
|
6
|
+
<th>Last name</th>
|
7
|
+
<th>Address</th>
|
8
|
+
<th>Some flag</th>
|
9
|
+
</tr>
|
10
|
+
|
11
|
+
<% @testies.each do |testy| %>
|
12
|
+
<tr>
|
13
|
+
<td><%=h testy.first_name %></td>
|
14
|
+
<td><%=h testy.last_name %></td>
|
15
|
+
<td><%=h testy.address %></td>
|
16
|
+
<td><%=h testy.some_flag %></td>
|
17
|
+
<td><%= link_to 'Show', testy %></td>
|
18
|
+
<td><%= link_to 'Edit', edit_testy_path(testy) %></td>
|
19
|
+
<td><%= link_to 'Destroy', testy, :confirm => 'Are you sure?', :method => :delete %></td>
|
20
|
+
</tr>
|
21
|
+
<% end %>
|
22
|
+
</table>
|
23
|
+
|
24
|
+
<br />
|
25
|
+
|
26
|
+
<%= link_to 'New testy', new_testy_path %>
|
File without changes
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require 'test_helper'
|
1
|
+
require File.dirname(__FILE__) + '/../../test_helper'
|
2
2
|
|
3
3
|
class PaperclipViewTest < Test::Unit::TestCase
|
4
4
|
|
@@ -129,8 +129,16 @@ class PaperclipViewTest < Test::Unit::TestCase
|
|
129
129
|
@gen = new_generator_for_test_model('view_for', ['--view', 'paperclip'])
|
130
130
|
end
|
131
131
|
|
132
|
-
should "return the proper source root
|
133
|
-
assert_equal '
|
132
|
+
should "return the proper source root" do
|
133
|
+
assert_equal File.expand_path(File.dirname(__FILE__) + '/../../..//lib/view_mapper/views/paperclip/templates'), ViewMapper::PaperclipView.source_root
|
134
|
+
end
|
135
|
+
|
136
|
+
should "have the proper value for source_roots_for_view" do
|
137
|
+
assert_equal [
|
138
|
+
File.expand_path(File.dirname(__FILE__) + '/../../..//lib/view_mapper/views/paperclip/templates'),
|
139
|
+
@gen.class.lookup('scaffold').path + '/templates',
|
140
|
+
@gen.class.lookup('model').path + '/templates'
|
141
|
+
], @gen.source_roots_for_view
|
134
142
|
end
|
135
143
|
|
136
144
|
view_for_templates = %w{ new edit index show }
|
@@ -140,9 +148,9 @@ class PaperclipViewTest < Test::Unit::TestCase
|
|
140
148
|
@singular_name = @gen.singular_name
|
141
149
|
@plural_name = @gen.plural_name
|
142
150
|
@attachments = @gen.attachments
|
143
|
-
template_file = File.open(
|
151
|
+
template_file = File.open(@gen.source_path("view_#{template}.html.erb"))
|
144
152
|
result = ERB.new(template_file.read, nil, '-').result(binding)
|
145
|
-
expected_file = File.open(File.join(File.dirname(__FILE__), "expected_templates
|
153
|
+
expected_file = File.open(File.join(File.dirname(__FILE__), "expected_templates/#{template}.html.erb"))
|
146
154
|
assert_equal expected_file.read, result
|
147
155
|
end
|
148
156
|
end
|
@@ -254,9 +262,9 @@ class PaperclipViewTest < Test::Unit::TestCase
|
|
254
262
|
@class_name = @gen.class_name
|
255
263
|
@attributes = @gen.attributes
|
256
264
|
@attachments = @gen.attachments
|
257
|
-
template_file = File.open(
|
265
|
+
template_file = File.open(@gen.source_path("model.rb"))
|
258
266
|
result = ERB.new(template_file.read, nil, '-').result(binding)
|
259
|
-
expected_file = File.open(File.join(File.dirname(__FILE__), "expected_templates/
|
267
|
+
expected_file = File.open(File.join(File.dirname(__FILE__), "expected_templates/testy.rb"))
|
260
268
|
assert_equal expected_file.read, result
|
261
269
|
end
|
262
270
|
|
@@ -267,9 +275,9 @@ class PaperclipViewTest < Test::Unit::TestCase
|
|
267
275
|
@migration_name = 'CreateTesties'
|
268
276
|
@table_name = @gen.table_name
|
269
277
|
@options = {}
|
270
|
-
template_file = File.open(
|
278
|
+
template_file = File.open(@gen.source_path("migration.rb"))
|
271
279
|
result = ERB.new(template_file.read, nil, '-').result(binding)
|
272
|
-
expected_file = File.open(File.join(File.dirname(__FILE__), "expected_templates/
|
280
|
+
expected_file = File.open(File.join(File.dirname(__FILE__), "expected_templates/create_testies.rb"))
|
273
281
|
assert_equal expected_file.read, result
|
274
282
|
end
|
275
283
|
end
|