spud_inquiries 0.8.3 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. data/README.markdown +19 -0
  2. data/Rakefile +2 -14
  3. data/app/controllers/contacts_controller.rb +11 -7
  4. data/app/controllers/spud/admin/inquiries_controller.rb +2 -2
  5. data/app/controllers/spud/admin/inquiry_forms_controller.rb +4 -3
  6. data/app/models/spud_inquiry.rb +9 -3
  7. data/app/observers/inquiry_observer.rb +43 -0
  8. data/app/observers/inquiry_sweeper.rb +44 -0
  9. data/app/views/contacts/_show.html.erb +34 -0
  10. data/app/views/contacts/show.html.erb +4 -9
  11. data/app/views/spud/admin/inquiries/index.html.erb +3 -3
  12. data/app/views/spud/inquiry_mailer/inquiry_notification.html.erb +2 -2
  13. data/app/views/spud/inquiry_mailer/inquiry_notification.text.erb +0 -1
  14. data/config/routes.rb +8 -3
  15. data/lib/spud_inquiries.rb +1 -0
  16. data/lib/spud_inquiries/configuration.rb +3 -2
  17. data/lib/spud_inquiries/engine.rb +7 -2
  18. data/lib/spud_inquiries/liquid_form.rb +42 -0
  19. data/lib/spud_inquiries/version.rb +1 -1
  20. data/{test → spec}/dummy/README.rdoc +0 -0
  21. data/{test → spec}/dummy/Rakefile +0 -0
  22. data/{test → spec}/dummy/app/assets/javascripts/application.js +0 -0
  23. data/{test → spec}/dummy/app/assets/stylesheets/application.css +0 -0
  24. data/{test → spec}/dummy/app/controllers/application_controller.rb +0 -0
  25. data/{test → spec}/dummy/app/helpers/application_helper.rb +0 -0
  26. data/{test → spec}/dummy/app/views/layouts/application.html.erb +0 -0
  27. data/{test → spec}/dummy/config.ru +0 -0
  28. data/{test → spec}/dummy/config/application.rb +0 -0
  29. data/{test → spec}/dummy/config/boot.rb +0 -0
  30. data/{test → spec}/dummy/config/database.yml +0 -0
  31. data/{test → spec}/dummy/config/environment.rb +0 -0
  32. data/{test → spec}/dummy/config/environments/development.rb +0 -0
  33. data/{test → spec}/dummy/config/environments/production.rb +0 -0
  34. data/{test → spec}/dummy/config/environments/test.rb +0 -0
  35. data/{test → spec}/dummy/config/initializers/backtrace_silencers.rb +0 -0
  36. data/{test → spec}/dummy/config/initializers/inflections.rb +0 -0
  37. data/{test → spec}/dummy/config/initializers/mime_types.rb +0 -0
  38. data/{test → spec}/dummy/config/initializers/secret_token.rb +0 -0
  39. data/{test → spec}/dummy/config/initializers/session_store.rb +0 -0
  40. data/{test → spec}/dummy/config/initializers/wrap_parameters.rb +0 -0
  41. data/{test → spec}/dummy/config/locales/en.yml +0 -0
  42. data/spec/dummy/config/routes.rb +3 -0
  43. data/spec/dummy/db/migrate/20120610131537_create_spud_admin_permissions.spud_core.rb +12 -0
  44. data/spec/dummy/db/migrate/20120610131538_create_spud_users.spud_core.rb +30 -0
  45. data/spec/dummy/db/migrate/20120610131539_add_time_zone_to_spud_user.spud_core.rb +7 -0
  46. data/spec/dummy/db/migrate/20120610131540_add_scope_to_spud_admin_permissions.spud_core.rb +7 -0
  47. data/spec/dummy/db/migrate/20120610131541_create_spud_user_settings.spud_core.rb +12 -0
  48. data/spec/dummy/db/schema.rb +108 -0
  49. data/spec/dummy/log/development.log +88 -0
  50. data/{test → spec}/dummy/public/404.html +0 -0
  51. data/{test → spec}/dummy/public/422.html +0 -0
  52. data/{test → spec}/dummy/public/500.html +0 -0
  53. data/{test → spec}/dummy/public/favicon.ico +0 -0
  54. data/{test → spec}/dummy/script/rails +0 -0
  55. data/spec/spec_helper.rb +40 -0
  56. data/spec/support/authlogic_helper.rb +2 -0
  57. metadata +195 -90
  58. data/test/dummy/config/routes.rb +0 -4
  59. data/test/test_helper.rb +0 -10
