refinerycms-inquiries 2.1.0 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +5 -6
  3. data/Gemfile +14 -18
  4. data/Rakefile +0 -1
  5. data/app/assets/stylesheets/refinery/inquiries/inquiries.css.scss +3 -0
  6. data/app/controllers/refinery/inquiries/admin/inquiries_controller.rb +9 -3
  7. data/app/controllers/refinery/inquiries/admin/settings_controller.rb +34 -16
  8. data/app/controllers/refinery/inquiries/inquiries_controller.rb +29 -13
  9. data/app/mailers/refinery/inquiries/inquiry_mailer.rb +20 -10
  10. data/app/models/refinery/inquiries/inquiry.rb +13 -11
  11. data/app/models/refinery/inquiries/setting.rb +33 -31
  12. data/app/views/refinery/inquiries/admin/inquiries/_submenu.html.erb +7 -7
  13. data/app/views/refinery/inquiries/admin/settings/_confirmation_email_form.html.erb +2 -2
  14. data/app/views/refinery/inquiries/inquiries/_form.html.erb +35 -0
  15. data/app/views/refinery/inquiries/inquiries/new.html.erb +4 -38
  16. data/bin/rails +5 -0
  17. data/bin/rake +21 -0
  18. data/bin/rspec +22 -0
  19. data/bin/spring +18 -0
  20. data/config/locales/bg.yml +2 -2
  21. data/config/locales/cs.yml +2 -2
  22. data/config/locales/da.yml +2 -2
  23. data/config/locales/de.yml +2 -2
  24. data/config/locales/en-GB.yml +2 -2
  25. data/config/locales/en.yml +2 -2
  26. data/config/locales/es.yml +2 -2
  27. data/config/locales/fr.yml +2 -2
  28. data/config/locales/it.yml +1 -1
  29. data/config/locales/lt.yml +2 -2
  30. data/config/locales/lv.yml +2 -2
  31. data/config/locales/nb.yml +2 -2
  32. data/config/locales/nl.yml +2 -2
  33. data/config/locales/pl.yml +2 -2
  34. data/config/locales/pt-BR.yml +2 -2
  35. data/config/locales/ru.yml +2 -2
  36. data/config/locales/sk.yml +2 -2
  37. data/config/locales/sl.yml +2 -2
  38. data/config/locales/sv.yml +2 -2
  39. data/config/locales/zh-CN.yml +2 -2
  40. data/config/locales/zh-TW.yml +79 -0
  41. data/config/routes.rb +11 -7
  42. data/db/migrate/20101208082840_create_inquiries.rb +4 -3
  43. data/db/seeds.rb +9 -11
  44. data/lib/generators/refinery/inquiries/templates/config/initializers/refinery/inquiries.rb.erb +8 -0
  45. data/lib/refinery/inquiries/configuration.rb +6 -0
  46. data/lib/refinery/inquiries/engine.rb +3 -7
  47. data/readme.md +23 -10
  48. data/refinerycms-inquiries.gemspec +4 -3
  49. data/spec/factories/inquiry.rb +4 -2
  50. data/spec/features/refinery/inquiries/admin/inquiries_spec.rb +32 -43
  51. data/spec/features/refinery/inquiries/inquiries_spec.rb +37 -32
  52. data/spec/features/refinery/inquiries/mailer_spec.rb +15 -14
  53. data/spec/models/refinery/inquiries/inquiry_spec.rb +62 -20
  54. data/spec/models/refinery/inquiries/setting_spec.rb +19 -0
  55. data/spec/spec_helper.rb +3 -3
  56. metadata +39 -18
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f114529cf10c2021be3716ce6f9cc8e50c75a621
4
- data.tar.gz: dc9e45204e308791b9f071815c990add3a12670a
3
+ metadata.gz: f72e5741f8019cc82253bc2479aa1e87ea3ebc96
4
+ data.tar.gz: 7062094890592ac5fa41531e7848f3d978610d75
5
5
  SHA512:
