Commit 65e6739cafd5dcb864185a5d65345c83c4dc8738
1 parent
588faac9
Exists in
master
and in
1 other branch
updating SMTP settings to default to Gmail. adding the Coulda plugin.
Showing
29 changed files
with
1147 additions
and
4 deletions
Show diff stats
1 | thoughtbot-clearance --version '>= 0.6.8' --source gems.github.com | 1 | thoughtbot-clearance --version '>= 0.6.8' --source gems.github.com |
2 | -RedCloth --version '= 3.0.4' | 2 | +RedCloth --version '= 4.1.1' |
3 | mislav-will_paginate --version '~> 2.3.11' --source gems.github.com | 3 | mislav-will_paginate --version '~> 2.3.11' --source gems.github.com |
4 | 4 |
config/initializers/mail.rb
1 | +config.action_mailer.delivery_method = :smtp | ||
2 | + | ||
1 | ActionMailer::Base.smtp_settings = { | 3 | ActionMailer::Base.smtp_settings = { |
2 | - :address => "smtp.thoughtbot.com", | ||
3 | - :port => 25, | ||
4 | - :domain => "thoughtbot.com" | 4 | + :tls => true, |
5 | + :address => "smtp.gmail.com", | ||
6 | + :port => "587", | ||
7 | + :domain => "heroku.com", | ||
8 | + :authentication => :plain, | ||
9 | + :user_name => "YOUREMAIL", | ||
10 | + :password => "YOURPASSWORD" | ||
5 | } | 11 | } |
6 | 12 | ||
7 | DO_NOT_REPLY = "donotreply@example.com" | 13 | DO_NOT_REPLY = "donotreply@example.com" |
@@ -0,0 +1,145 @@ | @@ -0,0 +1,145 @@ | ||
1 | +h1. Coulda generators | ||
2 | + | ||
3 | +A plugin that overrides Rails' model, controller, & helper generators. It also adds a view generator. It uses Shoulda & Factory Girl for tests. | ||
4 | + | ||
5 | +h2. Requirements | ||
6 | + | ||
7 | +* "Shoulda":http://github.com/thoughtbot/shoulda | ||
8 | +* "Factory Girl":http://github.com/thoughtbot/factory_girl | ||
9 | + | ||
10 | +h2. Installation | ||
11 | + | ||
12 | + $ script/plugin install git://github.com/dancroak/coulda.git | ||
13 | + | ||
14 | +h2. Model generator | ||
15 | + | ||
16 | + $ script/generate model User | ||
17 | + | ||
18 | +* factory (Factory Girl) | ||
19 | +* unit test (Shoulda) | ||
20 | +* migration | ||
21 | +* model | ||
22 | + | ||
23 | +h2. Controller generator | ||
24 | + | ||
25 | + $ script/generate controller Users new | ||
26 | + | ||
27 | +* functional test (Shoulda & Factory Girl), only test RESTful new action | ||
28 | +* controller, only RESTful new action | ||
29 | +* no helper file | ||
30 | + | ||
31 | +h2. Helper generator | ||
32 | + | ||
33 | + $ script/generate helper Navigation | ||
34 | + | ||
35 | +* empty helper test file | ||
36 | +* empty helper module | ||
37 | + | ||
38 | +h2. View generator | ||
39 | + | ||
40 | + $ script/generate view Posts new | ||
41 | + | ||
42 | +* We're not sure we like this one yet. Let us know what you think. | ||
43 | + | ||
44 | +h2. Model generator: belongs_to | ||
45 | + | ||
46 | + $ script/generate model post user:belongs_to | ||
47 | + | ||
48 | +* "add_index" in the migration | ||
49 | +* "belongs_to" in the model | ||
50 | +* "should_belong_to" in unit test | ||
51 | +* association in the factory | ||
52 | + | ||
53 | +<pre><code>class CreatePosts < ActiveRecord::Migration | ||
54 | + def self.up | ||
55 | + create_table :posts do |t| | ||
56 | + t.belongs_to :user | ||
57 | + t.timestamps | ||
58 | + end | ||
59 | + | ||
60 | + add_index :posts, :user_id | ||
61 | + end | ||
62 | + | ||
63 | + def self.down | ||
64 | + remove_index :posts, :user_id | ||
65 | + drop_table :posts | ||
66 | + end | ||
67 | +end | ||
68 | + | ||
69 | +class Post < ActiveRecord::Base | ||
70 | + belongs_to :user | ||
71 | +end | ||
72 | + | ||
73 | +class PostTest < ActiveSupport::TestCase | ||
74 | + should_belong_to :user | ||
75 | + should_have_index :user_id | ||
76 | +end | ||
77 | + | ||
78 | +Factory.define :post do |post| | ||
79 | + post.association(:user) | ||
80 | +end</code></pre> | ||
81 | + | ||
82 | +h2. Model generator: paperclip | ||
83 | + | ||
84 | + $ script/generate model design image:paperclip | ||
85 | + | ||
86 | +* all the necessary columns in the migration | ||
87 | +* "has_attached_file" in the model | ||
88 | +* "should_have_attached_file" in unit test | ||
89 | + | ||
90 | +<pre><code>class CreateDesigns < ActiveRecord::Migration | ||
91 | + def self.up | ||
92 | + create_table :designs do |t| | ||
93 | + t.string :image_file_name | ||
94 | + t.string :image_content_type | ||
95 | + t.integer :image_file_size | ||
96 | + t.datetime :image_updated_at | ||
97 | + t.timestamps | ||
98 | + end | ||
99 | + end | ||
100 | + | ||
101 | + def self.down | ||
102 | + drop_table :designs | ||
103 | + end | ||
104 | +end | ||
105 | + | ||
106 | +class Design < ActiveRecord::Base | ||
107 | + has_attached_file :image | ||
108 | +end | ||
109 | + | ||
110 | +class DesignTest < ActiveSupport::TestCase | ||
111 | + should "be valid with factory" do | ||
112 | + assert_valid Factory.build(:design) | ||
113 | + end | ||
114 | + should_have_attached_file :image | ||
115 | +end</code></pre> | ||
116 | + | ||
117 | +h2. Attribution | ||
118 | + | ||
119 | +"Mike Breen":http://github.com/hardbap and "Dan Croak":http://github.com/dancroak | ||
120 | + | ||
121 | +Inspired by "shoulda_generator":http://github.com/technicalpickles/shoulda_generator, "model_generator_with_factories":http://github.com/vigetlabs/model_generator_with_factories, and "nifty_generators":http://github.com/ryanb/nifty-generators | ||
122 | + | ||
123 | +h2. License | ||
124 | + | ||
125 | +The MIT License | ||
126 | + | ||
127 | +Copyright (c) 2008, 2009 Mike Breen | ||
128 | + | ||
129 | +Permission is hereby granted, free of charge, to any person obtaining a copy | ||
130 | +of this software and associated documentation files (the "Software"), to deal | ||
131 | +in the Software without restriction, including without limitation the rights | ||
132 | +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
133 | +copies of the Software, and to permit persons to whom the Software is | ||
134 | +furnished to do so, subject to the following conditions: | ||
135 | + | ||
136 | +The above copyright notice and this permission notice shall be included in | ||
137 | +all copies or substantial portions of the Software. | ||
138 | + | ||
139 | +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
140 | +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
141 | +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
142 | +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
143 | +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
144 | +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
145 | +THE SOFTWARE. |
vendor/plugins/coulda/features/controller_generator.feature
0 → 100644
@@ -0,0 +1,61 @@ | @@ -0,0 +1,61 @@ | ||
1 | +Feature: Rails controller generator | ||
2 | + In order to better do Test-Driven Development with Rails | ||
3 | + As a user | ||
4 | + I want to generate Shoulda & Factory Girl tests for only RESTful actions I need. | ||
5 | + | ||
6 | + Scenario: Controller generator for index action | ||
7 | + Given a Rails app | ||
8 | + And the coulda plugin is installed | ||
9 | + When I generate a "Posts" controller with "index" action | ||
10 | + Then a standard "index" functional test for "posts" should be generated | ||
11 | + And an empty "index" controller action for "posts" should be generated | ||
12 | + And only a "index" action for RESTful "posts" route should be generated | ||
13 | + | ||
14 | + Scenario: Controller generator for new action | ||
15 | + Given a Rails app | ||
16 | + And the coulda plugin is installed | ||
17 | + When I generate a "Posts" controller with "new" action | ||
18 | + Then a standard "new" functional test for "posts" should be generated | ||
19 | + And a "new" controller action for "posts" should be generated | ||
20 | + And only a "new" action for RESTful "posts" route should be generated | ||
21 | + | ||
22 | + Scenario: Controller generator for create action | ||
23 | + Given a Rails app | ||
24 | + And the coulda plugin is installed | ||
25 | + When I generate a "Posts" controller with "create" action | ||
26 | + Then a standard "create" functional test for "posts" should be generated | ||
27 | + And a "create" controller action for "posts" should be generated | ||
28 | + And only a "create" action for RESTful "posts" route should be generated | ||
29 | + | ||
30 | + Scenario: Controller generator for show action | ||
31 | + Given a Rails app | ||
32 | + And the coulda plugin is installed | ||
33 | + When I generate a "Posts" controller with "show" action | ||
34 | + Then a standard "show" functional test for "posts" should be generated | ||
35 | + And a "show" controller action for "posts" should be generated | ||
36 | + And only a "show" action for RESTful "posts" route should be generated | ||
37 | + | ||
38 | + Scenario: Controller generator for edit action | ||
39 | + Given a Rails app | ||
40 | + And the coulda plugin is installed | ||
41 | + When I generate a "Posts" controller with "edit" action | ||
42 | + Then a standard "edit" functional test for "posts" should be generated | ||
43 | + And a "edit" controller action for "posts" should be generated | ||
44 | + And only a "edit" action for RESTful "posts" route should be generated | ||
45 | + | ||
46 | + Scenario: Controller generator for update action | ||
47 | + Given a Rails app | ||
48 | + And the coulda plugin is installed | ||
49 | + When I generate a "Posts" controller with "update" action | ||
50 | + Then a standard "update" functional test for "posts" should be generated | ||
51 | + And a "update" controller action for "posts" should be generated | ||
52 | + And only a "update" action for RESTful "posts" route should be generated | ||
53 | + | ||
54 | + Scenario: Controller generator for destroy action | ||
55 | + Given a Rails app | ||
56 | + And the coulda plugin is installed | ||
57 | + When I generate a "Posts" controller with "destroy" action | ||
58 | + Then a standard "destroy" functional test for "posts" should be generated | ||
59 | + And a "destroy" controller action for "posts" should be generated | ||
60 | + And only a "destroy" action for RESTful "posts" route should be generated | ||
61 | + |
@@ -0,0 +1,12 @@ | @@ -0,0 +1,12 @@ | ||
1 | +Feature: Rails helper generator | ||
2 | + In order to better do Test-Driven Development with Rails | ||
3 | + As a user | ||
4 | + I want to generate just the module and test I need. | ||
5 | + | ||
6 | + Scenario: Helper | ||
7 | + Given a Rails app | ||
8 | + And the coulda plugin is installed | ||
9 | + When I generate a helper named "Navigation" | ||
10 | + Then a helper should be generated for "Navigation" | ||
11 | + And a helper test should be generated for "Navigation" | ||
12 | + |
@@ -0,0 +1,37 @@ | @@ -0,0 +1,37 @@ | ||
1 | +Feature: Rails model generator | ||
2 | + In order to better do Test-Driven Development with Rails | ||
3 | + As a user | ||
4 | + I want to generate a Factory definition and Shoulda tests. | ||
5 | + | ||
6 | + Scenario: Model generator without attributes | ||
7 | + Given a Rails app | ||
8 | + And the coulda plugin is installed | ||
9 | + When I generate a model named "User" | ||
10 | + Then a factory should be generated for "User" | ||
11 | + And a unit test should be generated for "User" | ||
12 | + | ||
13 | + Scenario: Model generator with attributes | ||
14 | + Given a Rails app | ||
15 | + And the coulda plugin is installed | ||
16 | + When I generate a model "User" with a string "email" | ||
17 | + Then a factory for "User" should have an "email" string | ||
18 | + And a unit test should be generated for "User" | ||
19 | + | ||
20 | + Scenario: Model generator with association | ||
21 | + Given a Rails app | ||
22 | + And the coulda plugin is installed | ||
23 | + When I generate a model "Post" that belongs to a "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 | ||
26 | + And the "Post" unit test should have "should_have_db_index :user_id" macro | ||
27 | + And the "posts" table should have db index on "user_id" | ||
28 | + And the "Post" model should have "belongs_to :user" macro | ||
29 | + | ||
30 | + Scenario: Model generator with Paperclip | ||
31 | + Given a Rails app | ||
32 | + And the coulda plugin is installed | ||
33 | + When I generate a model "Design" with file "Image" | ||
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 | ||
36 | + And the "designs" table should have paperclip columns for "image" | ||
37 | + |
vendor/plugins/coulda/features/step_definitions/controller_steps.rb
0 → 100644
@@ -0,0 +1,189 @@ | @@ -0,0 +1,189 @@ | ||
1 | +When /^I generate a "(.*)" controller with "(.*)" action$/ do |controller, action| | ||
2 | + system "cd #{@rails_root} && " << | ||
3 | + "script/generate controller #{controller} #{action} && " << | ||
4 | + "cd .." | ||
5 | +end | ||
6 | + | ||
7 | +Then /^a standard "index" functional test for "posts" should be generated$/ do | ||
8 | + assert_generated_functional_test_for("posts") do |body| | ||
9 | + expected = " context 'GET to index' do\n" << | ||
10 | + " setup { get :index }\n\n" << | ||
11 | + " should_render_template :index\n" << | ||
12 | + " should_respond_with :success\n" << | ||
13 | + " end" | ||
14 | + assert body.include?(expected), | ||
15 | + "expected #{expected} but was #{body.inspect}" | ||
16 | + end | ||
17 | +end | ||
18 | + | ||
19 | +Then /^a standard "new" functional test for "posts" should be generated$/ do | ||
20 | + assert_generated_functional_test_for("posts") do |body| | ||
21 | + expected = " context 'GET to new' do\n" << | ||
22 | + " setup { get :new }\n\n" << | ||
23 | + " should_assign_to :post\n" << | ||
24 | + " should_render_template :new\n" << | ||
25 | + " should_respond_with :success\n" << | ||
26 | + " end" | ||
27 | + assert body.include?(expected), | ||
28 | + "expected #{expected} but was #{body.inspect}" | ||
29 | + end | ||
30 | +end | ||
31 | + | ||
32 | +Then /^a standard "create" functional test for "posts" should be generated$/ do | ||
33 | + assert_generated_functional_test_for("posts") do |body| | ||
34 | + expected = " context 'POST to create with valid parameters' do\n" << | ||
35 | + " setup do\n" << | ||
36 | + " post :create, :post => Factory.attributes_for(:post)\n" << | ||
37 | + " end\n\n" << | ||
38 | + " should_create :post\n" << | ||
39 | + " should_set_the_flash_to /created/i\n" << | ||
40 | + " should_redirect_to('posts index') { posts_path }\n" << | ||
41 | + " end" | ||
42 | + assert body.include?(expected), | ||
43 | + "expected #{expected} but was #{body.inspect}" | ||
44 | + end | ||
45 | +end | ||
46 | + | ||
47 | +Then /^a standard "show" functional test for "posts" should be generated$/ do | ||
48 | + assert_generated_functional_test_for("posts") do |body| | ||
49 | + expected = " context 'GET to show for existing post' do\n" << | ||
50 | + " setup do\n" << | ||
51 | + " @post = Factory(:post)\n" << | ||
52 | + " get :show, :id => @post.to_param\n" << | ||
53 | + " end\n\n" << | ||
54 | + " should_assign_to :post, :equals => '@post'\n" << | ||
55 | + " should_render_template :show\n" << | ||
56 | + " should_respond_with :success\n" << | ||
57 | + " end" | ||
58 | + assert body.include?(expected), | ||
59 | + "expected #{expected} but was #{body.inspect}" | ||
60 | + end | ||
61 | +end | ||
62 | + | ||
63 | +Then /^a standard "edit" functional test for "posts" should be generated$/ do | ||
64 | + assert_generated_functional_test_for("posts") do |body| | ||
65 | + expected = " context 'GET to edit for existing post' do\n" << | ||
66 | + " setup do\n" << | ||
67 | + " @post = Factory(:post)\n" << | ||
68 | + " get :edit, :id => @post.to_param\n" << | ||
69 | + " end\n\n" << | ||
70 | + " should_assign_to :post, :equals => '@post'\n" << | ||
71 | + " should_render_template :edit\n" << | ||
72 | + " should_respond_with :success\n" << | ||
73 | + " end" | ||
74 | + assert body.include?(expected), | ||
75 | + "expected #{expected} but was #{body.inspect}" | ||
76 | + end | ||
77 | +end | ||
78 | + | ||
79 | +Then /^a standard "update" functional test for "posts" should be generated$/ do | ||
80 | + assert_generated_functional_test_for("posts") do |body| | ||
81 | + expected = " context 'PUT to update for existing post' do\n" << | ||
82 | + " setup do\n" << | ||
83 | + " @post = Factory(:post)\n" << | ||
84 | + " put :update, :id => @post.to_param,\n" << | ||
85 | + " :post => Factory.attributes_for(:post)\n" << | ||
86 | + " end\n\n" << | ||
87 | + " should_set_the_flash_to /updated/i\n" << | ||
88 | + " should_redirect_to('posts index') { posts_path }\n" << | ||
89 | + " end" | ||
90 | + assert body.include?(expected), | ||
91 | + "expected #{expected} but was #{body.inspect}" | ||
92 | + end | ||
93 | +end | ||
94 | + | ||
95 | +Then /^a standard "destroy" functional test for "posts" should be generated$/ do | ||
96 | + assert_generated_functional_test_for("posts") do |body| | ||
97 | + expected = " context 'given a post' do\n" << | ||
98 | + " setup { @post = Factory(:post) }\n\n" << | ||
99 | + " context 'DELETE to destroy' do\n" << | ||
100 | + " setup { delete :destroy, :id => @post.to_param }\n\n" << | ||
101 | + " should_destroy :post\n" << | ||
102 | + " should_set_the_flash_to /deleted/i\n" << | ||
103 | + " should_redirect_to('posts index') { posts_path }\n" << | ||
104 | + " end\n" << | ||
105 | + " end" | ||
106 | + assert body.include?(expected), | ||
107 | + "expected #{expected} but was #{body.inspect}" | ||
108 | + end | ||
109 | +end | ||
110 | + | ||
111 | +Then /^a "new" controller action for "posts" should be generated$/ do | ||
112 | + assert_generated_controller_for("posts") do |body| | ||
113 | + expected = " def new\n" << | ||
114 | + " @post = Post.new\n" << | ||
115 | + " end" | ||
116 | + assert body.include?(expected), | ||
117 | + "expected #{expected} but was #{body.inspect}" | ||
118 | + end | ||
119 | +end | ||
120 | + | ||
121 | +Then /^a "create" controller action for "posts" should be generated$/ do | ||
122 | + assert_generated_controller_for("posts") do |body| | ||
123 | + expected = " def create\n" << | ||
124 | + " @post = Post.new(params[:post])\n" << | ||
125 | + " @post.save\n" << | ||
126 | + " flash[:success] = 'Post created.'\n" << | ||
127 | + " redirect_to posts_path\n" << | ||
128 | + " end" | ||
129 | + assert body.include?(expected), | ||
130 | + "expected #{expected} but was #{body.inspect}" | ||
131 | + end | ||
132 | +end | ||
133 | + | ||
134 | +Then /^a "show" controller action for "posts" should be generated$/ do | ||
135 | + assert_generated_controller_for("posts") do |body| | ||
136 | + expected = " def show\n" << | ||
137 | + " @post = Post.find(params[:id])\n" << | ||
138 | + " end" | ||
139 | + assert body.include?(expected), | ||
140 | + "expected #{expected} but was #{body.inspect}" | ||
141 | + end | ||
142 | +end | ||
143 | + | ||
144 | +Then /^a "edit" controller action for "posts" should be generated$/ do | ||
145 | + assert_generated_controller_for("posts") do |body| | ||
146 | + expected = " def edit\n" << | ||
147 | + " @post = Post.find(params[:id])\n" << | ||
148 | + " end" | ||
149 | + assert body.include?(expected), | ||
150 | + "expected #{expected} but was #{body.inspect}" | ||
151 | + end | ||
152 | +end | ||
153 | + | ||
154 | +Then /^a "update" controller action for "posts" should be generated$/ do | ||
155 | + assert_generated_controller_for("posts") do |body| | ||
156 | + expected = " def update\n" << | ||
157 | + " @post = Post.find(params[:id])\n" << | ||
158 | + " @post.update_attributes(params[:post])\n" << | ||
159 | + " flash[:success] = 'Post updated.'\n" << | ||
160 | + " redirect_to posts_path\n" << | ||
161 | + " end" | ||
162 | + assert body.include?(expected), | ||
163 | + "expected #{expected} but was #{body.inspect}" | ||
164 | + end | ||
165 | +end | ||
166 | + | ||
167 | +Then /^a "destroy" controller action for "posts" should be generated$/ do | ||
168 | + assert_generated_controller_for("posts") do |body| | ||
169 | + expected = " def destroy\n" << | ||
170 | + " @post = Post.find(params[:id])\n" << | ||
171 | + " @post.destroy\n" << | ||
172 | + " flash[:success] = 'Post deleted.'\n" << | ||
173 | + " redirect_to posts_path\n" << | ||
174 | + " end" | ||
175 | + assert body.include?(expected), | ||
176 | + "expected #{expected} but was #{body.inspect}" | ||
177 | + end | ||
178 | +end | ||
179 | + | ||
180 | +Then /^an empty "(.*)" controller action for "(.*)" should be generated$/ do |action, controller| | ||
181 | + assert_generated_controller_for(controller) do |body| | ||
182 | + assert_has_empty_method(body, action) | ||
183 | + end | ||
184 | +end | ||
185 | + | ||
186 | +Then /^only a "([^\"]*)" action for RESTful "([^\"]*)" route should be generated$/ do |action, resource| | ||
187 | + assert_generated_route_for resource, action | ||
188 | +end | ||
189 | + |
vendor/plugins/coulda/features/step_definitions/generator_steps.rb
0 → 100644
@@ -0,0 +1,16 @@ | @@ -0,0 +1,16 @@ | ||
1 | +Given 'a Rails app' do | ||
2 | + system "rails rails_root" | ||
3 | + @rails_root = File.join(File.dirname(__FILE__), "..", "..", "rails_root") | ||
4 | +end | ||
5 | + | ||
6 | +Given /^the coulda plugin is installed$/ do | ||
7 | + plugin_dir = File.join(@rails_root, "vendor", "plugins") | ||
8 | + target = File.join(File.dirname(__FILE__), "..", "..", "generators") | ||
9 | + FileUtils.mkdir_p "#{plugin_dir}/coulda" | ||
10 | + system "cp -r #{target} #{plugin_dir}/coulda" | ||
11 | +end | ||
12 | + | ||
13 | +After do | ||
14 | + FileUtils.rm_rf @rails_root if @rails_root | ||
15 | +end | ||
16 | + |
vendor/plugins/coulda/features/step_definitions/helper_steps.rb
0 → 100644
@@ -0,0 +1,14 @@ | @@ -0,0 +1,14 @@ | ||
1 | +When /^I generate a helper named "(.*)"$/ do |name| | ||
2 | + system "cd #{@rails_root} && " << | ||
3 | + "script/generate helper #{name} && " << | ||
4 | + "cd .." | ||
5 | +end | ||
6 | + | ||
7 | +Then /^a helper should be generated for "(.*)"$/ do |name| | ||
8 | + assert_generated_helper_for(name) | ||
9 | +end | ||
10 | + | ||
11 | +Then /^a helper test should be generated for "(.*)"$/ do |name| | ||
12 | + assert_generated_helper_test_for(name) | ||
13 | +end | ||
14 | + |
vendor/plugins/coulda/features/step_definitions/migration_steps.rb
0 → 100644
@@ -0,0 +1,14 @@ | @@ -0,0 +1,14 @@ | ||
1 | +Then /^the paperclip migration should add "(.*)" columns to the "(.*)"$/ do |attr, table| | ||
2 | + up = " add_column :#{table}, :#{attr}_file_name, :string\n" << | ||
3 | + " add_column :#{table}, :#{attr}_content_type, :string\n" << | ||
4 | + " add_column :#{table}, :#{attr}_file_size, :integer\n" << | ||
5 | + " add_column :#{table}, :#{attr}_updated_at, :datetime" | ||
6 | + down = " remove_column :#{table}, :#{attr}_file_name\n" << | ||
7 | + " remove_column :#{table}, :#{attr}_content_type\n" << | ||
8 | + " remove_column :#{table}, :#{attr}_file_size\n" << | ||
9 | + " remove_column :#{table}, :#{attr}_updated_at" | ||
10 | + assert_generated_migration(table) do |body| | ||
11 | + assert body.include?(up), body.inspect | ||
12 | + assert body.include?(down), body.inspect | ||
13 | + end | ||
14 | +end |
vendor/plugins/coulda/features/step_definitions/model_steps.rb
0 → 100644
@@ -0,0 +1,122 @@ | @@ -0,0 +1,122 @@ | ||
1 | +# GENERATION | ||
2 | + | ||
3 | +When /^I generate a model named "(.*)"$/ do |model| | ||
4 | + system "cd #{@rails_root} && " << | ||
5 | + "script/generate model #{model} && " << | ||
6 | + "cd .." | ||
7 | +end | ||
8 | + | ||
9 | +When /^I generate a model "(.*)" with a (.*) "(.*)"$/ do |model, attr_type, attr_name| | ||
10 | + system "cd #{@rails_root} && " << | ||
11 | + "script/generate model #{model} #{attr_name}:#{attr_type} && " << | ||
12 | + "cd .." | ||
13 | +end | ||
14 | + | ||
15 | +When /^I generate a model "(.*)" that belongs to a "(.*)"$/ do |model, association| | ||
16 | + association.downcase! | ||
17 | + system "cd #{@rails_root} && " << | ||
18 | + "script/generate model #{model} #{association}:belongs_to && " << | ||
19 | + "cd .." | ||
20 | +end | ||
21 | + | ||
22 | +When /^I generate a model "(.*)" with file "(.*)"$/ do |model, file| | ||
23 | + file.downcase! | ||
24 | + system "cd #{@rails_root} && " << | ||
25 | + "script/generate model #{model} #{file}:paperclip && " << | ||
26 | + "cd .." | ||
27 | +end | ||
28 | + | ||
29 | +# MODEL | ||
30 | + | ||
31 | +Then /^a model with comments should be generated for "(.*)"$/ do |model| | ||
32 | + model.downcase! | ||
33 | + assert_generated_model_for(model) do |body| | ||
34 | + comments = [] | ||
35 | + comments << "# includes: mixed in behavior" << | ||
36 | + "# properties: attributes, associations" << | ||
37 | + "# lifecycle: validations, callbacks" << | ||
38 | + "# class methods: self.method, named_scopes" << | ||
39 | + "# instance methods" << | ||
40 | + "# non-public interface: protected helpers" | ||
41 | + comments.each do |comment| | ||
42 | + assert body.include?(comment), body.inspect | ||
43 | + end | ||
44 | + end | ||
45 | +end | ||
46 | + | ||
47 | +Then /^the "(.*)" model should have "(.*)" macro$/ do |model, macro| | ||
48 | + model.downcase! | ||
49 | + assert_generated_model_for(model) do |body| | ||
50 | + assert body.include?(macro), body.inspect | ||
51 | + end | ||
52 | +end | ||
53 | + | ||
54 | +# FACTORY | ||
55 | + | ||
56 | +Then /^a factory should be generated for "(.*)"$/ do |model| | ||
57 | + model.downcase! | ||
58 | + assert_generated_factory_for(model) do |body| | ||
59 | + expected = "Factory.define :#{model.downcase} do |#{model.downcase}|\n" << | ||
60 | + "end\n" | ||
61 | + assert_equal expected, body | ||
62 | + end | ||
63 | +end | ||
64 | + | ||
65 | +Then /^a factory for "(.*)" should have an? "(.*)" (.*)$/ do |model, attr_name, attr_type| | ||
66 | + model.downcase! | ||
67 | + assert_generated_factory_for(model) do |body| | ||
68 | + expected = "Factory.define :#{model} do |#{model}|\n" << | ||
69 | + " #{model}.#{attr_name} { '#{attr_type}' }\n" << | ||
70 | + "end\n" | ||
71 | + assert_equal expected, body | ||
72 | + end | ||
73 | +end | ||
74 | + | ||
75 | +Then /^a factory for "(.*)" should have an association to "(.*)"$/ do |model, associated_model| | ||
76 | + model.downcase! | ||
77 | + associated_model.downcase! | ||
78 | + assert_generated_factory_for(model) do |body| | ||
79 | + expected = "Factory.define :#{model} do |#{model}|\n" << | ||
80 | + " #{model}.association(:#{associated_model})\n" << | ||
81 | + "end\n" | ||
82 | + assert_equal expected, body | ||
83 | + end | ||
84 | +end | ||
85 | + | ||
86 | +# UNIT TEST | ||
87 | + | ||
88 | +Then /^a unit test should be generated for "(.*)"$/ do |model| | ||
89 | + model.downcase! | ||
90 | + assert_generated_unit_test_for(model) do |body| | ||
91 | + match = "assert_valid Factory.build(:#{model})" | ||
92 | + assert body.include?(match), body.inspect | ||
93 | + end | ||
94 | +end | ||
95 | + | ||
96 | +Then /^the "(.*)" unit test should have "(.*)" macro$/ do |model, macro| | ||
97 | + model.downcase! | ||
98 | + assert_generated_unit_test_for(model) do |body| | ||
99 | + assert body.include?(macro), body.inspect | ||
100 | + end | ||
101 | +end | ||
102 | + | ||
103 | +# MIGRATION | ||
104 | + | ||
105 | +Then /^the "(.*)" table should have db index on "(.*)"$/ do |table, foreign_key| | ||
106 | + assert_generated_migration(table) do |body| | ||
107 | + index = "add_index :#{table}, :#{foreign_key}" | ||
108 | + assert body.include?(index), body.inspect | ||
109 | + end | ||
110 | +end | ||
111 | + | ||
112 | +Then /^the "(.*)" table should have paperclip columns for "(.*)"$/ do |table, attr| | ||
113 | + up = " table.string :#{attr}_file_name\n" << | ||
114 | + " table.string :#{attr}_content_type\n" << | ||
115 | + " table.integer :#{attr}_file_size\n" << | ||
116 | + " table.datetime :#{attr}_updated_at" | ||
117 | + assert_generated_migration(table) do |body| | ||
118 | + assert body.include?(up), body.inspect | ||
119 | + end | ||
120 | +end | ||
121 | + | ||
122 | + |
vendor/plugins/coulda/features/step_definitions/view_steps.rb
0 → 100644
@@ -0,0 +1,104 @@ | @@ -0,0 +1,104 @@ | ||
1 | +require 'test/unit' | ||
2 | + | ||
3 | +module Test::Unit::Assertions | ||
4 | + | ||
5 | + def assert_generated_controller_for(name) | ||
6 | + assert_generated_file "app/controllers/#{name}_controller.rb" do |body| | ||
7 | + yield body if block_given? | ||
8 | + end | ||
9 | + end | ||
10 | + | ||
11 | + def assert_generated_model_for(name) | ||
12 | + assert_generated_file "app/models/#{name}.rb" do |body| | ||
13 | + yield body if block_given? | ||
14 | + end | ||
15 | + end | ||
16 | + | ||
17 | + def assert_generated_helper_for(name) | ||
18 | + assert_generated_file "app/helpers/#{name}_helper.rb" do |body| | ||
19 | + yield body if block_given? | ||
20 | + end | ||
21 | + end | ||
22 | + | ||
23 | + def assert_generated_factory_for(name) | ||
24 | + assert_generated_file "test/factories/#{name}.rb" do |body| | ||
25 | + yield body if block_given? | ||
26 | + end | ||
27 | + end | ||
28 | + | ||
29 | + def assert_generated_functional_test_for(name) | ||
30 | + assert_generated_file "test/functional/#{name}_controller_test.rb" do |body| | ||
31 | + yield body if block_given? | ||
32 | + end | ||
33 | + end | ||
34 | + | ||
35 | + def assert_generated_unit_test_for(name) | ||
36 | + assert_generated_file "test/unit/#{name}_test.rb" do |body| | ||
37 | + yield body if block_given? | ||
38 | + end | ||
39 | + end | ||
40 | + | ||
41 | + def assert_generated_helper_test_for(name) | ||
42 | + assert_generated_file "test/unit/helpers/#{name}_helper_test.rb" do |body| | ||
43 | + yield body if block_given? | ||
44 | + end | ||
45 | + end | ||
46 | + | ||
47 | + def assert_generated_file(path) | ||
48 | + assert_file_exists(path) | ||
49 | + File.open(File.join(@rails_root, path)) do |file| | ||
50 | + yield file.read if block_given? | ||
51 | + end | ||
52 | + end | ||
53 | + | ||
54 | + def assert_file_exists(path) | ||
55 | + file = File.join(@rails_root, path) | ||
56 | + | ||
57 | + assert File.exists?(file), "#{file} expected to exist, but did not" | ||
58 | + assert File.file?(file), "#{file} expected to be a file, but is not" | ||
59 | + end | ||
60 | + | ||
61 | + def assert_generated_views_for(name, *actions) | ||
62 | + actions.each do |action| | ||
63 | + assert_generated_file("app/views/#{name}/#{action}.html.erb") do |body| | ||
64 | + yield body if block_given? | ||
65 | + end | ||
66 | + end | ||
67 | + end | ||
68 | + | ||
69 | + def assert_generated_migration(name) | ||
70 | + file = Dir.glob("#{@rails_root}/db/migrate/*_#{name}.rb").first | ||
71 | + file = file.match(/db\/migrate\/[0-9]+_\w+/).to_s << ".rb" | ||
72 | + assert_generated_file file do |body| | ||
73 | + assert_match /timestamps/, body, "should have timestamps defined" | ||
74 | + yield body if block_given? | ||
75 | + end | ||
76 | + end | ||
77 | + | ||
78 | + def assert_generated_route_for(name, *actions) | ||
79 | + assert_generated_file("config/routes.rb") do |body| | ||
80 | + routeable_actions = actions.collect { |action| ":#{action}" }.join(", ") | ||
81 | + expected = " map.resources :#{name.to_s}, :only => [#{routeable_actions}]" | ||
82 | + assert body.include?(expected), | ||
83 | + "expected #{expected} but was #{body.inspect}" | ||
84 | + end | ||
85 | + end | ||
86 | + | ||
87 | + def assert_has_empty_method(body, *methods) | ||
88 | + methods.each do |name| | ||
89 | + assert body.include?(" def #{name}\n end"), | ||
90 | + "should have method #{name} in #{body.inspect}" | ||
91 | + yield(name, $2) if block_given? | ||
92 | + end | ||
93 | + end | ||
94 | + | ||
95 | +end | ||
96 | + | ||
97 | +class CouldaWorld | ||
98 | + include Test::Unit::Assertions | ||
99 | +end | ||
100 | + | ||
101 | +World do | ||
102 | + CouldaWorld.new | ||
103 | +end | ||
104 | + |
vendor/plugins/coulda/generators/controller/controller_generator.rb
0 → 100644
@@ -0,0 +1,29 @@ | @@ -0,0 +1,29 @@ | ||
1 | +require File.join(File.dirname(__FILE__), "..", "support", "insert_commands") | ||
2 | + | ||
3 | +class ControllerGenerator < Rails::Generator::NamedBase | ||
4 | + def manifest | ||
5 | + record do |m| | ||
6 | + m.class_collisions "#{class_name}Controller", "#{class_name}ControllerTest" | ||
7 | + | ||
8 | + m.directory File.join('app/controllers', class_path) | ||
9 | + m.directory File.join('test/functional', class_path) | ||
10 | + | ||
11 | + m.template 'controller.rb', | ||
12 | + File.join('app/controllers', | ||
13 | + class_path, | ||
14 | + "#{file_name}_controller.rb") | ||
15 | + | ||
16 | + m.template 'functional_test.rb', | ||
17 | + File.join('test/functional', | ||
18 | + class_path, | ||
19 | + "#{file_name}_controller_test.rb") | ||
20 | + | ||
21 | + m.insert_into "config/routes.rb", | ||
22 | + "map.resources :#{file_name}, :only => [#{routeable_actions}]" | ||
23 | + end | ||
24 | + end | ||
25 | + | ||
26 | + def routeable_actions | ||
27 | + actions.collect { |action| ":#{action}" }.join(", ") | ||
28 | + end | ||
29 | +end |
vendor/plugins/coulda/generators/controller/templates/controller.rb
0 → 100644
@@ -0,0 +1,56 @@ | @@ -0,0 +1,56 @@ | ||
1 | +class <%= class_name %>Controller < ApplicationController | ||
2 | +<% resource = file_name.singularize -%> | ||
3 | +<% resources = file_name.pluralize -%> | ||
4 | +<% resource_class = class_name.singularize -%> | ||
5 | + | ||
6 | +<% if actions.include?("index") -%> | ||
7 | + def index | ||
8 | + end | ||
9 | + | ||
10 | +<% end -%> | ||
11 | +<% if actions.include?("new") -%> | ||
12 | + def new | ||
13 | + @<%= resource %> = <%= resource_class %>.new | ||
14 | + end | ||
15 | + | ||
16 | +<% end -%> | ||
17 | +<% if actions.include?("create") -%> | ||
18 | + def create | ||
19 | + @<%= resource %> = <%= resource_class %>.new(params[:<%= resource %>]) | ||
20 | + @<%= resource %>.save | ||
21 | + flash[:success] = '<%= resource_class %> created.' | ||
22 | + redirect_to <%= resources %>_path | ||
23 | + end | ||
24 | + | ||
25 | +<% end -%> | ||
26 | +<% if actions.include?("show") -%> | ||
27 | + def show | ||
28 | + @<%= resource %> = <%= resource_class %>.find(params[:id]) | ||
29 | + end | ||
30 | + | ||
31 | +<% end -%> | ||
32 | +<% if actions.include?("edit") -%> | ||
33 | + def edit | ||
34 | + @<%= resource %> = <%= resource_class %>.find(params[:id]) | ||
35 | + end | ||
36 | + | ||
37 | +<% end -%> | ||
38 | +<% if actions.include?("update") -%> | ||
39 | + def update | ||
40 | + @<%= resource %> = <%= resource_class %>.find(params[:id]) | ||
41 | + @<%= resource %>.update_attributes(params[:<%= resource %>]) | ||
42 | + flash[:success] = '<%= resource_class %> updated.' | ||
43 | + redirect_to <%= resources %>_path | ||
44 | + end | ||
45 | + | ||
46 | +<% end -%> | ||
47 | +<% if actions.include?("destroy") -%> | ||
48 | + def destroy | ||
49 | + @<%= resource %> = <%= resource_class %>.find(params[:id]) | ||
50 | + @<%= resource %>.destroy | ||
51 | + flash[:success] = '<%= resource_class %> deleted.' | ||
52 | + redirect_to <%= resources %>_path | ||
53 | + end | ||
54 | + | ||
55 | +<% end -%> | ||
56 | +end |
vendor/plugins/coulda/generators/controller/templates/functional_test.rb
0 → 100644
@@ -0,0 +1,93 @@ | @@ -0,0 +1,93 @@ | ||
1 | +require 'test_helper' | ||
2 | + | ||
3 | +class <%= class_name %>ControllerTest < ActionController::TestCase | ||
4 | +<% resource = file_name.singularize -%> | ||
5 | +<% resources = file_name.pluralize -%> | ||
6 | +<% resource_class = class_name.singularize -%> | ||
7 | + | ||
8 | +<% if actions.include?("index") -%> | ||
9 | + context 'GET to index' do | ||
10 | + setup { get :index } | ||
11 | + | ||
12 | + should_render_template :index | ||
13 | + should_respond_with :success | ||
14 | + end | ||
15 | + | ||
16 | +<% end -%> | ||
17 | +<% if actions.include?("new") -%> | ||
18 | + context 'GET to new' do | ||
19 | + setup { get :new } | ||
20 | + | ||
21 | + should_assign_to :<%= resource %> | ||
22 | + should_render_template :new | ||
23 | + should_respond_with :success | ||
24 | + end | ||
25 | + | ||
26 | +<% end -%> | ||
27 | +<% if actions.include?("create") -%> | ||
28 | + context 'POST to create with valid parameters' do | ||
29 | + setup do | ||
30 | + post :create, :<%= resource %> => Factory.attributes_for(:<%= resource %>) | ||
31 | + end | ||
32 | + | ||
33 | + should_create :<%= resource %> | ||
34 | + should_set_the_flash_to /created/i | ||
35 | + should_redirect_to('<%= resources %> index') { <%= resources %>_path } | ||
36 | + end | ||
37 | + | ||
38 | +<% end -%> | ||
39 | +<% if actions.include?("show") -%> | ||
40 | + context 'GET to show for existing <%= resource %>' do | ||
41 | + setup do | ||
42 | + @<%= resource %> = Factory(:<%= resource %>) | ||
43 | + get :show, :id => @<%= resource %>.to_param | ||
44 | + end | ||
45 | + | ||
46 | + should_assign_to :<%= resource %>, :equals => '@<%= resource %>' | ||
47 | + should_render_template :show | ||
48 | + should_respond_with :success | ||
49 | + end | ||
50 | + | ||
51 | +<% end -%> | ||
52 | +<% if actions.include?("edit") -%> | ||
53 | + context 'GET to edit for existing <%= resource %>' do | ||
54 | + setup do | ||
55 | + @<%= resource %> = Factory(:<%= resource %>) | ||
56 | + get :edit, :id => @<%= resource %>.to_param | ||
57 | + end | ||
58 | + | ||
59 | + should_assign_to :<%= resource %>, :equals => '@<%= resource %>' | ||
60 | + should_render_template :edit | ||
61 | + should_respond_with :success | ||
62 | + end | ||
63 | + | ||
64 | +<% end -%> | ||
65 | +<% if actions.include?("update") -%> | ||
66 | + context 'PUT to update for existing <%= resource %>' do | ||
67 | + setup do | ||
68 | + @<%= resource %> = Factory(:<%= resource %>) | ||
69 | + put :update, :id => @<%= resource %>.to_param, | ||
70 | + :<%= resource %> => Factory.attributes_for(:<%= resource %>) | ||
71 | + end | ||
72 | + | ||
73 | + should_set_the_flash_to /updated/i | ||
74 | + should_redirect_to('<%= resources %> index') { <%= resources %>_path } | ||
75 | + end | ||
76 | + | ||
77 | +<% end -%> | ||
78 | +<% if actions.include?("destroy") -%> | ||
79 | + context 'given a <%= resource %>' do | ||
80 | + setup { @<%= resource %> = Factory(:<%= resource %>) } | ||
81 | + | ||
82 | + context 'DELETE to destroy' do | ||
83 | + setup { delete :destroy, :id => @<%= resource %>.to_param } | ||
84 | + | ||
85 | + should_destroy :<%= resource %> | ||
86 | + should_set_the_flash_to /deleted/i | ||
87 | + should_redirect_to('<%= resources %> index') { <%= resources %>_path } | ||
88 | + end | ||
89 | + end | ||
90 | + | ||
91 | +<% end -%> | ||
92 | +end | ||
93 | + |
vendor/plugins/coulda/generators/helper/helper_generator.rb
0 → 100644
@@ -0,0 +1,23 @@ | @@ -0,0 +1,23 @@ | ||
1 | +class HelperGenerator < Rails::Generator::NamedBase | ||
2 | + def manifest | ||
3 | + record do |m| | ||
4 | + # Check for class naming collisions. | ||
5 | + m.class_collisions "#{class_name}Helper", "#{class_name}HelperTest" | ||
6 | + | ||
7 | + # Helper and test directories. | ||
8 | + m.directory File.join('app/helpers', class_path) | ||
9 | + m.directory File.join('test/unit/helpers', class_path) | ||
10 | + | ||
11 | + # Helper module and test. | ||
12 | + m.template 'helper.rb', | ||
13 | + File.join('app/helpers', | ||
14 | + class_path, | ||
15 | + "#{file_name}_helper.rb") | ||
16 | + | ||
17 | + m.template 'helper_test.rb', | ||
18 | + File.join('test/unit/helpers', | ||
19 | + class_path, | ||
20 | + "#{file_name}_helper_test.rb") | ||
21 | + end | ||
22 | + end | ||
23 | +end |
vendor/plugins/coulda/generators/helper/templates/helper.rb
0 → 100644
vendor/plugins/coulda/generators/helper/templates/helper_test.rb
0 → 100644
vendor/plugins/coulda/generators/model/model_generator.rb
0 → 100644
@@ -0,0 +1,79 @@ | @@ -0,0 +1,79 @@ | ||
1 | +class ModelGenerator < Rails::Generator::NamedBase | ||
2 | + default_options :skip_timestamps => false, | ||
3 | + :skip_migration => false, | ||
4 | + :skip_factories => false | ||
5 | + | ||
6 | + def manifest | ||
7 | + record do |m| | ||
8 | + # Check for class naming collisions. | ||
9 | + m.class_collisions class_name, "#{class_name}Test" | ||
10 | + | ||
11 | + # Model, test, and factories directories. | ||
12 | + m.directory File.join('app/models', class_path) | ||
13 | + m.directory File.join('test/unit', class_path) | ||
14 | + m.directory File.join('test/factories', class_path) | ||
15 | + | ||
16 | + # Model class, unit test, and factories. | ||
17 | + m.template 'model.rb', File.join('app/models', class_path, | ||
18 | + "#{file_name}.rb") | ||
19 | + m.template 'unit_test.rb', File.join('test/unit', class_path, | ||
20 | + "#{file_name}_test.rb") | ||
21 | + | ||
22 | + m.template 'factory.rb', File.join('test/factories', "#{file_name}.rb") | ||
23 | + | ||
24 | + unless options[:skip_migration] | ||
25 | + m.migration_template 'migration.rb', 'db/migrate', :assigns => { | ||
26 | + :migration_name => "Create#{class_name.pluralize.gsub(/::/, '')}" | ||
27 | + }, :migration_file_name => "create_#{file_path.gsub(/\//, '_').pluralize}" | ||
28 | + end | ||
29 | + end | ||
30 | + end | ||
31 | + | ||
32 | + def factory_line(attribute, file_name) | ||
33 | + if attribute.reference? | ||
34 | + "#{file_name}.association(:#{attribute.name})" | ||
35 | + else | ||
36 | + "#{file_name}.#{attribute.name} #{attribute.default_for_factory}" | ||
37 | + end | ||
38 | + end | ||
39 | + | ||
40 | + protected | ||
41 | + | ||
42 | + def banner | ||
43 | + "Usage: #{$0} #{spec.name} ModelName [field:type, field:type]" | ||
44 | + end | ||
45 | + | ||
46 | + def add_options!(opt) | ||
47 | + opt.separator '' | ||
48 | + opt.separator 'Options:' | ||
49 | + opt.on("--skip-timestamps", | ||
50 | + "Don't add timestamps to the migration file for this model") { |v| | ||
51 | + options[:skip_timestamps] = v | ||
52 | + } | ||
53 | + opt.on("--skip-migration", | ||
54 | + "Don't generate a migration file for this model") { |v| | ||
55 | + options[:skip_migration] = v | ||
56 | + } | ||
57 | + end | ||
58 | +end | ||
59 | + | ||
60 | +module Rails | ||
61 | + module Generator | ||
62 | + class GeneratedAttribute | ||
63 | + def default_for_factory | ||
64 | + @default ||= case type | ||
65 | + when :integer then "{ 1 }" | ||
66 | + when :float then "{ 1.5 }" | ||
67 | + when :decimal then "{ 9.99 }" | ||
68 | + when :datetime, :timestamp, :time then "{ Time.now.to_s(:db) }" | ||
69 | + when :date then "{ Date.today.to_s(:db) }" | ||
70 | + when :string then "{ 'string' }" | ||
71 | + when :text then "{ 'text' }" | ||
72 | + when :boolean then "{ false }" | ||
73 | + else | ||
74 | + "" | ||
75 | + end | ||
76 | + end | ||
77 | + end | ||
78 | + end | ||
79 | +end |
vendor/plugins/coulda/generators/model/templates/factory.rb
0 → 100644
vendor/plugins/coulda/generators/model/templates/migration.rb
0 → 100644
@@ -0,0 +1,30 @@ | @@ -0,0 +1,30 @@ | ||
1 | +class <%= migration_name %> < ActiveRecord::Migration | ||
2 | + def self.up | ||
3 | + create_table :<%= table_name %> do |table| | ||
4 | +<% attributes.each do |attribute| -%> | ||
5 | +<% if attribute.type == :paperclip -%> | ||
6 | + table.string :<%= attribute.name %>_file_name | ||
7 | + table.string :<%= attribute.name %>_content_type | ||
8 | + table.integer :<%= attribute.name %>_file_size | ||
9 | + table.datetime :<%= attribute.name %>_updated_at | ||
10 | +<% else -%> | ||
11 | + table.<%= attribute.type %> :<%= attribute.name %> | ||
12 | +<% end -%> | ||
13 | +<% end -%> | ||
14 | +<% unless options[:skip_timestamps] -%> | ||
15 | + table.timestamps | ||
16 | +<% end -%> | ||
17 | + end | ||
18 | + | ||
19 | +<% attributes.select(&:reference?).each do |attribute| -%> | ||
20 | + add_index :<%= table_name %>, :<%= attribute.name %>_id | ||
21 | +<% end -%> | ||
22 | + end | ||
23 | + | ||
24 | + def self.down | ||
25 | +<% attributes.select(&:reference?).each do |attribute| -%> | ||
26 | + remove_index :<%= table_name %>, :<%= attribute.name %>_id | ||
27 | +<% end -%> | ||
28 | + drop_table :<%= table_name %> | ||
29 | + end | ||
30 | +end |
vendor/plugins/coulda/generators/model/templates/model.rb
0 → 100644
@@ -0,0 +1,8 @@ | @@ -0,0 +1,8 @@ | ||
1 | +class <%= class_name %> < ActiveRecord::Base | ||
2 | +<% attributes.select(&:reference?).each do |each| -%> | ||
3 | + belongs_to :<%= each.name %> | ||
4 | +<% end -%> | ||
5 | +<% attributes.select { |each| each.type == :paperclip }.each do |each| -%> | ||
6 | + has_attached_file :<%= each.name %> | ||
7 | +<% end -%> | ||
8 | +end |
vendor/plugins/coulda/generators/model/templates/unit_test.rb
0 → 100644
@@ -0,0 +1,16 @@ | @@ -0,0 +1,16 @@ | ||
1 | +require File.dirname(__FILE__) + '/../test_helper' | ||
2 | + | ||
3 | +class <%= class_name %>Test < ActiveSupport::TestCase | ||
4 | + should "be valid with factory" do | ||
5 | + assert_valid Factory.build(:<%= file_name -%>) | ||
6 | + end | ||
7 | +<% attributes.each do |attribute| -%> | ||
8 | +<% if attribute.reference? -%> | ||
9 | + should_belong_to :<%= attribute.name %> | ||
10 | + should_have_db_index :<%= attribute.name %>_id | ||
11 | +<% end -%> | ||
12 | +<% if attribute.type == :paperclip -%> | ||
13 | + should_have_attached_file :<%= attribute.name %> | ||
14 | +<% end -%> | ||
15 | +<% end -%> | ||
16 | +end |
vendor/plugins/coulda/generators/support/insert_commands.rb
0 → 100644
@@ -0,0 +1,35 @@ | @@ -0,0 +1,35 @@ | ||
1 | +# Mostly pinched from http://github.com/ryanb/nifty-generators/tree/master | ||
2 | + | ||
3 | +Rails::Generator::Commands::Base.class_eval do | ||
4 | + def file_contains?(relative_destination, line) | ||
5 | + File.read(destination_path(relative_destination)).include?(line) | ||
6 | + end | ||
7 | +end | ||
8 | + | ||
9 | +Rails::Generator::Commands::Create.class_eval do | ||
10 | + def insert_into(file, line) | ||
11 | + logger.insert "#{line} into #{file}" | ||
12 | + unless options[:pretend] || file_contains?(file, line) | ||
13 | + start_of_routes_file = "ActionController::Routing::Routes.draw" | ||
14 | + gsub_file file, /^(class|module|#{start_of_routes_file}) .+$/ do |match| | ||
15 | + "#{match}\n #{line}" | ||
16 | + end | ||
17 | + end | ||
18 | + end | ||
19 | +end | ||
20 | + | ||
21 | +Rails::Generator::Commands::Destroy.class_eval do | ||
22 | + def insert_into(file, line) | ||
23 | + logger.remove "#{line} from #{file}" | ||
24 | + unless options[:pretend] | ||
25 | + gsub_file file, "\n #{line}", '' | ||
26 | + end | ||
27 | + end | ||
28 | +end | ||
29 | + | ||
30 | +Rails::Generator::Commands::List.class_eval do | ||
31 | + def insert_into(file, line) | ||
32 | + logger.insert "#{line} into #{file}" | ||
33 | + end | ||
34 | +end | ||
35 | + |
vendor/plugins/coulda/generators/view/templates/view_new.html.erb
0 → 100644
@@ -0,0 +1,14 @@ | @@ -0,0 +1,14 @@ | ||
1 | +class ViewGenerator < Rails::Generator::NamedBase | ||
2 | + def manifest | ||
3 | + record do |m| | ||
4 | + m.directory File.join('app/views', class_path, file_name) | ||
5 | + | ||
6 | + # View template for specified action. | ||
7 | + if actions.include?("new") | ||
8 | + path = File.join('app/views', class_path, file_name, "new.html.erb") | ||
9 | + m.template 'view_new.html.erb', path, | ||
10 | + :assigns => { :action => action, :path => path } | ||
11 | + end | ||
12 | + end | ||
13 | + end | ||
14 | +end |