data/README.markdown CHANGED
@@ -40,3 +40,22 @@ Creating a Contact Form
40
40
  -----------------------
41
41
  Creating a contact form is still fairly new and improvements will be made as time goes on. To create a new form, go to the Inquiries app inside of your spud admin panel. Click the forms button to manage various forms. Here you can set the form name, any content (html safe) you wish to render before the form renders, and add the form fields to the form (Email address is currently at the top of all forms and not adjustable).
42
42
 
43
+ Testing
44
+ -----------------
45
+
46
+ Spud uses RSpec for testing. Get the tests running with a few short commands:
47
+
48
+ 1. Create and migrate the databases:
49
+
50
+ rake db:create
51
+ rake db:migrate
52
+
53
+ 2. Load the schema in to the test database:
54
+
55
+ rake app:db:test:prepare
56
+
57
+ 3. Run the tests with RSpec
58
+
59
+ rspec spec
60
+
61
+ After the tests have completed the current code coverage stats is available by opening ```/coverage/index.html``` in a browser.
data/Rakefile CHANGED
@@ -20,21 +20,9 @@ RDoc::Task.new(:rdoc) do |rdoc|
20
20
  rdoc.rdoc_files.include('lib/**/*.rb')
21
21
  end
22
22
 
23
- APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
23
+ APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
24
24
  load 'rails/tasks/engine.rake'
25
25
 
26
-
27
-
28
26
  Bundler::GemHelper.install_tasks
29
27
 
30
- require 'rake/testtask'
31
-
32
- Rake::TestTask.new(:test) do |t|
33
- t.libs << 'lib'
34
- t.libs << 'test'
35
- t.pattern = 'test/**/*_test.rb'
36
- t.verbose = false
37
- end
38
-
39
-
40
- task :default => :test
28
+ require 'rake'
@@ -1,6 +1,7 @@
1
1
  class ContactsController < ApplicationController
2
2
  caches_action :show,:if => Proc.new { |c| Spud::Inquiries.enable_action_caching }
3
3
  caches_action :thankyou,:if => Proc.new { |c| Spud::Inquiries.enable_action_caching }
4
+ skip_before_filter :verify_authenticity_token
4
5
  layout Spud::Inquiries.base_layout
5
6
  def show
6
7
  url_name = !params[:id].blank? ? params[:id] : Spud::Inquiries.default_contact_form
@@ -12,13 +13,13 @@ class ContactsController < ApplicationController
12
13
  redirect_to root_url and return
13
14
  end
14
15
  @inquiry = SpudInquiry.new(:spud_inquiry_form_id => @inquiry_form.id)
15
-
16
+
16
17
  end
17
18
 
18
19
  def inquire
19
20
  if !params[:other_email].blank?
20
21
  flash[:error] = "You must be a robot! No robots allowed here!"
21
- redirect_to request.referer and return
22
+ redirect_to request.referer and return
22
23
  end
23
24
  unless params[:spud_inquiry]
24
25
  flash[:error] = "Inquiry Not Found!"
@@ -27,13 +28,13 @@ class ContactsController < ApplicationController
27
28
  @inquiry_form = SpudInquiryForm.find(params[:spud_inquiry][:spud_inquiry_form_id])
28
29
  if @inquiry_form.blank?
29
30
  flash[:error] = "Form Not Found!"
30
- redirect_to request.referer and return
31
+ redirect_to request.referer and return
31
32
  end
