dry_crud 1.4.0 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +32 -24
- data/Rakefile +73 -19
- data/VERSION +1 -1
- data/lib/generators/dry_crud/dry_crud_generator.rb +11 -2
- data/lib/generators/dry_crud/templates/app/assets/images/actions/delete.png +0 -0
- data/lib/generators/dry_crud/templates/app/assets/stylesheets/crud.scss +64 -0
- data/lib/generators/dry_crud/templates/app/assets/stylesheets/sample.scss +258 -0
- data/lib/generators/dry_crud/templates/app/controllers/crud_controller.rb +30 -24
- data/lib/generators/dry_crud/templates/app/controllers/list_controller.rb +93 -7
- data/lib/generators/dry_crud/templates/app/helpers/crud_helper.rb +70 -16
- data/lib/generators/dry_crud/templates/app/helpers/list_helper.rb +1 -0
- data/lib/generators/dry_crud/templates/app/helpers/standard_form_builder.rb +11 -3
- data/lib/generators/dry_crud/templates/app/helpers/standard_helper.rb +36 -45
- data/lib/generators/dry_crud/templates/app/helpers/standard_table_builder.rb +4 -3
- data/lib/generators/dry_crud/templates/app/views/crud/_actions_edit.html.erb +2 -2
- data/lib/generators/dry_crud/templates/app/views/crud/_actions_edit.html.haml +3 -0
- data/lib/generators/dry_crud/templates/app/views/crud/_actions_index.html.haml +1 -0
- data/lib/generators/dry_crud/templates/app/views/crud/_actions_show.html.erb +2 -2
- data/lib/generators/dry_crud/templates/app/views/crud/_actions_show.html.haml +3 -0
- data/lib/generators/dry_crud/templates/app/views/crud/_attrs.html.erb +1 -1
- data/lib/generators/dry_crud/templates/app/views/crud/_attrs.html.haml +1 -0
- data/lib/generators/dry_crud/templates/app/views/crud/_form.html.haml +1 -0
- data/lib/generators/dry_crud/templates/app/views/crud/_list.html.haml +1 -0
- data/lib/generators/dry_crud/templates/app/views/crud/edit.html.erb +0 -2
- data/lib/generators/dry_crud/templates/app/views/crud/edit.html.haml +5 -0
- data/lib/generators/dry_crud/templates/app/views/crud/new.html.erb +0 -2
- data/lib/generators/dry_crud/templates/app/views/crud/new.html.haml +5 -0
- data/lib/generators/dry_crud/templates/app/views/crud/show.html.erb +0 -2
- data/lib/generators/dry_crud/templates/app/views/crud/show.html.haml +7 -0
- data/lib/generators/dry_crud/templates/app/views/layouts/_flash.html.erb +8 -0
- data/lib/generators/dry_crud/templates/app/views/layouts/_flash.html.haml +4 -0
- data/lib/generators/dry_crud/templates/app/views/layouts/_menu.html.erb +3 -0
- data/lib/generators/dry_crud/templates/app/views/layouts/_menu.html.haml +3 -0
- data/lib/generators/dry_crud/templates/app/views/layouts/_nav.html.erb +6 -0
- data/lib/generators/dry_crud/templates/app/views/layouts/_nav.html.haml +3 -0
- data/lib/generators/dry_crud/templates/app/views/layouts/crud.html.erb +40 -21
- data/lib/generators/dry_crud/templates/app/views/layouts/crud.html.haml +42 -0
- data/lib/generators/dry_crud/templates/app/views/list/_actions_index.html.haml +0 -0
- data/lib/generators/dry_crud/templates/app/views/list/_list.html.haml +1 -0
- data/lib/generators/dry_crud/templates/app/views/list/_search.html.erb +4 -3
- data/lib/generators/dry_crud/templates/app/views/list/_search.html.haml +5 -0
- data/lib/generators/dry_crud/templates/app/views/list/index.html.erb +2 -4
- data/lib/generators/dry_crud/templates/app/views/list/index.html.haml +7 -0
- data/lib/generators/dry_crud/templates/app/views/shared/_error_messages.html.erb +1 -1
- data/lib/generators/dry_crud/templates/app/views/shared/_error_messages.html.haml +6 -0
- data/lib/generators/dry_crud/templates/app/views/shared/_labeled.html.erb +1 -1
- data/lib/generators/dry_crud/templates/app/views/shared/_labeled.html.haml +3 -0
- data/lib/generators/dry_crud/templates/config/locales/en_crud.yml +6 -6
- data/lib/generators/dry_crud/templates/test/crud_test_model.rb +5 -1
- data/lib/generators/dry_crud/templates/test/custom_assertions.rb +4 -4
- data/lib/generators/dry_crud/templates/test/functional/crud_controller_test_helper.rb +40 -32
- data/lib/generators/dry_crud/templates/test/functional/crud_test_models_controller_test.rb +3 -5
- data/lib/generators/dry_crud/templates/test/unit/helpers/crud_helper_test.rb +5 -3
- data/lib/generators/dry_crud/templates/test/unit/helpers/standard_form_builder_test.rb +4 -4
- data/lib/generators/dry_crud/templates/test/unit/helpers/standard_helper_test.rb +11 -25
- data/lib/generators/dry_crud/templates/test/unit/helpers/standard_table_builder_test.rb +9 -9
- data/test/templates/Gemfile +13 -6
- data/test/templates/app/controllers/admin/cities_controller.rb +14 -0
- data/test/templates/app/controllers/admin/countries_controller.rb +14 -0
- data/test/templates/app/controllers/people_controller.rb +1 -1
- data/test/templates/app/controllers/vips_controller.rb +2 -2
- data/test/templates/app/helpers/cities_helper.rb +9 -0
- data/test/templates/app/models/city.rb +4 -3
- data/test/templates/app/models/country.rb +14 -0
- data/test/templates/app/views/admin/cities/_actions_index.html.erb +2 -0
- data/test/templates/app/views/admin/cities/_actions_index.html.haml +2 -0
- data/test/templates/app/views/admin/cities/_form.html.erb +1 -0
- data/test/templates/app/views/admin/cities/_form.html.haml +1 -0
- data/test/templates/app/views/{cities → admin/cities}/_hello.html.erb +0 -0
- data/test/templates/app/views/admin/cities/_hello.html.haml +1 -0
- data/test/templates/app/views/admin/cities/_list.html.erb +6 -0
- data/test/templates/app/views/admin/cities/_list.html.haml +5 -0
- data/test/templates/app/views/admin/countries/_list.html.erb +5 -0
- data/test/templates/app/views/admin/countries/_list.html.haml +4 -0
- data/test/templates/app/views/ajax/_actions_index.html.haml +8 -0
- data/test/templates/app/views/ajax/_hello.html.haml +1 -0
- data/test/templates/app/views/ajax/ajax.js.haml +1 -0
- data/test/templates/app/views/layouts/_menu.html.erb +1 -1
- data/test/templates/app/views/layouts/_menu.html.haml +3 -0
- data/test/templates/app/views/people/_attrs.html.haml +4 -0
- data/test/templates/app/views/people/_list.html.haml +1 -0
- data/test/templates/config/database.yml +8 -9
- data/test/templates/config/locales/en_cities.yml +3 -3
- data/test/templates/config/routes.rb +16 -8
- data/test/templates/db/migrate/20100511174904_create_people_and_cities.rb +7 -7
- data/test/templates/db/seeds.rb +11 -5
- data/test/templates/test/fixtures/cities.yml +3 -3
- data/test/templates/test/fixtures/countries.yml +11 -0
- data/test/templates/test/functional/admin/cities_controller_test.rb +59 -0
- data/test/templates/test/functional/admin/countries_controller_test.rb +43 -0
- data/test/templates/test/functional/people_controller_test.rb +6 -1
- metadata +54 -15
- data/lib/generators/dry_crud/templates/app/assets/stylesheets/crud.css +0 -239
- data/test/templates/app/controllers/cities_controller.rb +0 -10
- data/test/templates/app/views/cities/_form.html.erb +0 -8
- data/test/templates/app/views/cities/_list.html.erb +0 -4
- data/test/templates/test/functional/cities_controller_test.rb +0 -45
@@ -4,34 +4,53 @@
|
|
4
4
|
<head>
|
5
5
|
<meta charset="utf-8" />
|
6
6
|
<title><%= strip_tags(@title) %></title>
|
7
|
-
<%= stylesheet_link_tag 'crud' %>
|
8
7
|
<%= csrf_meta_tag %>
|
8
|
+
|
9
|
+
<!-- HTML5 shim, for IE6-8 support of HTML elements -->
|
10
|
+
<!--[if lt IE 9]>
|
11
|
+
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js" type="text/javascript"></script>
|
12
|
+
<![endif]-->
|
13
|
+
|
14
|
+
<%= stylesheet_link_tag 'application', :media => 'all' %>
|
15
|
+
|
16
|
+
<!-- fav and touch icons -->
|
17
|
+
<link href="images/favicon.ico" rel="shortcut icon">
|
18
|
+
<link href="images/apple-touch-icon.png" rel="apple-touch-icon">
|
19
|
+
<link href="images/apple-touch-icon-72x72.png" rel="apple-touch-icon" sizes="72x72">
|
20
|
+
<link href="images/apple-touch-icon-114x114.png" rel="apple-touch-icon" sizes="114x114">
|
21
|
+
|
9
22
|
<%= yield :head %>
|
10
23
|
</head>
|
11
24
|
<body>
|
25
|
+
|
26
|
+
|
27
|
+
<div class="container">
|
28
|
+
<%= render 'layouts/nav' %>
|
29
|
+
|
30
|
+
<h1><%= @title %></h1>
|
31
|
+
|
32
|
+
<%= render :partial => 'layouts/flash', :collection => [:notice, :alert], :as => :level %>
|
33
|
+
|
34
|
+
<div class="actions btn-toolbar">
|
35
|
+
<div class="pull-left">
|
36
|
+
<%= yield :tools %>
|
37
|
+
</div>
|
38
|
+
<div class="pull-right">
|
39
|
+
<%= yield :actions %>
|
40
|
+
</div>
|
41
|
+
</div>
|
12
42
|
|
13
|
-
<div id="
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
<h1><%= @title %></h1>
|
19
|
-
|
20
|
-
<% if flash.notice.present? %>
|
21
|
-
<div id="flash_notice"><%= raw(flash.notice) %></div>
|
22
|
-
<% elsif flash.alert.present? %>
|
23
|
-
<div id="flash_alert"><%= raw(flash.alert) %></div>
|
24
|
-
<% end %>
|
25
|
-
|
26
|
-
<div class="actions">
|
27
|
-
<%= yield :actions %>
|
28
|
-
</div>
|
29
|
-
|
30
|
-
<div id="content">
|
31
|
-
<%= yield %>
|
32
|
-
</div>
|
43
|
+
<div id="content">
|
44
|
+
<%= yield %>
|
45
|
+
</div>
|
46
|
+
|
33
47
|
</div>
|
34
48
|
|
49
|
+
<footer>
|
50
|
+
<p>© Company <%= Time.now.year %></p>
|
51
|
+
</footer>
|
52
|
+
|
53
|
+
<!-- Javascript placed at the end of the document so the pages load faster -->
|
35
54
|
<%= javascript_include_tag 'application' %>
|
36
55
|
<%= javascript_tag yield(:javascripts) if content_for?(:javascripts) %>
|
37
56
|
|
@@ -0,0 +1,42 @@
|
|
1
|
+
!!! 5
|
2
|
+
|
3
|
+
%html
|
4
|
+
%head
|
5
|
+
%meta{:charset => 'utf-8'}
|
6
|
+
%title= strip_tags(@title)
|
7
|
+
= csrf_meta_tag
|
8
|
+
|
9
|
+
<!-- HTML5 shim, for IE6-8 support of HTML elements -->
|
10
|
+
<!--[if lt IE 9]>
|
11
|
+
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js" type="text/javascript"></script>
|
12
|
+
<![endif]-->
|
13
|
+
|
14
|
+
= stylesheet_link_tag 'application', :media => 'all'
|
15
|
+
|
16
|
+
%link{:href => "images/favicon.ico", :rel => "shortcut icon"}
|
17
|
+
%link{:href => "images/apple-touch-icon.png", :rel => "apple-touch-icon"}
|
18
|
+
%link{:href => "images/apple-touch-icon-72x72.png", :rel => "apple-touch-icon", :sizes => "72x72"}
|
19
|
+
%link{:href => "images/apple-touch-icon-114x114.png", :rel => "apple-touch-icon", :sizes => "114x114"}
|
20
|
+
|
21
|
+
= yield :head
|
22
|
+
|
23
|
+
%body
|
24
|
+
.container
|
25
|
+
= render 'layouts/nav'
|
26
|
+
|
27
|
+
%h1= @title
|
28
|
+
|
29
|
+
= render :partial => 'layouts/flash', :collection => [:notice, :alert], :as => :level
|
30
|
+
|
31
|
+
.actions.btn-toolbar.clearfix
|
32
|
+
.pull-left=yield :tools
|
33
|
+
.pull-right= yield :actions
|
34
|
+
|
35
|
+
#content= yield
|
36
|
+
|
37
|
+
%footer
|
38
|
+
%p
|
39
|
+
© MyCompany #{Time.now.year}
|
40
|
+
|
41
|
+
= javascript_include_tag 'application'
|
42
|
+
= javascript_tag yield(:javascripts) if content_for?(:javascripts)
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
= list_table
|
@@ -1,5 +1,6 @@
|
|
1
|
-
<%= form_tag(nil, {:method => :get, :class => 'search'}) do %>
|
1
|
+
<%= form_tag(nil, {:method => :get, :class => 'form-search'}) do %>
|
2
2
|
<%= hidden_field_tag :returning, true %>
|
3
|
-
<%=
|
4
|
-
<%=
|
3
|
+
<%= hidden_field_tag :page, 1 %>
|
4
|
+
<%= search_field_tag :q, params[:q], :class => 'search-query' %>
|
5
|
+
<%= submit_tag ti(:"button.search"), :class => 'btn' %>
|
5
6
|
<% end %>
|
@@ -1,9 +1,7 @@
|
|
1
1
|
<% @title ||= ti(:title, :models => models_label) -%>
|
2
2
|
|
3
|
-
<% content_for(:
|
4
|
-
|
5
|
-
<%= render 'search' if search_support? %>
|
3
|
+
<% content_for(:tools, render('search')) if search_support? %>
|
6
4
|
|
7
|
-
|
5
|
+
<% content_for(:actions, render('actions_index')) %>
|
8
6
|
|
9
7
|
<%= render 'list' %>
|
@@ -1,4 +1,4 @@
|
|
1
1
|
<div class="labeled">
|
2
|
-
<
|
2
|
+
<label><%= label.presence || raw(StandardHelper::EMPTY_STRING) %></label>
|
3
3
|
<div class="value"><%= content.presence || raw(StandardHelper::EMPTY_STRING) %></div>
|
4
4
|
</div>
|
@@ -47,17 +47,17 @@ en:
|
|
47
47
|
# crud controller
|
48
48
|
crud:
|
49
49
|
show:
|
50
|
-
title: %{model}
|
50
|
+
title: "%{model}"
|
51
51
|
new:
|
52
|
-
title: New %{model}
|
52
|
+
title: "New %{model}"
|
53
53
|
edit:
|
54
|
-
title: Edit %{model}
|
54
|
+
title: "Edit %{model}"
|
55
55
|
create:
|
56
56
|
flash:
|
57
|
-
success: %{model} was successfully created.
|
57
|
+
success: "%{model} was successfully created."
|
58
58
|
update:
|
59
59
|
flash:
|
60
|
-
success: %{model} was successfully updated.
|
60
|
+
success: "%{model} was successfully updated."
|
61
61
|
destroy:
|
62
62
|
flash:
|
63
|
-
success: %{model} was successfully deleted.
|
63
|
+
success: "%{model} was successfully deleted."
|
@@ -38,7 +38,7 @@ class CrudTestModelsController < CrudController #:nodoc:
|
|
38
38
|
|
39
39
|
# don't use the standard layout as it may require different routes
|
40
40
|
# than just the test route for this controller
|
41
|
-
layout
|
41
|
+
layout false
|
42
42
|
|
43
43
|
def destroy
|
44
44
|
super do |success, format|
|
@@ -125,6 +125,10 @@ module CrudTestHelper
|
|
125
125
|
def params
|
126
126
|
{}
|
127
127
|
end
|
128
|
+
|
129
|
+
def path_args(entry)
|
130
|
+
entry
|
131
|
+
end
|
128
132
|
|
129
133
|
def sortable?(attr)
|
130
134
|
true
|
@@ -37,7 +37,7 @@ module CustomAssertions
|
|
37
37
|
record.valid?
|
38
38
|
full_message = build_message(message,
|
39
39
|
"? expected to be valid, but has the following errors: \n ?.",
|
40
|
-
record, record.errors.full_messages.join("\n"))
|
40
|
+
record.to_s, record.errors.full_messages.join("\n"))
|
41
41
|
assert_block(full_message) { record.valid? }
|
42
42
|
end
|
43
43
|
|
@@ -46,19 +46,19 @@ module CustomAssertions
|
|
46
46
|
# attributes are expected to have errors. If no invalid attributes are
|
47
47
|
# specified, only the invalidity of the record is asserted.
|
48
48
|
def assert_not_valid(record, *invalid_attrs)
|
49
|
-
message = build_message("", "? expected to be invalid, but is valid.", record)
|
49
|
+
message = build_message("", "? expected to be invalid, but is valid.", record.to_s)
|
50
50
|
assert_block(message) { !record.valid? }
|
51
51
|
|
52
52
|
# assert that the given attributes have errors.
|
53
53
|
invalid_attrs.each do |a|
|
54
|
-
message = build_message("", "Attribute <?> expected to be invalid, but is valid.", a)
|
54
|
+
message = build_message("", "Attribute <?> expected to be invalid, but is valid.", a.to_s)
|
55
55
|
assert_block(message) { record.errors[a].present? }
|
56
56
|
end
|
57
57
|
|
58
58
|
if invalid_attrs.present?
|
59
59
|
# assert that no other than the invalid attributes have errors.
|
60
60
|
record.errors.each do |a, error|
|
61
|
-
message = build_message("", "Attribute <?> not declared as invalid attribute, but has the following error: \n?.", a, error)
|
61
|
+
message = build_message("", "Attribute <?> not declared as invalid attribute, but has the following error: \n?.", a.to_s, error)
|
62
62
|
assert_block(message) { invalid_attrs.include?(a) }
|
63
63
|
end
|
64
64
|
end
|
@@ -5,14 +5,14 @@
|
|
5
5
|
module CrudControllerTestHelper
|
6
6
|
|
7
7
|
def test_index
|
8
|
-
get :index
|
8
|
+
get :index, test_params
|
9
9
|
assert_response :success
|
10
10
|
assert_template 'index'
|
11
11
|
assert_present assigns(:entries)
|
12
12
|
end
|
13
13
|
|
14
14
|
def test_index_json
|
15
|
-
get :index, :format => 'json'
|
15
|
+
get :index, test_params(:format => 'json')
|
16
16
|
assert_response :success
|
17
17
|
assert_present assigns(:entries)
|
18
18
|
assert @response.body.starts_with?("[{"), @response.body
|
@@ -23,7 +23,7 @@ module CrudControllerTestHelper
|
|
23
23
|
val = field && test_entry[field].to_s
|
24
24
|
return if val.blank? # does not support search or no value in this field
|
25
25
|
|
26
|
-
get :index, :q => val[0..((val.size + 1)/ 2)]
|
26
|
+
get :index, test_params(:q => val[0..((val.size + 1)/ 2)])
|
27
27
|
assert_response :success
|
28
28
|
assert_present assigns(:entries)
|
29
29
|
assert assigns(:entries).include?(test_entry)
|
@@ -31,7 +31,7 @@ module CrudControllerTestHelper
|
|
31
31
|
|
32
32
|
def test_index_sort_asc
|
33
33
|
col = model_class.column_names.first
|
34
|
-
get :index, :sort => col, :sort_dir => 'asc'
|
34
|
+
get :index, test_params(:sort => col, :sort_dir => 'asc')
|
35
35
|
assert_response :success
|
36
36
|
assert_present assigns(:entries)
|
37
37
|
sorted = assigns(:entries).sort_by &(col.to_sym)
|
@@ -40,7 +40,7 @@ module CrudControllerTestHelper
|
|
40
40
|
|
41
41
|
def test_index_sort_desc
|
42
42
|
col = model_class.column_names.first
|
43
|
-
get :index, :sort => col, :sort_dir => 'desc'
|
43
|
+
get :index, test_params(:sort => col, :sort_dir => 'desc')
|
44
44
|
assert_response :success
|
45
45
|
assert_present assigns(:entries)
|
46
46
|
sorted = assigns(:entries).sort_by &(col.to_sym)
|
@@ -48,33 +48,27 @@ module CrudControllerTestHelper
|
|
48
48
|
end
|
49
49
|
|
50
50
|
def test_show
|
51
|
-
get :show, :id => test_entry.id
|
51
|
+
get :show, test_params(:id => test_entry.id)
|
52
52
|
assert_response :success
|
53
53
|
assert_template 'show'
|
54
54
|
assert_equal test_entry, assigns(:entry)
|
55
55
|
end
|
56
56
|
|
57
57
|
def test_show_json
|
58
|
-
get :show, :id => test_entry.id, :format => 'json'
|
58
|
+
get :show, test_params(:id => test_entry.id, :format => 'json')
|
59
59
|
assert_response :success
|
60
60
|
assert_equal test_entry, assigns(:entry)
|
61
61
|
assert @response.body.starts_with?("{")
|
62
62
|
end
|
63
63
|
|
64
|
-
def
|
64
|
+
def test_show_with_non_existing_id_raises_RecordNotFound
|
65
65
|
assert_raise(ActiveRecord::RecordNotFound) do
|
66
|
-
get :show, :id => 9999
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
def test_show_without_id_redirects_to_index
|
71
|
-
assert_raise(ActionController::RoutingError) do
|
72
|
-
get :show
|
66
|
+
get :show, test_params(:id => 9999)
|
73
67
|
end
|
74
68
|
end
|
75
69
|
|
76
70
|
def test_new
|
77
|
-
get :new
|
71
|
+
get :new, test_params
|
78
72
|
assert_response :success
|
79
73
|
assert_template 'new'
|
80
74
|
assert assigns(:entry).new_record?
|
@@ -82,45 +76,39 @@ module CrudControllerTestHelper
|
|
82
76
|
|
83
77
|
def test_create
|
84
78
|
assert_difference("#{model_class.name}.count") do
|
85
|
-
post :create, model_identifier => test_entry_attrs
|
79
|
+
post :create, test_params(model_identifier => test_entry_attrs)
|
86
80
|
end
|
87
|
-
|
81
|
+
assert_redirected_to_show assigns(:entry)
|
88
82
|
assert ! assigns(:entry).new_record?
|
89
83
|
assert_test_attrs_equal
|
90
84
|
end
|
91
85
|
|
92
86
|
def test_create_json
|
93
87
|
assert_difference("#{model_class.name}.count") do
|
94
|
-
post :create, model_identifier => test_entry_attrs, :format => 'json'
|
88
|
+
post :create, test_params(model_identifier => test_entry_attrs, :format => 'json')
|
95
89
|
end
|
96
90
|
assert_response :success
|
97
91
|
assert @response.body.starts_with?("{")
|
98
92
|
end
|
99
93
|
|
100
94
|
def test_edit
|
101
|
-
get :edit, :id => test_entry.id
|
95
|
+
get :edit, test_params(:id => test_entry.id)
|
102
96
|
assert_response :success
|
103
97
|
assert_template 'edit'
|
104
98
|
assert_equal test_entry, assigns(:entry)
|
105
99
|
end
|
106
100
|
|
107
|
-
def test_edit_without_id_raises_RecordNotFound
|
108
|
-
assert_raise(ActionController::RoutingError) do
|
109
|
-
get :edit
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
101
|
def test_update
|
114
102
|
assert_no_difference("#{model_class.name}.count") do
|
115
|
-
put :update, :id => test_entry.id, model_identifier => test_entry_attrs
|
103
|
+
put :update, test_params(:id => test_entry.id, model_identifier => test_entry_attrs)
|
116
104
|
end
|
117
105
|
assert_test_attrs_equal
|
118
|
-
|
106
|
+
assert_redirected_to_show assigns(:entry)
|
119
107
|
end
|
120
108
|
|
121
109
|
def test_update_json
|
122
110
|
assert_no_difference("#{model_class.name}.count") do
|
123
|
-
put :update, :id => test_entry.id, model_identifier => test_entry_attrs, :format => 'json'
|
111
|
+
put :update, test_params(:id => test_entry.id, model_identifier => test_entry_attrs, :format => 'json')
|
124
112
|
end
|
125
113
|
assert_response :success
|
126
114
|
assert_equal "", @response.body.strip
|
@@ -128,14 +116,14 @@ module CrudControllerTestHelper
|
|
128
116
|
|
129
117
|
def test_destroy
|
130
118
|
assert_difference("#{model_class.name}.count", -1) do
|
131
|
-
delete :destroy, :id => test_entry.id
|
119
|
+
delete :destroy, test_params(:id => test_entry.id)
|
132
120
|
end
|
133
121
|
assert_redirected_to_index
|
134
122
|
end
|
135
123
|
|
136
124
|
def test_destroy_json
|
137
125
|
assert_difference("#{model_class.name}.count", -1) do
|
138
|
-
delete :destroy, :id => test_entry.id, :format => 'json'
|
126
|
+
delete :destroy, test_params(:id => test_entry.id, :format => 'json')
|
139
127
|
end
|
140
128
|
assert_response :success
|
141
129
|
assert_equal "", @response.body.strip
|
@@ -144,7 +132,11 @@ module CrudControllerTestHelper
|
|
144
132
|
protected
|
145
133
|
|
146
134
|
def assert_redirected_to_index
|
147
|
-
assert_redirected_to :action => 'index', :returning => true
|
135
|
+
assert_redirected_to test_params(:action => 'index', :returning => true)
|
136
|
+
end
|
137
|
+
|
138
|
+
def assert_redirected_to_show(entry)
|
139
|
+
assert_redirected_to test_params(:action => 'show', :id => entry.id)
|
148
140
|
end
|
149
141
|
|
150
142
|
def assert_test_attrs_equal
|
@@ -171,5 +163,21 @@ module CrudControllerTestHelper
|
|
171
163
|
def test_entry_attrs
|
172
164
|
raise "Implement this method in your test class"
|
173
165
|
end
|
166
|
+
|
167
|
+
def test_params(params = {})
|
168
|
+
nesting_params.merge(params)
|
169
|
+
end
|
170
|
+
|
171
|
+
def nesting_params
|
172
|
+
params = {}
|
173
|
+
# for nested controllers, add parent ids to each request
|
174
|
+
Array(@controller.nesting).collect do |p|
|
175
|
+
if p.is_a?(Class) && p < ActiveRecord::Base
|
176
|
+
assoc = p.name.underscore
|
177
|
+
params["#{assoc}_id"] = test_entry.send(:"#{assoc}_id")
|
178
|
+
end
|
179
|
+
end
|
180
|
+
params
|
181
|
+
end
|
174
182
|
|
175
183
|
end
|
@@ -85,9 +85,7 @@ class CrudTestModelsControllerTest < ActionController::TestCase
|
|
85
85
|
assert names.index('EEEEE') < names.index('AAAAA')
|
86
86
|
assert names.index('EEEEE') < names.index('DDDDD')
|
87
87
|
assert names.index('AAAAA') < names.index('CCCCC')
|
88
|
-
assert names.index('AAAAA') < names.index('FFFFF')
|
89
88
|
assert names.index('DDDDD') < names.index('CCCCC')
|
90
|
-
assert names.index('DDDDD') < names.index('FFFFF')
|
91
89
|
end
|
92
90
|
|
93
91
|
def test_sort_with_search
|
@@ -170,8 +168,8 @@ class CrudTestModelsControllerTest < ActionController::TestCase
|
|
170
168
|
end
|
171
169
|
|
172
170
|
def test_models_label
|
173
|
-
assert_equal 'Crud
|
174
|
-
assert_equal 'Crud
|
171
|
+
assert_equal 'Crud Test Models', @controller.models_label
|
172
|
+
assert_equal 'Crud Test Model', @controller.models_label(false)
|
175
173
|
end
|
176
174
|
|
177
175
|
protected
|
@@ -191,7 +189,7 @@ class CrudTestModelsControllerTest < ActionController::TestCase
|
|
191
189
|
def test_entry
|
192
190
|
crud_test_models(:AAAAA)
|
193
191
|
end
|
194
|
-
|
192
|
+
|
195
193
|
def test_entry_attrs
|
196
194
|
{:name => 'foo',
|
197
195
|
:children => 42,
|
@@ -7,7 +7,7 @@ class CrudHelperTest < ActionView::TestCase
|
|
7
7
|
REGEXP_ROWS = /<tr.+?<\/tr>/m
|
8
8
|
REGEXP_HEADERS = /<th.+?<\/th>/m
|
9
9
|
REGEXP_SORT_HEADERS = /<th><a .*?sort_dir=asc.*?>.*?<\/a><\/th>/m
|
10
|
-
REGEXP_ACTION_CELL = /<td class=\"
|
10
|
+
REGEXP_ACTION_CELL = /<td class=\"action\"><a href.+?<\/a><\/td>/m
|
11
11
|
|
12
12
|
include CustomAssertions
|
13
13
|
include StandardHelper
|
@@ -74,7 +74,6 @@ class CrudHelperTest < ActionView::TestCase
|
|
74
74
|
|
75
75
|
|
76
76
|
test "crud form" do
|
77
|
-
@entry = CrudTestModel.first
|
78
77
|
f = with_test_routing do
|
79
78
|
capture { crud_form }
|
80
79
|
end
|
@@ -90,5 +89,8 @@ class CrudHelperTest < ActionView::TestCase
|
|
90
89
|
assert_match /select .*?name="crud_test_model\[companion_id\]"/, f
|
91
90
|
assert_match /textarea .*?name="crud_test_model\[remarks\]"/, f
|
92
91
|
end
|
93
|
-
|
92
|
+
|
93
|
+
def entry
|
94
|
+
@entry ||= CrudTestModel.first
|
95
|
+
end
|
94
96
|
end
|
@@ -98,24 +98,24 @@ class StandardFormBuilderTest < ActionView::TestCase
|
|
98
98
|
end
|
99
99
|
|
100
100
|
test "label creates captionized label" do
|
101
|
-
assert_match /label for.+Gugus dada/, form.label(:gugus_dada)
|
101
|
+
assert_match /label [^>]*for.+Gugus dada/, form.label(:gugus_dada)
|
102
102
|
assert form.label(:gugus_dada).html_safe?
|
103
103
|
end
|
104
104
|
|
105
105
|
test "classic label still works" do
|
106
|
-
assert_match /label for.+hoho/, form.label(:gugus_dada, "hoho")
|
106
|
+
assert_match /label [^>]*for.+hoho/, form.label(:gugus_dada, "hoho")
|
107
107
|
assert form.label(:gugus_dada, "hoho").html_safe?
|
108
108
|
end
|
109
109
|
|
110
110
|
test "labeled_text_field create label" do
|
111
|
-
assert_match /label for.+input/m, form.labeled_string_field(:name)
|
111
|
+
assert_match /label [^>]*for.+input/m, form.labeled_string_field(:name)
|
112
112
|
assert form.labeled_string_field(:name).html_safe?
|
113
113
|
end
|
114
114
|
|
115
115
|
test "labeled field creates label" do
|
116
116
|
result = form.labeled("gugus", "<input type='text' name='gugus' />")
|
117
117
|
assert result.html_safe?
|
118
|
-
assert_match /label for.+input/m, result
|
118
|
+
assert_match /label [^>]*for.+input/m, result
|
119
119
|
end
|
120
120
|
|
121
121
|
test "required mark is shown" do
|