ajax_scaffold_generator 3.1.3 → 3.1.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/CHANGELOG +90 -0
- data/ajax_scaffold_generator.rb +1 -1
- data/templates/functional_test.rb +103 -7
- data/templates/lib_ajax_scaffold.rb +1 -1
- data/templates/unit_test.rb +43 -3
- metadata +3 -2
data/CHANGELOG
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
|
2
|
+
3.1.4 =========
|
3
|
+
|
4
|
+
* Removed some vestigal CSS styling of textarea's that was setting the height
|
5
|
+
* Added unit and functional tests (Thanks to Nic Williams)
|
6
|
+
* Fixed bug with CamelCased model names not being converted to underscored names correctly
|
7
|
+
|
8
|
+
3.1.3 =========
|
9
|
+
|
10
|
+
* Fixed the generated test code so that it doesn't fail (even though there aren't any tests in there)
|
11
|
+
* Fixed a problem with a column sort direction not resetting when you select a new column to sort
|
12
|
+
* Fixed the "parenthesize method" warning messages
|
13
|
+
* Changed component.rhtml to rely on a variable for determining whether to display the scaffold wrapper elements instead of simply using request.xhr?
|
14
|
+
* ScaffoldColumns will escape column data (If you set :eval then it is your responsibility to wrap it in h() if necessary).
|
15
|
+
* Added the disabling of the add/edit forms on submit
|
16
|
+
* Moved calls to update_params up into a before_filter
|
17
|
+
|
18
|
+
3.1.2 =========
|
19
|
+
|
20
|
+
* Fixed bug with default sort not working for non-standard (overridden) table names.
|
21
|
+
* Fixed bug that allowed models to be generated in the plural form and in subdirectories.
|
22
|
+
* Fixed bug with edit/delete links not working for non-standard primary keys.
|
23
|
+
* Removed test methods from the controller functional test since they were all outdated and broken anyways.
|
24
|
+
* Changed the helper methods for column header and element row id's to be more properly namespaced.
|
25
|
+
* Changed controller actions to explicitly call RJS templates so there aren't any errors with conflicting RHTML templates.
|
26
|
+
|
27
|
+
3.1.1 =========
|
28
|
+
|
29
|
+
* Fixed two bugs with :eval and :sort_sql introspection in ScaffoldColumn. Should fix problems people have been having with
|
30
|
+
underscored table names.
|
31
|
+
* Made the code that gets the @sort_by for a component more robust so that invalid values in the session doesn't continue
|
32
|
+
to hose scaffolds.
|
33
|
+
|
34
|
+
3.1.0 =========
|
35
|
+
|
36
|
+
* Added support for defining your own scaffold columns in models by assigning an array of ScaffoldColumn's to @scaffold_columns.
|
37
|
+
If @scaffold_columns is not defined it will be created defaulting to columns for model.content_columns. See more about
|
38
|
+
ScaffoldColumns in lib/ajax_scaffold.rb or by reading the documentation on the site. Model classes now must "require 'ajax_scaffold'"
|
39
|
+
to support this new functionality.
|
40
|
+
* Added cancel as an action. There was enough inline code in _new_edit.rhtml that I thought, for consistency, it should be
|
41
|
+
refactored into a server-side method.
|
42
|
+
* Refactoring: All common server side code has been moved into lib/ajax_scaffold.rb.
|
43
|
+
This replaces the previous helpers/ajax_scaffold_helper.rb with an include in the helpers to AjaxScaffold::Helper
|
44
|
+
* Changed CSS styling of sorted columns to a more subtle darker blue from the yellow
|
45
|
+
|
46
|
+
3.0.4 =========
|
47
|
+
|
48
|
+
* Pagination loading indicator was not being namespaced using the scaffold_id. Caused all pagination loaders to show when
|
49
|
+
any pagination links were clicked.
|
50
|
+
* Fixed more issues related to controllers in subdirectories. Relative path controller names caused problems as well so
|
51
|
+
all url hashes now have a leading / on all controller names
|
52
|
+
|
53
|
+
3.0.3 =========
|
54
|
+
|
55
|
+
* Fixed a bug where destroy.rjs was throwing element not found errors
|
56
|
+
|
57
|
+
3.0.2 =========
|
58
|
+
|
59
|
+
* Added loading indicators for sorting and pagination
|
60
|
+
* Fixed a major bug that was causing problems with scaffolds generated with :: seperated controller names (eg Admin::Widgets)
|
61
|
+
* Refactored the default page size into AjaxScaffoldUtil library
|
62
|
+
|
63
|
+
3.0.1 =========
|
64
|
+
|
65
|
+
* Removed hardcoded controller value from ajax_scaffold_helper.rb that was left in there by accident.
|
66
|
+
|
67
|
+
3.0.0 ==========
|
68
|
+
|
69
|
+
* Generated scaffold uses RJS templates. This should make adding and changing behavior much easier, but this also means that Rails 1.1+ is now required.
|
70
|
+
* Sorting & Pagination support.
|
71
|
+
|
72
|
+
2.2.1 ==========
|
73
|
+
|
74
|
+
* Bug Fix : Generated scaffolds using controllers in modules no longer throw RoutingErrors.
|
75
|
+
|
76
|
+
2.2.0 ==========
|
77
|
+
|
78
|
+
* Graceful degredation in the absence of Javascript support.
|
79
|
+
|
80
|
+
2.1.0 ==========
|
81
|
+
|
82
|
+
* Safari: no longer crashes browser when editing the last row.
|
83
|
+
* Row colors always alternate instead of being overwritten by Effect.Highlight.
|
84
|
+
* Works when you generate with different controller and model parameters.
|
85
|
+
* Creating a new places that new element where its create form previously was, not at the top as it was previously.
|
86
|
+
* Now have the option to enable or disable highlighting via the generated scaffold
|
87
|
+
|
88
|
+
2.0.0 ==========
|
89
|
+
|
90
|
+
* Initial release of overhauled generator
|
data/ajax_scaffold_generator.rb
CHANGED
@@ -64,7 +64,7 @@ class AjaxScaffoldGenerator < ScaffoldGenerator
|
|
64
64
|
# Model class, unit test, and fixtures.
|
65
65
|
m.template 'model.rb', File.join('app/models', "#{singular_name}.rb")
|
66
66
|
m.template 'unit_test.rb', File.join('test/unit', "#{singular_name}_test.rb")
|
67
|
-
m.template 'fixtures.yml', File.join('test/fixtures', "#{
|
67
|
+
m.template 'fixtures.yml', File.join('test/fixtures', "#{table_name}.yml")
|
68
68
|
|
69
69
|
# Scaffolded forms.
|
70
70
|
m.complex_template 'form.rhtml',
|
@@ -7,14 +7,110 @@ class <%= controller_class_name %>Controller; def rescue_action(e) raise e end;
|
|
7
7
|
class <%= controller_class_name %>ControllerTest < Test::Unit::TestCase
|
8
8
|
fixtures :<%= table_name %>
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
10
|
+
NEW_<%= class_name.upcase %> = {} # e.g. {:name => 'Test <%= class_name %>', :description => 'Dummy'}
|
11
|
+
REDIRECT_TO_MAIN = {:action => 'list'} # put hash or string redirection that you normally expect
|
12
|
+
|
13
|
+
def setup
|
14
|
+
@controller = <%= controller_class_name %>Controller.new
|
15
|
+
@request = ActionController::TestRequest.new
|
16
|
+
@response = ActionController::TestResponse.new
|
17
|
+
# Retrieve fixtures via their name
|
18
|
+
# @first = <%= table_name %>(:first)
|
19
|
+
@first = <%= class_name %>.find_first
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_component
|
23
|
+
get :component
|
24
|
+
assert_response :success
|
25
|
+
assert_template '<%= base_controller_file_path %>/component'
|
26
|
+
<%= table_name %> = check_attrs(%w(<%= table_name %>))
|
27
|
+
assert_equal <%= class_name %>.find(:all).length, <%= table_name %>.length, "Incorrect number of <%= table_name %> shown"
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_component_update
|
31
|
+
get :component_update
|
32
|
+
assert_response :redirect
|
33
|
+
assert_redirected_to REDIRECT_TO_MAIN
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_component_update_xhr
|
37
|
+
xhr :get, :component_update
|
38
|
+
assert_response :success
|
39
|
+
assert_template '<%= base_controller_file_path %>/component'
|
40
|
+
<%= table_name %> = check_attrs(%w(<%= table_name %>))
|
41
|
+
assert_equal <%= class_name %>.find(:all).length, <%= table_name %>.length, "Incorrect number of <%= table_name %> shown"
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_create
|
45
|
+
<%= class_name.upcase.swapcase %>_count = <%= class_name %>.find(:all).length
|
46
|
+
post :create, {:<%= class_name.upcase.swapcase %> => NEW_<%= class_name.upcase %>}
|
47
|
+
<%= class_name.upcase.swapcase %> = check_attrs(%w(<%= class_name.upcase.swapcase %>))
|
48
|
+
assert_response :redirect
|
49
|
+
assert_redirected_to REDIRECT_TO_MAIN
|
50
|
+
assert_equal <%= class_name.upcase.swapcase %>_count + 1, <%= class_name %>.find(:all).length, "Expected an additional <%= class_name %>"
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_create_xhr
|
54
|
+
<%= class_name.upcase.swapcase %>_count = <%= class_name %>.find(:all).length
|
55
|
+
xhr :post, :create, {:<%= class_name.upcase.swapcase %> => NEW_<%= class_name.upcase %>}
|
56
|
+
<%= class_name.upcase.swapcase %> = check_attrs(%w(<%= class_name.upcase.swapcase %>))
|
57
|
+
assert_response :success
|
58
|
+
assert_template 'create.rjs'
|
59
|
+
assert_equal <%= class_name.upcase.swapcase %>_count + 1, <%= class_name %>.find(:all).length, "Expected an additional <%= class_name %>"
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_update
|
63
|
+
<%= class_name.upcase.swapcase %>_count = <%= class_name %>.find(:all).length
|
64
|
+
post :update, {:id => @first.id, :<%= class_name.upcase.swapcase %> => @first.attributes.merge(NEW_<%= class_name.upcase %>)}
|
65
|
+
<%= class_name.upcase.swapcase %> = check_attrs(%w(<%= class_name.upcase.swapcase %>))
|
66
|
+
<%= class_name.upcase.swapcase %>.reload
|
67
|
+
NEW_<%= class_name.upcase %>.each do |attr_name|
|
68
|
+
assert_equal NEW_<%= class_name.upcase %>[attr_name], <%= class_name.upcase.swapcase %>.attributes[attr_name], "@<%= class_name.upcase.swapcase %>.#{attr_name.to_s} incorrect"
|
69
|
+
end
|
70
|
+
assert_equal <%= class_name.upcase.swapcase %>_count, <%= class_name %>.find(:all).length, "Number of <%= class_name %>s should be the same"
|
71
|
+
assert_response :redirect
|
72
|
+
assert_redirected_to REDIRECT_TO_MAIN
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_update_xhr
|
76
|
+
<%= class_name.upcase.swapcase %>_count = <%= class_name %>.find(:all).length
|
77
|
+
xhr :post, :update, {:id => @first.id, :<%= class_name.upcase.swapcase %> => @first.attributes.merge(NEW_<%= class_name.upcase %>)}
|
78
|
+
<%= class_name.upcase.swapcase %> = check_attrs(%w(<%= class_name.upcase.swapcase %>))
|
79
|
+
<%= class_name.upcase.swapcase %>.reload
|
80
|
+
NEW_<%= class_name.upcase %>.each do |attr_name|
|
81
|
+
assert_equal NEW_<%= class_name.upcase %>[attr_name], <%= class_name.upcase.swapcase %>.attributes[attr_name], "@<%= class_name.upcase.swapcase %>.#{attr_name.to_s} incorrect"
|
82
|
+
end
|
83
|
+
assert_equal <%= class_name.upcase.swapcase %>_count, <%= class_name %>.find(:all).length, "Number of <%= class_name %>s should be the same"
|
84
|
+
assert_response :success
|
85
|
+
assert_template 'update.rjs'
|
86
|
+
end
|
87
|
+
|
88
|
+
def test_destroy
|
89
|
+
<%= class_name.upcase.swapcase %>_count = <%= class_name %>.find(:all).length
|
90
|
+
post :destroy, {:id => @first.id}
|
91
|
+
assert_response :redirect
|
92
|
+
assert_equal <%= class_name.upcase.swapcase %>_count - 1, <%= class_name %>.find(:all).length, "Number of <%= class_name %>s should be one less"
|
93
|
+
assert_redirected_to REDIRECT_TO_MAIN
|
94
|
+
end
|
95
|
+
|
96
|
+
def test_destroy_xhr
|
97
|
+
<%= class_name.upcase.swapcase %>_count = <%= class_name %>.find(:all).length
|
98
|
+
xhr :post, :destroy, {:id => @first.id}
|
99
|
+
assert_response :success
|
100
|
+
assert_equal <%= class_name.upcase.swapcase %>_count - 1, <%= class_name %>.find(:all).length, "Number of <%= class_name %>s should be one less"
|
101
|
+
assert_template 'destroy.rjs'
|
14
102
|
end
|
15
103
|
|
16
|
-
|
17
|
-
|
18
|
-
|
104
|
+
protected
|
105
|
+
# Could be put in a Helper library and included at top of test class
|
106
|
+
def check_attrs(attr_list)
|
107
|
+
attrs = []
|
108
|
+
attr_list.each do |attr_sym|
|
109
|
+
attr = assigns(attr_sym.to_sym)
|
110
|
+
assert_not_nil attr, "Attribute @#{attr_sym} should not be nil"
|
111
|
+
assert !attr.new_record?, "Should have saved the @#{attr_sym} obj" if attr.class == ActiveRecord
|
112
|
+
attrs << attr
|
113
|
+
end
|
114
|
+
attrs.length > 1 ? attrs : attrs[0]
|
19
115
|
end
|
20
116
|
end
|
@@ -8,7 +8,7 @@ module AjaxScaffold
|
|
8
8
|
# based on the given class.
|
9
9
|
def initialize(klass, options)
|
10
10
|
@name = options[:name]
|
11
|
-
@eval = options[:eval].nil? ? "h(#{klass.to_s
|
11
|
+
@eval = options[:eval].nil? ? "h(#{Inflector.underscore(klass.to_s)}.#{@name})" : options[:eval]
|
12
12
|
@label = options[:label].nil? ? Inflector.titleize(@name) : options[:label]
|
13
13
|
@sortable = options[:sortable].nil? ? true : options[:sortable]
|
14
14
|
@sort_sql = options[:sort_sql].nil? ? Inflector.tableize(klass.to_s) + "." + @name : options[:sort_sql] unless !@sortable
|
data/templates/unit_test.rb
CHANGED
@@ -3,8 +3,48 @@ require File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../test_hel
|
|
3
3
|
class <%= class_name %>Test < Test::Unit::TestCase
|
4
4
|
fixtures :<%= table_name %>
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
NEW_<%= class_name.upcase %> = {} # e.g. {:name => 'Test <%= class_name %>', :description => 'Dummy'}
|
7
|
+
REQ_ATTR_NAMES = %w( ) # name of fields that must be present, e.g. %(name description)
|
8
|
+
DUPLICATE_ATTR_NAMES = %w( ) # name of fields that cannot be a duplicate, e.g. %(name description)
|
9
|
+
|
10
|
+
def setup
|
11
|
+
# Retrieve fixtures via their name
|
12
|
+
# @first = <%= table_name %>(:first)
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_raw_validation
|
16
|
+
<%= class_name.upcase.swapcase %> = <%= class_name %>.new
|
17
|
+
assert <%= class_name.upcase.swapcase %>.valid?, "<%= class_name %> should be valid without initialisation parameters"
|
18
|
+
# If <%= class_name %> has validation, then use the following:
|
19
|
+
#assert !<%= class_name.upcase.swapcase %>.valid?, "<%= class_name %> should not be valid without initialisation parameters"
|
20
|
+
#REQ_ATTR_NAMES.each {|attr_name| assert forum.errors.invalid?(attr_name.to_sym), "Should be an error message for :#{attr_name}"}
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_new
|
24
|
+
<%= class_name.upcase.swapcase %> = <%= class_name %>.new(NEW_<%= class_name.upcase %>)
|
25
|
+
assert <%= class_name.upcase.swapcase %>.valid?, "<%= class_name %> should be valid"
|
26
|
+
NEW_<%= class_name.upcase %>.each do |attr_name|
|
27
|
+
assert_equal NEW_FORUM[attr_name], forum.attributes[attr_name], "<%= class_name %>.@#{attr_name.to_s} incorrect"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_validates_presence_of
|
32
|
+
REQ_ATTR_NAMES.each do |attr_name|
|
33
|
+
tmp_<%= class_name.upcase.swapcase %> = NEW_<%= class_name.upcase %>.clone
|
34
|
+
tmp_<%= class_name.upcase.swapcase %>.delete attr_name.to_sym
|
35
|
+
<%= class_name.upcase.swapcase %> = <%= class_name %>.new(tmp_<%= class_name.upcase.swapcase %>)
|
36
|
+
assert !<%= class_name.upcase.swapcase %>.valid?, "<%= class_name %> should be invalid, as @#{attr_name} is invalid"
|
37
|
+
assert forum.errors.invalid?(attr_name.to_sym), "Should be an error message for :#{attr_name}"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_duplicate
|
42
|
+
current_<%= class_name.upcase.swapcase %> = <%= class_name %>.find_first
|
43
|
+
DUPLICATE_ATTR_NAMES.each do |attr_name|
|
44
|
+
<%= class_name.upcase.swapcase %> = <%= class_name %>.new(NEW_<%= class_name.upcase %>.merge(attr_name.to_sym => current_<%= class_name.upcase.swapcase %>[attr_name]))
|
45
|
+
assert !<%= class_name.upcase.swapcase %>.valid?, "<%= class_name %> should be invalid, as @#{attr_name} is a duplicate"
|
46
|
+
assert forum.errors.invalid?(attr_name.to_sym), "Should be an error message for :#{attr_name}"
|
47
|
+
end
|
9
48
|
end
|
10
49
|
end
|
50
|
+
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.11
|
|
3
3
|
specification_version: 1
|
4
4
|
name: ajax_scaffold_generator
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 3.1.
|
7
|
-
date: 2006-07-
|
6
|
+
version: 3.1.4
|
7
|
+
date: 2006-07-14 00:00:00 -06:00
|
8
8
|
summary: Ajax scaffold generator is a rails generator for ajaxified scaffolds
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -29,6 +29,7 @@ cert_chain:
|
|
29
29
|
authors: []
|
30
30
|
files:
|
31
31
|
- README
|
32
|
+
- CHANGELOG
|
32
33
|
- MIT-LICENSE
|
33
34
|
- ajax_scaffold_generator.rb
|
34
35
|
- templates/
|