32
- @inquiry = SpudInquiry.new(:email => params[:spud_inquiry][:email],:spud_inquiry_form_id => params[:spud_inquiry][:spud_inquiry_form_id])
33
-
33
+ @inquiry = SpudInquiry.new(:spud_inquiry_form_id => params[:spud_inquiry][:spud_inquiry_form_id])
34
+
34
35
  @inquiry.recipients = @inquiry_form.recipients
35
36
  @inquiry.subject = @inquiry_form.subject
36
-
37
+
37
38
  @inquiry_form.spud_inquiry_form_fields.order(:field_order).all.each do |field|
38
39
  val = params[:spud_inquiry][field.name]
39
40
  if field.required && val.blank?
@@ -58,11 +59,14 @@ class ContactsController < ApplicationController
58
59
  end
59
60
  else
60
61
  flash[:error] = "Whoops! Something went wrong. Please try again!"
62
+ render :action => "show" and return
61
63
  end
62
64
  redirect_to contact_thankyou_url
63
65
  end
64
66
 
67
+
68
+
65
69
  def thankyou
66
70
  render
67
- end
71
+ end
68
72
  end
@@ -2,14 +2,14 @@ class Spud::Admin::InquiriesController < Spud::Admin::ApplicationController
2
2
  layout 'spud/admin/detail'
3
3
  belongs_to_spud_app :inquiries
4
4
  add_breadcrumb "Inquiries", :spud_admin_inquiries_path
5
- before_filter :load_inquiries,:only => [:edit,:update,:show,:destroy]
5
+ before_filter :load_inquiries,:only => [:edit,:update,:show,:destroy]
6
6
  def index
7
7
  @inquiries = SpudInquiry.order("created_at DESC").includes(:spud_inquiry_form).paginate :page => params[:page]
8
8
  respond_with @inquiries
9
9
  end
10
10
 
11
11
  def show
12
- add_breadcrumb "#{@inquiry.email}", :spud_admin_inquiry_path
12
+ add_breadcrumb "#{@inquiry.email || "Unknown"}", :spud_admin_inquiry_path
13
13
  respond_with @inquiry
14
14
  end
15
15
 
@@ -1,11 +1,12 @@
1
1
  class Spud::Admin::InquiryFormsController < Spud::Admin::ApplicationController
2
2
  layout 'spud/admin/detail'
3
3
  belongs_to_spud_app :inquiries
4
+ cache_sweeper :inquiry_sweeper, :only => [:update,:destroy,:create]
4
5
  add_breadcrumb "Inquiries", :spud_admin_inquiries_path
5
6
  add_breadcrumb "Forms", :spud_admin_inquiry_forms_path
6
- before_filter :load_form,:only => [:edit,:update,:show,:destroy]
7
+ before_filter :load_form,:only => [:edit,:update,:show,:destroy]
7
8
  def index
8
-
9
+
9
10
  @page_name = "Inquiry Forms"
10
11
  @inquiry_forms = SpudInquiryForm.order(:name).paginate :page => params[:page]
11
12
  respond_with @inquiry_forms
@@ -20,7 +21,7 @@ class Spud::Admin::InquiryFormsController < Spud::Admin::ApplicationController
20
21
  def create
21
22
  @inquiry_form = SpudInquiryForm.new(params[:spud_inquiry_form])
22
23
  flash[:notice] = "Form saved successfully!" if @inquiry_form.save
23
-
24
+
24
25
  respond_with @inquiry_form,:location => spud_admin_inquiry_forms_url
25
26
  end
26
27
 
@@ -2,8 +2,14 @@ class SpudInquiry < ActiveRecord::Base
2
2
 
3
3
  has_many :spud_inquiry_fields
4
4
  belongs_to :spud_inquiry_form
5
- accepts_nested_attributes_for :spud_inquiry_fields, :reject_if => lambda { |a| a[:name].blank? }
6
- validates :email,:presence => true
5
+ accepts_nested_attributes_for :spud_inquiry_fields, :reject_if => lambda { |a| a[:name].blank? }
6
+ attr_accessible :spud_inquiry_form_id,:spud_inquiry_fields
7
7
 
