email_form_generator 1.0.4 → 1.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,8 @@
1
+
2
+ == 1.0.5 / 2009-07-20
3
+ * Fixed bug where help screen would not show due to bad parsing of the arguments
4
+ * RSpec option (--spec)
5
+ * renamed email_config.rb to email.rb
1
6
  == 1.0.4 / 2009-07-03
2
7
  * Tests updated for Rails 2.3x
3
8
  * Fixed broken generator.
data/README.rdoc CHANGED
@@ -41,8 +41,12 @@ Notice that it generates a model called ContactForm with a RESTful resource Cont
41
41
 
42
42
  Also generates a configuration file and an initializer to make configuring email for various environments a snap and a tableless model is included so you can use validations and form helpers just like you do with regular models.
43
43
 
44
-
45
-
44
+ === RSpec support
45
+
46
+ If you prefer to have specs instead of tests, use the --spec flag.
47
+
48
+ ruby script/generate email_form Contact first_name:string last_name:string email:string message:string --spec
49
+
46
50
  === Configuration
47
51
  When the generator runs, it creates a configuration file called email.yml. You need to modify this file so that it reflects your settings for your email server.
48
52
 
@@ -92,6 +96,7 @@ This concept was inspired by Rick Olson
92
96
  == REQUIREMENTS:
93
97
 
94
98
  * The Mocha gem is required because I use it for testing. Change the tests if you want to use something else.
99
+ * If you're using RSpec and you want to use the tests generated, you need to enable Mocha's mocking, or change the mock lines to use RSpec's mocking instead.
95
100
  * Rails 2.x with ActiveRecord
96
101
 
97
102
  == INSTALL:
@@ -17,8 +17,10 @@ class EmailFormGenerator < Rails::Generator::NamedBase
17
17
 
18
18
  def initialize(runtime_args, runtime_options = {})
19
19
  @original_name = ARGV[0]
20
- if ! ARGV[0].downcase.include?("form")
21
- ARGV[0] = ARGV[0].underscore + "_form"
20
+ if ARGV[0]
21
+ if ! ARGV[0].downcase.include?("form")
22
+ ARGV[0] = ARGV[0].underscore + "_form"
23
+ end
22
24
  end
23
25
  super
24
26
 
@@ -47,8 +49,7 @@ class EmailFormGenerator < Rails::Generator::NamedBase
47
49
  m.directory(File.join('app/views', controller_class_path, controller_file_name))
48
50
  m.directory(File.join('app/views', controller_class_path, file_name + "_mailer"))
49
51
  m.directory(File.join('app/views/layouts', controller_class_path))
50
- m.directory(File.join('test/functional', controller_class_path))
51
- m.directory(File.join('test/unit', class_path))
52
+
52
53
 
53
54
  for action in scaffold_views
54
55
  m.template(
@@ -73,7 +74,7 @@ class EmailFormGenerator < Rails::Generator::NamedBase
73
74
  'tableless.rb', File.join('app/models', "tableless.rb"), :collision => :skip
74
75
  )
75
76
  m.template('config.yml', File.join('config', 'email.yml'), :collision => :skip)
76
- m.template('config.rb', File.join('config/initializers', 'email_config.rb'), :collision => :skip)
77
+ m.template('config.rb', File.join('config/initializers', 'email.rb'), :collision => :skip)
77
78
 
78
79
  m.template(
79
80
  'model.rb', File.join('app/models', "#{file_name}.rb")
@@ -83,10 +84,22 @@ class EmailFormGenerator < Rails::Generator::NamedBase
83
84
  'mailer.rb', File.join('app/models', "#{file_name}_mailer.rb")
84
85
  )
85
86
 
86
-
87
- m.template('functional_test.rb', File.join('test/functional', controller_class_path, "#{controller_file_name}_controller_test.rb"))
88
- m.template('mailer_test.rb', File.join('test/unit', "#{file_name}_mailer_test.rb"))
89
-
87
+ unless options[:rspec]
88
+ m.directory(File.join('test/functional', controller_class_path))
89
+ m.directory(File.join('test/unit', class_path))
90
+ m.template('functional_test.rb', File.join('test/functional', controller_class_path, "#{controller_file_name}_controller_test.rb"))
91
+ m.template('mailer_test.rb', File.join('test/unit', "#{file_name}_mailer_test.rb"))
92
+ m.template('unit_test.rb', File.join('test/unit', "#{file_name}_test.rb"))
93
+
94
+ else
95
+ m.directory(File.join('spec/controllers', controller_class_path))
96
+ m.directory(File.join('spec/models', class_path))
97
+ m.template('controller_spec.rb', File.join('spec/controllers', controller_class_path, "#{controller_file_name}_controller_spec.rb"))
98
+ m.template('mailer_spec.rb', File.join('spec/models', "#{file_name}_mailer_spec.rb"))
99
+ m.template('model_spec.rb', File.join('spec/models', "#{file_name}_spec.rb"))
100
+
101
+ end
102
+
90
103
  m.route_resource controller_singular_name
91
104
 
92
105
  action = nil
@@ -94,7 +107,7 @@ class EmailFormGenerator < Rails::Generator::NamedBase
94
107
  case action
95
108
  when "generate"
96
109
  puts "Your form is ready for use in your application."
97
- puts "Before you start the server, fill in the right details into config/config.yml."
110
+ puts "Before you start the server, fill in the right details into config/email.yml."
98
111
 
