lazy-head-gen 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +2 -1
- data/Gemfile.lock +8 -2
- data/README.md +226 -0
- data/Rakefile +3 -13
- data/VERSION +1 -1
- data/lazy-head-gen.gemspec +13 -10
- data/lib/lazy-head-gen.rb +1 -1
- data/lib/lazy-head-gen/{admin_controller_tests.rb → admin_controller_test.rb} +5 -5
- data/lib/lazy-head-gen/templates/admin_controller_test.rb.tt +13 -13
- data/lib/lazy-head-gen/templates/blueprints.rb.tt +1 -1
- data/test/lazy-head-gen/{test_admin_controller_tests.rb → test_admin_controller_test.rb} +4 -4
- data/test/test_lazy-head-gen.rb +1 -1
- metadata +65 -51
- data/README.rdoc +0 -18
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -75,13 +75,18 @@ GEM
|
|
75
75
|
rack (>= 1.0)
|
76
76
|
rake (0.9.2.2)
|
77
77
|
rbx-require-relative (0.0.9)
|
78
|
-
|
78
|
+
rdoc (3.12)
|
79
|
+
json (~> 1.4)
|
79
80
|
ruby-debug (0.10.4)
|
80
81
|
columnize (>= 0.1)
|
81
82
|
ruby-debug-base (~> 0.10.4.0)
|
82
83
|
ruby-debug-base (0.10.4)
|
83
84
|
linecache (>= 0.3)
|
84
85
|
shoulda (2.11.3)
|
86
|
+
simplecov (0.6.2)
|
87
|
+
multi_json (~> 1.3)
|
88
|
+
simplecov-html (~> 0.5.3)
|
89
|
+
simplecov-html (0.5.3)
|
85
90
|
sinatra (1.3.2)
|
86
91
|
rack (~> 1.3, >= 1.3.6)
|
87
92
|
rack-protection (~> 1.2)
|
@@ -129,9 +134,10 @@ DEPENDENCIES
|
|
129
134
|
rack (>= 1.3.0)
|
130
135
|
rack-test (>= 0.5.0)
|
131
136
|
rake (>= 0.8.7)
|
132
|
-
|
137
|
+
rdoc
|
133
138
|
ruby-debug
|
134
139
|
shoulda
|
140
|
+
simplecov
|
135
141
|
slim (>= 0.9.2)
|
136
142
|
system_timer (>= 1.0)
|
137
143
|
uuid (>= 2.3.1)
|
data/README.md
ADDED
@@ -0,0 +1,226 @@
|
|
1
|
+
lazy-head-gen
|
2
|
+
=============
|
3
|
+
|
4
|
+
Lazy Head Gen is simply a couple of extra generators for the excellent [Padrino](https://github.com/padrino/padrino-framework) framework.
|
5
|
+
|
6
|
+
It is currently tied into assuming that you are using ActiveRecord and MiniTest, as that is what I normally use when developing at Head.
|
7
|
+
|
8
|
+
Installation:
|
9
|
+
-------------
|
10
|
+
|
11
|
+
```
|
12
|
+
gem install lazy-head-gen
|
13
|
+
```
|
14
|
+
|
15
|
+
In a Gemfile:
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
gem 'lazy-head-gen'
|
19
|
+
```
|
20
|
+
|
21
|
+
Padrino gotcha: You'll need to put the `gem 'lazy-head-gen'` requirement *after* `gem 'padrino'` in your Gemfile.
|
22
|
+
Lazy Head Gen needs Padrino loaded before it can show up in a Gemfile.
|
23
|
+
|
24
|
+
Usage
|
25
|
+
-----
|
26
|
+
|
27
|
+
There are currently 2 extra generators, scaffold and admin_controller_tests.
|
28
|
+
|
29
|
+
Scaffold
|
30
|
+
========
|
31
|
+
|
32
|
+
To generate a new scaffold:
|
33
|
+
|
34
|
+
```
|
35
|
+
padrino g scaffold ModelName property:type
|
36
|
+
```
|
37
|
+
|
38
|
+
For example to generate a scaffold for Products:
|
39
|
+
|
40
|
+
```
|
41
|
+
padrino g scaffold Product title:string summary:text quantity:integer available_from:datetime display:boolean
|
42
|
+
```
|
43
|
+
|
44
|
+
This will generate the following:
|
45
|
+
|
46
|
+
* A controller, helper and controller test for Products
|
47
|
+
* An index and show view for Products
|
48
|
+
* A model, model test and database migration for Product
|
49
|
+
* A blueprints file if one doesn't exist
|
50
|
+
|
51
|
+
It will also add:
|
52
|
+
|
53
|
+
* A reference to blueprints.rb to test_config.rb if required
|
54
|
+
* Add a Product blueprint and it's properties to the blueprints.rb file
|
55
|
+
|
56
|
+
|
57
|
+
Admin Controller Tests
|
58
|
+
======================
|
59
|
+
|
60
|
+
To generate a new admin controller test:
|
61
|
+
|
62
|
+
```
|
63
|
+
padrino g admin_controller_tests ControllerName
|
64
|
+
```
|
65
|
+
|
66
|
+
Controller name should be the name of an existing admin controller.
|
67
|
+
|
68
|
+
For example to generate an admin controller test for products:
|
69
|
+
|
70
|
+
```
|
71
|
+
padrino g admin_controller_tests products
|
72
|
+
```
|
73
|
+
|
74
|
+
This will generate a fully tested admin controller test for the 7 CRUD routes.
|
75
|
+
|
76
|
+
Other requirements
|
77
|
+
------------------
|
78
|
+
|
79
|
+
test_config.rb
|
80
|
+
==============
|
81
|
+
|
82
|
+
You will need to add the following code to your test_config.rb for the generated tests to work correctly.
|
83
|
+
|
84
|
+
```
|
85
|
+
# Allows testing as a logged in admin user
|
86
|
+
#
|
87
|
+
def login_as_admin(account)
|
88
|
+
post "/admin/sessions/create", {
|
89
|
+
:email => account.email, :password => "password"
|
90
|
+
}
|
91
|
+
follow_redirect!
|
92
|
+
end
|
93
|
+
|
94
|
+
# Standard assertions to test when a user is not logged in
|
95
|
+
# and trys to view an admin page
|
96
|
+
#
|
97
|
+
def assert_not_logged_in
|
98
|
+
assert !ok?
|
99
|
+
assert_equal 302, status
|
100
|
+
assert_equal "http://example.org/admin/sessions/new", location
|
101
|
+
end
|
102
|
+
|
103
|
+
# Assertions to test when a user is not logged in
|
104
|
+
# and trys to call a destroy action
|
105
|
+
#
|
106
|
+
def assert_destroy_not_logged_in
|
107
|
+
assert !ok?
|
108
|
+
assert_equal 405, status
|
109
|
+
assert_nil location
|
110
|
+
end
|
111
|
+
|
112
|
+
# Standard assertions to test when a user is logged in
|
113
|
+
# and trys to view an admin page using GET
|
114
|
+
#
|
115
|
+
def assert_logged_in
|
116
|
+
assert ok?
|
117
|
+
assert_equal 200, status
|
118
|
+
end
|
119
|
+
|
120
|
+
# Returns a key and new value which is set depending
|
121
|
+
# on the old values class.
|
122
|
+
#
|
123
|
+
def get_key_and_value(instance)
|
124
|
+
# Discount PK and Timestamps
|
125
|
+
keys = instance.attributes.keys.delete_if do |k|
|
126
|
+
["id", "created_at", "updated_at"].include?(k) or instance.attributes[k].nil?
|
127
|
+
end
|
128
|
+
|
129
|
+
key = old_value = new_value = nil
|
130
|
+
|
131
|
+
if keys.length > 0
|
132
|
+
# Pick a key at random
|
133
|
+
key = keys[rand(keys.length)]
|
134
|
+
old_value = instance.attributes[key]
|
135
|
+
|
136
|
+
case old_value.class.name
|
137
|
+
when "Integer"
|
138
|
+
new_value = old_value + 1
|
139
|
+
when "Time"
|
140
|
+
new_value = old_value + 36000
|
141
|
+
when "String"
|
142
|
+
new_value = "This is a modified string"
|
143
|
+
when "TrueClass"
|
144
|
+
new_value = false
|
145
|
+
when "FalseClass"
|
146
|
+
new_value = true
|
147
|
+
else
|
148
|
+
puts old_value.class.name
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
return [key, new_value]
|
153
|
+
end
|
154
|
+
|
155
|
+
# Some shorthands for last_request and last_response varibles
|
156
|
+
#
|
157
|
+
def path
|
158
|
+
last_request.path
|
159
|
+
end
|
160
|
+
|
161
|
+
def session
|
162
|
+
last_request.env['rack.session']
|
163
|
+
end
|
164
|
+
|
165
|
+
def body
|
166
|
+
last_response.body
|
167
|
+
end
|
168
|
+
|
169
|
+
def status
|
170
|
+
last_response.status
|
171
|
+
end
|
172
|
+
|
173
|
+
def location
|
174
|
+
last_response.original_headers["Location"]
|
175
|
+
end
|
176
|
+
|
177
|
+
def ok?
|
178
|
+
last_response.ok?
|
179
|
+
end
|
180
|
+
```
|
181
|
+
|
182
|
+
blueprints.rb
|
183
|
+
=============
|
184
|
+
|
185
|
+
If you already have a blueprints.rb file in your current Padrino project then you will need to add the following for some of the tests to work:
|
186
|
+
|
187
|
+
```
|
188
|
+
module Factory
|
189
|
+
class << self
|
190
|
+
|
191
|
+
def make_admin
|
192
|
+
account = Account.make(:admin)
|
193
|
+
account.save!
|
194
|
+
account
|
195
|
+
end
|
196
|
+
|
197
|
+
end
|
198
|
+
end
|
199
|
+
```
|
200
|
+
|
201
|
+
Also the scaffold generator looks for *# END blueprints* as a marker to insert the generated models blueprint. This is a bit... well crap... but I currently haven't thought of another way to do it.
|
202
|
+
|
203
|
+
To Do List
|
204
|
+
----------
|
205
|
+
|
206
|
+
* Finish writing up the Read Me
|
207
|
+
* Get generators to check the test_config.rb to make sure that the test helpers have been added
|
208
|
+
* Tighten up some of the other requirements, certainly the blueprint inserts
|
209
|
+
|
210
|
+
|
211
|
+
Contributing to lazy-head-gen
|
212
|
+
-----------------------------
|
213
|
+
|
214
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
215
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
216
|
+
* Fork the project
|
217
|
+
* Start a feature/bugfix branch
|
218
|
+
* Commit and push until you are happy with your contribution
|
219
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
220
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
221
|
+
|
222
|
+
Copyright
|
223
|
+
---------
|
224
|
+
|
225
|
+
Copyright (c) 2012 Stuart Chinery, http://www.headlondon.com
|
226
|
+
See LICENSE.txt for further details.
|
data/Rakefile
CHANGED
@@ -18,7 +18,7 @@ Jeweler::Tasks.new do |gem|
|
|
18
18
|
gem.homepage = "http://github.com/sleepingstu/lazy-head-gen"
|
19
19
|
gem.license = "MIT"
|
20
20
|
gem.summary = %Q{Some extra generators for the glorious Padrino, using ActiveRecord and MiniTest.}
|
21
|
-
gem.description = %Q{
|
21
|
+
gem.description = %Q{Lazy Head Gen is simply a couple of extra generators for the excellent Padrino framework.}
|
22
22
|
gem.email = "stuart.chinery@headlondon.com"
|
23
23
|
gem.authors = ["Stuart Chinery"]
|
24
24
|
# dependencies defined in Gemfile
|
@@ -32,22 +32,12 @@ Rake::TestTask.new(:test) do |test|
|
|
32
32
|
test.verbose = true
|
33
33
|
end
|
34
34
|
|
35
|
-
require '
|
36
|
-
Rcov::RcovTask.new do |test|
|
37
|
-
test.libs << 'test'
|
38
|
-
test.pattern = 'test/**/test_*.rb'
|
39
|
-
test.verbose = true
|
40
|
-
test.rcov_opts << '--exclude "gems/*"'
|
41
|
-
end
|
42
|
-
|
43
|
-
task :default => :test
|
44
|
-
|
45
|
-
require 'rake/rdoctask'
|
35
|
+
require 'rdoc/task'
|
46
36
|
Rake::RDocTask.new do |rdoc|
|
47
37
|
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
48
38
|
|
49
39
|
rdoc.rdoc_dir = 'rdoc'
|
50
|
-
rdoc.title = "
|
40
|
+
rdoc.title = "diffrent #{version}"
|
51
41
|
rdoc.rdoc_files.include('README*')
|
52
42
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
53
43
|
end
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.1
|
data/lazy-head-gen.gemspec
CHANGED
@@ -5,28 +5,28 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "lazy-head-gen"
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Stuart Chinery"]
|
12
|
-
s.date = "2012-
|
13
|
-
s.description = "
|
12
|
+
s.date = "2012-05-02"
|
13
|
+
s.description = "Lazy Head Gen is simply a couple of extra generators for the excellent Padrino framework."
|
14
14
|
s.email = "stuart.chinery@headlondon.com"
|
15
15
|
s.extra_rdoc_files = [
|
16
16
|
"LICENSE.txt",
|
17
|
-
"README.
|
17
|
+
"README.md"
|
18
18
|
]
|
19
19
|
s.files = [
|
20
20
|
".document",
|
21
21
|
"Gemfile",
|
22
22
|
"Gemfile.lock",
|
23
23
|
"LICENSE.txt",
|
24
|
-
"README.
|
24
|
+
"README.md",
|
25
25
|
"Rakefile",
|
26
26
|
"VERSION",
|
27
27
|
"lazy-head-gen.gemspec",
|
28
28
|
"lib/lazy-head-gen.rb",
|
29
|
-
"lib/lazy-head-gen/
|
29
|
+
"lib/lazy-head-gen/admin_controller_test.rb",
|
30
30
|
"lib/lazy-head-gen/scaffold.rb",
|
31
31
|
"lib/lazy-head-gen/templates/admin_controller_test.rb.tt",
|
32
32
|
"lib/lazy-head-gen/templates/blueprints.rb.tt",
|
@@ -37,7 +37,7 @@ Gem::Specification.new do |s|
|
|
37
37
|
"lib/lazy-head-gen/templates/model_test.rb.tt",
|
38
38
|
"lib/lazy-head-gen/templates/view.erb.tt",
|
39
39
|
"test/helper.rb",
|
40
|
-
"test/lazy-head-gen/
|
40
|
+
"test/lazy-head-gen/test_admin_controller_test.rb",
|
41
41
|
"test/lazy-head-gen/test_scaffold.rb",
|
42
42
|
"test/load_paths.rb",
|
43
43
|
"test/test_lazy-head-gen.rb"
|
@@ -56,7 +56,8 @@ Gem::Specification.new do |s|
|
|
56
56
|
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
57
57
|
s.add_development_dependency(%q<bundler>, ["~> 1.1.3"])
|
58
58
|
s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
|
59
|
-
s.add_development_dependency(%q<
|
59
|
+
s.add_development_dependency(%q<simplecov>, [">= 0"])
|
60
|
+
s.add_development_dependency(%q<rdoc>, [">= 0"])
|
60
61
|
s.add_development_dependency(%q<json>, [">= 1.5.3"])
|
61
62
|
s.add_development_dependency(%q<nokogiri>, [">= 1.4.4"])
|
62
63
|
s.add_development_dependency(%q<grit>, [">= 2.4.1"])
|
@@ -83,7 +84,8 @@ Gem::Specification.new do |s|
|
|
83
84
|
s.add_dependency(%q<shoulda>, [">= 0"])
|
84
85
|
s.add_dependency(%q<bundler>, ["~> 1.1.3"])
|
85
86
|
s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
|
86
|
-
s.add_dependency(%q<
|
87
|
+
s.add_dependency(%q<simplecov>, [">= 0"])
|
88
|
+
s.add_dependency(%q<rdoc>, [">= 0"])
|
87
89
|
s.add_dependency(%q<json>, [">= 1.5.3"])
|
88
90
|
s.add_dependency(%q<nokogiri>, [">= 1.4.4"])
|
89
91
|
s.add_dependency(%q<grit>, [">= 2.4.1"])
|
@@ -111,7 +113,8 @@ Gem::Specification.new do |s|
|
|
111
113
|
s.add_dependency(%q<shoulda>, [">= 0"])
|
112
114
|
s.add_dependency(%q<bundler>, ["~> 1.1.3"])
|
113
115
|
s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
|
114
|
-
s.add_dependency(%q<
|
116
|
+
s.add_dependency(%q<simplecov>, [">= 0"])
|
117
|
+
s.add_dependency(%q<rdoc>, [">= 0"])
|
115
118
|
s.add_dependency(%q<json>, [">= 1.5.3"])
|
116
119
|
s.add_dependency(%q<nokogiri>, [">= 1.4.4"])
|
117
120
|
s.add_dependency(%q<grit>, [">= 2.4.1"])
|
data/lib/lazy-head-gen.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
begin
|
2
2
|
require 'padrino-gen'
|
3
|
-
Padrino::Generators.load_paths << Dir[File.dirname(__FILE__) + '/lazy-head-gen/{
|
3
|
+
Padrino::Generators.load_paths << Dir[File.dirname(__FILE__) + '/lazy-head-gen/{admin_controller_test,scaffold}.rb']
|
4
4
|
rescue LoadError
|
5
5
|
# Fail silently
|
6
6
|
end
|
@@ -1,14 +1,14 @@
|
|
1
1
|
module Padrino
|
2
2
|
module Generators
|
3
3
|
|
4
|
-
class
|
4
|
+
class AdminControllerTest < Thor::Group
|
5
5
|
# register with Padrino
|
6
|
-
Padrino::Generators.add_generator(:
|
6
|
+
Padrino::Generators.add_generator(:admin_controller_test, self)
|
7
7
|
|
8
8
|
# Define the source template root
|
9
9
|
def self.source_root; File.expand_path(File.dirname(__FILE__)); end
|
10
10
|
# Defines the banner for this CLI generator
|
11
|
-
def self.banner; "padrino-gen
|
11
|
+
def self.banner; "padrino-gen admin_controller_test [name]"; end
|
12
12
|
|
13
13
|
# Include related modules
|
14
14
|
include Thor::Actions
|
@@ -17,7 +17,7 @@ module Padrino
|
|
17
17
|
include Padrino::Generators::Runner
|
18
18
|
include Padrino::Generators::Components::Actions
|
19
19
|
|
20
|
-
desc "Description:\n\n\tlazy-head-gen
|
20
|
+
desc "Description:\n\n\tlazy-head-gen admin_controller_test generates basic tests for an admin controller"
|
21
21
|
|
22
22
|
argument :name, :desc => "The name of your admin controller"
|
23
23
|
|
@@ -25,7 +25,7 @@ module Padrino
|
|
25
25
|
|
26
26
|
require_arguments!
|
27
27
|
|
28
|
-
def
|
28
|
+
def create_admin_controller_test
|
29
29
|
self.destination_root = options[:root]
|
30
30
|
|
31
31
|
if in_app_root?
|
@@ -32,7 +32,7 @@ describe "Admin::<%= @controller if @controller %>Controller" do
|
|
32
32
|
# START POST create
|
33
33
|
describe "Post create" do
|
34
34
|
before do
|
35
|
-
post "/admin/<%= @pluralized %>/create", :<%= @singular %> => <%= @model %>.
|
35
|
+
post "/admin/<%= @pluralized %>/create", :<%= @singular %> => <%= @model %>.make.attributes
|
36
36
|
end
|
37
37
|
|
38
38
|
it "should not return the created text" do
|
@@ -44,7 +44,7 @@ describe "Admin::<%= @controller if @controller %>Controller" do
|
|
44
44
|
# START GET edit
|
45
45
|
describe "GET edit" do
|
46
46
|
before do
|
47
|
-
@<%= @singular %> = <%= @model %>.make
|
47
|
+
@<%= @singular %> = <%= @model %>.make!
|
48
48
|
get "/admin/<%= @pluralized %>/edit/#{@<%= @singular %>.to_param}"
|
49
49
|
end
|
50
50
|
|
@@ -57,8 +57,8 @@ describe "Admin::<%= @controller if @controller %>Controller" do
|
|
57
57
|
# START PUT update
|
58
58
|
describe "PUT update" do
|
59
59
|
before do
|
60
|
-
@<%= @singular %> = <%= @model %>.make
|
61
|
-
put "/admin/<%= @pluralized %>/update/#{@<%= @singular %>.to_param}", :<%= @singular %> => <%= @model %>.
|
60
|
+
@<%= @singular %> = <%= @model %>.make!
|
61
|
+
put "/admin/<%= @pluralized %>/update/#{@<%= @singular %>.to_param}", :<%= @singular %> => <%= @model %>.make.attributes
|
62
62
|
end
|
63
63
|
|
64
64
|
it "should not return the updated text" do
|
@@ -70,7 +70,7 @@ describe "Admin::<%= @controller if @controller %>Controller" do
|
|
70
70
|
# START DELETE destroy
|
71
71
|
describe "on DELETE destroy" do
|
72
72
|
before do
|
73
|
-
@<%= @singular %> = <%= @model %>.make
|
73
|
+
@<%= @singular %> = <%= @model %>.make!
|
74
74
|
get "/admin/<%= @pluralized %>/destroy/#{@<%= @singular %>.to_param}"
|
75
75
|
end
|
76
76
|
|
@@ -87,7 +87,7 @@ describe "Admin::<%= @controller if @controller %>Controller" do
|
|
87
87
|
describe "when logged in" do
|
88
88
|
|
89
89
|
before do
|
90
|
-
@account = Factory.
|
90
|
+
@account = Factory.make!_admin
|
91
91
|
login_as_admin(@account)
|
92
92
|
end
|
93
93
|
|
@@ -121,7 +121,7 @@ describe "Admin::<%= @controller if @controller %>Controller" do
|
|
121
121
|
describe "POST create" do
|
122
122
|
before do
|
123
123
|
@<%= @singular %>_count = <%= @model %>.count
|
124
|
-
post "/admin/<%= @pluralized %>/create", :<%= @singular %> => <%= @model %>.
|
124
|
+
post "/admin/<%= @pluralized %>/create", :<%= @singular %> => <%= @model %>.make.attributes
|
125
125
|
end
|
126
126
|
|
127
127
|
it "should create a <%= @singular %>" do
|
@@ -135,7 +135,7 @@ describe "Admin::<%= @controller if @controller %>Controller" do
|
|
135
135
|
# START GET edit
|
136
136
|
describe "GET edit" do
|
137
137
|
before do
|
138
|
-
@<%= @singular %> = <%= @model %>.make
|
138
|
+
@<%= @singular %> = <%= @model %>.make!
|
139
139
|
get "/admin/<%= @pluralized %>/edit/#{@<%= @singular %>.to_param}"
|
140
140
|
end
|
141
141
|
|
@@ -149,15 +149,15 @@ describe "Admin::<%= @controller if @controller %>Controller" do
|
|
149
149
|
# START PUT update
|
150
150
|
describe "PUT update" do
|
151
151
|
before do
|
152
|
-
@<%= @singular %> = <%= @model %>.make
|
152
|
+
@<%= @singular %> = <%= @model %>.make!
|
153
153
|
@<%= @singular %>_count = <%= @model %>.count
|
154
|
-
@<%= @singular %>_hash =
|
154
|
+
@<%= @singular %>_hash = {}
|
155
155
|
|
156
|
-
key_and_value = get_key_and_value(@
|
156
|
+
key_and_value = get_key_and_value(@singular)
|
157
157
|
if key_and_value[0] and key_and_value[1]
|
158
158
|
@key = key_and_value[0]
|
159
159
|
@value = key_and_value[1]
|
160
|
-
@<%= @singular %>_hash = <%= @model %>.
|
160
|
+
@<%= @singular %>_hash = <%= @model %>.make(@key => @value).attributes
|
161
161
|
end
|
162
162
|
|
163
163
|
put "/admin/<%= @pluralized %>/update/#{@<%= @singular %>.to_param}", :<%= @singular %> => @<%= @singular %>_hash
|
@@ -179,7 +179,7 @@ describe "Admin::<%= @controller if @controller %>Controller" do
|
|
179
179
|
# START DELETE destroy
|
180
180
|
describe "DELETE destroy" do
|
181
181
|
before do
|
182
|
-
@<%= @singular %> = <%= @model %>.make
|
182
|
+
@<%= @singular %> = <%= @model %>.make!
|
183
183
|
@<%= @singular %>_count = <%= @model %>.count
|
184
184
|
delete "/admin/<%= @pluralized %>/destroy/#{@<%= @singular %>.to_param}"
|
185
185
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
|
-
describe "
|
3
|
+
describe "AdminControllerTest generator" do
|
4
4
|
def setup
|
5
5
|
@app_tmp = "#{Dir.tmpdir}/lazy-head-gen-tests/#{UUID.new.generate}"
|
6
6
|
capture_io { FileUtils.mkdir_p(@app_tmp) }
|
@@ -14,7 +14,7 @@ describe "AdminControllerTests generator" do
|
|
14
14
|
|
15
15
|
describe "when generating a new admin controller test" do
|
16
16
|
it "should fail outside of the app root" do
|
17
|
-
out, err = capture_io { generate(:
|
17
|
+
out, err = capture_io { generate(:admin_controller_test, 'demo_items') }
|
18
18
|
assert_match(/not at the root/, out)
|
19
19
|
end
|
20
20
|
|
@@ -24,7 +24,7 @@ describe "AdminControllerTests generator" do
|
|
24
24
|
end
|
25
25
|
|
26
26
|
it "should fail if the admin controller does not exist" do
|
27
|
-
out, err = capture_io { generate(:
|
27
|
+
out, err = capture_io { generate(:admin_controller_test, 'demo_items', "-r=#{@project_dir}") }
|
28
28
|
assert_match(/demo_items.rb does not exist/, out)
|
29
29
|
assert_match(/padrino g admin_page DemoItem/, out)
|
30
30
|
assert_no_file_exists("#{@project_dir}/test/admin/controllers/demo_items_controller_test.rb")
|
@@ -37,7 +37,7 @@ describe "AdminControllerTests generator" do
|
|
37
37
|
FileUtils.mkdir_p("#{@project_dir}/admin/controllers")
|
38
38
|
FileUtils.touch("#{@project_dir}/admin/controllers/demo_items.rb")
|
39
39
|
|
40
|
-
out, err = capture_io { generate(:
|
40
|
+
out, err = capture_io { generate(:admin_controller_test, 'demo_items', "-r=#{@project_dir}") }
|
41
41
|
assert_file_exists("#{@project_dir}/test/admin/controllers/demo_items_controller_test.rb")
|
42
42
|
assert_match(/test\/admin\/controllers\/demo_items_controller_test.rb/, out)
|
43
43
|
assert_match(/Admin controller tests generation for 'demo_items' completed/, out)
|
data/test/test_lazy-head-gen.rb
CHANGED
@@ -4,7 +4,7 @@ describe "LazyHeadGen" do
|
|
4
4
|
|
5
5
|
describe "the generator" do
|
6
6
|
it "should have default generators" do
|
7
|
-
%w{controller mailer migration model app plugin
|
7
|
+
%w{controller mailer migration model app plugin admin_controller_test scaffold}.each do |gen|
|
8
8
|
assert Padrino::Generators.mappings.has_key?(gen.to_sym)
|
9
9
|
assert_equal "Padrino::Generators::#{gen.camelize}", Padrino::Generators.mappings[gen.to_sym].name
|
10
10
|
assert Padrino::Generators.mappings[gen.to_sym].respond_to?(:start)
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lazy-head-gen
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 1
|
10
|
+
version: 0.1.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Stuart Chinery
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-
|
18
|
+
date: 2012-05-02 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
type: :runtime
|
@@ -89,11 +89,25 @@ dependencies:
|
|
89
89
|
- 0
|
90
90
|
version: "0"
|
91
91
|
version_requirements: *id005
|
92
|
-
name:
|
92
|
+
name: simplecov
|
93
93
|
prerelease: false
|
94
94
|
- !ruby/object:Gem::Dependency
|
95
95
|
type: :development
|
96
96
|
requirement: &id006 !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
hash: 3
|
102
|
+
segments:
|
103
|
+
- 0
|
104
|
+
version: "0"
|
105
|
+
version_requirements: *id006
|
106
|
+
name: rdoc
|
107
|
+
prerelease: false
|
108
|
+
- !ruby/object:Gem::Dependency
|
109
|
+
type: :development
|
110
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
97
111
|
none: false
|
98
112
|
requirements:
|
99
113
|
- - ">="
|
@@ -104,12 +118,12 @@ dependencies:
|
|
104
118
|
- 5
|
105
119
|
- 3
|
106
120
|
version: 1.5.3
|
107
|
-
version_requirements: *
|
121
|
+
version_requirements: *id007
|
108
122
|
name: json
|
109
123
|
prerelease: false
|
110
124
|
- !ruby/object:Gem::Dependency
|
111
125
|
type: :development
|
112
|
-
requirement: &
|
126
|
+
requirement: &id008 !ruby/object:Gem::Requirement
|
113
127
|
none: false
|
114
128
|
requirements:
|
115
129
|
- - ">="
|
@@ -120,12 +134,12 @@ dependencies:
|
|
120
134
|
- 4
|
121
135
|
- 4
|
122
136
|
version: 1.4.4
|
123
|
-
version_requirements: *
|
137
|
+
version_requirements: *id008
|
124
138
|
name: nokogiri
|
125
139
|
prerelease: false
|
126
140
|
- !ruby/object:Gem::Dependency
|
127
141
|
type: :development
|
128
|
-
requirement: &
|
142
|
+
requirement: &id009 !ruby/object:Gem::Requirement
|
129
143
|
none: false
|
130
144
|
requirements:
|
131
145
|
- - ">="
|
@@ -136,12 +150,12 @@ dependencies:
|
|
136
150
|
- 4
|
137
151
|
- 1
|
138
152
|
version: 2.4.1
|
139
|
-
version_requirements: *
|
153
|
+
version_requirements: *id009
|
140
154
|
name: grit
|
141
155
|
prerelease: false
|
142
156
|
- !ruby/object:Gem::Dependency
|
143
157
|
type: :development
|
144
|
-
requirement: &
|
158
|
+
requirement: &id010 !ruby/object:Gem::Requirement
|
145
159
|
none: false
|
146
160
|
requirements:
|
147
161
|
- - ">="
|
@@ -152,12 +166,12 @@ dependencies:
|
|
152
166
|
- 3
|
153
167
|
- 0
|
154
168
|
version: 1.3.0
|
155
|
-
version_requirements: *
|
169
|
+
version_requirements: *id010
|
156
170
|
name: rack
|
157
171
|
prerelease: false
|
158
172
|
- !ruby/object:Gem::Dependency
|
159
173
|
type: :development
|
160
|
-
requirement: &
|
174
|
+
requirement: &id011 !ruby/object:Gem::Requirement
|
161
175
|
none: false
|
162
176
|
requirements:
|
163
177
|
- - ">="
|
@@ -168,12 +182,12 @@ dependencies:
|
|
168
182
|
- 8
|
169
183
|
- 7
|
170
184
|
version: 0.8.7
|
171
|
-
version_requirements: *
|
185
|
+
version_requirements: *id011
|
172
186
|
name: rake
|
173
187
|
prerelease: false
|
174
188
|
- !ruby/object:Gem::Dependency
|
175
189
|
type: :development
|
176
|
-
requirement: &
|
190
|
+
requirement: &id012 !ruby/object:Gem::Requirement
|
177
191
|
none: false
|
178
192
|
requirements:
|
179
193
|
- - ">="
|
@@ -184,12 +198,12 @@ dependencies:
|
|
184
198
|
- 7
|
185
199
|
- 2
|
186
200
|
version: 0.7.2
|
187
|
-
version_requirements: *
|
201
|
+
version_requirements: *id012
|
188
202
|
name: yard
|
189
203
|
prerelease: false
|
190
204
|
- !ruby/object:Gem::Dependency
|
191
205
|
type: :development
|
192
|
-
requirement: &
|
206
|
+
requirement: &id013 !ruby/object:Gem::Requirement
|
193
207
|
none: false
|
194
208
|
requirements:
|
195
209
|
- - ">="
|
@@ -200,12 +214,12 @@ dependencies:
|
|
200
214
|
- 5
|
201
215
|
- 0
|
202
216
|
version: 0.5.0
|
203
|
-
version_requirements: *
|
217
|
+
version_requirements: *id013
|
204
218
|
name: rack-test
|
205
219
|
prerelease: false
|
206
220
|
- !ruby/object:Gem::Dependency
|
207
221
|
type: :development
|
208
|
-
requirement: &
|
222
|
+
requirement: &id014 !ruby/object:Gem::Requirement
|
209
223
|
none: false
|
210
224
|
requirements:
|
211
225
|
- - ">="
|
@@ -216,12 +230,12 @@ dependencies:
|
|
216
230
|
- 2
|
217
231
|
- 8
|
218
232
|
version: 1.2.8
|
219
|
-
version_requirements: *
|
233
|
+
version_requirements: *id014
|
220
234
|
name: fakeweb
|
221
235
|
prerelease: false
|
222
236
|
- !ruby/object:Gem::Dependency
|
223
237
|
type: :development
|
224
|
-
requirement: &
|
238
|
+
requirement: &id015 !ruby/object:Gem::Requirement
|
225
239
|
none: false
|
226
240
|
requirements:
|
227
241
|
- - ">="
|
@@ -232,12 +246,12 @@ dependencies:
|
|
232
246
|
- 5
|
233
247
|
- 1
|
234
248
|
version: 0.5.1
|
235
|
-
version_requirements: *
|
249
|
+
version_requirements: *id015
|
236
250
|
name: webrat
|
237
251
|
prerelease: false
|
238
252
|
- !ruby/object:Gem::Dependency
|
239
253
|
type: :development
|
240
|
-
requirement: &
|
254
|
+
requirement: &id016 !ruby/object:Gem::Requirement
|
241
255
|
none: false
|
242
256
|
requirements:
|
243
257
|
- - ">="
|
@@ -248,12 +262,12 @@ dependencies:
|
|
248
262
|
- 2
|
249
263
|
- 22
|
250
264
|
version: 2.2.22
|
251
|
-
version_requirements: *
|
265
|
+
version_requirements: *id016
|
252
266
|
name: haml
|
253
267
|
prerelease: false
|
254
268
|
- !ruby/object:Gem::Dependency
|
255
269
|
type: :development
|
256
|
-
requirement: &
|
270
|
+
requirement: &id017 !ruby/object:Gem::Requirement
|
257
271
|
none: false
|
258
272
|
requirements:
|
259
273
|
- - ">="
|
@@ -264,12 +278,12 @@ dependencies:
|
|
264
278
|
- 7
|
265
279
|
- 0
|
266
280
|
version: 2.7.0
|
267
|
-
version_requirements: *
|
281
|
+
version_requirements: *id017
|
268
282
|
name: erubis
|
269
283
|
prerelease: false
|
270
284
|
- !ruby/object:Gem::Dependency
|
271
285
|
type: :development
|
272
|
-
requirement: &
|
286
|
+
requirement: &id018 !ruby/object:Gem::Requirement
|
273
287
|
none: false
|
274
288
|
requirements:
|
275
289
|
- - ">="
|
@@ -280,12 +294,12 @@ dependencies:
|
|
280
294
|
- 9
|
281
295
|
- 2
|
282
296
|
version: 0.9.2
|
283
|
-
version_requirements: *
|
297
|
+
version_requirements: *id018
|
284
298
|
name: slim
|
285
299
|
prerelease: false
|
286
300
|
- !ruby/object:Gem::Dependency
|
287
301
|
type: :development
|
288
|
-
requirement: &
|
302
|
+
requirement: &id019 !ruby/object:Gem::Requirement
|
289
303
|
none: false
|
290
304
|
requirements:
|
291
305
|
- - ">="
|
@@ -296,12 +310,12 @@ dependencies:
|
|
296
310
|
- 3
|
297
311
|
- 1
|
298
312
|
version: 2.3.1
|
299
|
-
version_requirements: *
|
313
|
+
version_requirements: *id019
|
300
314
|
name: uuid
|
301
315
|
prerelease: false
|
302
316
|
- !ruby/object:Gem::Dependency
|
303
317
|
type: :development
|
304
|
-
requirement: &
|
318
|
+
requirement: &id020 !ruby/object:Gem::Requirement
|
305
319
|
none: false
|
306
320
|
requirements:
|
307
321
|
- - ">="
|
@@ -312,12 +326,12 @@ dependencies:
|
|
312
326
|
- 1
|
313
327
|
- 2
|
314
328
|
version: 2.1.2
|
315
|
-
version_requirements: *
|
329
|
+
version_requirements: *id020
|
316
330
|
name: builder
|
317
331
|
prerelease: false
|
318
332
|
- !ruby/object:Gem::Dependency
|
319
333
|
type: :development
|
320
|
-
requirement: &
|
334
|
+
requirement: &id021 !ruby/object:Gem::Requirement
|
321
335
|
none: false
|
322
336
|
requirements:
|
323
337
|
- - ">="
|
@@ -326,12 +340,12 @@ dependencies:
|
|
326
340
|
segments:
|
327
341
|
- 0
|
328
342
|
version: "0"
|
329
|
-
version_requirements: *
|
343
|
+
version_requirements: *id021
|
330
344
|
name: bcrypt-ruby
|
331
345
|
prerelease: false
|
332
346
|
- !ruby/object:Gem::Dependency
|
333
347
|
type: :development
|
334
|
-
requirement: &
|
348
|
+
requirement: &id022 !ruby/object:Gem::Requirement
|
335
349
|
none: false
|
336
350
|
requirements:
|
337
351
|
- - ">="
|
@@ -341,12 +355,12 @@ dependencies:
|
|
341
355
|
- 1
|
342
356
|
- 0
|
343
357
|
version: "1.0"
|
344
|
-
version_requirements: *
|
358
|
+
version_requirements: *id022
|
345
359
|
name: system_timer
|
346
360
|
prerelease: false
|
347
361
|
- !ruby/object:Gem::Dependency
|
348
362
|
type: :development
|
349
|
-
requirement: &
|
363
|
+
requirement: &id023 !ruby/object:Gem::Requirement
|
350
364
|
none: false
|
351
365
|
requirements:
|
352
366
|
- - ">="
|
@@ -355,12 +369,12 @@ dependencies:
|
|
355
369
|
segments:
|
356
370
|
- 0
|
357
371
|
version: "0"
|
358
|
-
version_requirements: *
|
372
|
+
version_requirements: *id023
|
359
373
|
name: jruby-openssl
|
360
374
|
prerelease: false
|
361
375
|
- !ruby/object:Gem::Dependency
|
362
376
|
type: :development
|
363
|
-
requirement: &
|
377
|
+
requirement: &id024 !ruby/object:Gem::Requirement
|
364
378
|
none: false
|
365
379
|
requirements:
|
366
380
|
- - ~>
|
@@ -371,12 +385,12 @@ dependencies:
|
|
371
385
|
- 10
|
372
386
|
- 0
|
373
387
|
version: 0.10.0
|
374
|
-
version_requirements: *
|
388
|
+
version_requirements: *id024
|
375
389
|
name: mocha
|
376
390
|
prerelease: false
|
377
391
|
- !ruby/object:Gem::Dependency
|
378
392
|
type: :development
|
379
|
-
requirement: &
|
393
|
+
requirement: &id025 !ruby/object:Gem::Requirement
|
380
394
|
none: false
|
381
395
|
requirements:
|
382
396
|
- - ~>
|
@@ -387,12 +401,12 @@ dependencies:
|
|
387
401
|
- 6
|
388
402
|
- 0
|
389
403
|
version: 2.6.0
|
390
|
-
version_requirements: *
|
404
|
+
version_requirements: *id025
|
391
405
|
name: minitest
|
392
406
|
prerelease: false
|
393
407
|
- !ruby/object:Gem::Dependency
|
394
408
|
type: :development
|
395
|
-
requirement: &
|
409
|
+
requirement: &id026 !ruby/object:Gem::Requirement
|
396
410
|
none: false
|
397
411
|
requirements:
|
398
412
|
- - ">="
|
@@ -401,12 +415,12 @@ dependencies:
|
|
401
415
|
segments:
|
402
416
|
- 0
|
403
417
|
version: "0"
|
404
|
-
version_requirements: *
|
418
|
+
version_requirements: *id026
|
405
419
|
name: lumberjack
|
406
420
|
prerelease: false
|
407
421
|
- !ruby/object:Gem::Dependency
|
408
422
|
type: :development
|
409
|
-
requirement: &
|
423
|
+
requirement: &id027 !ruby/object:Gem::Requirement
|
410
424
|
none: false
|
411
425
|
requirements:
|
412
426
|
- - ">="
|
@@ -415,10 +429,10 @@ dependencies:
|
|
415
429
|
segments:
|
416
430
|
- 0
|
417
431
|
version: "0"
|
418
|
-
version_requirements: *
|
432
|
+
version_requirements: *id027
|
419
433
|
name: ruby-debug
|
420
434
|
prerelease: false
|
421
|
-
description:
|
435
|
+
description: Lazy Head Gen is simply a couple of extra generators for the excellent Padrino framework.
|
422
436
|
email: stuart.chinery@headlondon.com
|
423
437
|
executables: []
|
424
438
|
|
@@ -426,18 +440,18 @@ extensions: []
|
|
426
440
|
|
427
441
|
extra_rdoc_files:
|
428
442
|
- LICENSE.txt
|
429
|
-
- README.
|
443
|
+
- README.md
|
430
444
|
files:
|
431
445
|
- .document
|
432
446
|
- Gemfile
|
433
447
|
- Gemfile.lock
|
434
448
|
- LICENSE.txt
|
435
|
-
- README.
|
449
|
+
- README.md
|
436
450
|
- Rakefile
|
437
451
|
- VERSION
|
438
452
|
- lazy-head-gen.gemspec
|
439
453
|
- lib/lazy-head-gen.rb
|
440
|
-
- lib/lazy-head-gen/
|
454
|
+
- lib/lazy-head-gen/admin_controller_test.rb
|
441
455
|
- lib/lazy-head-gen/scaffold.rb
|
442
456
|
- lib/lazy-head-gen/templates/admin_controller_test.rb.tt
|
443
457
|
- lib/lazy-head-gen/templates/blueprints.rb.tt
|
@@ -448,7 +462,7 @@ files:
|
|
448
462
|
- lib/lazy-head-gen/templates/model_test.rb.tt
|
449
463
|
- lib/lazy-head-gen/templates/view.erb.tt
|
450
464
|
- test/helper.rb
|
451
|
-
- test/lazy-head-gen/
|
465
|
+
- test/lazy-head-gen/test_admin_controller_test.rb
|
452
466
|
- test/lazy-head-gen/test_scaffold.rb
|
453
467
|
- test/load_paths.rb
|
454
468
|
- test/test_lazy-head-gen.rb
|
data/README.rdoc
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
= lazy-head-gen
|
2
|
-
|
3
|
-
Description goes here.
|
4
|
-
|
5
|
-
== Contributing to lazy-head-gen
|
6
|
-
|
7
|
-
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
8
|
-
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
9
|
-
* Fork the project
|
10
|
-
* Start a feature/bugfix branch
|
11
|
-
* Commit and push until you are happy with your contribution
|
12
|
-
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
13
|
-
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
14
|
-
|
15
|
-
== Copyright
|
16
|
-
|
17
|
-
Copyright (c) 2012 Stuart Chinery. See LICENSE.txt for
|
18
|
-
further details.
|