8
- attr_accessible :spud_inquiry_form_id,:email,:spud_inquiry_fields
8
+ def email
9
+ email_field = self.spud_inquiry_fields.where(:name => "email").first
10
+ if !email_field.blank?
11
+ return email_field.value
12
+ end
13
+ return "Unknown Sender"
14
+ end
9
15
  end
@@ -0,0 +1,43 @@
1
+ class InquiryObserver < ActiveRecord::Observer
2
+ observe :spud_inquiry_form,:spud_inquiry_form_field
3
+
4
+ def before_save(record)
5
+ if record.is_a?(SpudInquiryForm)
6
+ @old_name = record.name_was
7
+ else
8
+ @old_name = nil
9
+ end
10
+ end
11
+
12
+ def after_save(record)
13
+ if record.is_a?(SpudInquiryFormField)
14
+ reset_cms_pages(record.spud_inquiry_form)
15
+ else
16
+ reset_cms_pages(record)
17
+ end
18
+ end
19
+ def after_destroy(record)
20
+ if record.is_a?(SpudInquiryFormField)
21
+ reset_cms_pages(record.spud_inquiry_form)
22
+ else
23
+ reset_cms_pages(record)
24
+ end
25
+ end
26
+ private
27
+ def reset_cms_pages(record)
28
+ if SpudPageLiquidTag
29
+ values = [record.name]
30
+ values << @old_name if !@old_name.blank?
31
+ SpudPageLiquidTag.where(:tag_name => "inquiry",:value => values).includes(:spud_page_partial).each do |tag|
32
+ partial = tag.spud_page_partial
33
+ partial.postprocess_content
34
+ partial.save
35
+ partial.spud_page.updated_at = Time.now.utc
36
+ partial.spud_page.save
37
+ end
38
+
39
+ end
40
+ end
41
+
42
+
43
+ end
@@ -0,0 +1,44 @@
1
+ class InquirySweeper < ActionController::Caching::Sweeper
2
+ observe :spud_inquiry_form,:spud_inquiry_form_field
3
+
4
+ def before_save(record)
5
+ if record.is_a?(SpudInquiryForm)
6
+ @old_name = record.name_was
7
+ else
8
+ @old_name = nil
9
+ end
10
+ end
11
+
12
+ def after_save(record)
13
+ if record.is_a?(SpudInquiryFormField)
14
+ reset_cms_pages(record.spud_inquiry_form)
15
+ else
16
+ reset_cms_pages(record)
17
+ end
18
+ end
19
+ def after_destroy(record)
20
+ if record.is_a?(SpudInquiryFormField)
21
+ reset_cms_pages(record.spud_inquiry_form)
22
+ else
23
+ reset_cms_pages(record)
24
+ end
25
+ end
26
+ private
27
+ def reset_cms_pages(record)
28
+ if defined? Spud::Cms::Engine #Is CMS Being Used?
29
+ values = [record.name]
30
+ values << @old_name if !@old_name.blank?
31
+ SpudPageLiquidTag.where(:tag_name => "inquiry",:value => values).includes(:spud_page_partial).each do |tag|
32
+ partial = tag.spud_page_partial
33
+ partial.postprocess_content
34
+ partial.save
35
+ partial.spud_page.updated_at = Time.now.utc
36
+ partial.spud_page.save
37
+ end
38
+
39
+ end
40
+ end
41
+
42
+
43
+
44
+ end
@@ -0,0 +1,34 @@
1
+
2
+ <%=form_for :spud_inquiry, :url => "/contact/inquire",:html => {:class => "form-horizontal"} do |f|%>
3
+ <fieldset>
4
+ <%=f.hidden_field :spud_inquiry_form_id,:value => inquiry_form.id%>
5
+
6
+ <%inquiry_form.spud_inquiry_form_fields.each do |field|%>
7
+ <div class="control-group">
8
+ <%=f.label field.name,:class => "control-label"%>
9
+ <div class="controls">
10
+ <%=case field.field_type
11
+ when '0'
12
+ f.text_field field.name,:value => field.default_value
13
+ when '1'
14
+ f.check_box field.name,:value => field.default_value
15
+ when '2'
16
+ f.text_area field.name,:value => field.default_value,:rows=>5,:cols => 70
17
+ when '3'
18
+ f.select field.name,field.options_list.collect {|opt| [opt,opt]},:include_blank => true
19
+ end%>
20
+ </div>
21
+ </div>
22
+ <%end%>
23
+ <div class="spud_inquiry_hide">
24
+ <label id='other_email_label' for='other_email'>Please leave blank:</label>
25
+ <input type='text' name='other_email' id='other_email'>
26
+ </div>
27
+ <div class="form-actions">
28
+ <%=f.submit "Submit Inquiry",:class => "btn btn-primary"%>
29
+ </div>
30
+
31
+
32
+ </fieldset>
33
+
34
+ <%end%>
@@ -6,12 +6,7 @@
6
6
  <fieldset>