6
- metadata.gz: efd97df61475b46d4abbc14ff1cf085e8b1e81835d4fc5c0129c3a31b2f74f1ac6dedc658a91d53df3fac44ed9a794ecbcbd6d9401641fb29552c27d0c36679f
7
- data.tar.gz: fc7caa590ec372433a099f6aea1531a36c21e1fbdd157210e469634beda91b742707f4dfa8e82946d5b2219cfa2fcfc968a85311aa6391fd4902b554b86e6016
6
+ metadata.gz: ddcd85adb7c887f5be98bf117abaf28fe2e2ac1839efadb52dbb2093bf8fa6bbbf9cc033d09360c164be25f139a3fa2637fe5a7b4af1e63c01fa43e4c6e139da
7
+ data.tar.gz: c4412b554ae3000ad8f5f4832471b46750fd38ee9f3fc7d01df64f8164e3ed24f553981499714b9c5e0879255f839c4c1ed233d8250229fb088315556f2ea705
@@ -1,4 +1,6 @@
1
1
  language: ruby
2
+ sudo: false
3
+ cache: bundler
2
4
  bundler_args: --without development
3
5
  before_script:
4
6
  - "sh -e /etc/init.d/xvfb start"
@@ -17,14 +19,11 @@ notifications:
17
19
  on_failure: always
18
20
  rooms:
19
21
  - secure: "JaX+Ckvdd2wqL2bD6t8PHvMDBHxWBlCrkBKPcDKxV0t0DOwzzzwxMryVqcRi\nPsmM/zvmWFATDyRmivhNOpu4lRg9RytSroxZ9nkmbLDqjCyEAZ6tv4yZXME/\nPaxPwmfwgS9g8TKjj3lSWS7rEpqqg0D5S0XIfIHrj6KB6LUmFHc="
22
+ webhooks:
23
+ - https://webhooks.gitter.im/e/b5d48907cdc89864b874
20
24
  env:
21
25
  - DB=postgresql
22
26
  - DB=mysql
23
- matrix:
24
- allow_failures:
25
- - rvm: rbx-19mode
26
27
  rvm:
28
+ - 2.1
27
29
  - 2.0.0
28
- - 1.9.3
29
- - rbx-19mode
30
- - jruby-19mode
data/Gemfile CHANGED
@@ -2,39 +2,35 @@ source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
4
 
5
- gem 'refinerycms', '~> 2.1.0'
6
- gem 'refinerycms-acts-as-indexed', '~> 1.0.0'
5
+ gem 'refinerycms', github: 'refinery/refinerycms'
6
+ gem 'refinerycms-settings', github: 'refinery/refinerycms-settings'
7
7
 
8
8
  group :test do
9
- gem 'refinerycms-testing', '~> 2.1.0'
10
- gem 'capybara-email', '~> 2.1.2'
9
+ gem 'refinerycms-testing', github: 'refinery/refinerycms'
10
+ gem 'capybara-email', '~> 2.4.0'
11
+ gem 'poltergeist'
11
12
  end
12
13
 
13
14
  # Database Configuration
14
15
  unless ENV['TRAVIS']
15
- gem 'activerecord-jdbcsqlite3-adapter', :platform => :jruby
16
- gem 'sqlite3', :platform => :ruby
16
+ gem 'activerecord-jdbcsqlite3-adapter', platform: :jruby
17
+ gem 'sqlite3', platform: :ruby
17
18
  end
18
19
 
19
20
  if !ENV['TRAVIS'] || ENV['DB'] == 'mysql'
20
- gem 'activerecord-jdbcmysql-adapter', :platform => :jruby
21
- gem 'jdbc-mysql', '= 5.1.13', :platform => :jruby
22
- gem 'mysql2', :platform => :ruby
21
+ gem 'activerecord-jdbcmysql-adapter', platform: :jruby
22
+ gem 'jdbc-mysql', '= 5.1.13', platform: :jruby
23
+ gem 'mysql2', platform: :ruby
23
24
  end
24
25
 
25
26
  if !ENV['TRAVIS'] || ENV['DB'] == 'postgresql'
