spree_contact_us 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. data/.gitignore +13 -0
  2. data/.rspec +1 -0
  3. data/.travis.yml +11 -0
  4. data/Gemfile +3 -0
  5. data/LICENSE +26 -0
  6. data/README.md +98 -0
  7. data/Rakefile +15 -0
  8. data/Versionfile +11 -0
  9. data/app/assets/javascripts/admin/spree_contact_us.js +1 -0
  10. data/app/assets/javascripts/store/spree_contact_us.js +1 -0
  11. data/app/assets/stylesheets/admin/spree_contact_us.css +3 -0
  12. data/app/assets/stylesheets/store/spree_contact_us.css +3 -0
  13. data/app/controllers/spree/contact_us/contacts_controller.rb +23 -0
  14. data/app/mailers/spree/contact_us/contact_mailer.rb +9 -0
  15. data/app/models/spree/contact_us/contact.rb +36 -0
  16. data/app/overrides/contact_us_in_footer.rb +5 -0
  17. data/app/overrides/contact_us_in_header.rb +4 -0
  18. data/app/views/spree/contact_us/contact_mailer/contact_email.html.erb +3 -0
  19. data/app/views/spree/contact_us/contact_mailer/contact_email.text.plain.erb +4 -0
  20. data/app/views/spree/contact_us/contacts/new.html.erb +44 -0
  21. data/config/locales/spree_contact_us.en.yml +21 -0
  22. data/config/routes.rb +6 -0
  23. data/lib/generators/spree_contact_us/install/install_generator.rb +14 -0
  24. data/lib/generators/spree_contact_us/templates/spree_contact_us.rb +23 -0
  25. data/lib/spree_contact_us.rb +24 -0
  26. data/lib/spree_contact_us/engine.rb +12 -0
  27. data/script/rails +7 -0
  28. data/spec/lib/generators/spree_contact_us/dummy/config/initializers/spree_contact_us.rb +23 -0
  29. data/spec/lib/generators/spree_contact_us/install/install_generator_spec.rb +19 -0
  30. data/spec/lib/spree_contact_us_spec.rb +52 -0
  31. data/spec/mailers/spree/contact_us/contact_mailer_spec.rb +61 -0
  32. data/spec/models/spree/contact_us/contact_spec.rb +66 -0
  33. data/spec/requests/spree_contact_us_lint_spec.rb +140 -0
  34. data/spec/spec_helper.rb +38 -0
  35. data/spec/support/active_model_lint.rb +17 -0
  36. data/spree_contact_us.gemspec +29 -0
  37. metadata +236 -0
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ \#*
2
+ *~
3
+ .#*
4
+ .DS_Store
5
+ .idea
6
+ .project
7
+ coverage
8
+ Gemfile.lock
9
+ tmp
10
+ nbproject
11
+ pkg
12
+ *.swp
13
+ spec/dummy
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --colour
data/.travis.yml ADDED
@@ -0,0 +1,11 @@
1
+ before_script:
2
+ - 'bundle exec rake test_app'
3
+ script: 'bundle exec rspec spec'
4
+ rvm:
5
+ - 1.9.2
6
+ - 1.9.3
7
+ - ruby-head
8
+ language: ruby
9
+ notifications:
10
+ recipients:
11
+ - JDutil@BurlingtonWebApps.com
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,26 @@
1
+ Copyright (c) 2012 Jeff Dutil
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without modification,
5
+ are permitted provided that the following conditions are met:
6
+
7
+ * Redistributions of source code must retain the above copyright notice,
8
+ this list of conditions and the following disclaimer.
9
+ * Redistributions in binary form must reproduce the above copyright notice,
10
+ this list of conditions and the following disclaimer in the documentation
11
+ and/or other materials provided with the distribution.
12
+ * Neither the name Spree nor the names of its contributors may be used to
13
+ endorse or promote products derived from this software without specific
14
+ prior written permission.
15
+
16
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
20
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
23
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
24
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
25
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README.md ADDED
@@ -0,0 +1,98 @@
1
+ # SpreeContactUs [![Build Status](https://secure.travis-ci.org/jdutil/spree_contact_us.png)](http://travis-ci.org/jdutil/spree_contact_us) [![Dependency Status](https://gemnasium.com/jdutil/spree_contact_us.png?travis)](https://gemnasium.com/jdutil/contact_us) [![Click here to lend your support to: ContactUs and make a donation at www.pledgie.com !](https://www.pledgie.com/campaigns/17259.png?skin_name=chrome)][pledgie]
2
+ A Rails 3+ Engine providing a basic contact form as a Spree Extension.
3
+
4
+ [travis]: http://travis-ci.org/jdutil/spree_contact_us
5
+ [gemnasium]: https://gemnasium.com/jdutil/spree_contact_us
6
+ [pledgie]: http://www.pledgie.com/campaigns/17259
7
+
8
+ Modified version of the `contact_us` gem to work with Spree.
9
+
10
+ For more information please see https://github.com/jdutil/contact_us
11
+
12
+ ## REQUIREMENTS
13
+
14
+ SpreeContactUs requires:
15
+
16
+ * Spree Core 1.1.0.rc2 or greater
17
+ * Ruby 1.9.2 or greater.
18
+
19
+ If you would like to run on Spree 1.0.x or Ruby 1.8.7 everything should just work by modifying your forks gemspec. I do not intend to support these older versions though.
20
+
21
+ ## INSTALLATION
22
+
23
+ In your `Gemfile`, add the following dependencies:
24
+
25
+ To install from edge:
26
+
27
+ gem 'spree_contact_us', :git => 'https://github.com/jdutil/spree_contact_us'
28
+
29
+ Or install from latest stable version:
30
+
31
+ gem 'spree_contact_us', '~> 1.0.0'
32
+
33
+ From `Rails.root` run:
34
+
35
+ $ bundle
36
+ $ bundle exec rails g spree_contact_us:install
37
+
38
+ In `config/initializers/spree_contact_us.rb` modify:
39
+
40
+ config.mailer_to = "contact@please-change-me.com"
41
+
42
+ Change to the email address you would like to receive the form submissions at for example:
43
+
44
+ config.mailer_to = "contact@yourdomain.com"
45
+
46
+ By default the emails from field will be the email entered by the user to easily reply, but this may not be allowed if your required to verify your sending email addresses.
47
+ You may also specify an email address for the notification emails from field:
48
+
49
+ config.mailer_from = "dontreply@yourdomain.com"
50
+
51
+ ## CONFIGURATION
52
+
53
+ If you would like to add a name or subject field to the form you may simply set the options to true within the spree_contact_us initializer located at `config/initializers/spree_contact_us.rb`:
54
+
55
+ config.name = true
56
+ config.subject = true
57
+
58
+ You may also update your locales under `config/locales/spree_contact_us.en.yml` or create your own. Please feel free to submit your own locales so that other users will hopefully find this gem more useful.
59
+
60
+ ## USAGE
61
+
62
+ Visit your website and navigate to `/contact_us` to see the form in action.
63
+
64
+ ## ISSUES
65
+
66
+ Please report any bugs or feature requests to the Github issues page @ https://github.com/jdutil/spree_contact_us/issues
67
+
68
+ ## CONTRIBUTING
69
+
70
+ In the spirit of [free software](http://www.fsf.org/licensing/essays/free-sw.html), **everyone** is encouraged to help improve this project.
71
+
72
+ Here are some ways *you* can contribute:
73
+
74
+ * by using prerelease versions
75
+ * by reporting bugs
76
+ * by suggesting new features
77
+ * by [translating to a new language](https://github.com/jdutil/spree_contact_us/tree/master/config/locales)
78
+ * by writing or editing documentation
79
+ * by writing specifications
80
+ * by writing code (**no patch is too small**: fix typos, add comments, clean up inconsistent whitespace)
81
+ * by refactoring code
82
+ * by resolving [issues](https://github.com/jdutil/spree_contact_us/issues)
83
+ * by reviewing patches
84
+
85
+ ## Testing
86
+
87
+ Be sure to bundle your dependencies and then create a dummy test app for the specs to run against.
88
+
89
+ $ bundle
90
+ $ bundle exec rake test_app
91
+ $ bundle exec rspec spec
92
+
93
+ ## TODO
94
+
95
+ * Modify settings within the admin
96
+ * Add new language translations
97
+
98
+ Copyright (c) 2012 Jeff Dutil, released under the [New BSD License](https://github.com/jdutil/spree_contact_us/tree/master/LICENSE).
data/Rakefile ADDED
@@ -0,0 +1,15 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require 'rspec/core/rake_task'
5
+ require 'spree/core/testing_support/common_rake'
6
+
7
+ RSpec::Core::RakeTask.new
8
+
9
+ task :default => [:spec]
10
+
11
+ desc "Generates a dummy app for testing"
12
+ task :test_app do
13
+ ENV['LIB_NAME'] = 'spree_contact_us'
14
+ Rake::Task['common:test_app'].invoke
15
+ end
data/Versionfile ADDED
@@ -0,0 +1,11 @@
1
+ # This file is used to designate compatibilty with different versions of Spree
2
+ # Please see http://spreecommerce.com/documentation/extensions.html#versionfile for details
3
+
4
+ # Examples
5
+ #
6
+ # "0.70.x" => { :branch => "master"}
7
+ # "0.60.x" => { :branch => "0-60-stable" }
8
+ # "0.40.x" => { :tag => "v1.0.0", :version => "1.0.0" }
9
+
10
+ "1.1.x" => { :branch => "master" }
11
+ "1.0.x" => { :branch => "master" }
@@ -0,0 +1 @@
1
+ //= require admin/spree_core
@@ -0,0 +1 @@
1
+ //= require store/spree_core
@@ -0,0 +1,3 @@
1
+ /*
2
+ *= require admin/spree_core
3
+ */
@@ -0,0 +1,3 @@
1
+ /*
2
+ *= require store/spree_core
3
+ */
@@ -0,0 +1,23 @@
1
+ class Spree::ContactUs::ContactsController < Spree::BaseController
2
+
3
+ def create
4
+ @contact = Spree::ContactUs::Contact.new(params[:contact_us_contact])
5
+
6
+ if @contact.save
7
+ redirect_to('/', :notice => t('spree.contact_us.notices.success'))
8
+ else
9
+ render :new
10
+ end
11
+ end
12
+
13
+ def new
14
+ @contact = Spree::ContactUs::Contact.new
15
+ end
16
+
17
+ private
18
+
19
+ def accurate_title
20
+ t('spree.contact_us.contacts.new.contact_us')
21
+ end
22
+
23
+ end
@@ -0,0 +1,9 @@
1
+ class Spree::ContactUs::ContactMailer < ActionMailer::Base
2
+ def contact_email(contact)
3
+ @contact = contact
4
+
5
+ mail :from => (SpreeContactUs.mailer_from || contact.email),
6
+ :subject => (SpreeContactUs.require_subject ? @contact.subject : t('spree.contact_us.contact_mailer.contact_email.subject', :email => contact.email)),
7
+ :to => SpreeContactUs.mailer_to
8
+ end
9
+ end
@@ -0,0 +1,36 @@
1
+ module Spree
2
+ module ContactUs
3
+ class Contact
4
+
5
+ include ActiveModel::Conversion
6
+ include ActiveModel::Validations
7
+
8
+ attr_accessor :email, :message, :name, :subject
9
+
10
+ validates :email, :format => { :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i },
11
+ :presence => true
12
+ validates :message, :presence => true
13
+ validates :name, :presence => {:if => Proc.new{SpreeContactUs.require_name}}
14
+ validates :subject, :presence => {:if => Proc.new{SpreeContactUs.require_subject}}
15
+
16
+ def initialize(attributes = {})
17
+ attributes.each do |key, value|
18
+ self.send("#{key}=", value)
19
+ end
20
+ end
21
+
22
+ def save
23
+ if self.valid?
24
+ Spree::ContactUs::ContactMailer.contact_email(self).deliver
25
+ return true
26
+ end
27
+ return false
28
+ end
29
+
30
+ def persisted?
31
+ false
32
+ end
33
+
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,5 @@
1
+ # If SpreeStaticContent extension is also being used we list a Contact Us link with the other footer page links.
2
+ Deface::Override.new(:virtual_path => "spree/layouts/spree_application",
3
+ :name => "contact_us_in_footer",
4
+ :insert_bottom => "#footer-pages ul",
5
+ :text => "<li class='<%= (request.fullpath.gsub('//','/') == '/contact_us') ? 'current' : 'not'%>'><%= link_to t('spree.contact_us.contacts.new.contact_us'), '/contact_us' %></li>")
@@ -0,0 +1,4 @@
1
+ Deface::Override.new(:virtual_path => "spree/layouts/spree_application",
2
+ :name => "contact_us_in_header",
3
+ :insert_bottom => "#main-nav-bar",
4
+ :text => "<li class='<%= (request.fullpath.gsub('//','/') == '/contact_us') ? 'current' : 'not'%>'><%= link_to t('spree.contact_us.contacts.new.contact_us'), '/contact_us' %></li>")
@@ -0,0 +1,3 @@
1
+ <p><%= @contact.message %></p>
2
+ <p>---------------------</p>
3
+ <p><%= SpreeContactUs.require_name ? t('.sent_by_name', :email => @contact.email, :name => @contact.name) : t('.sent_by_contact_form', :email => @contact.email) %></p>
@@ -0,0 +1,4 @@
1
+ <%= @contact.message %>
2
+
3
+ -------------------------------------
4
+ <%= SpreeContactUs.require_name ? t('.sent_by_name', :email => @contact.email, :name => @contact.name) : t('.sent_by_contact_form', :email => @contact.email) %>
@@ -0,0 +1,44 @@
1
+ <% content_for :head do -%>
2
+ <meta name="title" content="Contact Us">
3
+ <% end -%>
4
+
5
+ <% content_for :sidebar do %>
6
+ <% if "products" == @current_controller && @taxon %>
7
+ <%= render :partial => "spree/shared/filters" %>
8
+ <% else %>
9
+ <%= render :partial => "spree/shared/taxonomies" %>
10
+ <% end %>
11
+ <% end %>
12
+
13
+ <%= render :partial => 'spree/shared/error_messages', :locals => { :target => @contact } %>
14
+
15
+ <h1><%= t('.contact_us') %></h1>
16
+ <%= form_for @contact, :url => contacts_path do |f| %>
17
+ <% if SpreeContactUs.require_name %>
18
+ <p>
19
+ <%= f.label :name %>
20
+ <br/>
21
+ <%= f.text_field :name %>
22
+ </p>
23
+ <% end %>
24
+ <p>
25
+ <%= f.label :email %>
26
+ <br/>
27
+ <%= f.email_field :email %>
28
+ </p>
29
+ <% if SpreeContactUs.require_subject %>
30
+ <p>
31
+ <%= f.label :subject %>
32
+ <br/>
33
+ <%= f.text_field :subject %>
34
+ </p>
35
+ <% end %>
36
+ <p>
37
+ <%= f.label :message %>
38
+ <br/>
39
+ <%= f.text_area :message %>
40
+ </p>
41
+ <p>
42
+ <%= f.submit t('.submit'), :alt => t('.submit'), :id => 'contact_us_contact_submit', :title => t('.submit') %>
43
+ </p>
44
+ <% end %>
@@ -0,0 +1,21 @@
1
+ # Sample localization file for English. Add more files in this directory for other locales.
2
+ # See https://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
3
+
4
+ en:
5
+ spree:
6
+ contact_us:
7
+ contact_mailer:
8
+ contact_email:
9
+ sent_by_contact_form: "Sent by contact form from %{email}"
10
+ sent_by_name: "Sent by %{name} from %{email}"
11
+ subject: "Contact Us message from %{email}"
12
+ contacts:
13
+ new:
14
+ contact_us: "Contact Us"
15
+ email: "Email"
16
+ message: "Message"
17
+ name: "Name"
18
+ subject: "Subject"
19
+ submit: "Submit"
20
+ notices:
21
+ success: "Contact email was successfully sent."
data/config/routes.rb ADDED
@@ -0,0 +1,6 @@
1
+ Spree::Core::Engine.routes.draw do
2
+ resources :contacts,
3
+ :controller => 'contact_us/contacts',
4
+ :only => [:new, :create]
5
+ match 'contact_us' => 'contact_us/contacts#new'
6
+ end
@@ -0,0 +1,14 @@
1
+ module SpreeContactUs
2
+ module Generators
3
+ class InstallGenerator < Rails::Generators::Base
4
+
5
+ argument :file_name, :type => :string, :desc => 'rails app_path', :default => '.'
6
+ source_root File.expand_path('../../templates', __FILE__)
7
+
8
+ def copy_initializer_file
9
+ template 'spree_contact_us.rb', "#{file_name}/config/initializers/spree_contact_us.rb"
10
+ end
11
+
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,23 @@
1
+ # Use this initializer to configure the contact mailer.
2
+
3
+ SpreeContactUs.setup do |config|
4
+
5
+ # ==> Mailer Configuration
6
+
7
+ # Configure the e-mail address which email notifications should be sent from. If emails must be sent from a verified email address you may set it here.
8
+ # Example:
9
+ # config.mailer_from = "contact@please-change-me.com"
10
+ config.mailer_from = nil
11
+
12
+ # Configure the e-mail address which should receive the contact form email notifications.
13
+ config.mailer_to = "contact@please-change-me.com"
14
+
15
+ # ==> Form Configuration
16
+
17
+ # Configure the form to ask for the users name.
18
+ config.require_name = false
19
+
20
+ # Configure the form to ask for a subject.
21
+ config.require_subject = false
22
+
23
+ end
@@ -0,0 +1,24 @@
1
+ require 'spree_core'
2
+ require 'spree_contact_us/engine'
3
+
4
+ module SpreeContactUs
5
+
6
+ # Address ContactUs email notifications are sent from.
7
+ mattr_accessor :mailer_from
8
+
9
+ # Address to send ContactUs email notifications to.
10
+ mattr_accessor :mailer_to
11
+
12
+ # Enable or Disable name field.
13
+ mattr_accessor :require_name
14
+
15
+ # Enable or Disable subject field.
16
+ mattr_accessor :require_subject
17
+
18
+ # Default way to setup ContactUs. Run rake contact_us:install to create
19
+ # a fresh initializer with all configuration values.
20
+ def self.setup
21
+ yield self
22
+ end
23
+
24
+ end
@@ -0,0 +1,12 @@
1
+ module SpreeContactUs
2
+ class Engine < Rails::Engine
3
+ engine_name 'spree_contact_us'
4
+
5
+ config.autoload_paths += %W(#{config.root}/lib)
6
+
7
+ # use rspec for tests
8
+ config.generators do |g|
9
+ g.test_framework :rspec
10
+ end
11
+ end
12
+ end
data/script/rails ADDED
@@ -0,0 +1,7 @@
1
+ # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
2
+
3
+ ENGINE_ROOT = File.expand_path('../..', __FILE__)
4
+ ENGINE_PATH = File.expand_path('../../lib/spree_contact_us/engine', __FILE__)
5
+
6
+ require 'rails/all'
7
+ require 'rails/engine/commands'
@@ -0,0 +1,23 @@
1
+ # Use this initializer to configure the contact mailer.
2
+
3
+ SpreeContactUs.setup do |config|
4
+
5
+ # ==> Mailer Configuration
6
+
7
+ # Configure the e-mail address which email notifications should be sent from. If emails must be sent from a verified email address you may set it here.
8
+ # Example:
9
+ # config.mailer_from = "contact@please-change-me.com"
10
+ config.mailer_from = nil
11
+
12
+ # Configure the e-mail address which should receive the contact form email notifications.
13
+ config.mailer_to = "contact@please-change-me.com"
14
+
15
+ # ==> Form Configuration
16
+
17
+ # Configure the form to ask for the users name.
18
+ config.require_name = false
19
+
20
+ # Configure the form to ask for a subject.
21
+ config.require_subject = false
22
+
23
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+ require 'generator_spec/test_case'
3
+ require 'generators/spree_contact_us/install/install_generator'
4
+
5
+ describe SpreeContactUs::Generators::InstallGenerator do
6
+
7
+ include GeneratorSpec::TestCase
8
+ destination File.expand_path("../../dummy", __FILE__)
9
+
10
+ before do
11
+ prepare_destination
12
+ run_generator
13
+ end
14
+
15
+ it "creates initializer file" do
16
+ assert_file "config/initializers/spree_contact_us.rb"
17
+ end
18
+
19
+ end
@@ -0,0 +1,52 @@
1
+ require 'spec_helper'
2
+
3
+ describe SpreeContactUs do
4
+
5
+ after do
6
+ SpreeContactUs.mailer_from = nil
7
+ SpreeContactUs.mailer_to = nil
8
+ SpreeContactUs.require_name = false
9
+ SpreeContactUs.require_subject = false
10
+ end
11
+
12
+ it "should be valid" do
13
+ SpreeContactUs.should be_a(Module)
14
+ end
15
+
16
+ describe 'setup block' do
17
+ it 'should yield self' do
18
+ SpreeContactUs.setup do |config|
19
+ SpreeContactUs.should eql(config)
20
+ end
21
+ end
22
+ end
23
+
24
+ describe 'mailer_from' do
25
+ it 'should be configurable' do
26
+ SpreeContactUs.mailer_from = "contact@please-change-me.com"
27
+ SpreeContactUs.mailer_from.should eql("contact@please-change-me.com")
28
+ end
29
+ end
30
+
31
+ describe 'mailer_to' do
32
+ it 'should be configurable' do
33
+ SpreeContactUs.mailer_to = "contact@please-change-me.com"
34
+ SpreeContactUs.mailer_to.should eql("contact@please-change-me.com")
35
+ end
36
+ end
37
+
38
+ describe 'require_name' do
39
+ it 'should be configurable' do
40
+ SpreeContactUs.require_name = true
41
+ SpreeContactUs.require_name.should eql(true)
42
+ end
43
+ end
44
+
45
+ describe 'require_subject' do
46
+ it 'should be configurable' do
47
+ SpreeContactUs.require_subject = true
48
+ SpreeContactUs.require_subject.should eql(true)
49
+ end
50
+ end
51
+
52
+ end
@@ -0,0 +1,61 @@
1
+ require 'spec_helper'
2
+
3
+ describe Spree::ContactUs::ContactMailer do
4
+
5
+ describe "#contact_email" do
6
+
7
+ before do
8
+ SpreeContactUs.mailer_to = "contact@please-change-me.com"
9
+ @contact = Spree::ContactUs::Contact.new(:email => 'test@email.com', :message => 'Thanks!')
10
+ end
11
+
12
+ it "should render successfully" do
13
+ lambda { Spree::ContactUs::ContactMailer.contact_email(@contact) }.should_not raise_error
14
+ end
15
+
16
+ it "should use the ContactUs.mailer_from setting when it is set" do
17
+ SpreeContactUs.mailer_from = "contact@please-change-me.com"
18
+ @mailer = Spree::ContactUs::ContactMailer.contact_email(@contact)
19
+ @mailer.from.should eql([SpreeContactUs.mailer_from])
20
+ SpreeContactUs.mailer_from = nil
21
+ end
22
+
23
+ describe "rendered without error" do
24
+
25
+ before do
26
+ @mailer = Spree::ContactUs::ContactMailer.contact_email(@contact)
27
+ end
28
+
29
+ it "should have the initializers to address" do
30
+ @mailer.to.should eql([SpreeContactUs.mailer_to])
31
+ end
32
+
33
+ it "should use the users email in the from field when ContactUs.mailer_from is not set" do
34
+ @mailer.from.should eql([@contact.email])
35
+ end
36
+
37
+ it "should have users email in the subject line" do
38
+ @mailer.subject.should eql("Contact Us message from #{@contact.email}")
39
+ end
40
+
41
+ it "should have the message in the body" do
42
+ @mailer.body.should match("<p>Thanks!</p>")
43
+ end
44
+
45
+ it "should deliver successfully" do
46
+ lambda { Spree::ContactUs::ContactMailer.contact_email(@contact).deliver }.should_not raise_error
47
+ end
48
+
49
+ describe "and delivered" do
50
+
51
+ it "should be added to the delivery queue" do
52
+ lambda { Spree::ContactUs::ContactMailer.contact_email(@contact).deliver }.should change(ActionMailer::Base.deliveries,:size).by(1)
53
+ end
54
+
55
+ end
56
+
57
+ end
58
+
59
+ end
60
+
61
+ end
@@ -0,0 +1,66 @@
1
+ require 'spec_helper'
2
+
3
+ describe Spree::ContactUs::Contact do
4
+
5
+ it_should_behave_like 'ActiveModel'
6
+
7
+ describe "Validations" do
8
+
9
+ it {should validate_presence_of(:email)}
10
+ it {should validate_presence_of(:message)}
11
+ it {should_not validate_presence_of(:name)}
12
+ it {should_not validate_presence_of(:subject)}
13
+
14
+ context 'with name and subject settings' do
15
+
16
+ after do
17
+ SpreeContactUs.require_name = false
18
+ SpreeContactUs.require_subject = false
19
+ end
20
+
21
+ before do
22
+ SpreeContactUs.require_name = true
23
+ SpreeContactUs.require_subject =true
24
+ end
25
+
26
+ it {should validate_presence_of(:name)}
27
+ it {should validate_presence_of(:subject)}
28
+
29
+ end
30
+
31
+ end
32
+
33
+ describe 'Methods' do
34
+
35
+ describe '#read_attribute_for_validation' do
36
+ it 'should return attributes set during initialization' do
37
+ contact = Spree::ContactUs::Contact.new(:email => "Valid@Email.com", :message => "Test")
38
+ contact.read_attribute_for_validation(:email).should eql("Valid@Email.com")
39
+ contact.read_attribute_for_validation(:message).should eql("Test")
40
+ end
41
+ end
42
+
43
+ describe '#save' do
44
+
45
+ it 'should return false if records invalid' do
46
+ contact = Spree::ContactUs::Contact.new(:email => "Valid@Email.com", :message => "")
47
+ contact.save.should eql(false)
48
+ end
49
+
50
+ it 'should send email and return true if records valid' do
51
+ mail = Mail.new(:from=>"Valid@Email.com", :to => "test@test.com")
52
+ mail.stub(:deliver).and_return(true)
53
+ contact = Spree::ContactUs::Contact.new(:email => "Valid@Email.com", :message => "Test")
54
+ Spree::ContactUs::ContactMailer.should_receive(:contact_email).with(contact).and_return(mail)
55
+ contact.save.should eql(true)
56
+ end
57
+
58
+ end
59
+
60
+ describe '#to_key' do
61
+ it { subject.should respond_to(:to_key) }
62
+ end
63
+
64
+ end
65
+
66
+ end
@@ -0,0 +1,140 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Contact Us page' do
4
+
5
+ after do
6
+ ActionMailer::Base.deliveries = []
7
+ SpreeContactUs.mailer_from = nil
8
+ SpreeContactUs.mailer_to = nil
9
+ SpreeContactUs.require_name = false
10
+ SpreeContactUs.require_subject = false
11
+ end
12
+
13
+ before do
14
+ ActionMailer::Base.deliveries = []
15
+ SpreeContactUs.mailer_to = 'test@test.com'
16
+ end
17
+
18
+ it 'displays default contact form properly' do
19
+ visit spree.contact_us_path
20
+ within "form#new_contact_us_contact" do
21
+ page.should have_selector "input#contact_us_contact_email"
22
+ page.should have_selector "textarea#contact_us_contact_message"
23
+ page.should_not have_selector "input#contact_us_contact_name"
24
+ page.should_not have_selector "input#contact_us_contact_subject"
25
+ page.should have_selector "input#contact_us_contact_submit"
26
+ end
27
+ end
28
+
29
+ context "Submitting the form" do
30
+
31
+ before do
32
+ visit spree.contact_us_path
33
+ end
34
+
35
+ context "when valid" do
36
+ before do
37
+ fill_in 'Email', :with => 'test@example.com'
38
+ fill_in 'Message', :with => 'howdy'
39
+ click_button 'Submit'
40
+ end
41
+
42
+ it "I should be redirected to the homepage" do
43
+ current_path.should == "/"
44
+ end
45
+
46
+ it "An email should have been sent" do
47
+ ActionMailer::Base.deliveries.size.should == 1
48
+ end
49
+
50
+ it "The email should have the correct attributes" do
51
+ mail = ActionMailer::Base.deliveries.last
52
+ mail.to.should == ['test@test.com']
53
+ mail.from.should == ['test@example.com']
54
+ mail.body.should match 'howdy'
55
+ end
56
+ end
57
+
58
+ context "when invalid" do
59
+ context "Email and message are invalid" do
60
+ before do
61
+ fill_in 'Email', :with => 'a'
62
+ fill_in 'Message', :with => ''
63
+ click_button 'Submit'
64
+ end
65
+
66
+ it "I should see two error messages" do
67
+ within '#errorExplanation' do
68
+ page.should have_content "Email is invalid"
69
+ page.should have_content "Message can't be blank"
70
+ end
71
+ end
72
+
73
+ it "An email should not have been sent" do
74
+ ActionMailer::Base.deliveries.size.should == 0
75
+ end
76
+ end
77
+ end
78
+ end
79
+
80
+ context 'with name and subject configuration' do
81
+
82
+ before do
83
+ SpreeContactUs.require_name = true
84
+ SpreeContactUs.require_subject = true
85
+ visit spree.contact_us_path
86
+ end
87
+
88
+ it "displays an input for name and subject" do
89
+ page.should have_selector "input#contact_us_contact_name"
90
+ page.should have_selector "input#contact_us_contact_subject"
91
+ end
92
+
93
+ context "Submitting the form" do
94
+ context "when valid" do
95
+ before do
96
+ fill_in 'Email', :with => 'test@example.com'
97
+ fill_in 'Message', :with => 'howdy'
98
+ fill_in 'contact_us_contact[name]', :with => 'Jeff'
99
+ fill_in 'contact_us_contact[subject]', :with => 'Testing contact form.'
100
+ click_button 'Submit'
101
+ end
102
+
103
+ it "I should be redirected to the homepage" do
104
+ current_path.should == "/"
105
+ end
106
+
107
+ it "An email should have been sent" do
108
+ ActionMailer::Base.deliveries.size.should == 1
109
+ end
110
+
111
+ it "The email should have the correct attributes" do
112
+ mail = ActionMailer::Base.deliveries.last
113
+ mail.body.should match 'howdy'
114
+ mail.body.should match 'Jeff'
115
+ mail.from.should == ['test@example.com']
116
+ mail.subject.should match 'Testing contact form.'
117
+ mail.to.should == ['test@test.com']
118
+ end
119
+ end
120
+
121
+ context "when name and subject are blank" do
122
+ before do
123
+ click_button 'Submit'
124
+ end
125
+
126
+ it "I should see error messages" do
127
+ within '#errorExplanation' do
128
+ page.should have_content "Email can't be blank"
129
+ page.should have_content "Message can't be blank"
130
+ end
131
+ end
132
+
133
+ it "An email should not have been sent" do
134
+ ActionMailer::Base.deliveries.size.should == 0
135
+ end
136
+ end
137
+ end
138
+ end
139
+
140
+ end
@@ -0,0 +1,38 @@
1
+ # Configure simeplecov for test coverage report
2
+ require 'simplecov'
3
+ SimpleCov.start do
4
+ add_filter '/config/'
5
+ add_group 'Controllers', 'app/controllers'
6
+ add_group 'Helpers', 'app/helpers'
7
+ add_group 'Mailers', 'app/mailers'
8
+ add_group 'Models', 'app/models'
9
+ add_group 'Overrides', 'app/overrides'
10
+ add_group 'Libraries', 'lib'
11
+ add_group 'Specs', 'spec'
12
+ end
13
+
14
+ # Configure Rails Environment
15
+ ENV["RAILS_ENV"] = "test"
16
+
17
+ require File.expand_path("../dummy/config/environment.rb", __FILE__)
18
+
19
+ # Configure capybara for integration testing
20
+ require "capybara/rails"
21
+ Capybara.default_driver = :rack_test
22
+ Capybara.default_selector = :css
23
+
24
+ require 'ffaker'
25
+ require 'rspec/rails'
26
+ require 'shoulda-matchers'
27
+
28
+ # Requires supporting ruby files with custom matchers and macros, etc,
29
+ # in spec/support/ and its subdirectories.
30
+ Dir[File.join(File.dirname(__FILE__), "support/**/*.rb")].each {|f| require f }
31
+
32
+ # Requires factories defined in spree_core
33
+ require 'spree/core/testing_support/factories'
34
+ require 'spree/core/url_helpers'
35
+
36
+ RSpec.configure do |config|
37
+ config.include Spree::Core::UrlHelpers
38
+ end
@@ -0,0 +1,17 @@
1
+ # adapted from rspec-rails:
2
+ # http://github.com/rspec/rspec-rails/blob/master/spec/rspec/rails/mocks/mock_model_spec.rb
3
+
4
+ shared_examples_for 'ActiveModel' do
5
+ include ActiveModel::Lint::Tests
6
+
7
+ # to_s is to support ruby-1.9
8
+ ActiveModel::Lint::Tests.public_instance_methods.map(&:to_s).grep(/^test/).each do |m|
9
+ example m.gsub('_', ' ') do
10
+ send m
11
+ end
12
+ end
13
+
14
+ def model
15
+ subject
16
+ end
17
+ end
@@ -0,0 +1,29 @@
1
+ # encoding: UTF-8
2
+ Gem::Specification.new do |s|
3
+ s.platform = Gem::Platform::RUBY
4
+ s.name = 'spree_contact_us'
5
+ s.version = '1.0.0'
6
+ s.summary = 'Reworked the contact_us gem to work with Spree.'
7
+ s.description = 'Reworked the contact_us gem to work with Spree.'
8
+ s.required_ruby_version = '>= 1.9.2'
9
+
10
+ s.author = 'Jeff Dutil'
11
+ s.email = 'jdutil@burlingtonwebapps.com'
12
+ s.homepage = 'http://github.com/jdutil/spree_contact_us'
13
+
14
+ s.files = `git ls-files`.split("\n")
15
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
+ s.require_path = 'lib'
17
+ s.requirements << 'none'
18
+
19
+ s.add_dependency 'spree_core', '>= 1.1.0.rc2'
20
+
21
+ s.add_development_dependency 'capybara', '~> 1.1'
22
+ s.add_development_dependency 'factory_girl', '~> 2.6'
23
+ s.add_development_dependency 'ffaker', '~> 1.12'
24
+ s.add_development_dependency 'generator_spec', '~> 0.8'
25
+ s.add_development_dependency 'rspec-rails', '~> 2.9'
26
+ s.add_development_dependency 'shoulda-matchers', '~> 1.1'
27
+ s.add_development_dependency 'simplecov', '~> 0.6.2'
28
+ s.add_development_dependency 'sqlite3', '~> 1.3.6'
29
+ end
metadata ADDED
@@ -0,0 +1,236 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: spree_contact_us
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jeff Dutil
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-04-28 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: spree_core
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 1.1.0.rc2
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 1.1.0.rc2
30
+ - !ruby/object:Gem::Dependency
31
+ name: capybara
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '1.1'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '1.1'
46
+ - !ruby/object:Gem::Dependency
47
+ name: factory_girl
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: '2.6'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '2.6'
62
+ - !ruby/object:Gem::Dependency
63
+ name: ffaker
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: '1.12'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: '1.12'
78
+ - !ruby/object:Gem::Dependency
79
+ name: generator_spec
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ~>
84
+ - !ruby/object:Gem::Version
85
+ version: '0.8'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ~>
92
+ - !ruby/object:Gem::Version
93
+ version: '0.8'
94
+ - !ruby/object:Gem::Dependency
95
+ name: rspec-rails
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ~>
100
+ - !ruby/object:Gem::Version
101
+ version: '2.9'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ~>
108
+ - !ruby/object:Gem::Version
109
+ version: '2.9'
110
+ - !ruby/object:Gem::Dependency
111
+ name: shoulda-matchers
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ~>
116
+ - !ruby/object:Gem::Version
117
+ version: '1.1'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ~>
124
+ - !ruby/object:Gem::Version
125
+ version: '1.1'
126
+ - !ruby/object:Gem::Dependency
127
+ name: simplecov
128
+ requirement: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ~>
132
+ - !ruby/object:Gem::Version
133
+ version: 0.6.2
134
+ type: :development
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ~>
140
+ - !ruby/object:Gem::Version
141
+ version: 0.6.2
142
+ - !ruby/object:Gem::Dependency
143
+ name: sqlite3
144
+ requirement: !ruby/object:Gem::Requirement
145
+ none: false
146
+ requirements:
147
+ - - ~>
148
+ - !ruby/object:Gem::Version
149
+ version: 1.3.6
150
+ type: :development
151
+ prerelease: false
152
+ version_requirements: !ruby/object:Gem::Requirement
153
+ none: false
154
+ requirements:
155
+ - - ~>
156
+ - !ruby/object:Gem::Version
157
+ version: 1.3.6
158
+ description: Reworked the contact_us gem to work with Spree.
159
+ email: jdutil@burlingtonwebapps.com
160
+ executables: []
161
+ extensions: []
162
+ extra_rdoc_files: []
163
+ files:
164
+ - .gitignore
165
+ - .rspec
166
+ - .travis.yml
167
+ - Gemfile
168
+ - LICENSE
169
+ - README.md
170
+ - Rakefile
171
+ - Versionfile
172
+ - app/assets/javascripts/admin/spree_contact_us.js
173
+ - app/assets/javascripts/store/spree_contact_us.js
174
+ - app/assets/stylesheets/admin/spree_contact_us.css
175
+ - app/assets/stylesheets/store/spree_contact_us.css
176
+ - app/controllers/spree/contact_us/contacts_controller.rb
177
+ - app/mailers/spree/contact_us/contact_mailer.rb
178
+ - app/models/spree/contact_us/contact.rb
179
+ - app/overrides/contact_us_in_footer.rb
180
+ - app/overrides/contact_us_in_header.rb
181
+ - app/views/spree/contact_us/contact_mailer/contact_email.html.erb
182
+ - app/views/spree/contact_us/contact_mailer/contact_email.text.plain.erb
183
+ - app/views/spree/contact_us/contacts/new.html.erb
184
+ - config/locales/spree_contact_us.en.yml
185
+ - config/routes.rb
186
+ - lib/generators/spree_contact_us/install/install_generator.rb
187
+ - lib/generators/spree_contact_us/templates/spree_contact_us.rb
188
+ - lib/spree_contact_us.rb
189
+ - lib/spree_contact_us/engine.rb
190
+ - script/rails
191
+ - spec/lib/generators/spree_contact_us/dummy/config/initializers/spree_contact_us.rb
192
+ - spec/lib/generators/spree_contact_us/install/install_generator_spec.rb
193
+ - spec/lib/spree_contact_us_spec.rb
194
+ - spec/mailers/spree/contact_us/contact_mailer_spec.rb
195
+ - spec/models/spree/contact_us/contact_spec.rb
196
+ - spec/requests/spree_contact_us_lint_spec.rb
197
+ - spec/spec_helper.rb
198
+ - spec/support/active_model_lint.rb
199
+ - spree_contact_us.gemspec
200
+ homepage: http://github.com/jdutil/spree_contact_us
201
+ licenses: []
202
+ post_install_message:
203
+ rdoc_options: []
204
+ require_paths:
205
+ - lib
206
+ required_ruby_version: !ruby/object:Gem::Requirement
207
+ none: false
208
+ requirements:
209
+ - - ! '>='
210
+ - !ruby/object:Gem::Version
211
+ version: 1.9.2
212
+ required_rubygems_version: !ruby/object:Gem::Requirement
213
+ none: false
214
+ requirements:
215
+ - - ! '>='
216
+ - !ruby/object:Gem::Version
217
+ version: '0'
218
+ segments:
219
+ - 0
220
+ hash: -4355211758008457708
221
+ requirements:
222
+ - none
223
+ rubyforge_project:
224
+ rubygems_version: 1.8.19
225
+ signing_key:
226
+ specification_version: 3
227
+ summary: Reworked the contact_us gem to work with Spree.
228
+ test_files:
229
+ - spec/lib/generators/spree_contact_us/dummy/config/initializers/spree_contact_us.rb
230
+ - spec/lib/generators/spree_contact_us/install/install_generator_spec.rb
231
+ - spec/lib/spree_contact_us_spec.rb
232
+ - spec/mailers/spree/contact_us/contact_mailer_spec.rb
233
+ - spec/models/spree/contact_us/contact_spec.rb
234
+ - spec/requests/spree_contact_us_lint_spec.rb
235
+ - spec/spec_helper.rb
236
+ - spec/support/active_model_lint.rb