7
7
  <%=f.hidden_field :spud_inquiry_form_id,:value => @inquiry_form.id%>
8
8
 
9
- <div class="control-group">
10
- <%=f.label :email,:class => "control-label"%>
11
- <div class="controls">
12
- <%=f.text_field :email,:value => @inquiry.email%>
13
- </div>
14
- </div>
9
+
15
10
  <%@inquiry_form.spud_inquiry_form_fields.each do |field|%>
16
11
  <div class="control-group">
17
12
  <%=f.label field.name,:class => "control-label"%>
@@ -35,9 +30,9 @@
35
30
  </div>
36
31
  <div class="form-actions">
37
32
  <%=f.submit "Submit Inquiry",:class => "btn btn-primary"%>
38
- </div>
33
+ </div>
39
34
 
40
35
 
41
36
  </fieldset>
42
-
43
- <%end%>
37
+
38
+ <%end%>
@@ -6,11 +6,11 @@
6
6
  <div class="page_list">
7
7
  <%@inquiries.each do |inquiry|%>
8
8
  <div class="page_row">
9
-
9
+
10
10
  <span class="row_meta"><%=link_to "#{inquiry.spud_inquiry_form.blank? ? "No Form" : inquiry.spud_inquiry_form.name}: #{inquiry.email}",spud_admin_inquiry_path(inquiry)%></span>
11
11
 
12
12
  <span class="edit_controls">
13
-
13
+
14
14
  <%=link_to "Remove",spud_admin_inquiry_path(inquiry),:method => :delete,:class => 'btn btn-danger',:confirm => "Are you sure you want to remove this inquiry?"%></span>
15
15
  <br style="clear:both;"/>
16
16
  </div>
@@ -19,4 +19,4 @@
19
19
 
20
20
  </div>
21
21
 
22
- <%end%>
22
+ <%end%>
@@ -5,11 +5,11 @@
5
5
  </head>
6
6
  <body>
7
7
  <h2>Inquiry Received</h2>
8
- <p><strong>From:</strong> <%=link_to @inquiry.email,"mailto:#{@inquiry.email}"%></p>
8
+
9
9
  <%@inquiry.spud_inquiry_fields.each do |field|%>
10
10
  <p><strong><%=field.name%></strong>
11
11
  <%=field.value%>
12
12
  </p>
13
13
  <%end%>
14
14
  </body>
15
- </html>
15
+ </html>
@@ -2,7 +2,6 @@
2
2
  Inquiry Received
3
3
  =================
4
4
 
5
- From: <%=@inquiry.email%>
6
5
  <%@inquiry.spud_inquiry_fields.each do |field|%>
7
6
  <%=field.name%>: <%=field.value%>
8
7
  <%end%>
data/config/routes.rb CHANGED
@@ -8,11 +8,16 @@ Rails.application.routes.draw do
8
8
  resource :sitemap,:only => [:show]
9
9
  end
10
10
  end
