Skip to content

Commit

Permalink
Refactor admin settings controller and re-enable commented request sp…
Browse files Browse the repository at this point in the history
…ecs. Should fix refinery#69.
  • Loading branch information
ugisozols authored and parndt committed Mar 23, 2012
1 parent b985334 commit 573627d
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 59 deletions.
60 changes: 25 additions & 35 deletions app/controllers/refinery/inquiries/admin/settings_controller.rb
@@ -1,53 +1,43 @@
module Refinery
module Inquiries
module Admin
class SettingsController < ::Refinery::AdminController
class SettingsController < Refinery::AdminController

crudify :'refinery/setting',
:title_attribute => "name",
:order => 'name ASC',
:redirect_to_url => 'refinery.inquiries_admin_inquiries_path'
before_filter :check_setting, :only => [:edit, :update]
after_filter :save_subject_for_confirmation, :save_message_for_confirmation, :only => :update

before_filter :set_url_override?, :only => [:edit, :update]
after_filter :save_subject_for_confirmation?, :only => :update
after_filter :save_message_for_confirmation?, :only => :update
around_filter :rewrite_flash?, :only => :update
def edit
@setting = Refinery::Setting.find(params[:id])
end

protected
def update
@setting = Refinery::Setting.find(params[:id])

def rewrite_flash?
yield
if @setting.update_attributes(params[:setting])
flash[:notice] = t('refinery.crudify.updated', :what => @setting.name.gsub("inquiry_", "").titleize)

flash[:notice] = flash[:notice].to_s.gsub(/(\'.*\')/) {|m| m.titleize}.gsub('Inquiry ', '')
unless request.xhr? or from_dialog?
redirect_back_or_default(refinery.inquiries_admin_inquiries_path)
else
render :text => "<script type='text/javascript'>parent.window.location = '#{refinery.inquiries_admin_inquiries_path}';</script>"
end
end
end

def save_subject_for_confirmation?
Refinery::Inquiries::Setting.confirmation_subject = params[:subject] if params.keys.include?('subject')
end
protected

def save_message_for_confirmation?
Refinery::Inquiries::Setting.confirmation_message = params[:message] if params.keys.include?('message')
end
def check_setting
setting = params[:id].gsub("inquiry_", "")

def set_url_override?
@url_override = refinery.inquiries_admin_setting_path(@setting, :dialog => from_dialog?)
Refinery::Inquiries::Setting.send(setting) if Refinery::Inquiries::Setting.respond_to?(setting)
end

def find_setting
# ensure that we're dealing with the name of the setting, not the id.
begin
if params[:id].to_i.to_s == params[:id]
params[:id] = Refinery::Setting.find(params[:id]).name.to_s
end
rescue
end

# prime the setting first, if it's valid.
if Refinery::Inquiries::Setting.methods.map(&:to_sym).include?(params[:id].to_s.gsub('inquiry_', '').to_sym)
Refinery::Inquiries::Setting.send(params[:id].to_s.gsub('inquiry_', '').to_sym)
end
def save_subject_for_confirmation
Refinery::Inquiries::Setting.confirmation_subject = params[:subject] if params.keys.include?('subject')
end

@setting = Refinery::Setting.find_by_name(params[:id])
def save_message_for_confirmation
Refinery::Inquiries::Setting.confirmation_message = params[:message] if params.keys.include?('message')
end

end
Expand Down
@@ -1,4 +1,4 @@
<%= form_for @setting, :url => (@url_override || @url) do |f| %>
<%= form_for @setting, :url => refinery.inquiries_admin_setting_path(@setting) do |f| %>

<p>
<%= t('.explanation') %>
Expand Down
@@ -1,4 +1,4 @@
<%= form_for @setting, :url => (@url_override || @url) do |f| %>
<%= form_for @setting, :url => refinery.inquiries_admin_setting_path(@setting) do |f| %>

<div class='field'>
<span class='label_with_help'>
Expand Down
54 changes: 32 additions & 22 deletions spec/requests/refinery/inquiries/admin/inquiries_spec.rb
Expand Up @@ -101,37 +101,47 @@ module Admin
end
end

=begin
describe "update who gets notified" do
it "sets receiver", :js => true do
visit refinery.inquiries_admin_inquiries_path
describe "update who gets notified" do
before do
Rails.cache.clear
Refinery::Inquiries::Setting.notification_recipients
end

it "sets receiver", :js => true do
visit refinery.inquiries_admin_inquiries_path

click_link "Update who gets notified"
click_link "Update who gets notified"

within_frame "dialog_iframe" do
fill_in "Send notifications to", :with => "phil@refinerycms.com"
click_button "Save"
end
within_frame "dialog_iframe" do
fill_in "setting_value", :with => "phil@refinerycms.com"
click_button "submit_button"
end

page.should have_content("'Notification Recipients' was successfully updated.")
page.should have_content("Notification Recipients was successfully updated.")
end
end
end

describe "updating confirmation email copy" do
it "sets message", :js => true do
visit refinery.inquiries_admin_inquiries_path
describe "updating confirmation email copy" do
before do
Rails.cache.clear
Refinery::Inquiries::Setting.confirmation_body
end

click_link "Edit confirmation email"
it "sets message", :js => true do
visit refinery.inquiries_admin_inquiries_path

within_frame "dialog_iframe" do
fill_in "Message", :with => "Thanks %name%! We'll never get back to you!"
click_button "Save"
end
click_link "Edit confirmation email"

within_frame "dialog_iframe" do
fill_in "subject__en", :with => "subject"
fill_in "message__en", :with => "message"
click_button "Save"
end

page.should have_content("'Confirmation Body' was successfully updated.")
page.should have_content("Confirmation Body was successfully updated.")
end
end
end
=end

end
end
end
Expand Down

0 comments on commit 573627d

Please sign in to comment.