test_battery 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gem 'rails', '>= 3.0.3'
4
+
5
+ group :development do
6
+ gem 'bundler', '~> 1.0.0'
7
+ gem 'jeweler', '~> 1.5.2'
8
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,78 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ abstract (1.0.0)
5
+ actionmailer (3.0.3)
6
+ actionpack (= 3.0.3)
7
+ mail (~> 2.2.9)
8
+ actionpack (3.0.3)
9
+ activemodel (= 3.0.3)
10
+ activesupport (= 3.0.3)
11
+ builder (~> 2.1.2)
12
+ erubis (~> 2.6.6)
13
+ i18n (~> 0.4)
14
+ rack (~> 1.2.1)
15
+ rack-mount (~> 0.6.13)
16
+ rack-test (~> 0.5.6)
17
+ tzinfo (~> 0.3.23)
18
+ activemodel (3.0.3)
19
+ activesupport (= 3.0.3)
20
+ builder (~> 2.1.2)
21
+ i18n (~> 0.4)
22
+ activerecord (3.0.3)
23
+ activemodel (= 3.0.3)
24
+ activesupport (= 3.0.3)
25
+ arel (~> 2.0.2)
26
+ tzinfo (~> 0.3.23)
27
+ activeresource (3.0.3)
28
+ activemodel (= 3.0.3)
29
+ activesupport (= 3.0.3)
30
+ activesupport (3.0.3)
31
+ arel (2.0.6)
32
+ builder (2.1.2)
33
+ erubis (2.6.6)
34
+ abstract (>= 1.0.0)
35
+ git (1.2.5)
36
+ i18n (0.5.0)
37
+ jeweler (1.5.2)
38
+ bundler (~> 1.0.0)
39
+ git (>= 1.2.5)
40
+ rake
41
+ mail (2.2.14)
42
+ activesupport (>= 2.3.6)
43
+ i18n (>= 0.4.0)
44
+ mime-types (~> 1.16)
45
+ treetop (~> 1.4.8)
46
+ mime-types (1.16)
47
+ polyglot (0.3.1)
48
+ rack (1.2.1)
49
+ rack-mount (0.6.13)
50
+ rack (>= 1.0.0)
51
+ rack-test (0.5.7)
52
+ rack (>= 1.0)
53
+ rails (3.0.3)
54
+ actionmailer (= 3.0.3)
55
+ actionpack (= 3.0.3)
56
+ activerecord (= 3.0.3)
57
+ activeresource (= 3.0.3)
58
+ activesupport (= 3.0.3)
59
+ bundler (~> 1.0)
60
+ railties (= 3.0.3)
61
+ railties (3.0.3)
62
+ actionpack (= 3.0.3)
63
+ activesupport (= 3.0.3)
64
+ rake (>= 0.8.7)
65
+ thor (~> 0.14.4)
66
+ rake (0.8.7)
67
+ thor (0.14.6)
68
+ treetop (1.4.9)
69
+ polyglot (>= 0.3.1)
70
+ tzinfo (0.3.23)
71
+
72
+ PLATFORMS
73
+ ruby
74
+
75
+ DEPENDENCIES
76
+ bundler (~> 1.0.0)
77
+ jeweler (~> 1.5.2)
78
+ rails (>= 3.0.3)
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Oleg Khabarov, The Working Group Inc
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,22 @@
1
+ Test Battery
2
+ ============
3
+
4
+ Collection of generators and help methods
5
+
6
+ Install
7
+ -------
8
+
9
+ In your Gemfile:
10
+
11
+ group :development, :test do
12
+ gem 'test_battery'
13
+ end
14
+
15
+ Generators
16
+ ----------
17
+
18
+ Controller Crud Generator:
19
+
20
+ rails g crud_controller kittens
21
+
22
+
data/Rakefile ADDED
@@ -0,0 +1,37 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'rake'
11
+
12
+ require 'jeweler'
13
+ Jeweler::Tasks.new do |gem|
14
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
15
+ gem.name = "test_battery"
16
+ gem.homepage = "http://github.com/twg/test_battery"
17
+ gem.license = "MIT"
18
+ gem.summary = 'Collection of generators and test helpers'
19
+ gem.description = 'Collection of generators and test helpers'
20
+ gem.email = "oleg@theworkinggroup.ca"
21
+ gem.authors = ["Oleg Khabarov"]
22
+ # Include your dependencies below. Runtime dependencies are required when using your gem,
23
+ # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
24
+ # gem.add_runtime_dependency 'jabber4r', '> 0.1'
25
+ # gem.add_development_dependency 'rspec', '> 1.2.3'
26
+ end
27
+ Jeweler::RubygemsDotOrgTasks.new
28
+
29
+ require 'rake/testtask'
30
+ Rake::TestTask.new(:test) do |test|
31
+ test.libs << 'lib' << 'test'
32
+ test.pattern = 'test/**/test_*.rb'
33
+ test.verbose = true
34
+ end
35
+
36
+ task :default => :test
37
+
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.0
@@ -0,0 +1,30 @@
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
@@ -0,0 +1,59 @@
1
+ class <%=controller_class_name%>Controller < ApplicationController
2
+
3
+ before_filter :build_<%=model%>, :only => [:new, :create]
4
+ before_filter :load_<%=model%>, :only => [:show, :edit, :update, :destroy]
5
+
6
+ def index
7
+ @<%=models%> = <%=model_class_name%>
8
+ end
9
+
10
+ def show
11
+ render
12
+ end
13
+
14
+ def new
15
+ render
16
+ end
17
+
18
+ def edit
19
+ render
20
+ end
21
+
22
+ def create
23
+ @<%=model%>.save!
24
+ flash[:notice] = '<%model_class_name%> created'
25
+ redirect_to :action => :show, :id => @<%=model%>
26
+ rescue ActiveRecord::RecordInvalid
27
+ flash.now[:error] = 'Failed to create <%=model_class_name%>'
28
+ render :action => :new
29
+ end
30
+
31
+ def update
32
+ @<%=model%>.update_attributes!(params[:<%=model%>])
33
+ flash[:notice] = '<%=model_class_name%> updated'
34
+ redirect_to :action => :show, :id => @<%=model%>
35
+ rescue ActiveRecord::RecordInvalid
36
+ flash.now[:error] = 'Failed to update <%=model_class_name%>'
37
+ render :action => :edit
38
+ end
39
+
40
+ def destroy
41
+ @<%=model%>.destroy
42
+ flash[:notice] = '<%model_class_name%> deleted'
43
+ redirect_to :action => :index
44
+ end
45
+
46
+ protected
47
+
48
+ def build_<%=model%>
49
+ @<%=model%> = <%=model_class_name%>.new(params[:<%=model%>])
50
+ end
51
+
52
+ def load_<%=model%>
53
+ @<%=model%> = <%model_class_name%>.find(params[:<%=model%>])
54
+ rescue ActiveRecord::RecordNotFound
55
+ flash[:error] = '<%=model_class_name%> not found'
56
+ redirect_to :action => :index
57
+ end
58
+
59
+ end
@@ -0,0 +1,101 @@
1
+ require File.expand_path('../test_helper', File.dirname(__FILE__))
2
+
3
+ class <%=controller_class_name%>Test < ActionController::TestCase
4
+
5
+ def test_get_index
6
+ get :index
7
+ assert assigns(:<%=models%>)
8
+ assert_response :success
9
+ assert_template :index
10
+ end
11
+
12
+ def test_get_show
13
+ <%=model%> = <%=models%>(:default)
14
+ get :show, :id => <%=model%>
15
+ assert assigns(:<%model%>)
16
+ assert_response :success
17
+ assert_template :show
18
+ end
19
+
20
+ def test_get_show_failure
21
+ get :show, :id => 'invalid'
22
+ assert_reponse :redirect
23
+ assert_redirected_to :action => :index
24
+ assert_equal '<%=model_class_name%> not found', flash[:error]
25
+ end
26
+
27
+ def test_get_new
28
+ get :new
29
+ assert assigns(:<%=model%>)
30
+ assert_response :success
31
+ assert_template :new
32
+ assert_select 'form[action=/<%=models%>]'
33
+ end
34
+
35
+ def test_get_edit
36
+ <%=model%> = <%=models%>(:default)
37
+ get :edit, :id => <%=model%>
38
+ assert assigns(:<%=model%>)
39
+ assert_response :success
40
+ assert_template :edit
41
+ assert_select "form[action=/<%=models%>/#{<%=model%>.id}]"
42
+ end
43
+
44
+ def test_creation
45
+ assert_difference '<%=model_class_name%>.count' do
46
+ post :create, :<%=model%> => {
47
+
48
+ }
49
+ <%=model%> = <%=model_class_name%>.last
50
+ assert_response :redirect
51
+ assert_redirected_to :action => :show, :id => <%=model%>
52
+ assert_equal '<%=model_class_name%> created', flash[:notice]
53
+ end
54
+ end
55
+
56
+ def test_creation_failure
57
+ assert_no_difference '<%=model_class_name%>.count' do
58
+ post :create, :<%=model%> => {
59
+ :something => '???'
60
+ }
61
+ assert_response :success
62
+ assert_template :new
63
+ assert_equal 'Failed to create <%=model_class_name%>'
64
+ end
65
+ end
66
+
67
+ def test_update
68
+ <%=model%> = <%=models%>(:default)
69
+ put :update, :id => <%=model%>, :<%=model%> => {
70
+ :_attribute_ => '???'
71
+ }
72
+ assert_response :redirect
73
+ assert_redirected_to :action => :show, :id => <%=model%>
74
+ assert_equal '<%=model_class_name%> updated', flash[:notice]
75
+ <%=model%>.reload
76
+ assert_equal '???', <%=model%>._attribute_
77
+ end
78
+
79
+ def test_update_failure
80
+ <%=model%> = <%=models%>(:default)
81
+ put :update, :id => <%=model%>, :<%=model%> => {
82
+ :_attribute_ => '???'
83
+ }
84
+ assert_response :success
85
+ assert_template :edit
86
+ assert_equal 'Failed to update <%=model_class_name%>', flash[:error]
87
+ <%=model%>.reload
88
+ assert_not_equal '???', <%=model%>._attribute_
89
+ end
90
+
91
+ def test_destroy
92
+ <%=model%> = <%=models%>(:default)
93
+ assert_difference '<%=model_class_name%>.count', -1 do
94
+ delete :destroy, :id => <%=model%>
95
+ assert_response :redirect
96
+ assert_redirected_to :action => :index
97
+ assert_equal '<%model_class_name%> deleted', :flash[:notice]
98
+ end
99
+ end
100
+
101
+ end
File without changes
data/test/helper.rb ADDED
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+ require 'shoulda'
12
+
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
15
+ require 'test_battery'
16
+
17
+ class Test::Unit::TestCase
18
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestTestBattery < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
@@ -0,0 +1,64 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{test_battery}
8
+ s.version = "0.0.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Oleg Khabarov"]
12
+ s.date = %q{2011-02-02}
13
+ s.description = %q{Collection of generators and test helpers}
14
+ s.email = %q{oleg@theworkinggroup.ca}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.md"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ "Gemfile",
22
+ "Gemfile.lock",
23
+ "LICENSE.txt",
24
+ "README.md",
25
+ "Rakefile",
26
+ "VERSION",
27
+ "lib/generators/crud_controller_generator.rb",
28
+ "lib/generators/templates/crud_controller.rb",
29
+ "lib/generators/templates/crud_controller_test.rb",
30
+ "lib/test_battery.rb",
31
+ "test/helper.rb",
32
+ "test/test_test_battery.rb",
33
+ "test_battery.gemspec"
34
+ ]
35
+ s.homepage = %q{http://github.com/twg/test_battery}
36
+ s.licenses = ["MIT"]
37
+ s.require_paths = ["lib"]
38
+ s.rubygems_version = %q{1.3.7}
39
+ s.summary = %q{Collection of generators and test helpers}
40
+ s.test_files = [
41
+ "test/helper.rb",
42
+ "test/test_test_battery.rb"
43
+ ]
44
+
45
+ if s.respond_to? :specification_version then
46
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
47
+ s.specification_version = 3
48
+
49
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
50
+ s.add_runtime_dependency(%q<rails>, [">= 3.0.3"])
51
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
52
+ s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
53
+ else
54
+ s.add_dependency(%q<rails>, [">= 3.0.3"])
55
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
56
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
57
+ end
58
+ else
59
+ s.add_dependency(%q<rails>, [">= 3.0.3"])
60
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
61
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
62
+ end
63
+ end
64
+
metadata ADDED
@@ -0,0 +1,124 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: test_battery
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 0
9
+ version: 0.0.0
10
+ platform: ruby
11
+ authors:
12
+ - Oleg Khabarov
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2011-02-02 00:00:00 -05:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rails
22
+ requirement: &id001 !ruby/object:Gem::Requirement
23
+ none: false
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 3
29
+ - 0
30
+ - 3
31
+ version: 3.0.3
32
+ type: :runtime
33
+ prerelease: false
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: bundler
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ~>
41
+ - !ruby/object:Gem::Version
42
+ segments:
43
+ - 1
44
+ - 0
45
+ - 0
46
+ version: 1.0.0
47
+ type: :development
48
+ prerelease: false
49
+ version_requirements: *id002
50
+ - !ruby/object:Gem::Dependency
51
+ name: jeweler
52
+ requirement: &id003 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ~>
56
+ - !ruby/object:Gem::Version
57
+ segments:
58
+ - 1
59
+ - 5
60
+ - 2
61
+ version: 1.5.2
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: *id003
65
+ description: Collection of generators and test helpers
66
+ email: oleg@theworkinggroup.ca
67
+ executables: []
68
+
69
+ extensions: []
70
+
71
+ extra_rdoc_files:
72
+ - LICENSE.txt
73
+ - README.md
74
+ files:
75
+ - .document
76
+ - Gemfile
77
+ - Gemfile.lock
78
+ - LICENSE.txt
79
+ - README.md
80
+ - Rakefile
81
+ - VERSION
82
+ - lib/generators/crud_controller_generator.rb
83
+ - lib/generators/templates/crud_controller.rb
84
+ - lib/generators/templates/crud_controller_test.rb
85
+ - lib/test_battery.rb
86
+ - test/helper.rb
87
+ - test/test_test_battery.rb
88
+ - test_battery.gemspec
89
+ has_rdoc: true
90
+ homepage: http://github.com/twg/test_battery
91
+ licenses:
92
+ - MIT
93
+ post_install_message:
94
+ rdoc_options: []
95
+
96
+ require_paths:
97
+ - lib
98
+ required_ruby_version: !ruby/object:Gem::Requirement
99
+ none: false
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ hash: 2931395641961920697
104
+ segments:
105
+ - 0
106
+ version: "0"
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
+ none: false
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ segments:
113
+ - 0
114
+ version: "0"
115
+ requirements: []
116
+
117
+ rubyforge_project:
118
+ rubygems_version: 1.3.7
119
+ signing_key:
120
+ specification_version: 3
121
+ summary: Collection of generators and test helpers
122
+ test_files:
123
+ - test/helper.rb
124
+ - test/test_test_battery.rb