11
- match "/contact" => "contacts#show"
11
+
12
12
  post "contact/inquire" => "contacts#inquire"
13
13
  match "contact/thankyou" => "contacts#thankyou"
14
- match "/contact/:id" => "contacts#show"
14
+ if Spud::Inquiries.enable_routes
15
+ match "/contact" => "contacts#show"
16
+ match "/contact/:id" => "contacts#show"
17
+ end
18
+
19
+
20
+
15
21
 
16
-
17
22
  end
18
23
 
@@ -1,6 +1,7 @@
1
1
  module Spud
2
2
  module Inquiries
3
3
  require 'spud_inquiries/configuration'
4
+ require 'spud_inquiries/liquid_form'
4
5
  require 'spud_inquiries/engine' if defined?(Rails)
5
6
  end
6
7
  end
@@ -2,8 +2,9 @@ module Spud
2
2
  module Inquiries
3
3
  include ActiveSupport::Configurable
4
4
 
5
- config_accessor :default_contact_form,:mail_delivery_format,:base_layout,:from_address,:enable_sitemap,:enable_action_caching
5
+ config_accessor :default_contact_form,:enable_routes,:mail_delivery_format,:base_layout,:from_address,:enable_sitemap,:enable_action_caching
6
6
 
7
+ self.enable_routes = true
7
8
  self.default_contact_form = "contact"
8
9
  self.base_layout = "application"
9
10
  self.mail_delivery_format = :html
@@ -11,4 +12,4 @@ module Spud
11
12
  self.enable_sitemap = true
12
13
  self.enable_action_caching = false
13
14
  end
14
- end
15
+ end
@@ -1,8 +1,10 @@
1
1
  require 'spud_core'
2
+ require 'liquid'
2
3
  module Spud
3
4
  module Inquiries
4
5
  class Engine < Rails::Engine
5
- engine_name :spud_inquiries
6
+ engine_name :spud_inquiries
7
+
6
8
  initializer :admin do
7
9
  Spud::Core.configure do |config|
8
10
  config.admin_applications += [{:name => "Inquiries",:thumbnail => "spud/admin/contacts_thumb.png",:url => "/spud/admin/inquiries",:order => 88}]
@@ -10,7 +12,10 @@ module Spud
10
12
  config.sitemap_urls += [:spud_inquiries_sitemap_url]
11
13
  end
12
14
  end
13
-
15
+ end
16
+
17
+ initializer :liquid_form do
18
+ Liquid::Template.register_tag('inquiry', Spud::Inquiries::InquiryForm) if defined?(Liquid::Template)
14
19
  end
15
20
  end
16
21
  end
@@ -0,0 +1,42 @@
1
+ require 'liquid'
2
+ module Spud
3
+ module Inquiries
4
+ class FormActionView < ActionView::Base
5
+ include ActionView::Helpers
6
+ def protect_against_forgery?
7
+ return false
8
+ end
9
+ end
10
+
11
+ class InquiryForm < Liquid::Tag
12
+ def initialize(tag_name, form_name, tokens)
13
+ @form_name = form_name
14
+
15
+ @inquiry_form = SpudInquiryForm.where(:name => form_name).includes(:spud_inquiry_form_fields).first
16
+ @view = FormActionView.new([Rails.application.config.paths["app/views"].first,Spud::Inquiries::Engine.config.paths["app/views"].first])
17
+
18
+ end
19
+
20
+ def tag_name
21
+ return "inquiry"
22
+ end
23
+ def tag_value
24
+ return @form_name
25
+ end
26
+
27
+ def render(context)
28
+
29
+ if !@inquiry_form.blank?
30
+ @inquiry = SpudInquiry.new(:spud_inquiry_form_id => @inquiry_form.id)
31
+ @view.render(
32
+ :partial => "/contacts/show",
33
+ :locals => {:inquiry => @inquiry, :inquiry_form => @inquiry_form}
34
+ )
35
+ else
36
+ return ''
37
+ end
38
+
39
+ end
40
+ end
41
+ end
42
+ end