jzajpt-blueberry_scaffold 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +3 -0
- data/LICENSE +20 -0
- data/Manifest +26 -0
- data/README +27 -0
- data/Rakefile +39 -0
- data/VERSION +1 -0
- data/generators/blueberry_scaffold/USAGE +2 -0
- data/generators/blueberry_scaffold/blueberry_scaffold_generator.rb +183 -0
- data/generators/blueberry_scaffold/templates/controller.rb +63 -0
- data/generators/blueberry_scaffold/templates/controller_test.rb +171 -0
- data/generators/blueberry_scaffold/templates/factory.rb +5 -0
- data/generators/blueberry_scaffold/templates/helper.rb +14 -0
- data/generators/blueberry_scaffold/templates/migration.rb +16 -0
- data/generators/blueberry_scaffold/templates/model.rb +6 -0
- data/generators/blueberry_scaffold/templates/model_test.rb +15 -0
- data/generators/blueberry_scaffold/templates/views/_form.html.erb +7 -0
- data/generators/blueberry_scaffold/templates/views/edit.html.erb +9 -0
- data/generators/blueberry_scaffold/templates/views/index.html.erb +31 -0
- data/generators/blueberry_scaffold/templates/views/new.html.erb +4 -0
- data/generators/blueberry_scaffold/templates/views/show.html.erb +15 -0
- data/init.rb +1 -0
- data/install.rb +1 -0
- data/lib/blueberry_scaffold.rb +1 -0
- data/tasks/blueberry_scaffold_tasks.rake +4 -0
- data/test/blueberry_scaffold_test.rb +8 -0
- data/test/test_helper.rb +3 -0
- data/uninstall.rb +1 -0
- metadata +81 -0
data/CHANGELOG
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Jiří Zajpt
|
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/Manifest
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
CHANGELOG
|
2
|
+
generators/blueberry_scaffold/blueberry_scaffold_generator.rb
|
3
|
+
generators/blueberry_scaffold/templates/controller.rb
|
4
|
+
generators/blueberry_scaffold/templates/controller_test.rb
|
5
|
+
generators/blueberry_scaffold/templates/factory.rb
|
6
|
+
generators/blueberry_scaffold/templates/helper.rb
|
7
|
+
generators/blueberry_scaffold/templates/migration.rb
|
8
|
+
generators/blueberry_scaffold/templates/model.rb
|
9
|
+
generators/blueberry_scaffold/templates/model_test.rb
|
10
|
+
generators/blueberry_scaffold/templates/views/_form.html.erb
|
11
|
+
generators/blueberry_scaffold/templates/views/edit.html.erb
|
12
|
+
generators/blueberry_scaffold/templates/views/index.html.erb
|
13
|
+
generators/blueberry_scaffold/templates/views/new.html.erb
|
14
|
+
generators/blueberry_scaffold/templates/views/show.html.erb
|
15
|
+
generators/blueberry_scaffold/USAGE
|
16
|
+
init.rb
|
17
|
+
install.rb
|
18
|
+
lib/blueberry_scaffold.rb
|
19
|
+
LICENSE
|
20
|
+
Manifest
|
21
|
+
Rakefile
|
22
|
+
README
|
23
|
+
tasks/blueberry_scaffold_tasks.rake
|
24
|
+
test/blueberry_scaffold_test.rb
|
25
|
+
test/test_helper.rb
|
26
|
+
uninstall.rb
|
data/README
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
Blueberry Scaffold
|
2
|
+
==================
|
3
|
+
|
4
|
+
Scaffold generator used by Blueberry Apps. Features I18n support, Shoulda and Factory Girl tests.
|
5
|
+
|
6
|
+
|
7
|
+
Usage
|
8
|
+
======
|
9
|
+
|
10
|
+
script/generate blueberry_scaffold [namespace]/[name] [controller actions] [model attributes]
|
11
|
+
|
12
|
+
If you specify namespace, it will be used for controller not for model. Model attributes are
|
13
|
+
in format name:type.
|
14
|
+
|
15
|
+
|
16
|
+
Example
|
17
|
+
=======
|
18
|
+
|
19
|
+
script/generate blueberry_scaffold book index show new create title:string author:string
|
20
|
+
|
21
|
+
This creates Book model class and test with title and author attributes. And
|
22
|
+
BooksController class & test with index, show, new and create actions. You can specify
|
23
|
+
any of REST actions (index, show, new, edit, create, update, destroy), if you don't specify any
|
24
|
+
all 7 actions are created by default.
|
25
|
+
|
26
|
+
|
27
|
+
Copyright (c) 2009 Jiří Zajpt, released under the MIT license
|
data/Rakefile
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/testtask'
|
3
|
+
require 'rake/rdoctask'
|
4
|
+
require 'rubygems'
|
5
|
+
|
6
|
+
begin
|
7
|
+
require 'jeweler'
|
8
|
+
Jeweler::Tasks.new do |gemspec|
|
9
|
+
gemspec.name = "blueberry_scaffold"
|
10
|
+
gemspec.summary = "Rails scaffold generator plugin."
|
11
|
+
gemspec.email = "jzajpt@blueberryapps.com"
|
12
|
+
gemspec.homepage = "http://github.com/jzajpt/blueberry_scaffold"
|
13
|
+
gemspec.description = "Scaffold generator featuring i18n, shoulda & factory girl tests."
|
14
|
+
gemspec.authors = ["Jiří Zajpt"]
|
15
|
+
end
|
16
|
+
rescue LoadError
|
17
|
+
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
18
|
+
end
|
19
|
+
|
20
|
+
|
21
|
+
# desc 'Default: run unit tests.'
|
22
|
+
# task :default => :test
|
23
|
+
#
|
24
|
+
# desc 'Test the blueberry_scaffold plugin.'
|
25
|
+
# Rake::TestTask.new(:test) do |t|
|
26
|
+
# t.libs << 'lib'
|
27
|
+
# t.libs << 'test'
|
28
|
+
# t.pattern = 'test/**/*_test.rb'
|
29
|
+
# t.verbose = true
|
30
|
+
# end
|
31
|
+
#
|
32
|
+
# desc 'Generate documentation for the blueberry_scaffold plugin.'
|
33
|
+
# Rake::RDocTask.new(:rdoc) do |rdoc|
|
34
|
+
# rdoc.rdoc_dir = 'rdoc'
|
35
|
+
# rdoc.title = 'BlueberryScaffold'
|
36
|
+
# rdoc.options << '--line-numbers' << '--inline-source'
|
37
|
+
# rdoc.rdoc_files.include('README')
|
38
|
+
# rdoc.rdoc_files.include('lib/**/*.rb')
|
39
|
+
# end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
@@ -0,0 +1,183 @@
|
|
1
|
+
class BlueberryScaffoldGenerator < Rails::Generator::Base
|
2
|
+
attr_accessor :attributes
|
3
|
+
|
4
|
+
def initialize(runtime_args, runtime_options = {})
|
5
|
+
super
|
6
|
+
|
7
|
+
# First argument is our controller/model name
|
8
|
+
@name = runtime_args.shift
|
9
|
+
@namespace, @name = @name.split('/') if @name.include?('/')
|
10
|
+
|
11
|
+
# Model attributes
|
12
|
+
@attributes = []
|
13
|
+
# Controller actions
|
14
|
+
@actions = []
|
15
|
+
@args.each do |arg|
|
16
|
+
if arg.include? ':'
|
17
|
+
@attributes << Rails::Generator::GeneratedAttribute.new(*arg.split(":"))
|
18
|
+
else
|
19
|
+
@actions << arg
|
20
|
+
end
|
21
|
+
end
|
22
|
+
# Remove duplicate actions
|
23
|
+
@actions.uniq!
|
24
|
+
@actions = all_actions if @actions.empty?
|
25
|
+
|
26
|
+
puts "args = #{@args.inspect}"
|
27
|
+
puts "options = #{runtime_options.inspect}"
|
28
|
+
puts "------------------------"
|
29
|
+
puts "@name = #@name"
|
30
|
+
puts "@namespace = #@namespace"
|
31
|
+
puts "@action = #{@actions.inspect}"
|
32
|
+
puts "@attributes = #{@attributes.inspect}}"
|
33
|
+
end
|
34
|
+
|
35
|
+
def manifest
|
36
|
+
record do |m|
|
37
|
+
unless options[:skip_model]
|
38
|
+
# Create model
|
39
|
+
m.directory 'app/models'
|
40
|
+
m.template 'model.rb', "app/models/#{singular_name}.rb"
|
41
|
+
|
42
|
+
# Migration
|
43
|
+
unless options[:skip_migration]
|
44
|
+
m.migration_template 'migration.rb', 'db/migrate', :migration_file_name => "create_#{plural_name}"
|
45
|
+
end
|
46
|
+
|
47
|
+
# Factory
|
48
|
+
m.directory "test/factories"
|
49
|
+
m.template "factory.rb", "test/factories/#{singular_name}_factory.rb"
|
50
|
+
|
51
|
+
# Model test
|
52
|
+
m.directory "test/unit"
|
53
|
+
m.template "model_test.rb", "test/unit/#{singular_name}_test.rb"
|
54
|
+
end
|
55
|
+
|
56
|
+
unless options[:skip_controller]
|
57
|
+
# Create controller
|
58
|
+
m.directory controller_path
|
59
|
+
m.template 'controller.rb', "#{controller_path}/#{plural_name}_controller.rb"
|
60
|
+
|
61
|
+
# Create helper
|
62
|
+
m.directory helper_path
|
63
|
+
m.template "helper.rb", "#{helper_path}/#{plural_name}_helper.rb"
|
64
|
+
|
65
|
+
# Create views
|
66
|
+
m.directory "#{view_path}/#{plural_name}"
|
67
|
+
m.template "views/_form.html.erb", "#{view_path}/#{plural_name}/_form.html.erb"
|
68
|
+
@actions.each do |action|
|
69
|
+
template = "views/#{action}.html.erb"
|
70
|
+
next unless File.exists? source_path(template)
|
71
|
+
m.template template, "#{view_path}/#{plural_name}/#{action}.html.erb"
|
72
|
+
end
|
73
|
+
|
74
|
+
# Add resources route
|
75
|
+
m.route_resources plural_name
|
76
|
+
|
77
|
+
# Controller tst
|
78
|
+
m.directory controller_test_path
|
79
|
+
m.template "controller_test.rb", "#{controller_test_path}/#{plural_name}_controller_test.rb"
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
protected
|
86
|
+
|
87
|
+
def all_actions
|
88
|
+
%w(index show new edit create update destroy)
|
89
|
+
end
|
90
|
+
|
91
|
+
def action?(name)
|
92
|
+
@actions.include? name.to_s
|
93
|
+
end
|
94
|
+
|
95
|
+
def singular_name
|
96
|
+
@name.singularize.underscore
|
97
|
+
end
|
98
|
+
|
99
|
+
def class_name
|
100
|
+
@name.singularize.camelize
|
101
|
+
end
|
102
|
+
|
103
|
+
def plural_name
|
104
|
+
@name.underscore.pluralize
|
105
|
+
end
|
106
|
+
|
107
|
+
def plural_class_name
|
108
|
+
plural_name.camelize
|
109
|
+
end
|
110
|
+
|
111
|
+
def controller_class_name
|
112
|
+
@namespace ? "#{@namespace.camelize}::#{plural_name.camelize}Controller" :
|
113
|
+
"#{plural_name.camelize}Controller"
|
114
|
+
end
|
115
|
+
|
116
|
+
def helper_class_name
|
117
|
+
@namespace ? "#{@namespace.camelize}::#{plural_name.camelize}Helper" :
|
118
|
+
"#{plural_name.camelize}Helper"
|
119
|
+
end
|
120
|
+
|
121
|
+
def controller_test_name
|
122
|
+
"#{controller_class_name}Test"
|
123
|
+
end
|
124
|
+
|
125
|
+
def controller_path
|
126
|
+
@namespace ? "app/controllers/#{@namespace}" : "app/controllers"
|
127
|
+
end
|
128
|
+
|
129
|
+
def helper_path
|
130
|
+
@namespace ? "app/helpers/#{@namespace}" : "app/helpers"
|
131
|
+
end
|
132
|
+
|
133
|
+
def controller_test_path
|
134
|
+
@namespace ? "test/functional/#{@namespace}" : "test/functional"
|
135
|
+
end
|
136
|
+
|
137
|
+
def view_path
|
138
|
+
@namespace ? "app/views/#{@namespace}" : "app/views"
|
139
|
+
end
|
140
|
+
|
141
|
+
def url
|
142
|
+
@namespace ? "#{@namespace}_#{plural_name}_url" : "#{plural_name}_url"
|
143
|
+
end
|
144
|
+
|
145
|
+
def i18n_prefix
|
146
|
+
@namespace ? "#{@namespace}.#{plural_name}" : plural_name
|
147
|
+
end
|
148
|
+
|
149
|
+
def items_path
|
150
|
+
@namespace ? "#{@namespace}_#{plural_name}_path" : "#{plural_name}_path"
|
151
|
+
end
|
152
|
+
|
153
|
+
def item_path
|
154
|
+
@namespace ? "#{@namespace}_#{singular_name}_path" : "#{singular_name}_path"
|
155
|
+
end
|
156
|
+
|
157
|
+
def new_item_path
|
158
|
+
@namespace ? "new_#{@namespace}_#{singular_name}_path" : "new_#{singular_name}_path"
|
159
|
+
end
|
160
|
+
|
161
|
+
def edit_item_path
|
162
|
+
@namespace ? "edit_#{@namespace}_edit_#{singular_name}_path" : "edit_#{singular_name}_path"
|
163
|
+
end
|
164
|
+
|
165
|
+
def controller_route
|
166
|
+
@namespace ? "/#{@namespace}/#{plural_name}" : "/#{plural_name}"
|
167
|
+
end
|
168
|
+
|
169
|
+
def add_options!(opt)
|
170
|
+
opt.separator ''
|
171
|
+
opt.separator 'Options:'
|
172
|
+
|
173
|
+
opt.on("--skip-controller",
|
174
|
+
"Don't generate controller, helper, or views.") { |v| options[:skip_controller] = v }
|
175
|
+
opt.on("--skip-model",
|
176
|
+
"Don't generate a model or migration file.") { |v| options[:skip_model] = v }
|
177
|
+
opt.on("--skip-migration",
|
178
|
+
"Don't generate a migration file for this model") { |v| options[:skip_migration] = v }
|
179
|
+
opt.on("--skip-timestamps",
|
180
|
+
"Don't add timestamps to migration file.") { |v| options[:skip_timestamps] = v }
|
181
|
+
|
182
|
+
end
|
183
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
class <%= controller_class_name %> < ApplicationController
|
2
|
+
<% if action? :index -%>
|
3
|
+
# GET /<%= plural_name %>
|
4
|
+
def index
|
5
|
+
@<%= plural_name %> = <%= class_name %>.all
|
6
|
+
end
|
7
|
+
|
8
|
+
<% end -%>
|
9
|
+
<% if action? :show -%>
|
10
|
+
# GET /<%= plural_name %>/:id
|
11
|
+
def show
|
12
|
+
@<%= singular_name %> = <%= class_name %>.find(params[:id])
|
13
|
+
end
|
14
|
+
|
15
|
+
<% end -%>
|
16
|
+
<% if action? :new -%>
|
17
|
+
# GET /<%= plural_name %>/new
|
18
|
+
def new
|
19
|
+
@<%= singular_name %> = <%= class_name %>.new
|
20
|
+
end
|
21
|
+
|
22
|
+
<% end -%>
|
23
|
+
<% if action? :edit -%>
|
24
|
+
# GET /<%= plural_name %>/:id/edit
|
25
|
+
def edit
|
26
|
+
@<%= singular_name %> = <%= class_name %>.find(params[:id])
|
27
|
+
end
|
28
|
+
|
29
|
+
<% end -%>
|
30
|
+
<% if action? :create -%>
|
31
|
+
# POST /<%= plural_name %>
|
32
|
+
def create
|
33
|
+
@<%= singular_name %> = <%= class_name %>.new(params[:<%= singular_name %>])
|
34
|
+
@<%= singular_name %>.save!
|
35
|
+
flash[:notice] = t('<%= i18n_prefix %>.create.success')
|
36
|
+
redirect_to <%= url %>
|
37
|
+
rescue ActiveRecord::RecordInvalid
|
38
|
+
render 'new'
|
39
|
+
end
|
40
|
+
|
41
|
+
<% end -%>
|
42
|
+
<% if action? :update -%>
|
43
|
+
# PUT /<%= plural_name %>/:id
|
44
|
+
def update
|
45
|
+
@<%= singular_name %> = <%= class_name %>.find(params[:id])
|
46
|
+
@<%= singular_name %>.update_attributes!(params[:<%= singular_name %>])
|
47
|
+
flash[:notice] = t('<%= i18n_prefix %>.update.success')
|
48
|
+
redirect_to <%= url %>
|
49
|
+
rescue ActiveRecord::RecordInvalid
|
50
|
+
render 'edit'
|
51
|
+
end
|
52
|
+
|
53
|
+
<% end -%>
|
54
|
+
<% if action? :destroy -%>
|
55
|
+
# DELETE /<%= plural_name %>/:id
|
56
|
+
def destroy
|
57
|
+
@<%= singular_name %> = <%= class_name %>.find(params[:id])
|
58
|
+
@<%= singular_name %>.destroy
|
59
|
+
flash[:notice] = t('<%= i18n_prefix %>.destroy.success')
|
60
|
+
redirect_to <%= url %>
|
61
|
+
end
|
62
|
+
<% end -%>
|
63
|
+
end
|
@@ -0,0 +1,171 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class <%= controller_test_name %> < ActionController::TestCase
|
4
|
+
<% if action? :index -%>
|
5
|
+
context "on GET to #index" do
|
6
|
+
setup do
|
7
|
+
5.times { Factory :<%= singular_name %> }
|
8
|
+
get :index
|
9
|
+
end
|
10
|
+
|
11
|
+
should_respond_with :success
|
12
|
+
should_assign_to :<%= plural_name %>, :class => Array
|
13
|
+
# should_paginate_collection :<%= plural_name %>
|
14
|
+
should_render_template :index
|
15
|
+
should_not_set_the_flash
|
16
|
+
|
17
|
+
should "return 5 items" do
|
18
|
+
assert_equal 5, assigns(:<%= plural_name %>).size
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
<% end -%>
|
23
|
+
<% if action? :show -%>
|
24
|
+
context "on GET to #show" do
|
25
|
+
setup do
|
26
|
+
@<%= singular_name %> = Factory :<%= singular_name %>
|
27
|
+
get :show, :id => @<%= singular_name %>.id
|
28
|
+
end
|
29
|
+
|
30
|
+
should_respond_with :success
|
31
|
+
should_assign_to(:<%= singular_name %>, :class => <%= class_name %>) { @<%= singular_name %> }
|
32
|
+
should_render_template :show
|
33
|
+
should_not_set_the_flash
|
34
|
+
end
|
35
|
+
|
36
|
+
<% end -%>
|
37
|
+
<% if action? :new -%>
|
38
|
+
context "on GET to #new" do
|
39
|
+
setup { get :new }
|
40
|
+
|
41
|
+
should_respond_with :success
|
42
|
+
should_assign_to(:<%= singular_name %>, :class => <%= class_name %>)
|
43
|
+
should_render_template :new
|
44
|
+
should_render_a_form
|
45
|
+
should_not_set_the_flash
|
46
|
+
|
47
|
+
should "set build new <%= class_name %>" do
|
48
|
+
assert assigns(:<%= singular_name %>).new_record?
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
<% end -%>
|
53
|
+
<% if action? :edit -%>
|
54
|
+
context "on GET to #edit" do
|
55
|
+
setup do
|
56
|
+
@<%= singular_name %> = Factory :<%= singular_name %>
|
57
|
+
get :edit, :id => @<%= singular_name %>.id
|
58
|
+
end
|
59
|
+
|
60
|
+
should_respond_with :success
|
61
|
+
should_assign_to(:<%= singular_name %>, :class => <%= class_name %>) { @<%= singular_name %> }
|
62
|
+
should_render_template :edit
|
63
|
+
should_render_a_form
|
64
|
+
should_not_set_the_flash
|
65
|
+
end
|
66
|
+
|
67
|
+
<% end -%>
|
68
|
+
<% if action? :create -%>
|
69
|
+
context "on POST to #create" do
|
70
|
+
context "with valid attributes" do
|
71
|
+
setup do
|
72
|
+
<%= class_name %>.any_instance.stubs(:valid?).returns(true)
|
73
|
+
post :create
|
74
|
+
end
|
75
|
+
|
76
|
+
should_respond_with :redirect
|
77
|
+
should_redirect_to('portfolio items listing') { <%= url %> }
|
78
|
+
should_assign_to :<%= singular_name %>, :class => <%= class_name %>
|
79
|
+
should_set_the_flash_to I18n.t('<%= i18n_prefix %>.create.success')
|
80
|
+
end
|
81
|
+
|
82
|
+
context "with invalid attributes" do
|
83
|
+
setup do
|
84
|
+
<%= class_name %>.any_instance.stubs(:valid?).returns(false)
|
85
|
+
post :create
|
86
|
+
end
|
87
|
+
|
88
|
+
should_respond_with :success
|
89
|
+
should_assign_to :<%= singular_name %>, :class => <%= class_name %>
|
90
|
+
should_render_template :new
|
91
|
+
should_render_a_form
|
92
|
+
should_not_set_the_flash
|
93
|
+
|
94
|
+
should "build new <%= class_name %>" do
|
95
|
+
assert assigns(:<%= singular_name %>).new_record?
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
<% end -%>
|
101
|
+
<% if action? :update -%>
|
102
|
+
context "on PUT to #update" do
|
103
|
+
setup { @<%= singular_name %> = Factory :<%= singular_name %> }
|
104
|
+
|
105
|
+
context "with valid attributes" do
|
106
|
+
setup do
|
107
|
+
<%= class_name %>.any_instance.stubs(:valid?).returns(true)
|
108
|
+
put :update, :id => @<%= singular_name %>.id
|
109
|
+
end
|
110
|
+
|
111
|
+
should_respond_with :redirect
|
112
|
+
should_redirect_to('listing') { <%= url %> }
|
113
|
+
should_assign_to(:<%= singular_name %>, :class => <%= class_name %>) { @<%= singular_name %> }
|
114
|
+
should_set_the_flash_to I18n.t('<%= i18n_prefix %>.update.success')
|
115
|
+
end
|
116
|
+
|
117
|
+
context "with invalid attributes" do
|
118
|
+
setup do
|
119
|
+
<%= class_name %>.any_instance.stubs(:valid?).returns(false)
|
120
|
+
put :update, :id => @<%= singular_name %>.id
|
121
|
+
end
|
122
|
+
|
123
|
+
should_respond_with :success
|
124
|
+
should_assign_to(:<%= singular_name %>, :class => <%= class_name %>) { @<%= singular_name %> }
|
125
|
+
should_render_template :edit
|
126
|
+
should_render_a_form
|
127
|
+
should_not_set_the_flash
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
<% end -%>
|
132
|
+
<% if action? :destroy -%>
|
133
|
+
context "on DELETE to #destroy" do
|
134
|
+
setup do
|
135
|
+
@<%= singular_name %> = Factory :<%= singular_name %>
|
136
|
+
delete :destroy, :id => @<%= singular_name %>.id
|
137
|
+
end
|
138
|
+
|
139
|
+
should_respond_with :redirect
|
140
|
+
should_redirect_to('portfolio items listing') { <%= url %> }
|
141
|
+
should_assign_to(:<%= singular_name %>, :class => <%= class_name %>) { @<%= singular_name %> }
|
142
|
+
should_set_the_flash_to I18n.t('<%= i18n_prefix %>.destroy.success')
|
143
|
+
|
144
|
+
should "delete item" do
|
145
|
+
assert !<%= class_name %>.exists?(@<%= singular_name %>.id)
|
146
|
+
end
|
147
|
+
end
|
148
|
+
<% end -%>
|
149
|
+
|
150
|
+
<% if action? :index -%>
|
151
|
+
should_route :get, '<%= controller_route %>', :action => 'index'
|
152
|
+
<% end -%>
|
153
|
+
<% if action? :show -%>
|
154
|
+
should_route :get, '<%= controller_route %>/1', :action => 'show', :id => 1
|
155
|
+
<% end -%>
|
156
|
+
<% if action? :now -%>
|
157
|
+
should_route :get, '<%= controller_route %>/new', :action => 'new'
|
158
|
+
<% end -%>
|
159
|
+
<% if action? :edit -%>
|
160
|
+
should_route :get, '<%= controller_route %>/1/edit', :action => 'edit', :id => 1
|
161
|
+
<% end -%>
|
162
|
+
<% if action? :create -%>
|
163
|
+
should_route :post, '<%= controller_route %>', :action => 'create'
|
164
|
+
<% end -%>
|
165
|
+
<% if action? :update -%>
|
166
|
+
should_route :put, '<%= controller_route %>/1', :action => 'update', :id => 1
|
167
|
+
<% end -%>
|
168
|
+
<% if action? :destroy -%>
|
169
|
+
should_route :delete, '<%= controller_route %>/1', :action => 'destroy', :id => 1
|
170
|
+
<% end -%>
|
171
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module <%= helper_class_name %>
|
2
|
+
<%- if action? :edit -%>
|
3
|
+
def link_to_edit_<%= singular_name %>(<%= singular_name %>, *args)
|
4
|
+
link_to t('common.edit'), <%= edit_item_path %>(<%= singular_name %>, *args)
|
5
|
+
end
|
6
|
+
|
7
|
+
<%- end -%>
|
8
|
+
<%- if action? :destroy -%>
|
9
|
+
def link_to_destroy_<%= singular_name %>(<%= singular_name %>)
|
10
|
+
link_to t('common.destroy'), <%= item_path %>(<%= singular_name %>), :method => 'delete',
|
11
|
+
:confirm => t('common.confirm_destroy')
|
12
|
+
end
|
13
|
+
<%- end -%>
|
14
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
class Create<%= plural_class_name %> < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :<%= plural_name %> do |t|
|
4
|
+
<%- for attribute in attributes -%>
|
5
|
+
t.<%= attribute.type %> :<%= attribute.name %>
|
6
|
+
<%- end -%>
|
7
|
+
<%- unless options[:skip_timestamps] -%>
|
8
|
+
t.timestamps
|
9
|
+
<%- end -%>
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.down
|
14
|
+
drop_table :<%= plural_name %>
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class <%= class_name %>Test < ActiveSupport::TestCase
|
4
|
+
context "new record" do
|
5
|
+
setup do
|
6
|
+
@<%= singular_name %> = Factory :<%= singular_name %>
|
7
|
+
end
|
8
|
+
|
9
|
+
should_change "<%= class_name %>.count", :by => 1
|
10
|
+
end
|
11
|
+
|
12
|
+
# Mass assignment attributes
|
13
|
+
should_allow_mass_assignment_of <%= attributes.map(&:name).map { |a| ':'+a }.join(', ') %>
|
14
|
+
should_not_allow_mass_assignment_of :id<% unless options[:skip_timestamps] %>, :created_at, :modified_at<% end %>
|
15
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
<p>
|
2
|
+
<% if action? :index %><%%= link_to t('common.back'), <%= items_path %> %><% end -%>
|
3
|
+
<% if action? :destroy %><%%= link_to_destroy_<%=singular_name %> @<%= singular_name %> %><% end -%>
|
4
|
+
</p>
|
5
|
+
|
6
|
+
<%% form_for @<%= singular_name %> do |form| %>
|
7
|
+
<%%= render :partial => 'form', :object => form %>
|
8
|
+
<%%= form.submit t('common.update') %>
|
9
|
+
<%% end %>
|
@@ -0,0 +1,31 @@
|
|
1
|
+
<%- if action? :new -%>
|
2
|
+
<p><%%= link_to t('<%= i18n_prefix %>.new.link'), <%= new_item_path %> %></p>
|
3
|
+
<%- end -%>
|
4
|
+
<table class="list" id="<%= plural_name %>">
|
5
|
+
<thead>
|
6
|
+
<tr>
|
7
|
+
<% for attribute in attributes -%>
|
8
|
+
<th><%= attribute.column.human_name.titleize %></th>
|
9
|
+
<% end -%>
|
10
|
+
</tr>
|
11
|
+
</thead>
|
12
|
+
<tbody>
|
13
|
+
<%% @<%= plural_name %>.each do |<%= singular_name %>| -%>
|
14
|
+
<%% content_tag_for :tr, <%= singular_name %> do %>
|
15
|
+
<tr>
|
16
|
+
<% for attribute in attributes -%>
|
17
|
+
<td><%%=h <%= singular_name %>.<%= attribute.name %> %></td>
|
18
|
+
<% end -%>
|
19
|
+
<td class="actions">
|
20
|
+
<% if action? :edit -%>
|
21
|
+
<%%= link_to_edit_<%= singular_name %> <%= singular_name %> %>
|
22
|
+
<% end -%>
|
23
|
+
<% if action? :edit -%>
|
24
|
+
<%%= link_to_destroy_<%= singular_name %> <%= singular_name %> %>
|
25
|
+
<% end -%>
|
26
|
+
</td>
|
27
|
+
</tr>
|
28
|
+
<%% end %>
|
29
|
+
<%% end -%>
|
30
|
+
</tbody>
|
31
|
+
</table>
|
@@ -0,0 +1,15 @@
|
|
1
|
+
<p>
|
2
|
+
<% if action? :index %><%%= link_to t('common.back'), <%= items_path %> %><% end -%>
|
3
|
+
<% if action? :edit %><%%= link_to_edit_<%=singular_name %> @<%= singular_name %> %><% end -%>
|
4
|
+
<% if action? :destroy %><%%= link_to_destroy_<%=singular_name %> @<%= singular_name %> %><% end -%>
|
5
|
+
</p>
|
6
|
+
<%% content_tag_for :div, @<%= singular_name %> do %>
|
7
|
+
<ul>
|
8
|
+
<% for attribute in attributes -%>
|
9
|
+
<li>
|
10
|
+
<strong><%= attribute.column.human_name.titleize %>:</strong>
|
11
|
+
<%%=h @<%= singular_name %>.<%= attribute.name %> %>
|
12
|
+
</li>
|
13
|
+
<% end -%>
|
14
|
+
</ul>
|
15
|
+
<%% end %>
|
data/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# Include hook code here
|
data/install.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# Install hook code here
|
@@ -0,0 +1 @@
|
|
1
|
+
# BlueberryScaffold
|
data/test/test_helper.rb
ADDED
data/uninstall.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# Uninstall hook code here
|
metadata
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jzajpt-blueberry_scaffold
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- "Ji\xC5\x99\xC3\xAD Zajpt"
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-05-15 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Scaffold generator featuring i18n, shoulda & factory girl tests.
|
17
|
+
email: jzajpt@blueberryapps.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- LICENSE
|
24
|
+
- README
|
25
|
+
files:
|
26
|
+
- CHANGELOG
|
27
|
+
- LICENSE
|
28
|
+
- Manifest
|
29
|
+
- README
|
30
|
+
- Rakefile
|
31
|
+
- VERSION
|
32
|
+
- generators/blueberry_scaffold/USAGE
|
33
|
+
- generators/blueberry_scaffold/blueberry_scaffold_generator.rb
|
34
|
+
- generators/blueberry_scaffold/templates/controller.rb
|
35
|
+
- generators/blueberry_scaffold/templates/controller_test.rb
|
36
|
+
- generators/blueberry_scaffold/templates/factory.rb
|
37
|
+
- generators/blueberry_scaffold/templates/helper.rb
|
38
|
+
- generators/blueberry_scaffold/templates/migration.rb
|
39
|
+
- generators/blueberry_scaffold/templates/model.rb
|
40
|
+
- generators/blueberry_scaffold/templates/model_test.rb
|
41
|
+
- generators/blueberry_scaffold/templates/views/_form.html.erb
|
42
|
+
- generators/blueberry_scaffold/templates/views/edit.html.erb
|
43
|
+
- generators/blueberry_scaffold/templates/views/index.html.erb
|
44
|
+
- generators/blueberry_scaffold/templates/views/new.html.erb
|
45
|
+
- generators/blueberry_scaffold/templates/views/show.html.erb
|
46
|
+
- init.rb
|
47
|
+
- install.rb
|
48
|
+
- lib/blueberry_scaffold.rb
|
49
|
+
- tasks/blueberry_scaffold_tasks.rake
|
50
|
+
- test/blueberry_scaffold_test.rb
|
51
|
+
- test/test_helper.rb
|
52
|
+
- uninstall.rb
|
53
|
+
has_rdoc: true
|
54
|
+
homepage: http://github.com/jzajpt/blueberry_scaffold
|
55
|
+
post_install_message:
|
56
|
+
rdoc_options:
|
57
|
+
- --charset=UTF-8
|
58
|
+
require_paths:
|
59
|
+
- lib
|
60
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: "0"
|
65
|
+
version:
|
66
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: "0"
|
71
|
+
version:
|
72
|
+
requirements: []
|
73
|
+
|
74
|
+
rubyforge_project:
|
75
|
+
rubygems_version: 1.2.0
|
76
|
+
signing_key:
|
77
|
+
specification_version: 3
|
78
|
+
summary: Rails scaffold generator plugin.
|
79
|
+
test_files:
|
80
|
+
- test/blueberry_scaffold_test.rb
|
81
|
+
- test/test_helper.rb
|