view_mapper 0.3.3 → 0.3.4
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 +3 -1
- data/VERSION +1 -1
- data/lib/view_mapper.rb +1 -0
- data/lib/view_mapper/belongs_to_parent_models.rb +12 -26
- data/lib/view_mapper/has_many_child_models.rb +9 -9
- data/lib/view_mapper/model_info.rb +56 -18
- data/lib/view_mapper/views/belongs_to/belongs_to_view.rb +14 -0
- data/lib/view_mapper/views/belongs_to_auto_complete/belongs_to_auto_complete_view.rb +9 -2
- data/lib/view_mapper/views/has_many/templates/helper.rb +1 -1
- data/lib/view_mapper/views/has_many/templates/view_child_form.html.erb +1 -1
- data/lib/view_mapper/views/has_many/templates/view_form.html.erb +1 -1
- data/lib/view_mapper/views/has_many_existing/has_many_existing_view.rb +126 -0
- data/lib/view_mapper/views/has_many_existing/templates/model.rb +21 -0
- data/lib/view_mapper/views/has_many_existing/templates/view_child_form.html.erb +16 -0
- data/lib/view_mapper/views/has_many_existing/templates/view_form.html.erb +20 -0
- data/lib/view_mapper/views/has_many_existing/templates/view_show.html.erb +26 -0
- data/test/generators/scaffold_for_view/scaffold_for_view_generator_test.rb +15 -15
- data/test/generators/view_for/view_for_generator_test.rb +18 -18
- data/test/model_info_test.rb +91 -20
- data/test/test_helper.rb +75 -105
- data/test/views/auto_complete/auto_complete_test.rb +104 -102
- data/test/views/auto_complete/expected_templates/edit.html.erb +6 -6
- data/test/views/auto_complete/expected_templates/expected_routes.rb +1 -1
- data/test/views/auto_complete/expected_templates/index.html.erb +10 -10
- data/test/views/auto_complete/expected_templates/new.html.erb +5 -5
- data/test/views/auto_complete/expected_templates/show.html.erb +6 -6
- data/test/views/auto_complete/expected_templates/{testies.html.erb → test_models.html.erb} +1 -1
- data/test/views/auto_complete/expected_templates/test_models_controller.rb +89 -0
- data/test/views/belongs_to/belongs_to_test.rb +238 -202
- data/test/views/belongs_to/expected_templates/_form.html.erb +4 -4
- data/test/views/belongs_to/expected_templates/child_model.rb +10 -0
- data/test/views/belongs_to/expected_templates/create_child_models.rb +18 -0
- data/test/views/belongs_to/expected_templates/edit.html.erb +4 -4
- data/test/views/belongs_to/expected_templates/index.html.erb +11 -11
- data/test/views/belongs_to/expected_templates/new.html.erb +3 -3
- data/test/views/belongs_to/expected_templates/show.html.erb +7 -7
- data/test/views/belongs_to_auto_complete/belongs_to_auto_complete_test.rb +440 -406
- data/test/views/belongs_to_auto_complete/expected_templates/_form.html.erb +4 -4
- data/test/views/belongs_to_auto_complete/expected_templates/child_model.rb +16 -0
- data/test/views/belongs_to_auto_complete/expected_templates/{some_other_models.html.erb → child_models.html.erb} +1 -1
- data/test/views/belongs_to_auto_complete/expected_templates/child_models_controller.rb +89 -0
- data/test/views/belongs_to_auto_complete/expected_templates/create_child_models.rb +18 -0
- data/test/views/belongs_to_auto_complete/expected_templates/edit.html.erb +4 -4
- data/test/views/belongs_to_auto_complete/expected_templates/expected_routes.rb +2 -2
- data/test/views/belongs_to_auto_complete/expected_templates/index.html.erb +11 -11
- data/test/views/belongs_to_auto_complete/expected_templates/new.html.erb +3 -3
- data/test/views/belongs_to_auto_complete/expected_templates/show.html.erb +7 -7
- data/test/views/has_many/expected_templates/_form.html.erb +8 -8
- data/test/views/has_many/expected_templates/{_person.html.erb → _second_child_model.html.erb} +5 -5
- data/test/views/has_many/expected_templates/create_parent_models.rb +16 -0
- data/test/views/has_many/expected_templates/edit.html.erb +4 -4
- data/test/views/has_many/expected_templates/index.html.erb +7 -7
- data/test/views/has_many/expected_templates/new.html.erb +3 -3
- data/test/views/has_many/expected_templates/{parent.rb → parent_model.rb} +5 -5
- data/test/views/has_many/expected_templates/show.html.erb +15 -15
- data/test/views/has_many/has_many_view_test.rb +334 -292
- data/test/views/has_many_existing/expected_templates/_assignment.html.erb +14 -0
- data/test/views/has_many_existing/expected_templates/_form.html.erb +16 -0
- data/test/views/{has_many/expected_templates/create_parents.rb → has_many_existing/expected_templates/create_programmers.rb} +3 -3
- data/test/views/has_many_existing/expected_templates/edit.html.erb +11 -0
- data/test/views/has_many_existing/expected_templates/index.html.erb +20 -0
- data/test/views/has_many_existing/expected_templates/new.html.erb +10 -0
- data/test/views/has_many_existing/expected_templates/programmer.rb +10 -0
- data/test/views/has_many_existing/expected_templates/show.html.erb +20 -0
- data/test/views/has_many_existing/has_many_existing_test.rb +495 -0
- data/test/views/paperclip/expected_templates/{create_testies.rb → create_test_models.rb} +3 -3
- data/test/views/paperclip/expected_templates/edit.html.erb +4 -4
- data/test/views/paperclip/expected_templates/index.html.erb +10 -10
- data/test/views/paperclip/expected_templates/new.html.erb +3 -3
- data/test/views/paperclip/expected_templates/show.html.erb +8 -8
- data/test/views/paperclip/expected_templates/{testy.rb → test_model.rb} +1 -1
- data/test/views/paperclip/paperclip_view_test.rb +254 -226
- data/view_mapper.gemspec +43 -27
- metadata +64 -37
- data/test/views/auto_complete/expected_templates/actual_index +0 -26
- data/test/views/auto_complete/expected_templates/testies_controller.rb +0 -89
- data/test/views/belongs_to/expected_templates/create_some_other_models.rb +0 -18
- data/test/views/belongs_to/expected_templates/some_other_model.rb +0 -10
- data/test/views/belongs_to_auto_complete/expected_templates/create_some_other_models.rb +0 -18
- data/test/views/belongs_to_auto_complete/expected_templates/some_other_model.rb +0 -16
- data/test/views/belongs_to_auto_complete/expected_templates/some_other_models_controller.rb +0 -89
@@ -13,35 +13,34 @@ class BelongsToViewTest < Test::Unit::TestCase
|
|
13
13
|
|
14
14
|
context "A view_for generator instantiated for a test model" do
|
15
15
|
setup do
|
16
|
-
|
17
|
-
|
16
|
+
ClassFactory :parent_model
|
17
|
+
ClassFactory :second_parent_model
|
18
|
+
ClassFactory :child_model
|
18
19
|
end
|
19
20
|
|
20
21
|
should "detect the existing parents when no parent is specified" do
|
21
|
-
gen = new_generator_for_test_model('view_for', ['--view', 'belongs_to'], '
|
22
|
+
gen = new_generator_for_test_model('view_for', ['--view', 'belongs_to'], 'child_model')
|
22
23
|
parent_models = gen.parent_models
|
23
|
-
assert_equal
|
24
|
-
assert_equal '
|
24
|
+
assert_equal 2, parent_models.size
|
25
|
+
assert_equal 'ParentModel', parent_models[0].name
|
26
|
+
assert_equal 'SecondParentModel', parent_models[1].name
|
25
27
|
end
|
26
28
|
|
27
29
|
should "use the specified parent if provided" do
|
28
|
-
gen = new_generator_for_test_model('view_for', ['--view', 'belongs_to:
|
30
|
+
gen = new_generator_for_test_model('view_for', ['--view', 'belongs_to:parent_model'], 'child_model')
|
29
31
|
parent_models = gen.parent_models
|
30
32
|
assert_equal 1, parent_models.size
|
31
|
-
assert_equal '
|
33
|
+
assert_equal 'ParentModel', parent_models[0].name
|
32
34
|
end
|
33
35
|
|
34
36
|
should "return an error message with a bad parent param" do
|
37
|
+
ClassFactory :test_model
|
35
38
|
Rails::Generator::Base.logger.expects('error').with('Class \'blah\' does not exist or contains a syntax error and could not be loaded.')
|
36
39
|
new_generator_for_test_model('view_for', ['--view', 'belongs_to:blah'])
|
37
40
|
end
|
38
41
|
end
|
39
42
|
|
40
43
|
context "A scaffold_for_view generator instantiated for a test model" do
|
41
|
-
setup do
|
42
|
-
setup_test_model
|
43
|
-
setup_parent_test_model
|
44
|
-
end
|
45
44
|
|
46
45
|
should "return a warning when run with scaffold_for_view when no belongs_to is specified and not run any actions" do
|
47
46
|
expect_no_actions
|
@@ -53,13 +52,12 @@ class BelongsToViewTest < Test::Unit::TestCase
|
|
53
52
|
|
54
53
|
context "A test model with no belongs_to associations" do
|
55
54
|
setup do
|
56
|
-
|
57
|
-
setup_parent_test_model(true, false)
|
55
|
+
ClassFactory :test_model
|
58
56
|
end
|
59
57
|
|
60
58
|
should "return a error when run with view_for and not run any actions" do
|
61
59
|
expect_no_actions
|
62
|
-
Rails::Generator::Base.logger.expects('error').with('No belongs_to associations exist in class
|
60
|
+
Rails::Generator::Base.logger.expects('error').with('No belongs_to associations exist in class TestModel.')
|
63
61
|
@generator_script = Rails::Generator::Scripts::Generate.new
|
64
62
|
@generator_script.run(generator_script_cmd_line('view_for', ['--view', 'belongs_to']))
|
65
63
|
end
|
@@ -74,274 +72,312 @@ class BelongsToViewTest < Test::Unit::TestCase
|
|
74
72
|
|
75
73
|
context "A test model with a belongs_to association for a model for which it does not have a name virtual attribute" do
|
76
74
|
setup do
|
77
|
-
|
78
|
-
|
79
|
-
|
75
|
+
ClassFactory :parent_model
|
76
|
+
ClassFactory :second_parent_model
|
77
|
+
|
78
|
+
child_model_code_missing_virtual_attribute = <<END
|
79
|
+
belongs_to :parent_model
|
80
|
+
|
81
|
+
belongs_to :second_parent_model
|
82
|
+
def second_parent_model_name
|
83
|
+
'something else'
|
84
|
+
end
|
85
|
+
def second_parent_model_name=
|
86
|
+
end
|
87
|
+
END
|
88
|
+
ClassFactory :child_model, :class_eval => child_model_code_missing_virtual_attribute
|
80
89
|
end
|
81
90
|
|
82
91
|
should "return a warning and stop when the problem model is specified" do
|
83
92
|
expect_no_actions
|
84
|
-
Rails::Generator::Base.logger.expects('warning').with('Model
|
93
|
+
Rails::Generator::Base.logger.expects('warning').with('Model ChildModel does not have a method parent_model_name.')
|
85
94
|
@generator_script = Rails::Generator::Scripts::Generate.new
|
86
|
-
@generator_script.run(generator_script_cmd_line('view_for', ['--view', 'belongs_to:
|
95
|
+
@generator_script.run(generator_script_cmd_line('view_for', ['--view', 'belongs_to:parent_model'], 'child_model'))
|
87
96
|
end
|
88
97
|
|
89
98
|
should "return a warning and not include the problem model when run with view_for but continue to run for other models" do
|
90
99
|
stub_actions
|
91
|
-
Rails::Generator::Base.logger.expects('warning').with('Model
|
100
|
+
Rails::Generator::Base.logger.expects('warning').with('Model ChildModel does not have a method parent_model_name.')
|
92
101
|
Rails::Generator::Commands::Create.any_instance.expects(:directory).with('app/controllers/')
|
93
102
|
@generator_script = Rails::Generator::Scripts::Generate.new
|
94
|
-
@generator_script.run(generator_script_cmd_line('view_for', ['--view', 'belongs_to'], '
|
103
|
+
@generator_script.run(generator_script_cmd_line('view_for', ['--view', 'belongs_to'], 'child_model'))
|
95
104
|
end
|
96
105
|
end
|
97
106
|
|
98
107
|
context "A test model with a belongs_to association for a model which does not have a name method or column" do
|
99
108
|
setup do
|
100
|
-
|
101
|
-
|
102
|
-
|
109
|
+
ClassFactory :parent_model
|
110
|
+
ClassFactory :second_parent_model do |p|
|
111
|
+
p.string :not_the_name_column
|
112
|
+
end
|
113
|
+
ClassFactory :child_model
|
103
114
|
end
|
104
115
|
|
105
116
|
should "return a warning and stop when the problem model is specified" do
|
106
117
|
expect_no_actions
|
107
|
-
Rails::Generator::Base.logger.expects('warning').with('Model
|
118
|
+
Rails::Generator::Base.logger.expects('warning').with('Model SecondParentModel does not have a name attribute.')
|
108
119
|
@generator_script = Rails::Generator::Scripts::Generate.new
|
109
|
-
@generator_script.run(generator_script_cmd_line('view_for', ['--view', 'belongs_to:
|
120
|
+
@generator_script.run(generator_script_cmd_line('view_for', ['--view', 'belongs_to:second_parent_model'], 'child_model'))
|
110
121
|
end
|
111
122
|
|
112
123
|
should "return a warning and not include the problem model when run with view_for but continue to run for other models" do
|
113
124
|
stub_actions
|
114
|
-
Rails::Generator::Base.logger.expects('warning').with('Model
|
125
|
+
Rails::Generator::Base.logger.expects('warning').with('Model SecondParentModel does not have a name attribute.')
|
115
126
|
Rails::Generator::Commands::Create.any_instance.expects(:directory).with('app/controllers/')
|
116
127
|
@generator_script = Rails::Generator::Scripts::Generate.new
|
117
|
-
@generator_script.run(generator_script_cmd_line('view_for', ['--view', 'belongs_to'], '
|
128
|
+
@generator_script.run(generator_script_cmd_line('view_for', ['--view', 'belongs_to'], 'child_model'))
|
118
129
|
end
|
119
130
|
end
|
120
131
|
|
121
132
|
context "A test model with a belongs_to association for a model which has a name method but not a name column" do
|
122
133
|
setup do
|
123
|
-
|
124
|
-
|
125
|
-
|
134
|
+
ClassFactory :parent_model
|
135
|
+
parent_code_with_name_method = <<SRC
|
136
|
+
has_many :child_models
|
137
|
+
def name
|
138
|
+
'the name'
|
139
|
+
end
|
140
|
+
SRC
|
141
|
+
ClassFactory :second_parent_model, :class_eval => parent_code_with_name_method do |p|
|
142
|
+
p.string :not_the_name_column
|
143
|
+
end
|
144
|
+
ClassFactory :child_model
|
126
145
|
end
|
127
146
|
|
128
147
|
should "continue to generate as usual" do
|
129
148
|
stub_actions
|
130
149
|
Rails::Generator::Commands::Create.any_instance.expects(:directory).with('app/controllers/')
|
131
150
|
@generator_script = Rails::Generator::Scripts::Generate.new
|
132
|
-
@generator_script.run(generator_script_cmd_line('view_for', ['--view', 'belongs_to:
|
151
|
+
@generator_script.run(generator_script_cmd_line('view_for', ['--view', 'belongs_to:second_parent_model'], 'child_model'))
|
133
152
|
end
|
134
153
|
end
|
135
154
|
|
136
155
|
context "A test model with a belongs_to association for a model for which it does not have a foreign key" do
|
137
156
|
setup do
|
138
|
-
|
139
|
-
|
140
|
-
|
157
|
+
ClassFactory :parent_model
|
158
|
+
ClassFactory :second_parent_model
|
159
|
+
ClassFactory :child_model do |child|
|
160
|
+
child.string :name
|
161
|
+
child.integer :parent_model_id
|
162
|
+
end
|
141
163
|
end
|
142
164
|
|
143
165
|
should "return a warning and stop when the problem model is specified" do
|
144
166
|
expect_no_actions
|
145
|
-
Rails::Generator::Base.logger.expects('warning').with('Model
|
167
|
+
Rails::Generator::Base.logger.expects('warning').with('Model ChildModel does not contain a foreign key for SecondParentModel.')
|
146
168
|
@generator_script = Rails::Generator::Scripts::Generate.new
|
147
|
-
@generator_script.run(generator_script_cmd_line('view_for', ['--view', 'belongs_to:
|
169
|
+
@generator_script.run(generator_script_cmd_line('view_for', ['--view', 'belongs_to:second_parent_model'], 'child_model'))
|
148
170
|
end
|
149
171
|
|
150
172
|
should "return a warning and not include the problem model when run with view_for but continue to run for other models" do
|
151
173
|
stub_actions
|
152
|
-
Rails::Generator::Base.logger.expects('warning').with('Model
|
174
|
+
Rails::Generator::Base.logger.expects('warning').with('Model ChildModel does not contain a foreign key for SecondParentModel.')
|
153
175
|
Rails::Generator::Commands::Create.any_instance.expects(:directory).with('app/controllers/')
|
154
176
|
@generator_script = Rails::Generator::Scripts::Generate.new
|
155
|
-
@generator_script.run(generator_script_cmd_line('view_for', ['--view', 'belongs_to'], '
|
177
|
+
@generator_script.run(generator_script_cmd_line('view_for', ['--view', 'belongs_to'], 'child_model'))
|
156
178
|
end
|
157
179
|
end
|
158
180
|
|
159
|
-
context "A
|
181
|
+
context "A parent model, a child model and a second parent model" do
|
160
182
|
setup do
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
183
|
+
ClassFactory :parent_model
|
184
|
+
ClassFactory :second_parent_model
|
185
|
+
ClassFactory :child_model, :class_eval => <<END
|
186
|
+
belongs_to :parent_model
|
187
|
+
def parent_model_name
|
188
|
+
'something'
|
189
|
+
end
|
190
|
+
def parent_model_name=
|
191
|
+
end
|
192
|
+
|
193
|
+
belongs_to :second_parent_model
|
194
|
+
def second_parent_model_other_field
|
195
|
+
'something else'
|
196
|
+
end
|
197
|
+
def second_parent_model_other_field=
|
198
|
+
end
|
199
|
+
END
|
200
|
+
end
|
201
|
+
|
202
|
+
context "A view_for generator instantiated for a test model with two belongs_to associations" do
|
203
|
+
setup do
|
204
|
+
@gen = new_generator_for_test_model('view_for', ['--view', 'belongs_to:parent_model,second_parent_model[other_field]'], 'child_model')
|
205
|
+
end
|
166
206
|
|
167
|
-
|
168
|
-
|
169
|
-
|
207
|
+
should "return the proper source root" do
|
208
|
+
assert_equal File.expand_path(File.dirname(__FILE__) + '/../../..//lib/view_mapper/views/belongs_to/templates'), ViewMapper::BelongsToView.source_root
|
209
|
+
end
|
210
|
+
|
211
|
+
view_for_templates = %w{ new edit index show }
|
212
|
+
view_for_templates.each do | template |
|
213
|
+
should "render the #{template} template as expected" do
|
214
|
+
@attributes = @gen.attributes
|
215
|
+
@singular_name = @gen.singular_name
|
216
|
+
@plural_name = @gen.plural_name
|
217
|
+
@parent_models = @gen.parent_models
|
218
|
+
template_file = File.open(@gen.source_path("view_#{template}.html.erb"))
|
219
|
+
result = ERB.new(template_file.read, nil, '-').result(binding)
|
220
|
+
expected_file = File.open(File.join(File.dirname(__FILE__), "expected_templates/#{template}.html.erb"))
|
221
|
+
assert_equal expected_file.read, result
|
222
|
+
end
|
223
|
+
end
|
170
224
|
|
171
|
-
|
172
|
-
view_for_templates.each do | template |
|
173
|
-
should "render the #{template} template as expected" do
|
225
|
+
should "render the form template as expected" do
|
174
226
|
@attributes = @gen.attributes
|
175
227
|
@singular_name = @gen.singular_name
|
176
228
|
@plural_name = @gen.plural_name
|
177
229
|
@parent_models = @gen.parent_models
|
178
|
-
template_file = File.open(@gen.source_path("
|
230
|
+
template_file = File.open(@gen.source_path("view_form.html.erb"))
|
179
231
|
result = ERB.new(template_file.read, nil, '-').result(binding)
|
180
|
-
expected_file = File.open(File.join(File.dirname(__FILE__), "expected_templates
|
232
|
+
expected_file = File.open(File.join(File.dirname(__FILE__), "expected_templates/_form.html.erb"))
|
181
233
|
assert_equal expected_file.read, result
|
182
234
|
end
|
183
235
|
end
|
184
236
|
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
@parent_models = @gen.parent_models
|
190
|
-
template_file = File.open(@gen.source_path("view_form.html.erb"))
|
191
|
-
result = ERB.new(template_file.read, nil, '-').result(binding)
|
192
|
-
expected_file = File.open(File.join(File.dirname(__FILE__), "expected_templates/_form.html.erb"))
|
193
|
-
assert_equal expected_file.read, result
|
194
|
-
end
|
195
|
-
end
|
196
|
-
|
197
|
-
context "A scaffold_for_view generator instantiated for a test model with two belongs_to associations" do
|
198
|
-
setup do
|
199
|
-
setup_test_model
|
200
|
-
setup_parent_test_model
|
201
|
-
setup_second_parent_test_model
|
202
|
-
@gen = new_generator_for_test_model('scaffold_for_view', ['--view', 'belongs_to:parent,second_parent[other_field]'], 'some_other_model')
|
203
|
-
end
|
237
|
+
context "A scaffold_for_view generator instantiated for a test model with two belongs_to associations" do
|
238
|
+
setup do
|
239
|
+
@gen = new_generator_for_test_model('scaffold_for_view', ['--view', 'belongs_to:parent_model,second_parent_model[other_field]'], 'child_model')
|
240
|
+
end
|
204
241
|
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
242
|
+
should "render the model template as expected" do
|
243
|
+
@parent_models = @gen.parent_models
|
244
|
+
@class_name = @gen.class_name
|
245
|
+
@attributes = @gen.attributes
|
246
|
+
template_file = File.open(@gen.source_path("model.erb"))
|
247
|
+
result = ERB.new(template_file.read, nil, '-').result(binding)
|
248
|
+
expected_file = File.open(File.join(File.dirname(__FILE__), "expected_templates/child_model.rb"))
|
249
|
+
assert_equal expected_file.read, result
|
250
|
+
end
|
214
251
|
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
252
|
+
should "render the migration template as expected" do
|
253
|
+
@class_name = @gen.class_name
|
254
|
+
@attributes = @gen.attributes
|
255
|
+
@migration_name = 'CreateChildModels'
|
256
|
+
@table_name = @gen.table_name
|
257
|
+
@parent_models = @gen.parent_models
|
258
|
+
@options = {}
|
259
|
+
template_file = File.open(@gen.source_path("migration.rb"))
|
260
|
+
result = ERB.new(template_file.read, nil, '-').result(binding)
|
261
|
+
expected_file = File.open(File.join(File.dirname(__FILE__), "expected_templates/create_child_models.rb"))
|
262
|
+
assert_equal expected_file.read, result
|
263
|
+
end
|
226
264
|
end
|
227
|
-
end
|
228
265
|
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
@generator_script = Rails::Generator::Scripts::Generate.new
|
234
|
-
end
|
266
|
+
context "A Rails generator script" do
|
267
|
+
setup do
|
268
|
+
@generator_script = Rails::Generator::Scripts::Generate.new
|
269
|
+
end
|
235
270
|
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
271
|
+
should "return a warning when run with view_for on an invalid parent model and not run any actions" do
|
272
|
+
expect_no_actions
|
273
|
+
Rails::Generator::Base.logger.expects('error').with('Class \'blah\' does not exist or contains a syntax error and could not be loaded.')
|
274
|
+
@generator_script = Rails::Generator::Scripts::Generate.new
|
275
|
+
@generator_script.run(generator_script_cmd_line('view_for', ['--view', 'belongs_to:blah'], 'child_model'))
|
276
|
+
end
|
242
277
|
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
+
should "create the correct manifest when the view_for generator is run with a valid parent model" do
|
279
|
+
|
280
|
+
expect_no_warnings
|
281
|
+
|
282
|
+
directories = [
|
283
|
+
'app/controllers/',
|
284
|
+
'app/helpers/',
|
285
|
+
'app/views/child_models',
|
286
|
+
'app/views/layouts/',
|
287
|
+
'test/functional/',
|
288
|
+
'test/unit/',
|
289
|
+
'test/unit/helpers/',
|
290
|
+
'public/stylesheets/'
|
291
|
+
].each { |path| Rails::Generator::Commands::Create.any_instance.expects(:directory).with(path) }
|
292
|
+
|
293
|
+
templates = {
|
294
|
+
'view_index.html.erb' => 'app/views/child_models/index.html.erb',
|
295
|
+
'view_new.html.erb' => 'app/views/child_models/new.html.erb',
|
296
|
+
'view_edit.html.erb' => 'app/views/child_models/edit.html.erb',
|
297
|
+
'view_show.html.erb' => 'app/views/child_models/show.html.erb',
|
298
|
+
'view_form.html.erb' => 'app/views/child_models/_form.html.erb',
|
299
|
+
'layout.html.erb' => 'app/views/layouts/child_models.html.erb',
|
300
|
+
'style.css' => 'public/stylesheets/scaffold.css',
|
301
|
+
'controller.rb' => 'app/controllers/child_models_controller.rb',
|
302
|
+
'functional_test.rb' => 'test/functional/child_models_controller_test.rb',
|
303
|
+
'helper.rb' => 'app/helpers/child_models_helper.rb',
|
304
|
+
'helper_test.rb' => 'test/unit/helpers/child_models_helper_test.rb'
|
305
|
+
}.each { |template, target| Rails::Generator::Commands::Create.any_instance.expects(:template).with(template, target) }
|
306
|
+
|
307
|
+
Rails::Generator::Commands::Create.any_instance.expects(:route_resources).with('child_models')
|
308
|
+
Rails::Generator::Commands::Create.any_instance.expects(:file).never
|
309
|
+
Rails::Generator::Commands::Create.any_instance.expects(:dependency).never
|
310
|
+
|
311
|
+
@generator_script.run(generator_script_cmd_line('view_for', ['--view', 'belongs_to:parent_model'], 'child_model'))
|
312
|
+
end
|
278
313
|
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
314
|
+
should "create the correct manifest when the scaffold_for_view generator is run with a valid parent model" do
|
315
|
+
|
316
|
+
expect_no_warnings
|
317
|
+
|
318
|
+
directories = [
|
319
|
+
'app/models/',
|
320
|
+
'app/controllers/',
|
321
|
+
'app/helpers/',
|
322
|
+
'app/views/child_models',
|
323
|
+
'app/views/layouts/',
|
324
|
+
'test/functional/',
|
325
|
+
'test/unit/',
|
326
|
+
'test/unit/helpers/',
|
327
|
+
'test/fixtures/',
|
328
|
+
'public/stylesheets/'
|
329
|
+
].each { |path| Rails::Generator::Commands::Create.any_instance.expects(:directory).with(path) }
|
330
|
+
|
331
|
+
templates = {
|
332
|
+
'view_index.html.erb' => 'app/views/child_models/index.html.erb',
|
333
|
+
'view_new.html.erb' => 'app/views/child_models/new.html.erb',
|
334
|
+
'view_edit.html.erb' => 'app/views/child_models/edit.html.erb',
|
335
|
+
'view_show.html.erb' => 'app/views/child_models/show.html.erb',
|
336
|
+
'view_form.html.erb' => 'app/views/child_models/_form.html.erb',
|
337
|
+
'layout.html.erb' => 'app/views/layouts/child_models.html.erb',
|
338
|
+
'style.css' => 'public/stylesheets/scaffold.css',
|
339
|
+
'controller.rb' => 'app/controllers/child_models_controller.rb',
|
340
|
+
'functional_test.rb' => 'test/functional/child_models_controller_test.rb',
|
341
|
+
'helper.rb' => 'app/helpers/child_models_helper.rb',
|
342
|
+
'helper_test.rb' => 'test/unit/helpers/child_models_helper_test.rb',
|
343
|
+
'model.erb' => 'app/models/child_model.rb',
|
344
|
+
'unit_test.rb' => 'test/unit/child_model_test.rb',
|
345
|
+
'fixtures.yml' => 'test/fixtures/child_models.yml'
|
346
|
+
}.each { |template, target| Rails::Generator::Commands::Create.any_instance.expects(:template).with(template, target) }
|
347
|
+
|
348
|
+
Rails::Generator::Commands::Create.any_instance.expects(:route_resources).with('child_models')
|
349
|
+
Rails::Generator::Commands::Create.any_instance.expects(:file).never
|
350
|
+
Rails::Generator::Commands::Create.any_instance.expects(:dependency).never
|
351
|
+
|
352
|
+
Rails::Generator::Commands::Create.any_instance.expects(:migration_template).with(
|
353
|
+
'migration.rb',
|
354
|
+
'db/migrate',
|
355
|
+
:assigns => { :migration_name => "CreateChildModels" },
|
356
|
+
:migration_file_name => "create_child_models"
|
357
|
+
)
|
358
|
+
|
359
|
+
@generator_script.run(generator_script_cmd_line('scaffold_for_view', ['--view', 'belongs_to:parent_model'], 'child_model'))
|
360
|
+
end
|
325
361
|
end
|
326
|
-
end
|
327
362
|
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
363
|
+
context "A Rails generator script with a parent model without a has_many association" do
|
364
|
+
setup do
|
365
|
+
@generator_script = Rails::Generator::Scripts::Generate.new
|
366
|
+
ClassFactory :parent_model, :class_eval => ''
|
367
|
+
ClassFactory :child_model
|
368
|
+
end
|
334
369
|
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
370
|
+
should "return a warning when run with view_for and not run any actions" do
|
371
|
+
expect_no_actions
|
372
|
+
Rails::Generator::Base.logger.expects('warning').with('Model ParentModel does not contain a has_many association for ChildModel.')
|
373
|
+
@generator_script.run(generator_script_cmd_line('view_for', ['--view', 'belongs_to:parent_model'], 'child_model'))
|
374
|
+
end
|
340
375
|
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
376
|
+
should "return a warning when run with scaffold_for_view and not run any actions" do
|
377
|
+
expect_no_actions
|
378
|
+
Rails::Generator::Base.logger.expects('warning').with('Model ParentModel does not contain a has_many association for ChildModel.')
|
379
|
+
@generator_script.run(generator_script_cmd_line('scaffold_for_view', ['--view', 'belongs_to:parent_model'], 'child_model'))
|
380
|
+
end
|
345
381
|
end
|
346
382
|
end
|
347
383
|
|