Permalink
Browse files

Refactored syntax, switched to Poltergeist for testing.

* Now Refinery::Inquiries::Setting is inheriting Refinery::Setting
  • Loading branch information...
1 parent adc21d1 commit b63014801ecd1b9df2dafa6b63a3eec350c42241 @parndt parndt committed Sep 1, 2013
View
@@ -9,6 +9,9 @@ gem 'refinerycms-acts-as-indexed', '~> 1.0.0'
group :test do
gem 'refinerycms-testing', '~> 2.1.0'
gem 'capybara-email', '~> 2.1.2'
+ gem 'poltergeist'
+ gem 'pry'
+ gem 'pry-nav'
end
# Database Configuration
@@ -2,32 +2,34 @@ module Refinery
module Inquiries
class InquiriesController < ::ApplicationController
- before_filter :find_page, :only => [:create, :new]
+ before_filter :find_page, only: [:create, :new]
+ before_filter :find_thank_you_page, only: :thank_you
def thank_you
- @page = ::Refinery::Page.find_by_link_url("/contact/thank_you")
end
def new
- @inquiry = ::Refinery::Inquiries::Inquiry.new
+ @inquiry = Inquiry.new
end
def create
- @inquiry = ::Refinery::Inquiries::Inquiry.new(params[:inquiry])
+ @inquiry = Inquiry.new(params[:inquiry])
if @inquiry.save
- if @inquiry.ham? || Refinery::Inquiries.send_notifications_for_inquiries_marked_as_spam
+ if @inquiry.ham? || Inquiries.send_notifications_for_inquiries_marked_as_spam
begin
- ::Refinery::Inquiries::InquiryMailer.notification(@inquiry, request).deliver
+ InquiryMailer.notification(@inquiry, request).deliver
rescue
logger.warn "There was an error delivering an inquiry notification.\n#{$!}\n"
end
- begin
- ::Refinery::Inquiries::InquiryMailer.confirmation(@inquiry, request).deliver
- rescue
- logger.warn "There was an error delivering an inquiry confirmation:\n#{$!}\n"
- end if ::Refinery::Inquiries::Setting.send_confirmation?
+ if Setting.send_confirmation?
+ begin
+ InquiryMailer.confirmation(@inquiry, request).deliver
+ rescue
+ logger.warn "There was an error delivering an inquiry confirmation:\n#{$!}\n"
+ end
+ end
end
redirect_to refinery.thank_you_inquiries_inquiries_path
@@ -39,7 +41,11 @@ def create
protected
def find_page
- @page = ::Refinery::Page.find_by_link_url("/contact")
+ @page = Page.where(link_url: '/contact').first
+ end
+
+ def find_thank_you_page
+ @page = Page.where(link_url: '/contact/thank_you').first
end
end
@@ -5,17 +5,19 @@ module Refinery
module Inquiries
class Inquiry < Refinery::Core::BaseModel
- filters_spam :message_field => :message,
- :email_field => :email,
- :author_field => :name,
- :other_fields => [:phone],
- :extra_spam_words => %w()
+ filters_spam message_field: :message,
+ email_field: :email,
+ author_field: :name,
+ other_fields: [:phone],
+ extra_spam_words: %w()
- validates :name, :presence => true
- validates :email, :format=> { :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i }
- validates :message, :presence => true
+ validates :name, presence: true
+ validates :email, format: {
+ with: /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i
+ }
+ validates :message, presence: true
- default_scope :order => 'created_at DESC'
+ default_scope { order('created_at DESC') }
attr_accessible :name, :phone, :message, :email
@@ -1,61 +1,56 @@
+require 'refinery/setting'
+
module Refinery
module Inquiries
- class Setting
+ class Setting < ::Refinery::Setting
class << self
def confirmation_body
- Refinery::Setting.find_or_set(:inquiry_confirmation_body,
+ find_or_set(:inquiry_confirmation_body,
"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."
)
end
def confirmation_subject(locale='en')
- Refinery::Setting.find_or_set("inquiry_confirmation_subject_#{locale}".to_sym,
- "Thank you for your inquiry",
- :scoping => "inquiries")
+ find_or_set(:"inquiry_confirmation_subject_#{locale}",
+ "Thank you for your inquiry",
+ scoping: "inquiries"
+ )
end
def confirmation_subject=(value)
value.first.keys.each do |locale|
- Refinery::Setting.set("inquiry_confirmation_subject_#{locale}".to_sym, {
- :value => value.first[locale.to_sym],
- :scoping => "inquiries"
- })
+ set(:"inquiry_confirmation_subject_#{locale}", {
+ value: value.first[locale.to_sym],
+ scoping: "inquiries"
+ })
end
end
def confirmation_message(locale='en')
- Refinery::Setting.find_or_set("inquiry_confirmation_message_#{locale}".to_sym,
- Refinery::Setting[:inquiry_confirmation_body],
- :scoping => "inquiries")
+ find_or_set(:"inquiry_confirmation_message_#{locale}", confirmation_body, scoping: "inquiries")
end
-
def confirmation_message=(value)
value.first.keys.each do |locale|
- Refinery::Setting.set("inquiry_confirmation_message_#{locale}".to_sym, {
- :value => value.first[locale.to_sym],
- :scoping => "inquiries"
- })
+ set(:"inquiry_confirmation_message_#{locale}", {
+ value: value.first[locale.to_sym],
+ scoping: "inquiries"
+ })
end
end
def notification_recipients
- Refinery::Setting.find_or_set(:inquiry_notification_recipients,
- ((Refinery::Role[:refinery].users.first.email rescue nil) if defined?(Refinery::Role)).to_s,
- :scoping => "inquiries")
+ recipients = ((Role[:refinery].users.first.email rescue nil) if defined?(Role)).to_s
+ find_or_set(:inquiry_notification_recipients, recipients, scoping: "inquiries")
end
def notification_subject
- Refinery::Setting.find_or_set(:inquiry_notification_subject,
- "New inquiry from your website",
- :scoping => "inquiries")
+ find_or_set(:inquiry_notification_subject, "New inquiry from your website", scoping: "inquiries")
end
-
+
def send_confirmation?
- Refinery::Setting.find_or_set(:inquiry_send_confirmation,
- true,
- :scoping => "inquiries")
+ find_or_set(:inquiry_send_confirmation, true, scoping: "inquiries")
end
end
end
View
@@ -55,6 +55,6 @@
end
end
-(Refinery::Inquiries::Setting.methods.sort - ActiveRecord::Base.methods).each do |setting|
- Refinery::Inquiries::Setting.send(setting) unless setting.to_s =~ /=$/
+(Refinery::Inquiries::Setting.methods.sort - Refinery::Setting.methods).each do |setting|
+ Refinery::Inquiries::Setting.send(setting) if setting.to_s !~ /=\z/
end
@@ -1,7 +1,7 @@
FactoryGirl.define do
- factory :inquiry, :class => Refinery::Inquiries::Inquiry do
+ factory :inquiry, class: Refinery::Inquiries::Inquiry do
name "Refinery"
- email "refinery@cms.com"
+ email "refinery@example.com"
message "Hello..."
end
end
@@ -7,19 +7,20 @@ module Inquiries
before do
FactoryGirl.create(:page, :link_url => "/contact")
- Refinery::Inquiries::Setting.stub(:notification_recipients).and_return("rspec@refinerycms.com")
+ Refinery::Inquiries::Setting.stub(:notification_recipients)
+ .and_return("rspec@refinerycms.com")
clear_emails
visit refinery.inquiries_new_inquiry_path
- fill_in "Name", :with => "Ugis Ozols"
- fill_in "Email", :with => "ugis.ozols@refinerycms.com"
- fill_in "Message", :with => "Hey, I'm testing!"
+ fill_in "Name", with: "Ugis Ozols"
+ fill_in "Email", with: "ugis.ozols@refinerycms.com"
+ fill_in "Message", with: "Hey, I'm testing!"
click_button "Send message"
end
- it "sends confirmation email" do
+ it "sends confirmation email", :focus do
open_email("ugis.ozols@refinerycms.com")
current_email.from.should eq("Ugis Ozols [#{Refinery::Core.site_name}] <#{Refinery::Inquiries.from_name}@example.com>")
@@ -5,10 +5,11 @@ module Inquiries
describe Inquiry do
describe "validations" do
subject do
- FactoryGirl.build(:inquiry,
- :name => "Ugis Ozols",
- :email => "ugis.ozols@refinerycms.com",
- :message => "Hey, I'm testing!")
+ FactoryGirl.build(:inquiry, {
+ name: "Ugis Ozols",
+ email: "ugis.ozols@refinerycms.com",
+ message: "Hey, I'm testing!"
+ })
end
it { should be_valid }
@@ -20,9 +21,9 @@ module Inquiries
describe "default scope" do
it "orders by created_at in desc" do
- inquiry1 = FactoryGirl.create(:inquiry, :created_at => 1.hour.ago)
- inquiry2 = FactoryGirl.create(:inquiry, :created_at => 2.hours.ago)
- inquiries = Refinery::Inquiries::Inquiry.all
+ inquiry1 = FactoryGirl.create(:inquiry, created_at: 1.hour.ago)
+ inquiry2 = FactoryGirl.create(:inquiry, created_at: 2.hours.ago)
+ inquiries = Inquiry.all
inquiries.first.should == inquiry1
inquiries.second.should == inquiry2
end
@@ -31,19 +32,19 @@ module Inquiries
describe ".latest" do
it "returns latest 7 non-spam inquiries by default" do
8.times { FactoryGirl.create(:inquiry) }
- Refinery::Inquiries::Inquiry.last.toggle!(:spam)
- Refinery::Inquiries::Inquiry.latest.length.should == 7
+ Inquiry.last.toggle!(:spam)
+ Inquiry.latest.length.should == 7
end
it "returns latest 7 inquiries including spam ones" do
7.times { FactoryGirl.create(:inquiry) }
- Refinery::Inquiries::Inquiry.all[0..2].each { |inquiry| inquiry.toggle!(:spam) }
- Refinery::Inquiries::Inquiry.latest(7, true).length.should == 7
+ Inquiry.all[0..2].each { |inquiry| inquiry.toggle!(:spam) }
+ Inquiry.latest(7, true).length.should == 7
end
it "returns latest n inquiries" do
4.times { FactoryGirl.create(:inquiry) }
- Refinery::Inquiries::Inquiry.latest(3).length.should == 3
+ Inquiry.latest(3).length.should == 3
end
end
end
View
@@ -8,6 +8,8 @@
require 'rspec/rails'
require 'capybara/rspec'
require 'factory_girl_rails'
+require 'capybara/poltergeist'
+Capybara.javascript_driver = :poltergeist
Rails.backtrace_cleaner.remove_silencers!

0 comments on commit b630148

Please sign in to comment.