Skip to content

Commit dba0730

Browse files
authored
Merge pull request #175 from brigriffin/add-company
Add optional company field in inquiry form
2 parents 3fcf140 + 8218108 commit dba0730

File tree

12 files changed

+75
-2
lines changed

12 files changed

+75
-2
lines changed

app/controllers/refinery/inquiries/inquiries_controller.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def inquiry_params
4141
private
4242

4343
def permitted_inquiry_params
44-
[:name, :phone, :message, :email]
44+
[:name, :company, :phone, :message, :email]
4545
end
4646

4747
def inquiry_saved_and_validated?

app/models/refinery/inquiries/inquiry.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class Inquiry < Refinery::Core::BaseModel
99
filters_spam message_field: :message,
1010
email_field: :email,
1111
author_field: :name,
12-
other_fields: [:phone],
12+
other_fields: [:phone, :company],
1313
extra_spam_words: %w()
1414
end
1515

app/views/refinery/inquiries/admin/inquiries/show.html.erb

+10
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,16 @@
4646
<%= @inquiry.name %> [<%= mail_to @inquiry.email, @inquiry.email, {:title => t('.click_to_email')} %>]
4747
</td>
4848
</tr>
49+
<% if @inquiry.company.present? %>
50+
<tr>
51+
<td>
52+
<strong><%= t('.company') %></strong>
53+
</td>
54+
<td>
55+
<%= @inquiry.company %>
56+
</td>
57+
</tr>
58+
<% end %>
4959
<% unless @inquiry.phone.blank? %>
5060
<tr>
5161
<td>

app/views/refinery/inquiries/inquiries/_form.html.erb

+8
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@
1111
:placeholder => (t('name', :scope => 'activerecord.attributes.refinery/inquiries/inquiry') if Refinery::Inquiries.show_placeholders) %>
1212
</div>
1313

14+
<% if Refinery::Inquiries.show_company_field %>
15+
<div class="field">
16+
<%= f.label :company, :class => 'placeholder-fallback' %>
17+
<%= f.text_field :company, :class => 'text company',
18+
:placeholder => (t('company', :scope => 'activerecord.attributes.refinery/inquiries/inquiry') if Refinery::Inquiries.show_placeholders) %>
19+
</div>
20+
<% end %>
21+
1422
<div class="field">
1523
<%= f.label :email, :class => 'placeholder-fallback required' %>
1624
<%= f.email_field :email, :class => 'text email', :required => 'required',

app/views/refinery/inquiries/inquiry_mailer/notification.text.erb

+3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
<%=raw t('.inquiry_starts') %>
66

77
<%=raw t('.from') %>: <%= @inquiry.name %>
8+
<% if Refinery::Inquiries.show_company_field == true %>
9+
<%=raw t('.company') %>: <%= @inquiry.company %>
10+
<% end %>
811
<%=raw t('.email') %>: <%= @inquiry.email %>
912
<%=raw t('.phone') %>: <%= @inquiry.phone %>
1013
<%=raw t('.message') %>:

config/locales/de.yml

+3
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ de:
3838
to: An
3939
from: Von
4040
click_to_email: Klicken, um eine E-Mail an diese Adresse zu schicken
41+
company: Firma
4142
phone: Telefon
4243
date: Datum
4344
message: Nachricht
@@ -65,6 +66,7 @@ de:
6566
inquiry_ends: --- Ende der Kontaktanfrage ---
6667
from: Von
6768
email: E-Mail
69+
company: Firma
6870
phone: Telefon
6971
message: Nachricht
7072
closing_line: Mit freundlichen Grüßen
@@ -76,5 +78,6 @@ de:
7678
refinery/inquiries/inquiry:
7779
name: Name
7880
email: E-Mail
81+
company: Firma
7982
phone: Telefon
8083
message: Nachricht

config/locales/en.yml

+3
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ en:
4040
to: To
4141
from: From
4242
click_to_email: Click to email this address
43+
company: Company
4344
phone: Phone
4445
date: Date
4546
message: Message
@@ -65,6 +66,7 @@ en:
6566
inquiry_starts: --- inquiry starts ---
6667
inquiry_ends: --- inquiry ends ---
6768
from: From
69+
company: Company
6870
email: Email
6971
phone: Phone
7072
message: Message
@@ -76,6 +78,7 @@ en:
7678
attributes:
7779
refinery/inquiries/inquiry:
7880
name: Name
81+
company: Company
7982
email: Email
8083
phone: Phone
8184
message: Message