99
112
  end
100
113
 
@@ -107,7 +120,7 @@ class EmailFormGenerator < Rails::Generator::NamedBase
107
120
  protected
108
121
 
109
122
  def ran_before?
110
- options[:rspec] || (File.exist?('app/models/tableless.rb'))
123
+ (File.exist?('app/models/tableless.rb'))
111
124
  end
112
125
 
113
126
  # Override with your own usage banner.
@@ -118,6 +131,7 @@ class EmailFormGenerator < Rails::Generator::NamedBase
118
131
  def add_options!(opt)
119
132
  opt.separator ''
120
133
  opt.separator 'Options:'
134
+ opt.on("--spec", "Generate specs instead of test:unit files") {|v| options[:rspec] = v }
121
135
  opt.on("--skip-timestamps",
122
136
  "Don't add timestamps to the migration file for this model") { |v| options[:skip_timestamps] = v }
123
137
  opt.on("--skip-migration",
@@ -0,0 +1,23 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe <%= controller_class_name %>Controller do
4
+ integrate_views
5
+
6
+ it "should display the form" do
7
+ get :new
8
+ assigns(:<%= file_name %>).should_not be_nil
9
+ response.should render_template(:new)
10
+ end
11
+
12
+ it "Should display the success page when an email is sent" do
13
+ <%=class_name %>.any_instance.expects(:deliver).returns(true)
14
+ post :create, {:<%= file_name %> => {} }
15
+ response.should render_template(:success)
16
+ end
17
+
18
+ it "should show the new page again" do
19
+ <%=class_name %>.any_instance.expects(:deliver).returns(false)
20
+ post :create
21
+ response.should render_template(:new)
22
+ end
23
+ end
@@ -2,29 +2,22 @@ require File.dirname(__FILE__) + '/../test_helper'
2
2
 
3
3
  class <%= controller_class_name %>ControllerTest < ActionController::TestCase
4
4
 
5
- def setup
6
- ActionMailer::Base.delivery_method = :test
7
- ActionMailer::Base.perform_deliveries = false
8
- ActionMailer::Base.deliveries = []
9
- end
10
5
 
11
6
  def test_should_display_form
12
7
  get :new
13
8
  assert_not_nil assigns(:<%= file_name %>)
14
- assert_response :success
9
+ assert_template("new")
15
10
  end
16
11
 
17
12
  def test_should_show_success_when_created
18
13
  <%=class_name %>.any_instance.expects(:deliver).returns(true)
19
14
  post :create, {:<%= file_name %> => {} }
20
- assert_response :success
21
- assert_template "success"
15
+ assert_template("success")
22
16
  end
23
17
 
24
18
  def test_should_fail_to_send_and_show_form_again
25
19
  <%=class_name %>.any_instance.expects(:deliver).returns(false)
26
20
  post :create
27
- assert_response :success
28
- assert_template "new"
21
+ assert_template("new")
29
22
  end
30
23
  end
@@ -0,0 +1,22 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe <%=class_name %>Mailer do
4
+ before(:each) do
5
+ ActionMailer::Base.delivery_method = :test
6
+ ActionMailer::Base.perform_deliveries = true
7
+ ActionMailer::Base.deliveries = []
8
+ end
9
+
10
+ it "should deliver <%=singular_name %>" do
11
+ @f = <%=class_name %>.new
12
+
13
+ <% attributes.each do |attribute| %>
14
+ @f.<%=attribute.name %> = "foo"
15
+ <% end %>
16
+
17
+ <%=class_name%>Mailer::deliver_<%=singular_name %>(@f)
18
+ ActionMailer::Base.deliveries.length.should == 1
19
+
20
+ end
21
+
22
+ end
data/templates/model.rb CHANGED
@@ -11,6 +11,7 @@ class <%= class_name %> < Tableless
11
11
  if valid?
12
12
  begin
13
13
  <%= class_name %>Mailer::deliver_<%=singular_name %>(self)
14
+ return true
14
15
  rescue
15
16
  @errors.add_to_base "Your message could not be sent due to configuration issues with the server."
16
17
  return false
@@ -0,0 +1,26 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe <%= class_name %> do
4
+
5
+ it "should deliver the message" do
6
+
7
+ @f = <%=class_name %>.new
8
+
9
+ <% attributes.each do |attribute| %>
10
+ @f.<%=attribute.name %> = "foo"
11
+ <% end %>
12
+
13
+ @f.deliver.should == true
14
+ end
15
+
16
+ # modify this test in such a way as to cause the
17
+ # validations to fail, if you have any.
18
+ # it "should not deliver the message when there are errors" do
19
+ #
20
+ # @f = <%=class_name %>.new
21
+ # @f.deliver.should_not == true
22
+ #
23
+ # end
24
+
25
+
26
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: email_form_generator
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Hogan
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-07-03 00:00:00 -05:00
12
+ date: 2009-07-20 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -49,6 +49,9 @@ files:
49
49
  - templates/view_form.html.erb
50
50
  - templates/view_new.html.erb
51
51
  - templates/view_success.html.erb
52
+ - templates/model_spec.rb
53
+ - templates/controller_spec.rb
54
+ - templates/mailer_spec.rb
52
55
  has_rdoc: true
53
56
  homepage: This generator creates a working contact form with validations and delivery, and provides a method for working with configuration from YML files as well as a mechanism for working with models that don't require a database but still need validations and callbacks.
54
57
  post_install_message: