ajax_scaffold_generator 1.0.0 → 2.0.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.
@@ -1,71 +1,88 @@
1
- require File.dirname(__FILE__) + '<%= "/.." * controller_class_nesting_depth %>/../test_helper'
2
- require '<%= controller_file_path %>_controller'
3
-
4
- # Re-raise errors caught by the controller.
5
- class <%= controller_class_name %>Controller; def rescue_action(e) raise e end; end
6
-
7
- class <%= controller_class_name %>ControllerTest < Test::Unit::TestCase
8
- fixtures :<%= table_name %>
9
-
10
- def setup
11
- @controller = <%= controller_class_name %>Controller.new
12
- @request = ActionController::TestRequest.new
13
- @response = ActionController::TestResponse.new
14
- end
15
-
16
- <% for action in unscaffolded_actions -%>
17
- def test_<%= action %>
18
- get :<%= action %>
19
- assert_response :success
20
- assert_template '<%= action %>'
21
- end
22
-
23
- <% end -%>
24
- <% unless suffix -%>
25
- def test_index
26
- get :index
27
- assert_response :success
28
- assert_template 'list'
29
- end
30
-
31
- <% end -%>
32
- def test_list<%= suffix %>
33
- get :list<%= suffix %>
34
-
35
- assert_response :success
36
- assert_template 'list<%= suffix %>'
37
-
38
- assert_not_nil assigns(:<%= plural_name %>)
39
- end
40
-
41
- def test_new<%= suffix %>
42
- num_<%= plural_name %> = <%= model_name %>.count
43
-
44
- post :new<%= suffix %>, :<%= singular_name %> => {}
45
-
46
- assert_response :success
47
- assert_template '_item'
48
-
49
- assert_equal num_<%= plural_name %> + 1, <%= model_name %>.count
50
- end
51
-
52
- def test_edit<%= suffix %>
53
- post :edit<%= suffix %>, :id => 1
54
-
55
- assert_response :success
56
- assert_template '_item'
57
- end
58
-
59
- def test_destroy<%= suffix %>
60
- assert_not_nil <%= model_name %>.find(1)
61
-
62
- post :destroy<%= suffix %>, :id => 1
63
-
64
- assert_response :success
65
- assert_template nil
66
-
67
- assert_raise(ActiveRecord::RecordNotFound) {
68
- <%= model_name %>.find(1)
69
- }
70
- end
71
- end
1
+ require File.dirname(__FILE__) + '<%= "/.." * controller_class_nesting_depth %>/../test_helper'
2
+ require '<%= controller_file_path %>_controller'
3
+
4
+ # Re-raise errors caught by the controller.
5
+ class <%= controller_class_name %>Controller; def rescue_action(e) raise e end; end
6
+
7
+ class <%= controller_class_name %>ControllerTest < Test::Unit::TestCase
8
+ fixtures :<%= table_name %>
9
+
10
+ def setup
11
+ @controller = <%= controller_class_name %>Controller.new
12
+ @request = ActionController::TestRequest.new
13
+ @response = ActionController::TestResponse.new
14
+ end
15
+
16
+ <% for action in unscaffolded_actions -%>
17
+ def test_<%= action %>
18
+ get :<%= action %>
19
+ assert_response :success
20
+ assert_template '<%= action %>'
21
+ end
22
+
23
+ <% end -%>
24
+ <% unless suffix -%>
25
+ def test_index
26
+ get :index
27
+ assert_response :success
28
+ assert_template 'list'
29
+ end
30
+
31
+ <% end -%>
32
+ def test_list<%= suffix %>
33
+ get :list<%= suffix %>
34
+
35
+ assert_response :success
36
+ assert_template 'list<%= suffix %>'
37
+
38
+ assert_not_nil assigns(:<%= plural_name %>)
39
+ end
40
+
41
+ def test_new<%= suffix %>
42
+ get :new<%= suffix %>
43
+
44
+ assert_response :success
45
+ assert_template 'new<%= suffix %>'
46
+
47
+ assert_not_nil assigns(:<%= singular_name %>)
48
+ end
49
+
50
+ def test_create
51
+ num_<%= plural_name %> = <%= model_name %>.count
52
+
53
+ post :create<%= suffix %>, :<%= singular_name %> => {}
54
+
55
+ assert_response :redirect
56
+ assert_redirected_to :action => 'list<%= suffix %>'
57
+
58
+ assert_equal num_<%= plural_name %> + 1, <%= model_name %>.count
59
+ end
60
+
61
+ def test_edit<%= suffix %>
62
+ get :edit<%= suffix %>, :id => 1
63
+
64
+ assert_response :success
65
+ assert_template 'edit<%= suffix %>'
66
+
67
+ assert_not_nil assigns(:<%= singular_name %>)
68
+ assert assigns(:<%= singular_name %>).valid?
69
+ end
70
+
71
+ def test_update<%= suffix %>
72
+ post :update<%= suffix %>, :id => 1
73
+ assert_response :redirect
74
+ assert_redirected_to :action => 'show<%= suffix %>', :id => 1
75
+ end
76
+
77
+ def test_destroy<%= suffix %>
78
+ assert_not_nil <%= model_name %>.find(1)
79
+
80
+ post :destroy, :id => 1
81
+ assert_response :redirect
82
+ assert_redirected_to :action => 'list<%= suffix %>'
83
+
84
+ assert_raise(ActiveRecord::RecordNotFound) {
85
+ <%= model_name %>.find(1)
86
+ }
87
+ end
88
+ end
data/templates/helper.rb CHANGED
@@ -1,2 +1,12 @@
1
- module <%= controller_class_name %>Helper
2
- end
1
+ module <%= controller_class_name %>Helper
2
+
3
+ def num_columns
4
+ <%= model_name %>.content_columns.length + 1
5
+ end
6
+
7
+ # This can be moved into application_helper.rb
8
+ def loading_indicator_tag(scope,id)
9
+ "<img src=\"/images/indicator.gif\" style=\"display: none;\" id=\"#{scope}-#{id}-loading-indicator\" alt=\"loading indicator\" class=\"loading-indicator\" />"
10
+ end
11
+
12
+ end
Binary file
@@ -1,14 +1,15 @@
1
- <html>
2
- <head>
3
- <title><%= controller_class_name %>: <%%= controller.action_name %></title>
4
- <%%= stylesheet_link_tag 'scaffold' %>
5
- <%%= javascript_include_tag 'prototype' %>
6
- <%%= javascript_include_tag 'effects' %>
7
- <%%= javascript_include_tag '<%= singular_name %>' %>
8
- </head>
9
- <body>
10
-
11
- <%%= @content_for_layout %>
12
-
13
- </body>
14
- </html>
1
+ <!DOCTYPE html
2
+ PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
3
+ "DTD/xhtml1-strict.dtd">
4
+ <html xmlns="http://www.w3.org/1999/xhtml" lang="en">
5
+ <head>
6
+ <title><%= Inflector.titleize(plural_name) %></title>
7
+ <%%= stylesheet_link_tag 'ajax_scaffold', :media => 'all' %>
8
+ <%%= javascript_include_tag 'prototype', 'effects', 'rico_corner', 'ajax_scaffold' %>
9
+ </head>
10
+ <body>
11
+
12
+ <%%= @content_for_layout %>
13
+
14
+ </body>
15
+ </html>
@@ -0,0 +1,9 @@
1
+ <%% unless @<%= singular_name %>.nil? %>
2
+ <%%= error_messages_for '<%= singular_name %>' %>
3
+ <%% end -%>
4
+
5
+ <%% for name in [:notice, :warning, :error, :message] %>
6
+ <%% if @flash[name] %>
7
+ <%%= "<div class=\"#{name}\">#{@flash[name]}</div>" %>
8
+ <%% end %>
9
+ <%% end %>
@@ -1,16 +1,25 @@
1
- <div id="<%= singular_name %>_<%%= @<%= singular_name %>.id %>">
2
-
3
- <%% for column in <%= model_name %>.content_columns %>
4
- <p><b><%%= column.human_name %>:</b> <%%=h @<%= singular_name %>.send(column.name) %></p>
5
- <%% end %>
6
-
7
- <%%= link_to_function 'Edit', "<%= plural_name %>Block.edit(#{@<%= singular_name %>.id})" %>
8
- <%%= link_to_remote 'Destroy',
9
- :url => { :action => 'destroy', :id => @<%= singular_name %> },
10
- :complete => visual_effect(:fade, "<%= singular_name %>_#{@<%= singular_name %>.id}"),
11
- :confirm => "Are you sure you want to delete this item?" %>
12
- </div>
13
-
14
- <div id="edit_<%= singular_name %>_dialog_<%%= @<%= singular_name %>.id %>" style="display: none">
15
- <%%= render :partial => 'edit' %>
16
- </div>
1
+ <tr id="view-<%= singular_name %>-<%%= <%= singular_name %>.id %>">
2
+ <%% for column in <%= model_name %>.content_columns %>
3
+ <td><%%=h <%= singular_name %>.send(column.name) %>&nbsp;</td>
4
+ <%% end %>
5
+ <td class="actions">
6
+ <div>
7
+ <%%= loading_indicator_tag '<%= singular_name %>', "edit-#{<%= singular_name %>.id}" %>
8
+ <%%= link_to_remote "Edit",
9
+ :url => { :controller => '<%= controller_name %>', :action => 'edit', :id => <%= singular_name %> },
10
+ :loading => "AjaxScaffold.editOnLoading(request,'<%= singular_name %>', #{<%= singular_name %>.id});",
11
+ :success => "AjaxScaffold.editOnSuccess(request,'<%= singular_name %>', #{<%= singular_name %>.id});",
12
+ :failure => "AjaxScaffold.editOnFailure(request,'<%= singular_name %>', #{<%= singular_name %>.id});",
13
+ :complete => "AjaxScaffold.editOnComplete(request,'<%= singular_name %>', #{<%= singular_name %>.id});",
14
+ :post => true; %>
15
+ <%%= link_to_remote "Delete",
16
+ :url => { :controller => '<%= controller_name %>',:action => 'destroy', :id => <%= singular_name %> },
17
+ :confirm => 'Are you sure?',
18
+ :loading => "AjaxScaffold.deleteOnLoading('<%= singular_name %>', #{<%= singular_name %>.id});",
19
+ :success => "AjaxScaffold.deleteOnSuccess('<%= singular_name %>', #{<%= singular_name %>.id});",
20
+ :failure => "AjaxScaffold.deleteOnFailure('<%= singular_name %>', #{<%= singular_name %>.id});",
21
+ :complete => "AjaxScaffold.deleteOnComplete('<%= singular_name %>', #{<%= singular_name %>.id});",
22
+ :post => true; %>
23
+ </div>
24
+ </td>
25
+ </tr>