config/locales/fr.yml

+3
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ fr:
4040
to: À
4141
from: De
4242
click_to_email: Cliquer ici pour enyoyer un e-mail à cette adresse
43+
company: Compagnie
4344
phone: Téléphone
4445
date: Date
4546
message: Message
@@ -67,6 +68,7 @@ fr:
6768
inquiry_ends: --- Fin des requêtes ---
6869
from: De
6970
email: E-mail
71+
company: Compagnie
7072
phone: Téléphone
7173
message: Message
7274
closing_line: Cordialement
@@ -78,5 +80,6 @@ fr:
7880
refinery/inquiries/inquiry:
7981
name: Nom
8082
email: E-mail
83+
company: Compagnie
8184
phone: Téléphone
8285
message: Message
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class AddCompanyToRefineryInquiriesInquiry < ActiveRecord::Migration[4.2]
2+
def up
3+
add_column :refinery_inquiries_inquiries, :company, :string
4+
end
5+
6+
def down
7+
remove_column :refinery_inquiries_inquiries, :company
8+
end
9+
end

lib/generators/refinery/inquiries/templates/config/initializers/refinery/inquiries.rb.erb

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ Refinery::Inquiries.configure do |config|
22
# Configure whether to show privacy link
33
# config.show_contact_privacy_link = <%= Refinery::Inquiries.show_contact_privacy_link.inspect %>
44

5+
# Configure whether to show company field
6+
# config.show_company_field = <%= Refinery::Inquiries.show_company_field.inspect %>
7+
58
# Configure whether to show phone number field
69
# config.show_phone_number_field = <%= Refinery::Inquiries.show_phone_number_field.inspect %>
710

lib/refinery/inquiries/configuration.rb

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module Inquiries
33
include ActiveSupport::Configurable
44

55
config_accessor :show_contact_privacy_link
6+
config_accessor :show_company_field
67
config_accessor :show_phone_number_field
78
config_accessor :show_placeholders
89
config_accessor :send_notifications_for_inquiries_marked_as_spam
@@ -11,6 +12,7 @@ module Inquiries
1112
config_accessor :filter_spam, :recaptcha_site_key
1213

1314
self.show_contact_privacy_link = true
15+
self.show_company_field = false
1416
self.show_phone_number_field = true
1517
self.show_placeholders = true
1618
self.send_notifications_for_inquiries_marked_as_spam = false

spec/features/refinery/inquiries/inquiries_spec.rb

+29
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ module Inquiries
5151
expect(page).to have_content(email_error_message)
5252
expect(page).to have_content(message_error_message)
5353
expect(page).to have_no_content("Phone can't be blank")
54+
expect(page).to have_no_content("Company can't be blank")
5455

5556
expect(Refinery::Inquiries::Inquiry.count).to eq(0)
5657
end
@@ -145,6 +146,34 @@ module Inquiries
145146
end
146147
end
147148
end
149+
150+
describe "company" do
151+
context "when show company setting set to false" do
152+
before(:each) do
153+
allow(Refinery::Inquiries.config).to receive(:show_company_field).and_return(false)
154+
end
155+
156+
it "won't show company" do
157+
visit refinery.inquiries_new_inquiry_path
158+
159+
expect(page).to have_no_selector("label", :text => 'Company')
160+
expect(page).to have_no_selector("#inquiry_company")
161+
end
162+
end
163+
164+
context "when show company setting set to true" do
165+
before(:each) do
166+
allow(Refinery::Inquiries.config).to receive(:show_company_field).and_return(true)
167+
end
168+
169+
it "shows the company" do
170+
visit refinery.inquiries_new_inquiry_path
171+
172+
expect(page).to have_selector("label", :text => 'Company')
173+
expect(page).to have_selector("#inquiry_company")
174+
end
175+
end
176+
end
148177
end
149178
end
150179
end

0 commit comments

Comments
 (0)