nifty-generators-improved 0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +198 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +111 -0
- data/LICENSE +20 -0
- data/README.rdoc +109 -0
- data/Rakefile +10 -0
- data/features/nifty_authentication.feature +80 -0
- data/features/nifty_config.feature +17 -0
- data/features/nifty_layout.feature +20 -0
- data/features/nifty_scaffold.feature +80 -0
- data/features/step_definitions/common_steps.rb +62 -0
- data/features/step_definitions/rails_setup_steps.rb +6 -0
- data/features/support/env.rb +6 -0
- data/features/support/matchers.rb +7 -0
- data/lib/generators/nifty.rb +28 -0
- data/lib/generators/nifty/authentication/USAGE +50 -0
- data/lib/generators/nifty/authentication/authentication_generator.rb +154 -0
- data/lib/generators/nifty/authentication/templates/authlogic_session.rb +2 -0
- data/lib/generators/nifty/authentication/templates/controller_authentication.rb +60 -0
- data/lib/generators/nifty/authentication/templates/fixtures.yml +24 -0
- data/lib/generators/nifty/authentication/templates/migration.rb +20 -0
- data/lib/generators/nifty/authentication/templates/sessions_controller.rb +41 -0
- data/lib/generators/nifty/authentication/templates/sessions_helper.rb +2 -0
- data/lib/generators/nifty/authentication/templates/tests/rspec/sessions_controller.rb +39 -0
- data/lib/generators/nifty/authentication/templates/tests/rspec/user.rb +83 -0
- data/lib/generators/nifty/authentication/templates/tests/rspec/users_controller.rb +56 -0
- data/lib/generators/nifty/authentication/templates/tests/shoulda/sessions_controller.rb +40 -0
- data/lib/generators/nifty/authentication/templates/tests/shoulda/user.rb +85 -0
- data/lib/generators/nifty/authentication/templates/tests/shoulda/users_controller.rb +61 -0
- data/lib/generators/nifty/authentication/templates/tests/testunit/sessions_controller.rb +36 -0
- data/lib/generators/nifty/authentication/templates/tests/testunit/user.rb +88 -0
- data/lib/generators/nifty/authentication/templates/tests/testunit/users_controller.rb +53 -0
- data/lib/generators/nifty/authentication/templates/user.rb +38 -0
- data/lib/generators/nifty/authentication/templates/users_controller.rb +32 -0
- data/lib/generators/nifty/authentication/templates/users_helper.rb +2 -0
- data/lib/generators/nifty/authentication/templates/views/erb/_form.html.erb +20 -0
- data/lib/generators/nifty/authentication/templates/views/erb/edit.html.erb +3 -0
- data/lib/generators/nifty/authentication/templates/views/erb/login.html.erb +30 -0
- data/lib/generators/nifty/authentication/templates/views/erb/signup.html.erb +5 -0
- data/lib/generators/nifty/authentication/templates/views/haml/_form.html.haml +16 -0
- data/lib/generators/nifty/authentication/templates/views/haml/edit.html.haml +3 -0
- data/lib/generators/nifty/authentication/templates/views/haml/login.html.haml +26 -0
- data/lib/generators/nifty/authentication/templates/views/haml/signup.html.haml +5 -0
- data/lib/generators/nifty/config/USAGE +23 -0
- data/lib/generators/nifty/config/config_generator.rb +24 -0
- data/lib/generators/nifty/config/templates/config.yml +8 -0
- data/lib/generators/nifty/config/templates/load_config.rb +2 -0
- data/lib/generators/nifty/layout/USAGE +25 -0
- data/lib/generators/nifty/layout/layout_generator.rb +29 -0
- data/lib/generators/nifty/layout/templates/error_messages_helper.rb +23 -0
- data/lib/generators/nifty/layout/templates/layout.html.erb +19 -0
- data/lib/generators/nifty/layout/templates/layout.html.haml +17 -0
- data/lib/generators/nifty/layout/templates/layout_helper.rb +17 -0
- data/lib/generators/nifty/layout/templates/stylesheet.css +83 -0
- data/lib/generators/nifty/layout/templates/stylesheet.css.scss +88 -0
- data/lib/generators/nifty/scaffold/USAGE +51 -0
- data/lib/generators/nifty/scaffold/scaffold_generator.rb +318 -0
- data/lib/generators/nifty/scaffold/templates/actions/create.rb +8 -0
- data/lib/generators/nifty/scaffold/templates/actions/destroy.rb +5 -0
- data/lib/generators/nifty/scaffold/templates/actions/edit.rb +3 -0
- data/lib/generators/nifty/scaffold/templates/actions/index.rb +3 -0
- data/lib/generators/nifty/scaffold/templates/actions/new.rb +3 -0
- data/lib/generators/nifty/scaffold/templates/actions/show.rb +3 -0
- data/lib/generators/nifty/scaffold/templates/actions/update.rb +8 -0
- data/lib/generators/nifty/scaffold/templates/controller.rb +3 -0
- data/lib/generators/nifty/scaffold/templates/fixtures.yml +9 -0
- data/lib/generators/nifty/scaffold/templates/helper.rb +2 -0
- data/lib/generators/nifty/scaffold/templates/migration.rb +16 -0
- data/lib/generators/nifty/scaffold/templates/model.rb +4 -0
- data/lib/generators/nifty/scaffold/templates/tests/rspec/actions/create.rb +11 -0
- data/lib/generators/nifty/scaffold/templates/tests/rspec/actions/destroy.rb +6 -0
- data/lib/generators/nifty/scaffold/templates/tests/rspec/actions/edit.rb +4 -0
- data/lib/generators/nifty/scaffold/templates/tests/rspec/actions/index.rb +4 -0
- data/lib/generators/nifty/scaffold/templates/tests/rspec/actions/new.rb +4 -0
- data/lib/generators/nifty/scaffold/templates/tests/rspec/actions/show.rb +4 -0
- data/lib/generators/nifty/scaffold/templates/tests/rspec/actions/update.rb +11 -0
- data/lib/generators/nifty/scaffold/templates/tests/rspec/controller.rb +8 -0
- data/lib/generators/nifty/scaffold/templates/tests/rspec/model.rb +7 -0
- data/lib/generators/nifty/scaffold/templates/tests/shoulda/actions/create.rb +13 -0
- data/lib/generators/nifty/scaffold/templates/tests/shoulda/actions/destroy.rb +8 -0
- data/lib/generators/nifty/scaffold/templates/tests/shoulda/actions/edit.rb +6 -0
- data/lib/generators/nifty/scaffold/templates/tests/shoulda/actions/index.rb +6 -0
- data/lib/generators/nifty/scaffold/templates/tests/shoulda/actions/new.rb +6 -0
- data/lib/generators/nifty/scaffold/templates/tests/shoulda/actions/show.rb +6 -0
- data/lib/generators/nifty/scaffold/templates/tests/shoulda/actions/update.rb +13 -0
- data/lib/generators/nifty/scaffold/templates/tests/shoulda/controller.rb +5 -0
- data/lib/generators/nifty/scaffold/templates/tests/shoulda/model.rb +7 -0
- data/lib/generators/nifty/scaffold/templates/tests/testunit/actions/create.rb +11 -0
- data/lib/generators/nifty/scaffold/templates/tests/testunit/actions/destroy.rb +6 -0
- data/lib/generators/nifty/scaffold/templates/tests/testunit/actions/edit.rb +4 -0
- data/lib/generators/nifty/scaffold/templates/tests/testunit/actions/index.rb +4 -0
- data/lib/generators/nifty/scaffold/templates/tests/testunit/actions/new.rb +4 -0
- data/lib/generators/nifty/scaffold/templates/tests/testunit/actions/show.rb +4 -0
- data/lib/generators/nifty/scaffold/templates/tests/testunit/actions/update.rb +11 -0
- data/lib/generators/nifty/scaffold/templates/tests/testunit/controller.rb +5 -0
- data/lib/generators/nifty/scaffold/templates/tests/testunit/model.rb +7 -0
- data/lib/generators/nifty/scaffold/templates/views/erb/_form.html.erb +10 -0
- data/lib/generators/nifty/scaffold/templates/views/erb/edit.html.erb +14 -0
- data/lib/generators/nifty/scaffold/templates/views/erb/index.html.erb +29 -0
- data/lib/generators/nifty/scaffold/templates/views/erb/new.html.erb +7 -0
- data/lib/generators/nifty/scaffold/templates/views/erb/show.html.erb +20 -0
- data/lib/generators/nifty/scaffold/templates/views/haml/_form.html.haml +9 -0
- data/lib/generators/nifty/scaffold/templates/views/haml/edit.html.haml +14 -0
- data/lib/generators/nifty/scaffold/templates/views/haml/index.html.haml +25 -0
- data/lib/generators/nifty/scaffold/templates/views/haml/new.html.haml +7 -0
- data/lib/generators/nifty/scaffold/templates/views/haml/show.html.haml +20 -0
- data/test/test_helper.rb +119 -0
- data/test/test_nifty_authentication_generator.rb +274 -0
- data/test/test_nifty_config_generator.rb +37 -0
- data/test/test_nifty_layout_generator.rb +42 -0
- data/test/test_nifty_scaffold_generator.rb +534 -0
- metadata +231 -0
@@ -0,0 +1,8 @@
|
|
1
|
+
def create
|
2
|
+
@<%= instance_name %> = <%= class_name %>.new(params[:<%= instance_name %>])
|
3
|
+
if @<%= instance_name %>.save
|
4
|
+
redirect_to <%= item_url %>, :notice => "Successfully created <%= class_name.underscore.humanize.downcase %>."
|
5
|
+
else
|
6
|
+
render :new
|
7
|
+
end
|
8
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
def update
|
2
|
+
@<%= instance_name %> = <%= class_name %>.find(params[:id])
|
3
|
+
if @<%= instance_name %>.update_attributes(params[:<%= instance_name %>])
|
4
|
+
redirect_to <%= item_url %>, :notice => "Successfully updated <%= class_name.underscore.humanize.downcase %>."
|
5
|
+
else
|
6
|
+
render :edit
|
7
|
+
end
|
8
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
class Create<%= class_name.pluralize.delete('::') %> < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :<%= table_name || plural_name.split('/').last %> do |t|
|
4
|
+
<%- for attribute in model_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 :<%= table_name || plural_name.split('/').last %>
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
it "create action should render new template when model is invalid" do
|
2
|
+
<%= class_name %>.any_instance.stubs(:valid?).returns(false)
|
3
|
+
post :create
|
4
|
+
response.should render_template(:new)
|
5
|
+
end
|
6
|
+
|
7
|
+
it "create action should redirect when model is valid" do
|
8
|
+
<%= class_name %>.any_instance.stubs(:valid?).returns(true)
|
9
|
+
post :create
|
10
|
+
response.should redirect_to(<%= item_path_for_spec('url') %>)
|
11
|
+
end
|
@@ -0,0 +1,6 @@
|
|
1
|
+
it "destroy action should destroy model and redirect to index action" do
|
2
|
+
<%= instance_name %> = <%= class_name %>.first
|
3
|
+
delete :destroy, :id => <%= instance_name %>
|
4
|
+
response.should redirect_to(<%= items_url %>)
|
5
|
+
<%= class_name %>.exists?(<%= instance_name %>.id).should be_false
|
6
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
it "update action should render edit template when model is invalid" do
|
2
|
+
<%= class_name %>.any_instance.stubs(:valid?).returns(false)
|
3
|
+
put :update, :id => <%= class_name %>.first
|
4
|
+
response.should render_template(:edit)
|
5
|
+
end
|
6
|
+
|
7
|
+
it "update action should redirect when model is valid" do
|
8
|
+
<%= class_name %>.any_instance.stubs(:valid?).returns(true)
|
9
|
+
put :update, :id => <%= class_name %>.first
|
10
|
+
response.should redirect_to(<%= item_path_for_spec('url') %>)
|
11
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
context "create action" do
|
2
|
+
should "render new template when model is invalid" do
|
3
|
+
<%= class_name %>.any_instance.stubs(:valid?).returns(false)
|
4
|
+
post :create
|
5
|
+
assert_template 'new'
|
6
|
+
end
|
7
|
+
|
8
|
+
should "redirect when model is valid" do
|
9
|
+
<%= class_name %>.any_instance.stubs(:valid?).returns(true)
|
10
|
+
post :create
|
11
|
+
assert_redirected_to <%= item_path_for_test('url') %>
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
context "destroy action" do
|
2
|
+
should "destroy model and redirect to index action" do
|
3
|
+
<%= instance_name %> = <%= class_name %>.first
|
4
|
+
delete :destroy, :id => <%= instance_name %>
|
5
|
+
assert_redirected_to <%= items_url %>
|
6
|
+
assert !<%= class_name %>.exists?(<%= instance_name %>.id)
|
7
|
+
end
|
8
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
context "update action" do
|
2
|
+
should "render edit template when model is invalid" do
|
3
|
+
<%= class_name %>.any_instance.stubs(:valid?).returns(false)
|
4
|
+
put :update, :id => <%= class_name %>.first
|
5
|
+
assert_template 'edit'
|
6
|
+
end
|
7
|
+
|
8
|
+
should "redirect when model is valid" do
|
9
|
+
<%= class_name %>.any_instance.stubs(:valid?).returns(true)
|
10
|
+
put :update, :id => <%= class_name %>.first
|
11
|
+
assert_redirected_to <%= item_path_for_test('url') %>
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
def test_create_invalid
|
2
|
+
<%= class_name %>.any_instance.stubs(:valid?).returns(false)
|
3
|
+
post :create
|
4
|
+
assert_template 'new'
|
5
|
+
end
|
6
|
+
|
7
|
+
def test_create_valid
|
8
|
+
<%= class_name %>.any_instance.stubs(:valid?).returns(true)
|
9
|
+
post :create
|
10
|
+
assert_redirected_to <%= item_path_for_test('url') %>
|
11
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
def test_update_invalid
|
2
|
+
<%= class_name %>.any_instance.stubs(:valid?).returns(false)
|
3
|
+
put :update, :id => <%= class_name %>.first
|
4
|
+
assert_template 'edit'
|
5
|
+
end
|
6
|
+
|
7
|
+
def test_update_valid
|
8
|
+
<%= class_name %>.any_instance.stubs(:valid?).returns(true)
|
9
|
+
put :update, :id => <%= class_name %>.first
|
10
|
+
assert_redirected_to <%= item_path_for_test('url') %>
|
11
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
<%%= form_for <%= item_path :instance_variable => true %> do |f| %>
|
2
|
+
<%%= f.error_messages %>
|
3
|
+
<%- for attribute in model_attributes -%>
|
4
|
+
<div class="field">
|
5
|
+
<%%= f.label :<%= attribute.name %> %>
|
6
|
+
<%%= f.<%= attribute.field_type %> :<%= attribute.name %> %>
|
7
|
+
</div>
|
8
|
+
<%- end -%>
|
9
|
+
<div class="actions"><%%= f.submit %></div>
|
10
|
+
<%% end %>
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<%% title "Edit <%= singular_name.titleize %>" %>
|
2
|
+
|
3
|
+
<%= render_form %>
|
4
|
+
|
5
|
+
<%- if actions? :show, :index -%>
|
6
|
+
<p>
|
7
|
+
<%- if action? :show -%>
|
8
|
+
<%%= link_to "Show", <%= item_path :instance_variable => true %> %> |
|
9
|
+
<%- end -%>
|
10
|
+
<%- if action? :index -%>
|
11
|
+
<%%= link_to "View All", <%= items_path %> %>
|
12
|
+
<%- end -%>
|
13
|
+
</p>
|
14
|
+
<%- end -%>
|
@@ -0,0 +1,29 @@
|
|
1
|
+
<%% title "<%= plural_name.titleize %>" %>
|
2
|
+
|
3
|
+
<table>
|
4
|
+
<tr>
|
5
|
+
<%- for attribute in model_attributes -%>
|
6
|
+
<th><%= attribute.human_name.titleize %></th>
|
7
|
+
<%- end -%>
|
8
|
+
</tr>
|
9
|
+
<%% for <%= instance_name %> in @<%= instances_name %> %>
|
10
|
+
<tr>
|
11
|
+
<%- for attribute in model_attributes -%>
|
12
|
+
<td><%%= <%= instance_name %>.<%= attribute.name %> %></td>
|
13
|
+
<%- end -%>
|
14
|
+
<%- if action? :show -%>
|
15
|
+
<td><%%= link_to "Show", <%= item_path %> %></td>
|
16
|
+
<%- end -%>
|
17
|
+
<%- if action? :edit -%>
|
18
|
+
<td><%%= link_to "Edit", <%= item_path :action => :edit %> %></td>
|
19
|
+
<%- end -%>
|
20
|
+
<%- if action? :destroy -%>
|
21
|
+
<td><%%= link_to "Destroy", <%= item_path %>, :confirm => 'Are you sure?', :method => :delete %></td>
|
22
|
+
<%- end -%>
|
23
|
+
</tr>
|
24
|
+
<%% end %>
|
25
|
+
</table>
|
26
|
+
|
27
|
+
<%- if action? :new -%>
|
28
|
+
<p><%%= link_to "New <%= singular_name.titleize %>", <%= item_path :action => :new %> %></p>
|
29
|
+
<%- end -%>
|
@@ -0,0 +1,20 @@
|
|
1
|
+
<%% title "<%= singular_name.titleize %>" %>
|
2
|
+
|
3
|
+
<%- for attribute in model_attributes -%>
|
4
|
+
<p>
|
5
|
+
<strong><%= attribute.human_name.titleize %>:</strong>
|
6
|
+
<%%= @<%= instance_name %>.<%= attribute.name %> %>
|
7
|
+
</p>
|
8
|
+
<%- end -%>
|
9
|
+
|
10
|
+
<p>
|
11
|
+
<%- if action? :edit -%>
|
12
|
+
<%%= link_to "Edit", <%= item_path :action => :edit, :instance_variable => true %> %> |
|
13
|
+
<%- end -%>
|
14
|
+
<%- if action? :destroy -%>
|
15
|
+
<%%= link_to "Destroy", <%= item_path :instance_variable => true %>, :confirm => 'Are you sure?', :method => :delete %> |
|
16
|
+
<%- end -%>
|
17
|
+
<%- if action? :index -%>
|
18
|
+
<%%= link_to "View All", <%= items_path %> %>
|
19
|
+
<%- end -%>
|
20
|
+
</p>
|
@@ -0,0 +1,9 @@
|
|
1
|
+
= form_for <%= item_path :instance_variable => true %> do |f|
|
2
|
+
= f.error_messages
|
3
|
+
<%- for attribute in model_attributes -%>
|
4
|
+
.field
|
5
|
+
= f.label :<%= attribute.name %>
|
6
|
+
= f.<%= attribute.field_type %> :<%= attribute.name %>
|
7
|
+
<%- end -%>
|
8
|
+
.actions
|
9
|
+
= f.submit
|
@@ -0,0 +1,14 @@
|
|
1
|
+
- title "Edit <%= singular_name.titleize %>"
|
2
|
+
|
3
|
+
<%= render_form %>
|
4
|
+
|
5
|
+
<%- if actions? :show, :index -%>
|
6
|
+
%p
|
7
|
+
<%- if action? :show -%>
|
8
|
+
= link_to "Show", <%= item_path :instance_variable => true %>
|
9
|
+
|
|
10
|
+
<%- end -%>
|
11
|
+
<%- if action? :index -%>
|
12
|
+
= link_to "View All", <%= items_path %>
|
13
|
+
<%- end -%>
|
14
|
+
<%- end -%>
|
@@ -0,0 +1,25 @@
|
|
1
|
+
- title "<%= plural_name.titleize %>"
|
2
|
+
|
3
|
+
%table
|
4
|
+
%tr
|
5
|
+
<%- for attribute in model_attributes -%>
|
6
|
+
%th <%= attribute.human_name %>
|
7
|
+
<%- end -%>
|
8
|
+
- for <%= instance_name %> in @<%= instances_name %>
|
9
|
+
%tr
|
10
|
+
<%- for attribute in model_attributes -%>
|
11
|
+
%td= <%= instance_name %>.<%= attribute.name %>
|
12
|
+
<%- end -%>
|
13
|
+
<%- if action? :show -%>
|
14
|
+
%td= link_to 'Show', <%= item_path %>
|
15
|
+
<%- end -%>
|
16
|
+
<%- if action? :edit -%>
|
17
|
+
%td= link_to 'Edit', <%= item_path :action => :edit %>
|
18
|
+
<%- end -%>
|
19
|
+
<%- if action? :destroy -%>
|
20
|
+
%td= link_to 'Destroy', <%= item_path %>, :confirm => 'Are you sure?', :method => :delete
|
21
|
+
<%- end -%>
|
22
|
+
|
23
|
+
<%- if actions? :new -%>
|
24
|
+
%p= link_to "New <%= singular_name.titleize %>", <%= item_path :action => :new %>
|
25
|
+
<%- end -%>
|