26
- gem 'activerecord-jdbcpostgresql-adapter', :platform => :jruby
27
- gem 'pg', :platform => :ruby
27
+ gem 'activerecord-jdbcpostgresql-adapter', platform: :jruby
28
+ gem 'pg', platform: :ruby
28
29
  end
29
30
 
30
- gem 'jruby-openssl', :platform => :jruby
31
-
32
31
  # Refinery/rails should pull in the proper versions of these
33
- group :assets do
34
- gem 'sass-rails'
35
- gem 'coffee-rails'
36
- gem 'uglifier'
37
- end
32
+ gem 'sass-rails', '~> 4.0.0'
33
+ gem 'coffee-rails', '~> 4.0.0'
38
34
 
39
35
  # Load local gems according to Refinery developer preference.
40
36
  if File.exist? local_gemfile = File.expand_path('../.gemfile', __FILE__)
data/Rakefile CHANGED
@@ -13,7 +13,6 @@ if File.exists?(APP_RAKEFILE)
13
13
  end
14
14
 
15
15
  require "refinerycms-testing"
16
- Refinery::Testing::Railtie.load_tasks
17
16
  Refinery::Testing::Railtie.load_dummy_tasks(ENGINE_PATH)
18
17
 
19
18
  load File.expand_path('../tasks/rspec.rake', __FILE__)
@@ -4,6 +4,9 @@
4
4
  label {
5
5
  width: 150px;
6
6
  float: left;
7
+ &.required:after {
8
+ content:" *"
9
+ }
7
10
  }
