test_battery 0.0.0 → 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +1 -1
- data/VERSION +1 -1
- data/lib/generators/battery_controller_generator.rb +41 -0
- data/lib/generators/templates/crud_controller.rb +3 -3
- data/lib/generators/templates/crud_controller_test.rb +5 -5
- data/lib/generators/templates/views/_form.html.haml +1 -0
- data/lib/generators/templates/views/edit.html.haml +5 -0
- data/lib/generators/templates/views/index.html.haml +13 -0
- data/lib/generators/templates/views/new.html.haml +5 -0
- data/lib/generators/templates/views/show.html.haml +3 -0
- data/lib/test_battery.rb +44 -0
- data/test_battery.gemspec +8 -3
- metadata +10 -5
- data/lib/generators/crud_controller_generator.rb +0 -30
data/README.md
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.1
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
|
3
|
+
class BatteryControllerGenerator < Rails::Generators::Base
|
4
|
+
|
5
|
+
source_root File.expand_path('../templates', __FILE__)
|
6
|
+
argument :controller_name, :type => :string
|
7
|
+
|
8
|
+
def generate_controller
|
9
|
+
template 'crud_controller.rb', "app/controllers/#{models}_controller.rb"
|
10
|
+
end
|
11
|
+
|
12
|
+
def generate_views
|
13
|
+
template 'views/index.html.haml', "app/views/#{models}/index.html.haml"
|
14
|
+
template 'views/show.html.haml', "app/views/#{models}/show.html.haml"
|
15
|
+
template 'views/new.html.haml', "app/views/#{models}/new.html.haml"
|
16
|
+
template 'views/edit.html.haml', "app/views/#{models}/edit.html.haml"
|
17
|
+
template 'views/_form.html.haml', "app/views/#{models}/_form.html.haml"
|
18
|
+
end
|
19
|
+
|
20
|
+
def generate_test
|
21
|
+
template 'crud_controller_test.rb', "test/functional/#{models}_controller_test.rb"
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def model
|
27
|
+
@model ||= models.singularize
|
28
|
+
end
|
29
|
+
|
30
|
+
def models
|
31
|
+
@models ||= controller_name.underscore
|
32
|
+
end
|
33
|
+
|
34
|
+
def model_class_name
|
35
|
+
@model_class_name ||= model.camelize
|
36
|
+
end
|
37
|
+
|
38
|
+
def controller_class_name
|
39
|
+
@controller_class_name ||= models.camelize
|
40
|
+
end
|
41
|
+
end
|
@@ -21,7 +21,7 @@ class <%=controller_class_name%>Controller < ApplicationController
|
|
21
21
|
|
22
22
|
def create
|
23
23
|
@<%=model%>.save!
|
24
|
-
flash[:notice] = '
|
24
|
+
flash[:notice] = '<%=model_class_name%> created'
|
25
25
|
redirect_to :action => :show, :id => @<%=model%>
|
26
26
|
rescue ActiveRecord::RecordInvalid
|
27
27
|
flash.now[:error] = 'Failed to create <%=model_class_name%>'
|
@@ -39,7 +39,7 @@ class <%=controller_class_name%>Controller < ApplicationController
|
|
39
39
|
|
40
40
|
def destroy
|
41
41
|
@<%=model%>.destroy
|
42
|
-
flash[:notice] = '
|
42
|
+
flash[:notice] = '<%=model_class_name%> deleted'
|
43
43
|
redirect_to :action => :index
|
44
44
|
end
|
45
45
|
|
@@ -50,7 +50,7 @@ protected
|
|
50
50
|
end
|
51
51
|
|
52
52
|
def load_<%=model%>
|
53
|
-
@<%=model%> =
|
53
|
+
@<%=model%> = <%=model_class_name%>.find(params[:id])
|
54
54
|
rescue ActiveRecord::RecordNotFound
|
55
55
|
flash[:error] = '<%=model_class_name%> not found'
|
56
56
|
redirect_to :action => :index
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require File.expand_path('../test_helper', File.dirname(__FILE__))
|
2
2
|
|
3
|
-
class <%=controller_class_name%>
|
3
|
+
class <%=controller_class_name%>ControllerTest < ActionController::TestCase
|
4
4
|
|
5
5
|
def test_get_index
|
6
6
|
get :index
|
@@ -12,14 +12,14 @@ class <%=controller_class_name%>Test < ActionController::TestCase
|
|
12
12
|
def test_get_show
|
13
13
|
<%=model%> = <%=models%>(:default)
|
14
14
|
get :show, :id => <%=model%>
|
15
|
-
assert assigns(
|
15
|
+
assert assigns(:<%=model%>)
|
16
16
|
assert_response :success
|
17
17
|
assert_template :show
|
18
18
|
end
|
19
19
|
|
20
20
|
def test_get_show_failure
|
21
21
|
get :show, :id => 'invalid'
|
22
|
-
|
22
|
+
assert_response :redirect
|
23
23
|
assert_redirected_to :action => :index
|
24
24
|
assert_equal '<%=model_class_name%> not found', flash[:error]
|
25
25
|
end
|
@@ -60,7 +60,7 @@ class <%=controller_class_name%>Test < ActionController::TestCase
|
|
60
60
|
}
|
61
61
|
assert_response :success
|
62
62
|
assert_template :new
|
63
|
-
assert_equal 'Failed to create <%=model_class_name%>'
|
63
|
+
assert_equal 'Failed to create <%=model_class_name%>', flash[:error]
|
64
64
|
end
|
65
65
|
end
|
66
66
|
|
@@ -94,7 +94,7 @@ class <%=controller_class_name%>Test < ActionController::TestCase
|
|
94
94
|
delete :destroy, :id => <%=model%>
|
95
95
|
assert_response :redirect
|
96
96
|
assert_redirected_to :action => :index
|
97
|
-
assert_equal '
|
97
|
+
assert_equal '<%=model_class_name%> deleted', flash[:notice]
|
98
98
|
end
|
99
99
|
end
|
100
100
|
|
@@ -0,0 +1 @@
|
|
1
|
+
-# = form.text_field :name
|
@@ -0,0 +1,13 @@
|
|
1
|
+
%h1 <%=models%>
|
2
|
+
|
3
|
+
%table
|
4
|
+
%tr
|
5
|
+
%th <%=model%>
|
6
|
+
%th
|
7
|
+
- @<%=models%>.each do |<%=model%>|
|
8
|
+
%tr
|
9
|
+
%td= debug <%=model%>
|
10
|
+
%td
|
11
|
+
= link_to 'Show', <%=models%>_path
|
12
|
+
= link_to 'Edit', <%=model%>_path(<%=model%>)
|
13
|
+
= link_to 'Delete', <%=model%>_path(<%=model%>), :method => :delete, :confirm => 'Are you sure?'
|
data/lib/test_battery.rb
CHANGED
@@ -0,0 +1,44 @@
|
|
1
|
+
module TestBattery
|
2
|
+
|
3
|
+
module TestCase
|
4
|
+
|
5
|
+
# Example usage:
|
6
|
+
# assert_has_errors_on( @record, [:field_1, :field_2] )
|
7
|
+
# assert_has_errors_on( @record, {:field_1 => 'Message1', :field_2 => 'Message 2'} )
|
8
|
+
def assert_has_errors_on(record, fields)
|
9
|
+
fields = [fields].flatten unless fields.is_a?(Hash)
|
10
|
+
fields.each do |field, message|
|
11
|
+
assert record.errors.has_key?(field.to_sym), "#{record.class.name} should error on invalid #{field}"
|
12
|
+
if message && record.errors[field].is_a?(Array) && !message.is_a?(Array)
|
13
|
+
assert_not_nil record.errors[field].index(message)
|
14
|
+
elsif message
|
15
|
+
assert_equal message, record.errors[field]
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
# Example usage:
|
21
|
+
# assert_exception_raised do ... end
|
22
|
+
# assert_exception_raised ActiveRecord::RecordInvalid do ... end
|
23
|
+
# assert_exception_raised Plugin::Error, 'error_message' do ... end
|
24
|
+
def assert_exception_raised(exception_class = nil, error_message = nil, &block)
|
25
|
+
exception_raised = nil
|
26
|
+
yield
|
27
|
+
rescue => exception_raised
|
28
|
+
ensure
|
29
|
+
if exception_raised
|
30
|
+
if exception_class
|
31
|
+
assert_equal exception_class, exception_raised.class, exception_raised.to_s
|
32
|
+
else
|
33
|
+
assert true
|
34
|
+
end
|
35
|
+
assert_equal error_message, exception_raised.to_s if error_message
|
36
|
+
else
|
37
|
+
flunk 'Exception was not raised'
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
ActiveSupport::TestCase.send :include, TestBattery::TestCase
|
data/test_battery.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{test_battery}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Oleg Khabarov"]
|
12
|
-
s.date = %q{2011-02-
|
12
|
+
s.date = %q{2011-02-22}
|
13
13
|
s.description = %q{Collection of generators and test helpers}
|
14
14
|
s.email = %q{oleg@theworkinggroup.ca}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -24,9 +24,14 @@ Gem::Specification.new do |s|
|
|
24
24
|
"README.md",
|
25
25
|
"Rakefile",
|
26
26
|
"VERSION",
|
27
|
-
"lib/generators/
|
27
|
+
"lib/generators/battery_controller_generator.rb",
|
28
28
|
"lib/generators/templates/crud_controller.rb",
|
29
29
|
"lib/generators/templates/crud_controller_test.rb",
|
30
|
+
"lib/generators/templates/views/_form.html.haml",
|
31
|
+
"lib/generators/templates/views/edit.html.haml",
|
32
|
+
"lib/generators/templates/views/index.html.haml",
|
33
|
+
"lib/generators/templates/views/new.html.haml",
|
34
|
+
"lib/generators/templates/views/show.html.haml",
|
30
35
|
"lib/test_battery.rb",
|
31
36
|
"test/helper.rb",
|
32
37
|
"test/test_test_battery.rb",
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 1
|
9
|
+
version: 0.0.1
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Oleg Khabarov
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2011-02-
|
17
|
+
date: 2011-02-22 00:00:00 -05:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -79,9 +79,14 @@ files:
|
|
79
79
|
- README.md
|
80
80
|
- Rakefile
|
81
81
|
- VERSION
|
82
|
-
- lib/generators/
|
82
|
+
- lib/generators/battery_controller_generator.rb
|
83
83
|
- lib/generators/templates/crud_controller.rb
|
84
84
|
- lib/generators/templates/crud_controller_test.rb
|
85
|
+
- lib/generators/templates/views/_form.html.haml
|
86
|
+
- lib/generators/templates/views/edit.html.haml
|
87
|
+
- lib/generators/templates/views/index.html.haml
|
88
|
+
- lib/generators/templates/views/new.html.haml
|
89
|
+
- lib/generators/templates/views/show.html.haml
|
85
90
|
- lib/test_battery.rb
|
86
91
|
- test/helper.rb
|
87
92
|
- test/test_test_battery.rb
|
@@ -100,7 +105,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
100
105
|
requirements:
|
101
106
|
- - ">="
|
102
107
|
- !ruby/object:Gem::Version
|
103
|
-
hash:
|
108
|
+
hash: -2656427538802755959
|
104
109
|
segments:
|
105
110
|
- 0
|
106
111
|
version: "0"
|
@@ -1,30 +0,0 @@
|
|
1
|
-
require 'rails/generators'
|
2
|
-
|
3
|
-
class CrudControllerGenerator < Rails::Generators::Base
|
4
|
-
|
5
|
-
source_root File.expand_path('../templates', __FILE__)
|
6
|
-
argument :controller_name, :type => :string
|
7
|
-
|
8
|
-
def generate_controller
|
9
|
-
template 'crud_controller.rb', "app/controllers/#{models}_controller.rb"
|
10
|
-
template 'crud_controller_test.rb', "test/functional/#{models}_controller_test.rb"
|
11
|
-
end
|
12
|
-
|
13
|
-
private
|
14
|
-
|
15
|
-
def model
|
16
|
-
@model ||= models.singularize
|
17
|
-
end
|
18
|
-
|
19
|
-
def models
|
20
|
-
@models ||= controller_name.underscore
|
21
|
-
end
|
22
|
-
|
23
|
-
def model_class_name
|
24
|
-
@model_class_name ||= model.camelize
|
25
|
-
end
|
26
|
-
|
27
|
-
def controller_class_name
|
28
|
-
@controller_class_name ||= models.camelize
|
29
|
-
end
|
30
|
-
end
|