Commit 9f845b63c3d52344c60876e1c53aa6c87e122a0b
1 parent
1d5e39e0
Exists in
master
and in
1 other branch
updated blitz, semi formal
Showing
21 changed files
with
138 additions
and
65 deletions
Show diff stats
vendor/plugins/blitz/features/controller_generator.feature
@@ -5,49 +5,49 @@ Feature: Rails controller generator | @@ -5,49 +5,49 @@ Feature: Rails controller generator | ||
5 | 5 | ||
6 | Scenario: Controller generator for index action | 6 | Scenario: Controller generator for index action |
7 | Given a Rails app | 7 | Given a Rails app |
8 | - And the coulda plugin is installed | 8 | + And the blitz plugin is installed |
9 | When I generate a "Posts" controller with "index" action | 9 | When I generate a "Posts" controller with "index" action |
10 | And an empty "index" controller action for "posts" should be generated | 10 | And an empty "index" controller action for "posts" should be generated |
11 | 11 | ||
12 | Scenario: Controller generator for new action | 12 | Scenario: Controller generator for new action |
13 | Given a Rails app | 13 | Given a Rails app |
14 | - And the coulda plugin is installed | 14 | + And the blitz plugin is installed |
15 | When I generate a "Posts" controller with "new" action | 15 | When I generate a "Posts" controller with "new" action |
16 | And a "new" controller action for "posts" should be generated | 16 | And a "new" controller action for "posts" should be generated |
17 | 17 | ||
18 | Scenario: Controller generator for create action | 18 | Scenario: Controller generator for create action |
19 | Given a Rails app | 19 | Given a Rails app |
20 | - And the coulda plugin is installed | 20 | + And the blitz plugin is installed |
21 | When I generate a "Posts" controller with "create" action | 21 | When I generate a "Posts" controller with "create" action |
22 | And a "create" controller action for "posts" should be generated | 22 | And a "create" controller action for "posts" should be generated |
23 | 23 | ||
24 | Scenario: Controller generator for create action when Cucumber is installed | 24 | Scenario: Controller generator for create action when Cucumber is installed |
25 | Given a Rails app with Cucumber | 25 | Given a Rails app with Cucumber |
26 | - And the coulda plugin is installed | 26 | + And the blitz plugin is installed |
27 | When I generate a "Posts" controller with "create" action | 27 | When I generate a "Posts" controller with "create" action |
28 | And a "create" controller action for "posts" should be generated | 28 | And a "create" controller action for "posts" should be generated |
29 | 29 | ||
30 | Scenario: Controller generator for show action | 30 | Scenario: Controller generator for show action |
31 | Given a Rails app | 31 | Given a Rails app |
32 | - And the coulda plugin is installed | 32 | + And the blitz plugin is installed |
33 | When I generate a "Posts" controller with "show" action | 33 | When I generate a "Posts" controller with "show" action |
34 | And a "show" controller action for "posts" should be generated | 34 | And a "show" controller action for "posts" should be generated |
35 | 35 | ||
36 | Scenario: Controller generator for edit action | 36 | Scenario: Controller generator for edit action |
37 | Given a Rails app | 37 | Given a Rails app |
38 | - And the coulda plugin is installed | 38 | + And the blitz plugin is installed |
39 | When I generate a "Posts" controller with "edit" action | 39 | When I generate a "Posts" controller with "edit" action |
40 | And a "edit" controller action for "posts" should be generated | 40 | And a "edit" controller action for "posts" should be generated |
41 | 41 | ||
42 | Scenario: Controller generator for update action | 42 | Scenario: Controller generator for update action |
43 | Given a Rails app | 43 | Given a Rails app |
44 | - And the coulda plugin is installed | 44 | + And the blitz plugin is installed |
45 | When I generate a "Posts" controller with "update" action | 45 | When I generate a "Posts" controller with "update" action |
46 | And a "update" controller action for "posts" should be generated | 46 | And a "update" controller action for "posts" should be generated |
47 | 47 | ||
48 | Scenario: Controller generator for destroy action | 48 | Scenario: Controller generator for destroy action |
49 | Given a Rails app | 49 | Given a Rails app |
50 | - And the coulda plugin is installed | 50 | + And the blitz plugin is installed |
51 | When I generate a "Posts" controller with "destroy" action | 51 | When I generate a "Posts" controller with "destroy" action |
52 | And a "destroy" controller action for "posts" should be generated | 52 | And a "destroy" controller action for "posts" should be generated |
53 | 53 |
vendor/plugins/blitz/features/feature_generator.feature
@@ -5,7 +5,7 @@ Feature: Rails controller generator | @@ -5,7 +5,7 @@ Feature: Rails controller generator | ||
5 | 5 | ||
6 | Scenario: Feature generator for new action | 6 | Scenario: Feature generator for new action |
7 | Given a Rails app with Cucumber | 7 | Given a Rails app with Cucumber |
8 | - And the coulda plugin is installed | 8 | + And the blitz plugin is installed |
9 | When I generate a "new" feature for "Posts" | 9 | When I generate a "new" feature for "Posts" |
10 | Then a "posts" feature for the "create" scenario should be generated | 10 | Then a "posts" feature for the "create" scenario should be generated |
11 | And a "create posts" step definition should be generated | 11 | And a "create posts" step definition should be generated |
@@ -13,7 +13,7 @@ Feature: Rails controller generator | @@ -13,7 +13,7 @@ Feature: Rails controller generator | ||
13 | 13 | ||
14 | Scenario: Feature generator for create action same as new | 14 | Scenario: Feature generator for create action same as new |
15 | Given a Rails app with Cucumber | 15 | Given a Rails app with Cucumber |
16 | - And the coulda plugin is installed | 16 | + And the blitz plugin is installed |
17 | When I generate a "create" feature for "Posts" | 17 | When I generate a "create" feature for "Posts" |
18 | Then a "posts" feature for the "create" scenario should be generated | 18 | Then a "posts" feature for the "create" scenario should be generated |
19 | And a "create posts" step definition should be generated | 19 | And a "create posts" step definition should be generated |
@@ -21,7 +21,7 @@ Feature: Rails controller generator | @@ -21,7 +21,7 @@ Feature: Rails controller generator | ||
21 | 21 | ||
22 | Scenario: Feature generator for edit action | 22 | Scenario: Feature generator for edit action |
23 | Given a Rails app with Cucumber | 23 | Given a Rails app with Cucumber |
24 | - And the coulda plugin is installed | 24 | + And the blitz plugin is installed |
25 | When I generate a "edit" feature for "Posts" | 25 | When I generate a "edit" feature for "Posts" |
26 | Then a "posts" feature for the "edit" scenario should be generated | 26 | Then a "posts" feature for the "edit" scenario should be generated |
27 | And a "update posts" step definition should be generated | 27 | And a "update posts" step definition should be generated |
@@ -29,7 +29,7 @@ Feature: Rails controller generator | @@ -29,7 +29,7 @@ Feature: Rails controller generator | ||
29 | 29 | ||
30 | Scenario: Feature generator for update action same as edit | 30 | Scenario: Feature generator for update action same as edit |
31 | Given a Rails app with Cucumber | 31 | Given a Rails app with Cucumber |
32 | - And the coulda plugin is installed | 32 | + And the blitz plugin is installed |
33 | When I generate a "update" feature for "Posts" | 33 | When I generate a "update" feature for "Posts" |
34 | Then a "posts" feature for the "update" scenario should be generated | 34 | Then a "posts" feature for the "update" scenario should be generated |
35 | And a "update posts" step definition should be generated | 35 | And a "update posts" step definition should be generated |
vendor/plugins/blitz/features/functional_test_generator.feature
@@ -5,49 +5,49 @@ Feature: Rails controller generator | @@ -5,49 +5,49 @@ Feature: Rails controller generator | ||
5 | 5 | ||
6 | Scenario: Functional test generator for index action | 6 | Scenario: Functional test generator for index action |
7 | Given a Rails app | 7 | Given a Rails app |
8 | - And the coulda plugin is installed | 8 | + And the blitz plugin is installed |
9 | When I generate a "Posts" functional test with "index" action | 9 | When I generate a "Posts" functional test with "index" action |
10 | Then a standard "index" functional test for "posts" should be generated | 10 | Then a standard "index" functional test for "posts" should be generated |
11 | 11 | ||
12 | Scenario: Functional test generator for new action | 12 | Scenario: Functional test generator for new action |
13 | Given a Rails app | 13 | Given a Rails app |
14 | - And the coulda plugin is installed | 14 | + And the blitz plugin is installed |
15 | When I generate a "Posts" functional test with "new" action | 15 | When I generate a "Posts" functional test with "new" action |
16 | Then a standard "new" functional test for "posts" should be generated | 16 | Then a standard "new" functional test for "posts" should be generated |
17 | 17 | ||
18 | Scenario: Functional test generator for create action | 18 | Scenario: Functional test generator for create action |
19 | Given a Rails app | 19 | Given a Rails app |
20 | - And the coulda plugin is installed | 20 | + And the blitz plugin is installed |
21 | When I generate a "Posts" functional test with "create" action | 21 | When I generate a "Posts" functional test with "create" action |
22 | Then a standard "create" functional test for "posts" should be generated | 22 | Then a standard "create" functional test for "posts" should be generated |
23 | 23 | ||
24 | Scenario: Functional test generator for create action when Cucumber is installed | 24 | Scenario: Functional test generator for create action when Cucumber is installed |
25 | Given a Rails app with Cucumber | 25 | Given a Rails app with Cucumber |
26 | - And the coulda plugin is installed | 26 | + And the blitz plugin is installed |
27 | When I generate a "Posts" functional test with "create" action | 27 | When I generate a "Posts" functional test with "create" action |
28 | Then a standard "create" functional test for "posts" should be generated | 28 | Then a standard "create" functional test for "posts" should be generated |
29 | 29 | ||
30 | Scenario: Functional test generator for show action | 30 | Scenario: Functional test generator for show action |
31 | Given a Rails app | 31 | Given a Rails app |
32 | - And the coulda plugin is installed | 32 | + And the blitz plugin is installed |
33 | When I generate a "Posts" functional test with "show" action | 33 | When I generate a "Posts" functional test with "show" action |
34 | Then a standard "show" functional test for "posts" should be generated | 34 | Then a standard "show" functional test for "posts" should be generated |
35 | 35 | ||
36 | Scenario: Functional test generator for edit action | 36 | Scenario: Functional test generator for edit action |
37 | Given a Rails app | 37 | Given a Rails app |
38 | - And the coulda plugin is installed | 38 | + And the blitz plugin is installed |
39 | When I generate a "Posts" functional test with "edit" action | 39 | When I generate a "Posts" functional test with "edit" action |
40 | Then a standard "edit" functional test for "posts" should be generated | 40 | Then a standard "edit" functional test for "posts" should be generated |
41 | 41 | ||
42 | Scenario: Functional test generator for update action | 42 | Scenario: Functional test generator for update action |
43 | Given a Rails app | 43 | Given a Rails app |
44 | - And the coulda plugin is installed | 44 | + And the blitz plugin is installed |
45 | When I generate a "Posts" functional test with "update" action | 45 | When I generate a "Posts" functional test with "update" action |
46 | Then a standard "update" functional test for "posts" should be generated | 46 | Then a standard "update" functional test for "posts" should be generated |
47 | 47 | ||
48 | Scenario: Functional test generator for destroy action | 48 | Scenario: Functional test generator for destroy action |
49 | Given a Rails app | 49 | Given a Rails app |
50 | - And the coulda plugin is installed | 50 | + And the blitz plugin is installed |
51 | When I generate a "Posts" functional test with "destroy" action | 51 | When I generate a "Posts" functional test with "destroy" action |
52 | Then a standard "destroy" functional test for "posts" should be generated | 52 | Then a standard "destroy" functional test for "posts" should be generated |
53 | 53 |
vendor/plugins/blitz/features/helper_generator.feature
@@ -5,7 +5,7 @@ Feature: Rails helper generator | @@ -5,7 +5,7 @@ Feature: Rails helper generator | ||
5 | 5 | ||
6 | Scenario: Helper | 6 | Scenario: Helper |
7 | Given a Rails app | 7 | Given a Rails app |
8 | - And the coulda plugin is installed | 8 | + And the blitz plugin is installed |
9 | When I generate a helper named "Navigation" | 9 | When I generate a helper named "Navigation" |
10 | Then a helper should be generated for "Navigation" | 10 | Then a helper should be generated for "Navigation" |
11 | And a helper test should be generated for "Navigation" | 11 | And a helper test should be generated for "Navigation" |
vendor/plugins/blitz/features/model_generator.feature
@@ -5,21 +5,21 @@ Feature: Rails model generator | @@ -5,21 +5,21 @@ Feature: Rails model generator | ||
5 | 5 | ||
6 | Scenario: Model generator without attributes | 6 | Scenario: Model generator without attributes |
7 | Given a Rails app | 7 | Given a Rails app |
8 | - And the coulda plugin is installed | 8 | + And the blitz plugin is installed |
9 | When I generate a model named "User" | 9 | When I generate a model named "User" |
10 | Then a factory should be generated for "User" | 10 | Then a factory should be generated for "User" |
11 | And a unit test should be generated for "User" | 11 | And a unit test should be generated for "User" |
12 | 12 | ||
13 | Scenario: Model generator with attributes | 13 | Scenario: Model generator with attributes |
14 | Given a Rails app | 14 | Given a Rails app |
15 | - And the coulda plugin is installed | 15 | + And the blitz plugin is installed |
16 | When I generate a model "User" with a string "email" | 16 | When I generate a model "User" with a string "email" |
17 | Then a factory for "User" should have an "email" string | 17 | Then a factory for "User" should have an "email" string |
18 | And a unit test should be generated for "User" | 18 | And a unit test should be generated for "User" |
19 | 19 | ||
20 | Scenario: Model generator with association | 20 | Scenario: Model generator with association |
21 | Given a Rails app | 21 | Given a Rails app |
22 | - And the coulda plugin is installed | 22 | + And the blitz plugin is installed |
23 | When I generate a model "Post" that belongs to a "User" | 23 | When I generate a model "Post" that belongs to a "User" |
24 | Then a factory for "Post" should have an association to "User" | 24 | Then a factory for "Post" should have an association to "User" |
25 | And the "Post" unit test should have "should_belong_to :user" macro | 25 | And the "Post" unit test should have "should_belong_to :user" macro |
@@ -29,7 +29,7 @@ Feature: Rails model generator | @@ -29,7 +29,7 @@ Feature: Rails model generator | ||
29 | 29 | ||
30 | Scenario: Model generator with Paperclip | 30 | Scenario: Model generator with Paperclip |
31 | Given a Rails app | 31 | Given a Rails app |
32 | - And the coulda plugin is installed | 32 | + And the blitz plugin is installed |
33 | When I generate a model "Design" with file "Image" | 33 | When I generate a model "Design" with file "Image" |
34 | Then the "Design" model should have "has_attached_file :image" macro | 34 | Then the "Design" model should have "has_attached_file :image" macro |
35 | And the "Design" unit test should have "should_have_attached_file :image" macro | 35 | And the "Design" unit test should have "should_have_attached_file :image" macro |
vendor/plugins/blitz/features/step_definitions/controller_steps.rb
@@ -18,7 +18,7 @@ Then /^a "create" controller action for "posts" should be generated$/ do | @@ -18,7 +18,7 @@ Then /^a "create" controller action for "posts" should be generated$/ do | ||
18 | " @post = Post.new(params[:post])\n" << | 18 | " @post = Post.new(params[:post])\n" << |
19 | " @post.save\n" << | 19 | " @post.save\n" << |
20 | " flash[:success] = 'Post created.'\n" << | 20 | " flash[:success] = 'Post created.'\n" << |
21 | - " redirect_to posts_path\n" << | 21 | + " redirect_to root_path\n" << |
22 | " end" | 22 | " end" |
23 | end | 23 | end |
24 | end | 24 | end |
@@ -45,7 +45,7 @@ Then /^a "update" controller action for "posts" should be generated$/ do | @@ -45,7 +45,7 @@ Then /^a "update" controller action for "posts" should be generated$/ do | ||
45 | " @post = Post.find(params[:id])\n" << | 45 | " @post = Post.find(params[:id])\n" << |
46 | " @post.update_attributes(params[:post])\n" << | 46 | " @post.update_attributes(params[:post])\n" << |
47 | " flash[:success] = 'Post updated.'\n" << | 47 | " flash[:success] = 'Post updated.'\n" << |
48 | - " redirect_to posts_path\n" << | 48 | + " redirect_to root_path\n" << |
49 | " end" | 49 | " end" |
50 | end | 50 | end |
51 | end | 51 | end |
@@ -56,7 +56,7 @@ Then /^a "destroy" controller action for "posts" should be generated$/ do | @@ -56,7 +56,7 @@ Then /^a "destroy" controller action for "posts" should be generated$/ do | ||
56 | " @post = Post.find(params[:id])\n" << | 56 | " @post = Post.find(params[:id])\n" << |
57 | " @post.destroy\n" << | 57 | " @post.destroy\n" << |
58 | " flash[:success] = 'Post deleted.'\n" << | 58 | " flash[:success] = 'Post deleted.'\n" << |
59 | - " redirect_to posts_path\n" << | 59 | + " redirect_to root_path\n" << |
60 | " end" | 60 | " end" |
61 | end | 61 | end |
62 | end | 62 | end |
vendor/plugins/blitz/features/step_definitions/cucumber_steps.rb
@@ -14,6 +14,7 @@ end | @@ -14,6 +14,7 @@ end | ||
14 | Then /^a "posts" feature for the "([^\"]*)" scenario should be generated$/ do |action| | 14 | Then /^a "posts" feature for the "([^\"]*)" scenario should be generated$/ do |action| |
15 | if %w(new create).include?(action) | 15 | if %w(new create).include?(action) |
16 | assert_generated_file("features/posts.feature") do | 16 | assert_generated_file("features/posts.feature") do |
17 | + "Feature: Posts\n\n" << | ||
17 | " Scenario: Create a new post\n" << | 18 | " Scenario: Create a new post\n" << |
18 | " Given I am on the new post page\n" << | 19 | " Given I am on the new post page\n" << |
19 | " When I create a post named \"A new post\"\n" << | 20 | " When I create a post named \"A new post\"\n" << |
@@ -21,6 +22,7 @@ Then /^a "posts" feature for the "([^\"]*)" scenario should be generated$/ do |a | @@ -21,6 +22,7 @@ Then /^a "posts" feature for the "([^\"]*)" scenario should be generated$/ do |a | ||
21 | end | 22 | end |
22 | elsif %w(edit update).include?(action) | 23 | elsif %w(edit update).include?(action) |
23 | assert_generated_file("features/posts.feature") do | 24 | assert_generated_file("features/posts.feature") do |
25 | + "Feature: Posts\n\n" << | ||
24 | " Scenario: Update a post\n" << | 26 | " Scenario: Update a post\n" << |
25 | " Given I am on the edit \"An existing post\" post page\n" << | 27 | " Given I am on the edit \"An existing post\" post page\n" << |
26 | " When I update the post\n" << | 28 | " When I update the post\n" << |
@@ -32,8 +34,8 @@ end | @@ -32,8 +34,8 @@ end | ||
32 | Then /^a "create posts" step definition should be generated$/ do | 34 | Then /^a "create posts" step definition should be generated$/ do |
33 | assert_generated_file("features/step_definitions/posts_steps.rb") do | 35 | assert_generated_file("features/step_definitions/posts_steps.rb") do |
34 | "When /^I create a post named \"([^\\\"]*)\"$/ do |name|\n" << | 36 | "When /^I create a post named \"([^\\\"]*)\"$/ do |name|\n" << |
35 | - " fills_in :name, :with => name\n" << | ||
36 | - " click_button 'Create'\n" | 37 | + " fill_in :name, :with => name\n" << |
38 | + " click_button 'Create'\n" << | ||
37 | "end" | 39 | "end" |
38 | end | 40 | end |
39 | end | 41 | end |
@@ -48,8 +50,8 @@ end | @@ -48,8 +50,8 @@ end | ||
48 | Then /^a "update posts" step definition should be generated$/ do | 50 | Then /^a "update posts" step definition should be generated$/ do |
49 | assert_generated_file("features/step_definitions/posts_steps.rb") do | 51 | assert_generated_file("features/step_definitions/posts_steps.rb") do |
50 | "When /^I update a post named \"([^\\\"]*)\"$/ do |name|\n" << | 52 | "When /^I update a post named \"([^\\\"]*)\"$/ do |name|\n" << |
51 | - " fills_in :name, :with => name\n" << | ||
52 | - " click_button 'Update'\n" | 53 | + " fill_in :name, :with => name\n" << |
54 | + " click_button 'Update'\n" << | ||
53 | "end" | 55 | "end" |
54 | end | 56 | end |
55 | end | 57 | end |
vendor/plugins/blitz/features/step_definitions/generator_steps.rb
@@ -3,11 +3,11 @@ Given 'a Rails app' do | @@ -3,11 +3,11 @@ Given 'a Rails app' do | ||
3 | @rails_root = File.join(File.dirname(__FILE__), "..", "..", "rails_root") | 3 | @rails_root = File.join(File.dirname(__FILE__), "..", "..", "rails_root") |
4 | end | 4 | end |
5 | 5 | ||
6 | -Given /^the coulda plugin is installed$/ do | 6 | +Given /^the blitz plugin is installed$/ do |
7 | plugin_dir = File.join(@rails_root, "vendor", "plugins") | 7 | plugin_dir = File.join(@rails_root, "vendor", "plugins") |
8 | target = File.join(File.dirname(__FILE__), "..", "..", "generators") | 8 | target = File.join(File.dirname(__FILE__), "..", "..", "generators") |
9 | - FileUtils.mkdir_p "#{plugin_dir}/coulda" | ||
10 | - system "cp -r #{target} #{plugin_dir}/coulda" | 9 | + FileUtils.mkdir_p "#{plugin_dir}/blitz" |
10 | + system "cp -r #{target} #{plugin_dir}/blitz" | ||
11 | end | 11 | end |
12 | 12 | ||
13 | After do | 13 | After do |
vendor/plugins/blitz/features/step_definitions/view_steps.rb
@@ -4,6 +4,12 @@ When /^I generate a "([^\"]*)" view for "([^\"]*)"$/ do |view, resource| | @@ -4,6 +4,12 @@ When /^I generate a "([^\"]*)" view for "([^\"]*)"$/ do |view, resource| | ||
4 | "cd .." | 4 | "cd .." |
5 | end | 5 | end |
6 | 6 | ||
7 | +When /^I generate a "([^\"]*)" view for "([^\"]*)" with the empty option$/ do |view, resource| | ||
8 | + system "cd #{@rails_root} && " << | ||
9 | + "script/generate view #{resource} #{view} --empty && " << | ||
10 | + "cd .." | ||
11 | +end | ||
12 | + | ||
7 | When /^a SemiFormal "new" view for "posts" should be generated$/ do | 13 | When /^a SemiFormal "new" view for "posts" should be generated$/ do |
8 | assert_generated_file("app/views/posts/new.html.erb") do | 14 | assert_generated_file("app/views/posts/new.html.erb") do |
9 | "<h1>New post</h1>\n\n" << | 15 | "<h1>New post</h1>\n\n" << |
@@ -24,8 +30,9 @@ Then /^a SemiFormal "new" view for "posts" should be generated with fields$/ do | @@ -24,8 +30,9 @@ Then /^a SemiFormal "new" view for "posts" should be generated with fields$/ do | ||
24 | "<% form_for(@post) do |form| %>\n" << | 30 | "<% form_for(@post) do |form| %>\n" << |
25 | " <%= form.error_messages %>\n" << | 31 | " <%= form.error_messages %>\n" << |
26 | " <fieldset class=\"inputs\">\n" << | 32 | " <fieldset class=\"inputs\">\n" << |
27 | - " <%= form.string :title %>\n" << | ||
28 | - " <%= form.text :body %>\n" << | 33 | + " <%= form.string :title %>\n" << |
34 | + " <%= form.text :body %>\n" << | ||
35 | + " <%= form.collection :user %>\n" << | ||
29 | " </fieldset>\n" << | 36 | " </fieldset>\n" << |
30 | " <fieldset class=\"buttons\">\n" << | 37 | " <fieldset class=\"buttons\">\n" << |
31 | " <%= form.submit 'Create', :disable_with => 'Please wait...' %>\n" << | 38 | " <%= form.submit 'Create', :disable_with => 'Please wait...' %>\n" << |
@@ -34,3 +41,7 @@ Then /^a SemiFormal "new" view for "posts" should be generated with fields$/ do | @@ -34,3 +41,7 @@ Then /^a SemiFormal "new" view for "posts" should be generated with fields$/ do | ||
34 | end | 41 | end |
35 | end | 42 | end |
36 | 43 | ||
44 | +Then /^an empty "new" view for "posts" should be generated$/ do | ||
45 | + assert_generated_empty_file("app/views/posts/new.html.erb") | ||
46 | +end | ||
47 | + |
vendor/plugins/blitz/features/support/env.rb
@@ -14,6 +14,15 @@ module Test::Unit::Assertions | @@ -14,6 +14,15 @@ module Test::Unit::Assertions | ||
14 | end | 14 | end |
15 | end | 15 | end |
16 | 16 | ||
17 | + def assert_generated_empty_file(path) | ||
18 | + assert_file_exists(path) | ||
19 | + File.open(File.join(@rails_root, path)) do |file| | ||
20 | + body = file.read | ||
21 | + assert body.empty?, | ||
22 | + "expected body to be empty but was #{body.inspect}" | ||
23 | + end | ||
24 | + end | ||
25 | + | ||
17 | def assert_file_exists(path) | 26 | def assert_file_exists(path) |
18 | file = File.join(@rails_root, path) | 27 | file = File.join(@rails_root, path) |
19 | 28 |
vendor/plugins/blitz/features/view_generator.feature
@@ -5,14 +5,21 @@ Feature: Rails view generator | @@ -5,14 +5,21 @@ Feature: Rails view generator | ||
5 | 5 | ||
6 | Scenario: View generator for new action | 6 | Scenario: View generator for new action |
7 | Given a Rails app | 7 | Given a Rails app |
8 | - And the coulda plugin is installed | 8 | + And the blitz plugin is installed |
9 | When I generate a "new" view for "Posts" | 9 | When I generate a "new" view for "Posts" |
10 | Then a SemiFormal "new" view for "posts" should be generated | 10 | Then a SemiFormal "new" view for "posts" should be generated |
11 | 11 | ||
12 | Scenario: View generator for new action | 12 | Scenario: View generator for new action |
13 | Given a Rails app | 13 | Given a Rails app |
14 | - And the coulda plugin is installed | 14 | + And the blitz plugin is installed |
15 | When I generate a Post model with title, body, and User | 15 | When I generate a Post model with title, body, and User |
16 | And I generate a "new" view for "Posts" | 16 | And I generate a "new" view for "Posts" |
17 | Then a SemiFormal "new" view for "posts" should be generated with fields | 17 | Then a SemiFormal "new" view for "posts" should be generated with fields |
18 | 18 | ||
19 | + Scenario: View generator for new action | ||
20 | + Given a Rails app | ||
21 | + And the blitz plugin is installed | ||
22 | + When I generate a Post model with title, body, and User | ||
23 | + When I generate a "new" view for "Posts" with the empty option | ||
24 | + Then an empty "new" view for "posts" should be generated | ||
25 | + |
vendor/plugins/blitz/generators/controller/templates/controller.rb
@@ -15,7 +15,7 @@ class <%= class_name %>Controller < ApplicationController | @@ -15,7 +15,7 @@ class <%= class_name %>Controller < ApplicationController | ||
15 | @<%= resource %> = <%= resource_class %>.new(params[:<%= resource %>]) | 15 | @<%= resource %> = <%= resource_class %>.new(params[:<%= resource %>]) |
16 | @<%= resource %>.save | 16 | @<%= resource %>.save |
17 | flash[:success] = '<%= resource_class %> created.' | 17 | flash[:success] = '<%= resource_class %> created.' |
18 | - redirect_to <%= resources %>_path | 18 | + redirect_to root_path |
19 | end | 19 | end |
20 | 20 | ||
21 | <% end -%> | 21 | <% end -%> |
@@ -36,7 +36,7 @@ class <%= class_name %>Controller < ApplicationController | @@ -36,7 +36,7 @@ class <%= class_name %>Controller < ApplicationController | ||
36 | @<%= resource %> = <%= resource_class %>.find(params[:id]) | 36 | @<%= resource %> = <%= resource_class %>.find(params[:id]) |
37 | @<%= resource %>.update_attributes(params[:<%= resource %>]) | 37 | @<%= resource %>.update_attributes(params[:<%= resource %>]) |
38 | flash[:success] = '<%= resource_class %> updated.' | 38 | flash[:success] = '<%= resource_class %> updated.' |
39 | - redirect_to <%= resources %>_path | 39 | + redirect_to root_path |
40 | end | 40 | end |
41 | 41 | ||
42 | <% end -%> | 42 | <% end -%> |
@@ -45,7 +45,7 @@ class <%= class_name %>Controller < ApplicationController | @@ -45,7 +45,7 @@ class <%= class_name %>Controller < ApplicationController | ||
45 | @<%= resource %> = <%= resource_class %>.find(params[:id]) | 45 | @<%= resource %> = <%= resource_class %>.find(params[:id]) |
46 | @<%= resource %>.destroy | 46 | @<%= resource %>.destroy |
47 | flash[:success] = '<%= resource_class %> deleted.' | 47 | flash[:success] = '<%= resource_class %> deleted.' |
48 | - redirect_to <%= resources %>_path | 48 | + redirect_to root_path |
49 | end | 49 | end |
50 | 50 | ||
51 | <% end -%> | 51 | <% end -%> |
vendor/plugins/blitz/generators/feature/templates/feature.feature
1 | +Feature: <%= resource_class.pluralize %> | ||
2 | + | ||
1 | <% if %w(new create).any? { |action| actions.include?(action) } -%> | 3 | <% if %w(new create).any? { |action| actions.include?(action) } -%> |
2 | Scenario: Create a new <%= resource %> | 4 | Scenario: Create a new <%= resource %> |
3 | Given I am on the new <%= resource %> page | 5 | Given I am on the new <%= resource %> page |
vendor/plugins/blitz/generators/feature/templates/step_definition.rb
1 | <% if %w(new create).any? { |action| actions.include?(action) } -%> | 1 | <% if %w(new create).any? { |action| actions.include?(action) } -%> |
2 | When /^I create a <%= resource %> named "([^\"]*)"$/ do |name| | 2 | When /^I create a <%= resource %> named "([^\"]*)"$/ do |name| |
3 | - fills_in :name, :with => name | 3 | + fill_in :name, :with => name |
4 | click_button 'Create' | 4 | click_button 'Create' |
5 | end | 5 | end |
6 | <% elsif %w(edit update).any? { |action| actions.include?(action) } -%> | 6 | <% elsif %w(edit update).any? { |action| actions.include?(action) } -%> |
7 | When /^I update a post named "([^\"]*)"$/ do |name| | 7 | When /^I update a post named "([^\"]*)"$/ do |name| |
8 | - fills_in :name, :with => name | 8 | + fill_in :name, :with => name |
9 | click_button 'Update' | 9 | click_button 'Update' |
10 | end | 10 | end |
11 | <% end -%> | 11 | <% end -%> |
vendor/plugins/blitz/generators/support/generator_helper.rb
@@ -2,7 +2,7 @@ require File.join(File.dirname(__FILE__), "insert_commands") | @@ -2,7 +2,7 @@ require File.join(File.dirname(__FILE__), "insert_commands") | ||
2 | 2 | ||
3 | module Blitz | 3 | module Blitz |
4 | module GeneratorHelper | 4 | module GeneratorHelper |
5 | - REMOVABLE_COLUMNS = ["created_at", "updated_at", "email_confirmed", | 5 | + REMOVABLE_COLUMNS = ["id", "created_at", "updated_at", "email_confirmed", |
6 | "encrypted_password", "salt", "token", "token_expires_at"] | 6 | "encrypted_password", "salt", "token", "token_expires_at"] |
7 | 7 | ||
8 | def resource | 8 | def resource |
@@ -18,8 +18,8 @@ module Blitz | @@ -18,8 +18,8 @@ module Blitz | ||
18 | end | 18 | end |
19 | 19 | ||
20 | def columns_for_form | 20 | def columns_for_form |
21 | - resource_class.constantize.content_columns. | ||
22 | - collect { |column| [column.name, column.type] }. | 21 | + resource_class.constantize.columns. |
22 | + collect { |column| name_and_type(column) }. | ||
23 | delete_if { |column| remove_column?(column.first) } | 23 | delete_if { |column| remove_column?(column.first) } |
24 | end | 24 | end |
25 | 25 | ||
@@ -30,9 +30,21 @@ module Blitz | @@ -30,9 +30,21 @@ module Blitz | ||
30 | models.include?(resource_class) | 30 | models.include?(resource_class) |
31 | end | 31 | end |
32 | 32 | ||
33 | + def belongs_to_column?(column_name) | ||
34 | + !(column_name =~ /_id$/).nil? | ||
35 | + end | ||
36 | + | ||
37 | + def name_and_type(column) | ||
38 | + if belongs_to_column?(column.name) | ||
39 | + [column.name.gsub("_id", ""), :collection] | ||
40 | + else | ||
41 | + [column.name, column.type] | ||
42 | + end | ||
43 | + end | ||
44 | + | ||
33 | def remove_column?(column) | 45 | def remove_column?(column) |
34 | REMOVABLE_COLUMNS.include?(column) || | 46 | REMOVABLE_COLUMNS.include?(column) || |
35 | - !(column =~ /_id$/).nil? | 47 | + !(column =~ /_count$/).nil? |
36 | end | 48 | end |
37 | end | 49 | end |
38 | end | 50 | end |
vendor/plugins/blitz/generators/view/templates/empty.html.erb
0 → 100644
vendor/plugins/blitz/generators/view/templates/new.html.erb
0 → 100644
@@ -0,0 +1,15 @@ | @@ -0,0 +1,15 @@ | ||
1 | +<h1>New <%= resource %></h1> | ||
2 | + | ||
3 | +<%% form_for(@<%= resource %>) do |form| %> | ||
4 | + <%%= form.error_messages %> | ||
5 | + <fieldset class="inputs"> | ||
6 | +<% if active_record_defined? -%> | ||
7 | +<% columns_for_form.each do |attribute_name, attribute_type| -%> | ||
8 | + <%%= form.<%= attribute_type %> :<%= attribute_name %> %> | ||
9 | +<% end -%> | ||
10 | +<% end -%> | ||
11 | + </fieldset> | ||
12 | + <fieldset class="buttons"> | ||
13 | + <%%= form.submit 'Create', :disable_with => 'Please wait...' %> | ||
14 | + </fieldset> | ||
15 | +<%% end %> |
vendor/plugins/blitz/generators/view/templates/view_new.html.erb
@@ -1,15 +0,0 @@ | @@ -1,15 +0,0 @@ | ||
1 | -<h1>New <%= resource %></h1> | ||
2 | - | ||
3 | -<%% form_for(@<%= resource %>) do |form| %> | ||
4 | - <%%= form.error_messages %> | ||
5 | - <fieldset class="inputs"> | ||
6 | -<% if active_record_defined? -%> | ||
7 | -<% columns_for_form.each do |attribute_name, attribute_type| -%> | ||
8 | - <%%= form.<%= attribute_type %> :<%= attribute_name %> %> | ||
9 | -<% end -%> | ||
10 | -<% end -%> | ||
11 | - </fieldset> | ||
12 | - <fieldset class="buttons"> | ||
13 | - <%%= form.submit 'Create', :disable_with => 'Please wait...' %> | ||
14 | - </fieldset> | ||
15 | -<%% end %> |
vendor/plugins/blitz/generators/view/view_generator.rb
1 | require File.join(File.dirname(__FILE__), "..", "support", "generator_helper") | 1 | require File.join(File.dirname(__FILE__), "..", "support", "generator_helper") |
2 | 2 | ||
3 | class ViewGenerator < Rails::Generator::NamedBase | 3 | class ViewGenerator < Rails::Generator::NamedBase |
4 | + default_options :empty => false | ||
5 | + | ||
4 | def manifest | 6 | def manifest |
5 | record do |m| | 7 | record do |m| |
6 | m.directory File.join('app/views', class_path, file_name) | 8 | m.directory File.join('app/views', class_path, file_name) |
7 | 9 | ||
8 | if actions.include?("new") | 10 | if actions.include?("new") |
9 | path = File.join('app/views', class_path, file_name, "new.html.erb") | 11 | path = File.join('app/views', class_path, file_name, "new.html.erb") |
10 | - m.template 'view_new.html.erb', path | 12 | + if options[:empty] |
13 | + m.file 'empty.html.erb', path | ||
14 | + else | ||
15 | + m.template 'new.html.erb', path | ||
16 | + end | ||
11 | end | 17 | end |
12 | end | 18 | end |
13 | end | 19 | end |
20 | + | ||
21 | + def add_options!(opt) | ||
22 | + opt.on('-e', '--empty') { options[:empty] = true } | ||
23 | + end | ||
14 | end | 24 | end |
vendor/plugins/semi_formal/README.markdown
1 | SemiFormal | 1 | SemiFormal |
2 | ========== | 2 | ========== |
3 | 3 | ||
4 | -A FormBuilder meant to play well with [Coulda](http://github.com/dancroak/coulda) and [Evergreen](http://github.com/dancroak/evergreen). | 4 | +A FormBuilder meant to play well with [Blitz](http://github.com/dancroak/blitz) and [Evergreen](http://github.com/dancroak/evergreen). |
5 | 5 | ||
6 | Examples | 6 | Examples |
7 | -------- | 7 | -------- |
vendor/plugins/semi_formal/lib/semi_formal.rb
@@ -41,6 +41,26 @@ class SemiFormal < ActionView::Helpers::FormBuilder | @@ -41,6 +41,26 @@ class SemiFormal < ActionView::Helpers::FormBuilder | ||
41 | text_area(field, options[:text_area] || {}) + | 41 | text_area(field, options[:text_area] || {}) + |
42 | "<div>" | 42 | "<div>" |
43 | end | 43 | end |
44 | + | ||
45 | + def collection(field, *args) | ||
46 | + options = args.extract_options! | ||
47 | + | ||
48 | + reflection = @object.class.reflect_on_association(field) | ||
49 | + collection = reflection.class.all.collect {|each| [each.name, each.id] } | ||
50 | + | ||
51 | + html_options = {} | ||
52 | + options[:include_blank] = true | ||
53 | + | ||
54 | + if [:has_many, :has_and_belongs_to_many].include?(reflection.macro) | ||
55 | + html_options[:multiple] ||= true | ||
56 | + html_options[:size] ||= 5 | ||
57 | + end | ||
58 | + | ||
59 | + "<div class=\"collection\">" + | ||
60 | + label(field, options[:label] || {}) + | ||
61 | + select(field, collection, options, html_options) | ||
62 | + "<div>" | ||
63 | + end | ||
44 | end | 64 | end |
45 | 65 | ||
46 | ActionView::Base.default_form_builder = SemiFormal | 66 | ActionView::Base.default_form_builder = SemiFormal |