8
11
  input {
9
12
  width: 200px;
@@ -9,9 +9,9 @@ module Refinery
9
9
 
10
10
  helper_method :group_by_date
11
11
 
12
- before_filter :find_all_ham, :only => [:index]
13
- before_filter :find_all_spam, :only => [:spam]
14
- before_filter :get_spam_count, :only => [:index, :spam]
12
+ before_action :find_all_ham, :only => [:index]
13
+ before_action :find_all_spam, :only => [:spam]
14
+ before_action :get_spam_count, :only => [:index, :spam]
15
15
 
16
16
  def index
17
17
  @inquiries = @inquiries.with_query(params[:search]) if searching?
@@ -44,6 +44,12 @@ module Refinery
44
44
  @spam_count = Refinery::Inquiries::Inquiry.where(:spam => true).count
45
45
  end
46
46
 
47
+ private
48
+
49
+ def inquiry_params
50
+ params.require(:inquiry).permit(:name, :phone, :message, :email)
51
+ end
52
+
47
53
  end
48
54
  end
49
55
  end
@@ -3,41 +3,59 @@ module Refinery
3
3
  module Admin
4
4
  class SettingsController < Refinery::AdminController
5
5
 
6
- before_filter :check_setting, :only => [:edit, :update]
7
- after_filter :save_subject_for_confirmation, :save_message_for_confirmation, :only => :update
6
+ before_action :find_setting, :only => [:edit, :update]
7
+ after_action :save_subject_for_confirmation,
8
+ :save_message_for_confirmation, :save_notification_recipients, :only => :update
8
9
 
9
10
  def edit
10
- @setting = Refinery::Setting.find(params[:id])
11
11
  end
12
12
 
13
13
  def update
14
- @setting = Refinery::Setting.find(params[:id])
14
+ flash[:notice] = t('refinery.crudify.updated', :what => @setting.name.gsub("inquiry_", "").titleize)
15
15
 
16
- if @setting.update_attributes(params[:setting])
17
- flash[:notice] = t('refinery.crudify.updated', :what => @setting.name.gsub("inquiry_", "").titleize)
18
-
19
- unless request.xhr? or from_dialog?
20
- redirect_back_or_default(refinery.inquiries_admin_inquiries_path)
21
- else
22
- render :text => "<script type='text/javascript'>parent.window.location = '#{refinery.inquiries_admin_inquiries_path}';</script>"
23
- end
16
+ unless request.xhr? or from_dialog?
17
+ redirect_back_or_default(refinery.inquiries_admin_inquiries_path)
18
+ else
19
+ render text: "<script type='text/javascript'>parent.window.location = '#{refinery.inquiries_admin_inquiries_path}';</script>"
24
20
  end
25
21
  end
26
22
 
27
23
  protected
28
24
 
29
- def check_setting
25
+ def find_setting
30
26
  setting = params[:id].gsub("inquiry_", "")
31
27
 
32
- Refinery::Inquiries::Setting.send(setting) if Refinery::Inquiries::Setting.respond_to?(setting)
28
+ if Refinery::Inquiries::Setting.respond_to?(setting)
29
+ Refinery::Inquiries::Setting.send(setting)
30
+ end
31
+
32
+ @setting = Refinery::Setting.friendly.find(params[:id])
33
+ end
34
+
35
+ def save_notification_recipients
36
+ if setting_params.include?('value')
37
+ Refinery::Inquiries::Setting.notification_recipients = setting_params[:value]
38
+ end
33
39
  end
34
40
 
35
41
  def save_subject_for_confirmation
36
- Refinery::Inquiries::Setting.confirmation_subject = params[:subject] if params.keys.include?('subject')
42
+ if setting_params.include?('subject')
43
+ Refinery::Inquiries::Setting.confirmation_subject = setting_params[:subject]
44
+ end
37
45
  end
38
46
 
39
47
  def save_message_for_confirmation
40
- Refinery::Inquiries::Setting.confirmation_message = params[:message] if params.keys.include?('message')
48
+ if setting_params.include?('message')
49
+ Refinery::Inquiries::Setting.confirmation_message = setting_params[:message]
50
+ end
51
+ end
52
+
53
+ private
54
+
55
+ def setting_params
56
+ params.require(:setting).permit(:value,
57
+ subject: Refinery::I18n.frontend_locales,
58
+ message: Refinery::I18n.frontend_locales)
41
59
  end
42
60
 
43
61
  end
@@ -2,44 +2,60 @@ module Refinery
2
2
  module Inquiries
3
3
  class InquiriesController < ::ApplicationController
4
4
 
5
- before_filter :find_page, :only => [:create, :new]
5
+ before_action :find_page, only: [:create, :new]
6
+ before_action :find_thank_you_page, only: :thank_you
6
7
 
7
8
  def thank_you
8
- @page = ::Refinery::Page.find_by_link_url("/contact/thank_you")
9
9
  end
10
10
 
11
11
  def new
12
- @inquiry = ::Refinery::Inquiries::Inquiry.new
12
+ @inquiry = Inquiry.new
13
13
  end
14
14
 
15
15
  def create
16
- @inquiry = ::Refinery::Inquiries::Inquiry.new(params[:inquiry])
16
+ @inquiry = Inquiry.new(inquiry_params)
17
17
 
18
18
  if @inquiry.save
19
- if @inquiry.ham? || Refinery::Inquiries.send_notifications_for_inquiries_marked_as_spam
19
+ if @inquiry.ham? || Inquiries.send_notifications_for_inquiries_marked_as_spam
20
20
  begin
21
- ::Refinery::Inquiries::InquiryMailer.notification(@inquiry, request).deliver
21
+ InquiryMailer.notification(@inquiry, request).deliver_now
22
22
  rescue
23
23
  logger.warn "There was an error delivering an inquiry notification.\n#{$!}\n"
24
24
  end
25
25
 
26
- begin
27
- ::Refinery::Inquiries::InquiryMailer.confirmation(@inquiry, request).deliver
28
- rescue
29
- logger.warn "There was an error delivering an inquiry confirmation:\n#{$!}\n"
30
- end if ::Refinery::Inquiries::Setting.send_confirmation?
26
+ if Setting.send_confirmation?
27
+ begin
28
+ InquiryMailer.confirmation(@inquiry, request).deliver_now
29
+ rescue
30
+ logger.warn "There was an error delivering an inquiry confirmation:\n#{$!}\n"
31
+ end
32
+ end
31
33
  end
32
34
 
33
35
  redirect_to refinery.thank_you_inquiries_inquiries_path
34
36
  else
35
- render :action => 'new'
37
+ render action: 'new'
36
38
  end
37
39
  end
38
40
 
39
41
  protected
40
42
 
41
43
  def find_page
42
- @page = ::Refinery::Page.find_by_link_url("/contact")
44
+ @page = Page.find_by(link_url: Refinery::Inquiries.page_path_new)
45
+ end
46
+
47
+ def find_thank_you_page
48
+ @page = Page.find_by(link_url: Refinery::Inquiries.page_path_thank_you)
49
+ end
50
+
51
+ def inquiry_params
52
+ params.require(:inquiry).permit(permitted_inquiry_params)
53
+ end
54
+
55
+ private
56
+
57
+ def permitted_inquiry_params
58
+ [:name, :phone, :message, :email]
43
59
  end
44
60
 
45
61
  end
@@ -3,27 +3,37 @@ module Refinery
3
3
  class InquiryMailer < ActionMailer::Base
4
4
 
5
5
  def confirmation(inquiry, request)
6
- @inquiry = inquiry
6
+ @inquiry, @request = inquiry, request
7
7
  mail :subject => Refinery::Inquiries::Setting.confirmation_subject(Globalize.locale),
8
8
  :to => inquiry.email,
9
- :from => ::I18n.t('from_name',
10
- :scope => 'refinery.inquiries.config',
11
- :site_name => Refinery::Core.site_name,
12
- :name => @inquiry.name) + " <#{Refinery::Inquiries.from_name}@#{request.domain}>",
9
+ :from => from_info,
13
10
  :reply_to => Refinery::Inquiries::Setting.notification_recipients.split(',').first
14
11
  end
15
12
 
16
13
  def notification(inquiry, request)
17
- @inquiry = inquiry
14
+ @inquiry, @request = inquiry, request
18
15
  mail :subject => Refinery::Inquiries::Setting.notification_subject,
19
16
  :to => Refinery::Inquiries::Setting.notification_recipients,
20
- :from => ::I18n.t('from_name',
21
- :scope => 'refinery.inquiries.config',
22
- :site_name => Refinery::Core.site_name,
23
- :name => @inquiry.name) + " <#{Refinery::Inquiries.from_name}@#{request.domain}>",
17
+ :from => from_info,
24
18
  :reply_to => inquiry.email
25
19
  end
26
20
 
21
+ private
22
+
23
+ def from_info
24
+ "\"#{from_name}\" <#{from_mail}>"
25
+ end
26
+
27
+ def from_name
28
+ ::I18n.t('from_name',
29
+ :scope => 'refinery.inquiries.config',
30
+ :site_name => Refinery::Core.site_name,
31
+ :name => @inquiry.name)
32
+ end
33
+
34
+ def from_mail
35
+ "#{Refinery::Inquiries.from_name}@#{@request.domain}"
36
+ end
27
37
  end
28
38
  end
29
39
  end
@@ -5,19 +5,21 @@ module Refinery
5
5
  module Inquiries
6
6
  class Inquiry < Refinery::Core::BaseModel
7
7
 
8
- filters_spam :message_field => :message,
9
- :email_field => :email,
10
- :author_field => :name,
11
- :other_fields => [:phone],
12
- :extra_spam_words => %w()
13
-
14
- validates :name, :presence => true
15
- validates :email, :format => { :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i }
16
- validates :message, :presence => true
8
+ if Inquiries.config.filter_spam
9
+ filters_spam message_field: :message,
10
+ email_field: :email,
11
+ author_field: :name,
12
+ other_fields: [:phone],
13
+ extra_spam_words: %w()
14
+ end
17
15
 
18
- default_scope :order => 'created_at DESC'
16
+ validates :name, presence: true, length: { maximum: 255 }
17
+ validates :email, format: {
18
+ with: /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i
19
+ }, length: { maximum: 255 }
20
+ validates :message, presence: true
19
21
 
20
- attr_accessible :name, :phone, :message, :email
22
+ default_scope { order('created_at DESC') }
21
23
 
22
24
  def self.latest(number = 7, include_spam = false)
23
25
  include_spam ? limit(number) : ham.limit(number)
@@ -1,61 +1,63 @@
1
+ require 'refinery/setting'
2
+
1
3
  module Refinery
2
4
  module Inquiries
3
- class Setting
5
+ class Setting < ::Refinery::Setting
4
6
 
5
7
  class << self
6
8
  def confirmation_body
7
- Refinery::Setting.find_or_set(:inquiry_confirmation_body,
9
+ find_or_set(:inquiry_confirmation_body,
8
10
  "Thank you for your inquiry %name%,\n\nThis email is a receipt to confirm we have received your inquiry and we'll be in touch shortly.\n\nThanks."
9
11
  )
10
12
  end
11
13
 
12
14
  def confirmation_subject(locale='en')
13
- Refinery::Setting.find_or_set("inquiry_confirmation_subject_#{locale}".to_sym,
14
- "Thank you for your inquiry",
15
- :scoping => "inquiries")
15
+ find_or_set(:"inquiry_confirmation_subject_#{locale}",
16
+ "Thank you for your inquiry",
17
+ scoping: "inquiries"
18
+ )
16
19
  end
17
20
 
18
- def confirmation_subject=(value)
19
- value.first.keys.each do |locale|
20
- Refinery::Setting.set("inquiry_confirmation_subject_#{locale}".to_sym, {
21
- :value => value.first[locale.to_sym],
22
- :scoping => "inquiries"
23
- })
21
+ def confirmation_subject=(locales_subjects)
22
+ locales_subjects.each do |locale, subject|
23
+ set(:"inquiry_confirmation_subject_#{locale}", {
24
+ value: subject,
25
+ scoping: "inquiries"
26
+ })
24
27
  end
25
28
  end
26
29
 
27
30
  def confirmation_message(locale='en')
28
- Refinery::Setting.find_or_set("inquiry_confirmation_message_#{locale}".to_sym,
29
- Refinery::Setting[:inquiry_confirmation_body],
30
- :scoping => "inquiries")
31
+ find_or_set(:"inquiry_confirmation_message_#{locale}", confirmation_body, scoping: "inquiries")
31
32
  end
32
33
 
33
-
34
- def confirmation_message=(value)
35
- value.first.keys.each do |locale|
36
- Refinery::Setting.set("inquiry_confirmation_message_#{locale}".to_sym, {
37
- :value => value.first[locale.to_sym],
38
- :scoping => "inquiries"
39
- })
34
+ def confirmation_message=(locales_messages)
35
+ locales_messages.each do |locale, message|
36
+ set(:"inquiry_confirmation_message_#{locale}", {
37
+ value: message,
38
+ scoping: "inquiries"
39
+ })
40
40
  end
41
41
  end
42
42
 
43
43
  def notification_recipients
44
- Refinery::Setting.find_or_set(:inquiry_notification_recipients,
45
- ((Refinery::Role[:refinery].users.first.email rescue nil) if defined?(Refinery::Role)).to_s,
46
- :scoping => "inquiries")
44
+ recipients = ((Role[:refinery].users.first.email rescue nil) if defined?(Role)).to_s
45
+ find_or_set(:inquiry_notification_recipients, recipients, scoping: "inquiries")
46
+ end
47
+
48
+ def notification_recipients=(recipients)
49
+ set(:inquiry_notification_recipients, {
50
+ value: recipients,
51
+ scoping: "inquiries"
52
+ })
47
53
  end
48
54
 
49
55
  def notification_subject
50
- Refinery::Setting.find_or_set(:inquiry_notification_subject,
51
- "New inquiry from your website",
52
- :scoping => "inquiries")
56
+ find_or_set(:inquiry_notification_subject, "New inquiry from your website", scoping: "inquiries")
53
57
  end
54
-
58
+
55
59
  def send_confirmation?
56
- Refinery::Setting.find_or_set(:inquiry_send_confirmation,
57
- true,
58
- :scoping => "inquiries")
60
+ find_or_set(:inquiry_send_confirmation, true, scoping: "inquiries")
59
61
  end
60
62
  end
61
63
  end